Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: use sys session to build view for info_schema.columns retrieval (#33946) #34251

Merged
merged 3 commits into from
Feb 27, 2023

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Apr 26, 2022

cherry-pick #33946 to release-5.2
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr https://github.com/pingcap/tidb/pull/34251

After apply modifications, you can push your change to this PR via:

git push git@github.com:ti-srebot/tidb.git pr/34251:release-5.2-f16f0e844de4

What problem does this PR solve?

Issue Number: close #32459

Problem Summary:

From the panic cases related to information_schema.columns we encountered recently, the stack is like:

goroutine 656 [running]:
runtime.throw({0x103052e20, 0x15})
        /opt/homebrew/Cellar/go/1.17.5/libexec/src/runtime/panic.go:1198 +0x54 fp=0x14015deee20 sp=0x14015deedf0 pc=0x1008ced04
runtime.mapassign_fast64ptr(0x1036021e0, 0x14015c478c0, 0x140107b0900)
        /opt/homebrew/Cellar/go/1.17.5/libexec/src/runtime/map_fast64.go:266 +0x3c8 fp=0x14015deee80 sp=0x14015deee20 pc=0x1008a6bd8
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildDataSource(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, 0x14015d56410, 0x14015df4050)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:4315 +0x30b0 fp=0x14015defed0 sp=0x14015deee80 pc=0x10228ec10
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildResultSetNode(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, {0x103ad2ea8, 0x14015df4000})
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:348 +0x2dc fp=0x14015df0410 sp=0x14015defed0 pc=0x10225d3ac
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildJoin(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, 0x14010b60ab0)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:669 +0xe28 fp=0x14015df0c20 sp=0x14015df0410 pc=0x102262848
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildResultSetNode(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, {0x103ad22f8, 0x14010b60ab0})
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:335 +0x7b0 fp=0x14015df1160 sp=0x14015df0c20 pc=0x10225d880
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildTableRefs(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, 0x14015d78780)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:329 +0xb4 fp=0x14015df1270 sp=0x14015df1160 pc=0x10225cf54
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildSelect(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, 0x14015d4db00)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:3624 +0x760 fp=0x14015df1de0 sp=0x14015df1270 pc=0x102287440
github.com/pingcap/tidb/planner/core.(*PlanBuilder).Build(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, {0x103acacc0, 0x14015d4db00})
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/planbuilder.go:700 +0xa3c fp=0x14015df22e0 sp=0x14015df1de0 pc=0x1022f332c
github.com/pingcap/tidb/planner/core.(*PlanBuilder).BuildDataSourceFromView(0x14013e55d40, {0x103aaf4d0, 0x14013d17f20}, {{0x1401077ede0, 0x4}, {0x1401077ede4, 0x4}}, 0x140107b0a80)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/planner/core/logical_plan_builder.go:4597 +0x3f0 fp=0x14015df2770 sp=0x14015df22e0 pc=0x102293ce0
github.com/pingcap/tidb/executor.tryFillViewColumnType({0x103aaf4d0, 0x14013d17f20}, {0x103b212b0, 0x14010b7b680}, {0x103aeccc8, 0x14000331110}, {{0x1401077ede0, 0x4}, {0x1401077ede4, 0x4}}, ...)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/show.go:1901 +0x134 fp=0x14015df28c0 sp=0x14015df2770 pc=0x102c65d14
github.com/pingcap/tidb/executor.(*hugeMemTableRetriever).dataForColumnsInTable(0x14015d5dd50, {0x103aaf4d0, 0x14013d17f20}, {0x103b212b0, 0x14010b7b680}, 0x14000330700, 0x140107b0a80, 0x201c, 0x14013e21810)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/infoschema_reader.go:680 +0xf8 fp=0x14015df3100 sp=0x14015df28c0 pc=0x102ba2368
github.com/pingcap/tidb/executor.(*hugeMemTableRetriever).setDataForColumns(0x14015d5dd50, {0x103aaf4d0, 0x14013d17f20}, {0x103b212b0, 0x14010b7b680}, 0x14013e21810)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/infoschema_reader.go:669 +0x21c fp=0x14015df3230 sp=0x14015df3100 pc=0x102ba20cc
github.com/pingcap/tidb/executor.(*hugeMemTableRetriever).retrieve(0x14015d5dd50, {0x103aaf4d0, 0x14013d17f20}, {0x103b212b0, 0x14010b7b680})
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/infoschema_reader.go:2614 +0x300 fp=0x14015df3370 sp=0x14015df3230 pc=0x102bbaf00
github.com/pingcap/tidb/executor.(*MemTableReaderExec).Next(0x14010bcfdd0, {0x103aaf4d0, 0x14013d17f20}, 0x14015d3d950)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/memtable_reader.go:118 +0x390 fp=0x14015df3570 sp=0x14015df3370 pc=0x102c0bd30
github.com/pingcap/tidb/executor.Next({0x103aaf4d0, 0x14013d17f20}, {0x103ab6758, 0x14010bcfdd0}, 0x14015d3d950)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/executor.go:302 +0x61c fp=0x14015df3830 sp=0x14015df3570 pc=0x102b60efc
github.com/pingcap/tidb/executor.(*SelectionExec).Next(0x14015d560d0, {0x103aaf4d0, 0x14013d17f20}, 0x14015d78730)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/executor.go:1394 +0x2bc fp=0x14015df39f0 sp=0x14015df3830 pc=0x102b6874c
github.com/pingcap/tidb/executor.Next({0x103aaf4d0, 0x14013d17f20}, {0x103ab6bd8, 0x14015d560d0}, 0x14015d78730)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/executor.go:302 +0x61c fp=0x14015df3cb0 sp=0x14015df39f0 pc=0x102b60efc
github.com/pingcap/tidb/executor.(*HashJoinExec).fetchBuildSideRows(0x14015d3ab40, {0x103aaf4d0, 0x14013d17f20}, 0x140111bf4a0, 0x14000a7d6e0)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/join.go:282 +0x23c fp=0x14015df3e90 sp=0x14015df3cb0 pc=0x102beb1bc
github.com/pingcap/tidb/executor.(*HashJoinExec).fetchAndBuildHashTable.func2()
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/join.go:731 +0xd4 fp=0x14015df3f50 sp=0x14015df3e90 pc=0x102bf00c4
github.com/pingcap/tidb/util.WithRecovery(0x14015d7f500, 0x14015ca3e10)
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/util/misc.go:100 +0x5c fp=0x14015df3fc0 sp=0x14015df3f50 pc=0x101944b2c
runtime.goexit()
        /opt/homebrew/Cellar/go/1.17.5/libexec/src/runtime/asm_arm64.s:1133 +0x4 fp=0x14015df3fc0 sp=0x14015df3fc0 pc=0x1009071d4
created by github.com/pingcap/tidb/executor.(*HashJoinExec).fetchAndBuildHashTable
        /Users/tangenta/gopath/src/github.com/pingcap/tidb/executor/join.go:728 +0x280

All of these stacks have the common function: tryFillViewColumnType and fetchBuildSideRows.

  • tryFillViewColumnType is used to extract the field type of a view in information_schema.columns.
  • fetchBuildSideRows is used by HashJoinExec to get the build side of the result. It is run concurrently with fetchProbeSideChunks to speed up the query.

As explained in #32618, the root cause is: the goroutines created by HashJoinExec concurrently accessed a field in the same session.

What is changed and how it works?

This PR uses a system session to tryFillViewColumnType, preventing the same session is accessed concurrently.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix an issue that panic when joining `information_schema.columns` tables.

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 26, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • hawkingrei
  • wshwsh12

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 26, 2022
@ti-srebot ti-srebot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/5.2-cherry-pick labels Apr 26, 2022
@ti-srebot ti-srebot added this to the v5.2.4 milestone Apr 26, 2022
@ti-srebot
Copy link
Contributor Author

@tangenta you're already a collaborator in bot's repo.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 27, 2022
@VelocityLight
Copy link

This pull request is closed because it's related version has closed automatic cherry-picking.
If it's still needed, you can reopen it or just regenerate it using bot,
see:

You can find more details at:

@VelocityLight VelocityLight added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Sep 16, 2022
@VelocityLight VelocityLight added do-not-merge/cherry-pick-not-approved and removed cherry-pick-approved Cherry pick PR approved by release team. labels Nov 2, 2022
@tangenta tangenta reopened this Feb 20, 2023
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2023
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2023
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 20, 2023
@hawkingrei
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: b0300c2

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 20, 2023
@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Feb 20, 2023
@tangenta
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: c42cf52

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 20, 2023
@VelocityLight VelocityLight added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Feb 27, 2023
@ti-chi-bot ti-chi-bot merged commit 3e5bbbe into pingcap:release-5.2 Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/5.2-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants