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

Merged
merged 10 commits into from
Apr 26, 2022

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Apr 13, 2022

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.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 13, 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-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-6.0 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 13, 2022
@tangenta tangenta changed the title executor: use sys session to build a view for info_schema.columns retrieval executor: use sys session to build view for info_schema.columns retrieval Apr 13, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Apr 13, 2022

@tangenta tangenta requested a review from wshwsh12 April 13, 2022 15:24
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 13, 2022
@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 Apr 14, 2022
@tangenta
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 99dfe90

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 14, 2022
@Defined2014
Copy link
Contributor

/run-mysql-test

1 similar comment
@Defined2014
Copy link
Contributor

/run-mysql-test

@tangenta
Copy link
Contributor Author

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 14, 2022
@tangenta
Copy link
Contributor Author

Waiting for #33991.

@tangenta
Copy link
Contributor Author

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 19, 2022
@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 26, 2022
@tangenta
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 99ab519

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 26, 2022
@ti-chi-bot ti-chi-bot merged commit f16f0e8 into pingcap:master Apr 26, 2022
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Apr 26, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.2 in PR #34251

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Apr 26, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.3 in PR #34252

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Apr 26, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.4 in PR #34253

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Apr 26, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-6.0 in PR #34254

@sre-bot
Copy link
Contributor

sre-bot commented Apr 26, 2022

TiDB MergeCI notify

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-common-test 🟢 all 11 tests passed 16 min Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 10 min Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 9 min 9 sec Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 8 min 56 sec Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 8 min 46 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 8 min 37 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 7 min 58 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 7 min 11 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Joining views of information_schema.columns panic
8 participants