executor: new execution path for point execution within prepared plan cache#11970
executor: new execution path for point execution within prepared plan cache#11970sre-bot merged 43 commits intopingcap:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11970 +/- ##
===========================================
Coverage 81.3664% 81.3664%
===========================================
Files 454 454
Lines 99777 99777
===========================================
Hits 81185 81185
Misses 12840 12840
Partials 5752 5752 |
|
PTAL @dbjoa |
|
/bench |
@@ Benchmark Diff @@
================================================================================
--- tidb: 2aa3e27a6d535046efe789513d2fb60b474c5900
+++ tidb: 7f9aa0efe4fb91718006d4a53640bb9f4ca202e4
tikv: af70f367a38aad3305e32d8de17f60e09ea87fc3
pd: a1f8d9db4ac3e713c3259ca0979312fe3b61adac
================================================================================
test-1: < oltp_insert >
* QPS : 21549.68 ± 0.1964% (std=31.40) delta: -0.48%
* AvgMs : 11.87 ± 0.1965% (std=0.02) delta: 0.47%
* PercentileMs99 : 42.61 ± 0.0000% (std=0.00) delta: 0.00%
test-2: < oltp_update_non_index >
* QPS : 29577.49 ± 0.3464% (std=68.69) delta: 0.05%
* AvgMs : 8.65 ± 0.3699% (std=0.02) delta: -0.07%
* PercentileMs99 : 30.59 ± 1.0788% (std=0.27) delta: 0.36%
test-3: < oltp_read_write >
* QPS : 33062.96 ± 0.1520% (std=30.74) delta: 0.09%
* AvgMs : 155.55 ± 0.1414% (std=0.13) delta: -0.10%
* PercentileMs99 : 287.38 ± 0.0000% (std=0.00) delta: 0.00%
test-4: < oltp_point_select >
* QPS : 75946.31 ± 0.6928% (std=333.75) delta: 0.47%
* AvgMs : 3.37 ± 0.5935% (std=0.01) delta: -0.53%
* PercentileMs99 : 7.40 ± 2.1070% (std=0.10) delta: 0.35%
test-5: < oltp_update_index >
* QPS : 17111.05 ± 0.3533% (std=35.73) delta: -0.01%
* AvgMs : 14.96 ± 0.3209% (std=0.03) delta: 0.00%
* PercentileMs99 : 48.34 ± 0.0000% (std=0.00) delta: 0.73%
|
|
@zhouqiang-cl, is the plan cache enabled on our bench? |
Not enable yet, use the default value now. If we enable plan cache, what's the effect of sysbench benchmark? |
|
/bench again after enable plan cache |
@@ Benchmark Diff @@
================================================================================
--- tidb: b239f2f04d3aa19a732356b16e12796806f5f2d4
+++ tidb: 7f9aa0efe4fb91718006d4a53640bb9f4ca202e4
tikv: af70f367a38aad3305e32d8de17f60e09ea87fc3
pd: a1f8d9db4ac3e713c3259ca0979312fe3b61adac
================================================================================
test-1: < oltp_insert >
* QPS : 21633.61 ± 0.1336% (std=25.91) delta: 0.79%
* AvgMs : 11.83 ± 0.1268% (std=0.01) delta: -0.80%
* PercentileMs99 : 42.61 ± 0.0000% (std=0.00) delta: 0.00%
test-2: < oltp_update_non_index >
* QPS : 30287.80 ± 0.4567% (std=85.50) delta: 0.19%
* AvgMs : 8.45 ± 0.4498% (std=0.02) delta: -0.24%
* PercentileMs99 : 30.26 ± 0.0000% (std=0.00) delta: -0.72%
test-3: < oltp_read_write >
* QPS : 34709.85 ± 0.2059% (std=47.14) delta: 0.42%
* AvgMs : 148.18 ± 0.2038% (std=0.20) delta: -0.42%
* PercentileMs99 : 292.60 ± 0.0000% (std=0.00) delta: 0.00%
test-4: < oltp_point_select >
* QPS : 83757.10 ± 1.6038% (std=1052.79) delta: 10.30%
* AvgMs : 3.06 ± 1.5052% (std=0.04) delta: -9.05%
* PercentileMs99 : 5.88 ± 1.8707% (std=0.10) delta: -19.45%
test-5: < oltp_update_index >
* QPS : 17532.85 ± 0.1740% (std=27.29) delta: 0.10%
* AvgMs : 14.58 ± 0.4801% (std=0.04) delta: -0.23%
* PercentileMs99 : 46.63 ± 0.0000% (std=0.00) delta: -0.36%
|
|
from the benchmark result, it can improve 10% of the QPS on the |
|
Yes, it is true, @zz-jason . |
planner/core/common_plans.go
Outdated
| var cacheKey kvcache.Key | ||
| sessionVars := sctx.GetSessionVars() | ||
| sessionVars.StmtCtx.UseCache = prepared.UseCache | ||
| cacheKey := NewPSTMTPlanCacheKey(sctx.GetSessionVars(), e.ExecID, prepared.SchemaVersion) |
|
can tryUpdatePointPlan and tryDeletePointPlan take benefit from this~? @cfzjywxk |
|
maybe we should cache point-get plan for prepare even if plan cache is disabled @cfzjywxk ? |
I'm considering how should we do this.
|
I think it is OK for me. |
… prepared cache enabled or not
| } | ||
| sctx.GetSessionVars().StmtCtx.Priority = kv.PriorityHigh | ||
| b := newExecutorBuilder(sctx, is) | ||
| exec := b.build(a.Plan) |
There was a problem hiding this comment.
How about calling a.buildExecutor() to build the operator tree from the execution plan?
There was a problem hiding this comment.
here just keep necessary steps to make it clear for the short path
| // OptimizeExecStmt to optimize prepare statement protocol "execute" statement | ||
| // this is a short path ONLY does things filling prepare related params | ||
| // for point select like plan which does not need extra things | ||
| func OptimizeExecStmt(ctx context.Context, sctx sessionctx.Context, |
There was a problem hiding this comment.
I think we should check the privilege of the current user, just like what Optimize() function did. Can we call it directly?
There was a problem hiding this comment.
issue https://github.com/pingcap/qa/issues/66 has some explanations on this
|
/build |
|
/run-all-tests |
|
@cfzjywxk merge failed. |
planner/core/common_plans.go
Outdated
| if prepared.CachedPlan != nil { | ||
| // expression rewrite will transfer paramMarker in select.where into Constant Expression | ||
| // but point get execution dose not need to evaluate where condition, | ||
| // so prepared.UseCache here false is ok, only for point plan |
planner/core/common_plans.go
Outdated
| func (e *Execute) getPhysicalPlan(ctx context.Context, sctx sessionctx.Context, is infoschema.InfoSchema, prepared *ast.Prepared) error { | ||
| if prepared.CachedPlan != nil { | ||
| // expression rewrite will transfer paramMarker in select.where into Constant Expression | ||
| // but point get execution dose not need to evaluate where condition, |
There was a problem hiding this comment.
| // but point get execution dose not need to evaluate where condition, | |
| // When Point Select queries are executed, | |
| // the expression in the where condition will not be evaluated, |
planner/core/common_plans.go
Outdated
| if prepared.CachedPlan != nil { | ||
| // expression rewrite will transfer paramMarker in select.where into Constant Expression | ||
| // but point get execution dose not need to evaluate where condition, | ||
| // so prepared.UseCache here false is ok, only for point plan |
There was a problem hiding this comment.
| // so prepared.UseCache here false is ok, only for point plan | |
| // so you don't need to consider whether prepared.useCache is enabled. |
|
/merge |
|
/run-all-tests |
What problem does this PR solve?
move plan cache try fetching at start for prepare statement, used for optimizations based on this, like point select or maybe other code paths.(this will be done for non prepared statement with a more universal plan cache in the future)
for prepare plan cache execution path, make a short path for
point selectskipping unnecessary things like ast traverse, tso fetch etc.simplify optimization process of
execution statementwhen plan cache hitmake point get plan cache logic seperated with Prepare statement plan cache utils, point get plan will be cached and executed not affected by the
prepared-plan-cacheswitch, the parser related pull request executor: cache point get plan for prepared point parser#541sysbench with 1million rows 16 tables oltp_point_select, single tidb server instance
prepare plan cache enabled
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes
Release note