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: set the txn provider before building plan in 'show columns' #36540

Closed
wants to merge 2 commits into from

Conversation

tangenta
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #36426.

Problem Summary:

The problem is from txnManager's "context provider not set". Here is the stack trace:

session.(*txnManager).GetStmtReadTS (txnmanager.go:72) github.com/pingcap/tidb/session
executor.(*executorBuilder).getSnapshotTS (builder.go:1594) github.com/pingcap/tidb/executor
executor.buildNoRangeTableReader (builder.go:3168) github.com/pingcap/tidb/executor
executor.(*executorBuilder).buildTableReader (builder.go:3263) github.com/pingcap/tidb/executor
executor.(*executorBuilder).build (builder.go:277) github.com/pingcap/tidb/executor
executor.(*executorBuilder).buildTopN (builder.go:1917) github.com/pingcap/tidb/executor
executor.(*executorBuilder).build (builder.go:241) github.com/pingcap/tidb/executor
executor.(*executorBuilder).buildStreamAgg (builder.go:1499) github.com/pingcap/tidb/executor
executor.(*executorBuilder).build (builder.go:263) github.com/pingcap/tidb/executor
executor.(*executorBuilder).buildMaxOneRow (builder.go:2025) github.com/pingcap/tidb/executor
executor.(*executorBuilder).build (builder.go:273) github.com/pingcap/tidb/executor
executor.init.1.func1 (executor.go:1427) github.com/pingcap/tidb/executor
core.(*expressionRewriter).handleScalarSubquery (expression_rewriter.go:1030) github.com/pingcap/tidb/planner/core
core.(*expressionRewriter).Enter (expression_rewriter.go:409) github.com/pingcap/tidb/planner/core
ast.(*SubqueryExpr).Accept (expressions.go:391) github.com/pingcap/tidb/parser/ast
ast.(*BinaryOperationExpr).Accept (expressions.go:217) github.com/pingcap/tidb/parser/ast
core.(*PlanBuilder).rewriteExprNode (expression_rewriter.go:199) github.com/pingcap/tidb/planner/core
core.(*PlanBuilder).rewriteWithPreprocess (expression_rewriter.go:145) github.com/pingcap/tidb/planner/core
core.(*PlanBuilder).rewrite (expression_rewriter.go:113) github.com/pingcap/tidb/planner/core
core.(*PlanBuilder).buildSelection (logical_plan_builder.go:1000) github.com/pingcap/tidb/planner/core
core.(*PlanBuilder).buildSelect (logical_plan_builder.go:3892) github.com/pingcap/tidb/planner/core
core.(*PlanBuilder).Build (planbuilder.go:718) github.com/pingcap/tidb/planner/core
core.(*PlanBuilder).BuildDataSourceFromView (logical_plan_builder.go:4837) github.com/pingcap/tidb/planner/core
executor.tryFillViewColumnType.func1 (show.go:2066) github.com/pingcap/tidb/executor
executor.runWithSystemSession (show.go:2092) github.com/pingcap/tidb/executor
executor.tryFillViewColumnType (show.go:2063) github.com/pingcap/tidb/executor
executor.(*ShowExec).fetchShowColumns (show.go:624) github.com/pingcap/tidb/executor
executor.(*ShowExec).fetchAll (show.go:149) github.com/pingcap/tidb/executor
executor.(*ShowExec).Next (show.go:116) github.com/pingcap/tidb/executor
executor.Next (executor.go:319) github.com/pingcap/tidb/executor
executor.(*ExecStmt).next (adapter.go:898) github.com/pingcap/tidb/executor
executor.(*recordSet).Next (adapter.go:152) github.com/pingcap/tidb/executor
<autogenerated>:2
server.(*tidbResultSet).Next (driver_tidb.go:405) github.com/pingcap/tidb/server
server.(*clientConn).writeChunks (conn.go:2250) github.com/pingcap/tidb/server
server.(*clientConn).writeResultset (conn.go:2200) github.com/pingcap/tidb/server
server.(*clientConn).handleStmt (conn.go:2081) github.com/pingcap/tidb/server
server.(*clientConn).handleQuery (conn.go:1913) github.com/pingcap/tidb/server
server.(*clientConn).dispatch (conn.go:1397) github.com/pingcap/tidb/server
server.(*clientConn).Run (conn.go:1142) github.com/pingcap/tidb/server
server.(*Server).onConn (server.go:563) github.com/pingcap/tidb/server
server.(*Server).startNetworkListener.func2 (server.go:454) github.com/pingcap/tidb/server
runtime.goexit (asm_arm64.s:1259) runtime
 - Async Stack Trace
server.(*Server).startNetworkListener (server.go:454) github.com/pingcap/tidb/server

To get the accurate field types of a view, we need to build a plan for the SQL in the view(see tryFillViewColumnType). An internal session is used to build the plan to prevent concurrent access to the same sesssion(this can happen in join scenarios, see #32459).

The transaction context is not needed in normal cases. However, for the views that contain scalar subquery, an executor is built and run for the scalar subquery evaluation, which requires a startTS from the transaction. Because no transaction is set before using the system session, the error "context provider not set" occurs.

What is changed and how it works?

We can solve the issue by setting up a new transaction before using the internal session.

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.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jul 25, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • hawkingrei
  • xhebox

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-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-6.2 and removed do-not-merge/needs-triage-completed labels Jul 25, 2022
@hawkingrei hawkingrei self-requested a review July 25, 2022 13:37
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 25, 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 Jul 26, 2022
@xhebox
Copy link
Contributor

xhebox commented Jul 26, 2022

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 5303ab7

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

sre-bot commented Jul 26, 2022

@xiongjiwei
Copy link
Contributor

/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 Jul 26, 2022
@tangenta
Copy link
Contributor Author

The issue will be closed by #36613.

@tangenta tangenta closed this Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 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.

show columns from view error
6 participants