-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
planner: unify the Compile and CompileExecStmt functions #37065
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
db49c25
planner: unify the Compile and CompileExecStmt functions
Reminiscent 9f89e0b
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent 4201813
fix ut
Reminiscent 776e914
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent 84b9879
Merge branch 'master' into refactor-PC-compile
Reminiscent 8d30c20
fix ut
Reminiscent ab5c1c7
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent 27e68fc
Merge remote-tracking branch 'origin/refactor-PC-compile' into refact…
Reminiscent 7f1f5a2
add the short path for PointGet to compiler
Reminiscent 8ea4f0a
git pull upstream master
Reminiscent 2def5dc
fix ut
Reminiscent 7afc42f
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent 6ebd83a
revert
Reminiscent 5113185
Merge branch 'master' into refactor-PC-compile
qw4990 369ab78
fix ut
Reminiscent 647e903
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent 09b8056
Merge remote-tracking branch 'origin/refactor-PC-compile' into refact…
Reminiscent 762f07e
Merge the PointGet short path to general execute path
Reminiscent 276878c
Merge branch 'master' into refactor-PC-compile
Reminiscent 9837405
Revert "Merge the PointGet short path to general execute path"
Reminiscent 7517765
address comment
Reminiscent f60b21d
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent 82735e9
Merge remote-tracking branch 'origin/refactor-PC-compile' into refact…
Reminiscent 42c8e7e
Merge branch 'master' into refactor-PC-compile
qw4990 70167e2
address comment
Reminiscent 8adad8c
Merge branch 'master' of https://github.com/pingcap/tidb into refacto…
Reminiscent ce5c126
Merge remote-tracking branch 'origin/refactor-PC-compile' into refact…
Reminiscent aa06119
Merge branch 'master' into refactor-PC-compile
qw4990 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2015,7 +2015,15 @@ func (s *session) ExecuteStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlex | |
|
||
// Execute the physical plan. | ||
logStmt(stmt, s) | ||
recordSet, err := runStmt(ctx, s, stmt) | ||
|
||
var recordSet sqlexec.RecordSet | ||
if stmt.PsStmt != nil { // point plan short path | ||
recordSet, err = stmt.PointGet(ctx) | ||
s.txn.changeToInvalid() | ||
} else { | ||
recordSet, err = runStmt(ctx, s, stmt) | ||
} | ||
|
||
if err != nil { | ||
if !errIsNoisy(err) { | ||
logutil.Logger(ctx).Warn("run statement failed", | ||
|
@@ -2305,16 +2313,30 @@ func (s *session) preparedStmtExec(ctx context.Context, execStmt *ast.ExecuteStm | |
} | ||
}) | ||
|
||
is := sessiontxn.GetTxnManager(s).GetTxnInfoSchema() | ||
st, err := executor.CompileExecutePreparedStmt(ctx, s, execStmt, is) | ||
s.sessionVars.StartTime = time.Now() | ||
preparedObj, err := plannercore.GetPreparedStmt(execStmt, s.GetSessionVars()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
compiler := executor.Compiler{Ctx: s} | ||
stmt, err := compiler.Compile(ctx, execStmt) | ||
if err == nil { | ||
err = sessiontxn.OptimizeWithPlanAndThenWarmUp(s, st.Plan) | ||
err = sessiontxn.OptimizeWithPlanAndThenWarmUp(s, stmt.Plan) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
durCompile := time.Since(s.sessionVars.StartTime) | ||
s.GetSessionVars().DurationCompile = durCompile | ||
|
||
stmtCtx := s.GetSessionVars().StmtCtx | ||
stmt.Text = preparedObj.PreparedAst.Stmt.Text() | ||
stmtCtx.OriginalSQL = stmt.Text | ||
stmtCtx.InitSQLDigest(preparedObj.NormalizedSQL, preparedObj.SQLDigest) | ||
Comment on lines
+2330
to
+2336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is copied from the deleted function |
||
|
||
if !s.isInternal() && config.GetGlobalConfig().EnableTelemetry { | ||
tiFlashPushDown, tiFlashExchangePushDown := plannercore.IsTiFlashContained(st.Plan) | ||
tiFlashPushDown, tiFlashExchangePushDown := plannercore.IsTiFlashContained(stmt.Plan) | ||
telemetry.CurrentExecuteCount.Inc() | ||
if tiFlashPushDown { | ||
telemetry.CurrentTiFlashPushDownCount.Inc() | ||
|
@@ -2324,15 +2346,23 @@ func (s *session) preparedStmtExec(ctx context.Context, execStmt *ast.ExecuteStm | |
} | ||
} | ||
sessionExecuteCompileDurationGeneral.Observe(time.Since(s.sessionVars.StartTime).Seconds()) | ||
logGeneralQuery(st, s, true) | ||
logGeneralQuery(stmt, s, true) | ||
|
||
if st.PsStmt != nil { // point plan short path | ||
resultSet, err := st.PointGet(ctx) | ||
if stmt.PsStmt != nil { // point plan short path | ||
resultSet, err := stmt.PointGet(ctx) | ||
s.txn.changeToInvalid() | ||
return resultSet, err | ||
} | ||
|
||
return runStmt(ctx, s, st) | ||
var recordSet sqlexec.RecordSet | ||
|
||
if stmt.PsStmt != nil { // point plan short path | ||
recordSet, err = stmt.PointGet(ctx) | ||
s.txn.changeToInvalid() | ||
} else { | ||
recordSet, err = runStmt(ctx, s, stmt) | ||
} | ||
return recordSet, err | ||
} | ||
|
||
// ExecutePreparedStmt executes a prepared statement. | ||
|
@@ -2398,7 +2428,6 @@ func (s *session) executePlanCacheStmt(ctx context.Context, stmt *plannercore.Pl | |
} | ||
} | ||
|
||
executor.CountStmtNode(stmt.PreparedAst.Stmt, s.sessionVars.InRestrictedSQL) | ||
s.txn.onStmtStart(stmt.SQLDigest.String()) | ||
defer s.txn.onStmtEnd() | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is copied from the
ExecStmt.Exec
. We should set the process information here or we will failed to get the result forexplain for connection ...
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is short path. It only do the little things.(compare to
rumStmt
). We will refactor those part in the later PR.