From eb14afa2cf21eaf8ce2e3478098605cc2ec870d0 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Mon, 15 Nov 2021 16:09:57 +0800 Subject: [PATCH 01/11] fixup --- executor/compiler.go | 1 - planner/core/integration_test.go | 20 ++++++++++++ planner/optimize.go | 52 +++++++++++++++++--------------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/executor/compiler.go b/executor/compiler.go index 7a519dae6fae8..74a878b4d3293 100644 --- a/executor/compiler.go +++ b/executor/compiler.go @@ -61,7 +61,6 @@ func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (*ExecStm if err != nil { return nil, err } - stmtNode = plannercore.TryAddExtraLimit(c.Ctx, stmtNode) finalPlan, names, err := planner.Optimize(ctx, c.Ctx, stmtNode, ret.InfoSchema) if err != nil { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b895e2b81ab83..3b7490504241c 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4707,6 +4707,26 @@ func (s *testIntegrationSuite) TestIssue27797(c *C) { result.Check(testkit.Rows("")) } +func (s *testIntegrationSuite) TestIssue27949(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t27949") + tk.MustExec("create table t27949 (a int, b int, key(b))") + tk.MustQuery("explain select * from t27949 where b=1").Check(testkit.Rows("IndexLookUp_10 10.00 root ", + "├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:t27949, index:b(b) range:[1,1], keep order:false, stats:pseudo", + "└─TableRowIDScan_9(Probe) 10.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) + tk.MustExec("create global binding for select * from t27949 where b=1 using select * from t27949 ignore index(b) where b=1") + tk.MustQuery("explain select * from t27949 where b=1").Check(testkit.Rows("TableReader_7 10.00 root data:Selection_6", + "└─Selection_6 10.00 cop[tikv] eq(test.t27949.b, 1)", + " └─TableFullScan_5 10000.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) + tk.MustExec("set @@sql_select_limit=100") + tk.MustQuery("explain select * from t27949 where b=1").Check(testkit.Rows("Limit_8 10.00 root offset:0, count:100", + "└─TableReader_13 10.00 root data:Limit_12", + " └─Limit_12 10.00 cop[tikv] offset:0, count:100", + " └─Selection_11 10.00 cop[tikv] eq(test.t27949.b, 1)", + " └─TableFullScan_10 10000.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) +} + func (s *testIntegrationSuite) TestIssue28154(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/planner/optimize.go b/planner/optimize.go index 68c0a12d871f8..8dd63410a7c20 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -99,11 +99,34 @@ func GetExecuteForUpdateReadIS(node ast.Node, sctx sessionctx.Context) infoschem return nil } +func matchSQLBinding(node ast.Node, sctx sessionctx.Context) (bindRecord *bindinfo.BindRecord, scope string, matched bool) { + useBinding := sctx.GetSessionVars().UsePlanBaselines + stmtNode, ok := node.(ast.StmtNode) + if !ok { + useBinding = false + } + if !useBinding { + return nil, "", false + } + var err error + bindRecord, scope, err = getBindRecord(sctx, stmtNode) + if err != nil || bindRecord == nil || len(bindRecord.Bindings) == 0 { + return nil, "", false + } + return bindRecord, scope, true +} + // Optimize does optimization and creates a Plan. // The node must be prepared first. func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is infoschema.InfoSchema) (plannercore.Plan, types.NameSlice, error) { sessVars := sctx.GetSessionVars() + bindRecord, scope, useBinding := matchSQLBinding(node, sctx) + // add the extra Limit after matching the bind record + if stmtNode, ok := node.(ast.StmtNode); ok { + node = plannercore.TryAddExtraLimit(sctx, stmtNode) + } + // Because for write stmt, TiFlash has a different results when lock the data in point get plan. We ban the TiFlash // engine in not read only stmt. if _, isolationReadContainTiFlash := sessVars.IsolationReadEngines[kv.TiFlash]; isolationReadContainTiFlash && !IsReadOnly(node, sessVars) { @@ -144,30 +167,11 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in } sctx.PrepareTSFuture(ctx) - useBinding := sessVars.UsePlanBaselines - stmtNode, ok := node.(ast.StmtNode) - if !ok { - useBinding = false - } - var ( - bindRecord *bindinfo.BindRecord - scope string - err error - ) - if useBinding { - bindRecord, scope, err = getBindRecord(sctx, stmtNode) - if err != nil || bindRecord == nil || len(bindRecord.Bindings) == 0 { - useBinding = false - } - } - if useBinding && sessVars.SelectLimit != math.MaxUint64 { - sessVars.StmtCtx.AppendWarning(errors.New("sql_select_limit is set, ignore SQL bindings")) - useBinding = false - } - var names types.NameSlice var bestPlan, bestPlanFromBind plannercore.Plan + var err error if useBinding { + stmtNode := node.(ast.StmtNode) // must be StmtNode if useBinding is true minCost := math.MaxFloat64 var ( bindStmtHints stmtctx.StmtHints @@ -236,7 +240,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in }() if sessVars.EvolvePlanBaselines && bestPlanFromBind != nil { // Check bestPlanFromBind firstly to avoid nil stmtNode. - if _, ok := stmtNode.(*ast.SelectStmt); ok && !bindRecord.Bindings[0].Hint.ContainTableHint(plannercore.HintReadFromStorage) { + if _, ok := node.(*ast.SelectStmt); ok && !bindRecord.Bindings[0].Hint.ContainTableHint(plannercore.HintReadFromStorage) { sessVars.StmtCtx.StmtHints = originStmtHints defPlan, _, _, err := optimize(ctx, sctx, node, is) if err != nil { @@ -256,7 +260,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in defPlanHintsStr := hint.RestoreOptimizerHints(defPlanHints) binding := bindRecord.FindBinding(defPlanHintsStr) if binding == nil { - handleEvolveTasks(ctx, sctx, bindRecord, stmtNode, defPlanHintsStr) + handleEvolveTasks(ctx, sctx, bindRecord, node.(ast.StmtNode), defPlanHintsStr) } } } @@ -279,7 +283,7 @@ func allowInReadOnlyMode(sctx sessionctx.Context, node ast.Node) (bool, error) { switch node.(type) { // allow change variables (otherwise can't unset read-only mode) case *ast.SetStmt, - // allow analyze table + // allow analyze table *ast.AnalyzeTableStmt, *ast.UseStmt, *ast.ShowStmt, From 86d36e38c15bc9cd08d1ce6e722d8c3a747dc578 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Mon, 15 Nov 2021 17:13:35 +0800 Subject: [PATCH 02/11] fixup --- planner/optimize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/optimize.go b/planner/optimize.go index 8dd63410a7c20..f8200ac8ebdba 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -283,7 +283,7 @@ func allowInReadOnlyMode(sctx sessionctx.Context, node ast.Node) (bool, error) { switch node.(type) { // allow change variables (otherwise can't unset read-only mode) case *ast.SetStmt, - // allow analyze table + // allow analyze table *ast.AnalyzeTableStmt, *ast.UseStmt, *ast.ShowStmt, From ccbae05fb98bfa22fe5d042922c1f056aca9da4f Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 16:14:22 +0800 Subject: [PATCH 03/11] fixup --- planner/optimize.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/planner/optimize.go b/planner/optimize.go index f8200ac8ebdba..df7d8a98802e4 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -99,13 +99,9 @@ func GetExecuteForUpdateReadIS(node ast.Node, sctx sessionctx.Context) infoschem return nil } -func matchSQLBinding(node ast.Node, sctx sessionctx.Context) (bindRecord *bindinfo.BindRecord, scope string, matched bool) { +func matchSQLBinding(stmtNode ast.StmtNode, sctx sessionctx.Context) (bindRecord *bindinfo.BindRecord, scope string, matched bool) { useBinding := sctx.GetSessionVars().UsePlanBaselines - stmtNode, ok := node.(ast.StmtNode) - if !ok { - useBinding = false - } - if !useBinding { + if !useBinding || stmtNode == nil { return nil, "", false } var err error @@ -121,9 +117,13 @@ func matchSQLBinding(node ast.Node, sctx sessionctx.Context) (bindRecord *bindin func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is infoschema.InfoSchema) (plannercore.Plan, types.NameSlice, error) { sessVars := sctx.GetSessionVars() - bindRecord, scope, useBinding := matchSQLBinding(node, sctx) - // add the extra Limit after matching the bind record - if stmtNode, ok := node.(ast.StmtNode); ok { + var bindRecord *bindinfo.BindRecord + var scope string + var useBinding bool + stmtNode, isStmtNode := node.(ast.StmtNode) + if isStmtNode { + bindRecord, scope, useBinding = matchSQLBinding(stmtNode, sctx) + // add the extra Limit after matching the bind record node = plannercore.TryAddExtraLimit(sctx, stmtNode) } @@ -171,7 +171,6 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in var bestPlan, bestPlanFromBind plannercore.Plan var err error if useBinding { - stmtNode := node.(ast.StmtNode) // must be StmtNode if useBinding is true minCost := math.MaxFloat64 var ( bindStmtHints stmtctx.StmtHints @@ -283,7 +282,7 @@ func allowInReadOnlyMode(sctx sessionctx.Context, node ast.Node) (bool, error) { switch node.(type) { // allow change variables (otherwise can't unset read-only mode) case *ast.SetStmt, - // allow analyze table + // allow analyze table *ast.AnalyzeTableStmt, *ast.UseStmt, *ast.ShowStmt, From 851cf901d979b5ae443fb8a826d35af3717a12f4 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 16:24:54 +0800 Subject: [PATCH 04/11] fixup --- planner/optimize.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/planner/optimize.go b/planner/optimize.go index df7d8a98802e4..6b7702cccea6d 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -117,16 +117,6 @@ func matchSQLBinding(stmtNode ast.StmtNode, sctx sessionctx.Context) (bindRecord func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is infoschema.InfoSchema) (plannercore.Plan, types.NameSlice, error) { sessVars := sctx.GetSessionVars() - var bindRecord *bindinfo.BindRecord - var scope string - var useBinding bool - stmtNode, isStmtNode := node.(ast.StmtNode) - if isStmtNode { - bindRecord, scope, useBinding = matchSQLBinding(stmtNode, sctx) - // add the extra Limit after matching the bind record - node = plannercore.TryAddExtraLimit(sctx, stmtNode) - } - // Because for write stmt, TiFlash has a different results when lock the data in point get plan. We ban the TiFlash // engine in not read only stmt. if _, isolationReadContainTiFlash := sessVars.IsolationReadEngines[kv.TiFlash]; isolationReadContainTiFlash && !IsReadOnly(node, sessVars) { @@ -167,6 +157,16 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in } sctx.PrepareTSFuture(ctx) + var bindRecord *bindinfo.BindRecord + var scope string + var useBinding bool + stmtNode, isStmtNode := node.(ast.StmtNode) + if isStmtNode { + bindRecord, scope, useBinding = matchSQLBinding(stmtNode, sctx) + // add the extra Limit after matching the bind record + node = plannercore.TryAddExtraLimit(sctx, stmtNode) + } + var names types.NameSlice var bestPlan, bestPlanFromBind plannercore.Plan var err error From 78a524209af4cc1b48f1de60b7ee593d3f6553e1 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 16:29:21 +0800 Subject: [PATCH 05/11] fixup --- planner/optimize.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/planner/optimize.go b/planner/optimize.go index 6b7702cccea6d..c29663bf08e6e 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -157,19 +157,28 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in } sctx.PrepareTSFuture(ctx) - var bindRecord *bindinfo.BindRecord - var scope string - var useBinding bool - stmtNode, isStmtNode := node.(ast.StmtNode) - if isStmtNode { - bindRecord, scope, useBinding = matchSQLBinding(stmtNode, sctx) - // add the extra Limit after matching the bind record - node = plannercore.TryAddExtraLimit(sctx, stmtNode) + useBinding := sessVars.UsePlanBaselines + stmtNode, ok := node.(ast.StmtNode) + if !ok { + useBinding = false } + var ( + bindRecord *bindinfo.BindRecord + scope string + err error + ) + if useBinding { + bindRecord, scope, err = getBindRecord(sctx, stmtNode) + if err != nil || bindRecord == nil || len(bindRecord.Bindings) == 0 { + useBinding = false + } + } + // add the extra Limit after matching the bind record + stmtNode = plannercore.TryAddExtraLimit(sctx, stmtNode) + node = stmtNode var names types.NameSlice var bestPlan, bestPlanFromBind plannercore.Plan - var err error if useBinding { minCost := math.MaxFloat64 var ( @@ -239,7 +248,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in }() if sessVars.EvolvePlanBaselines && bestPlanFromBind != nil { // Check bestPlanFromBind firstly to avoid nil stmtNode. - if _, ok := node.(*ast.SelectStmt); ok && !bindRecord.Bindings[0].Hint.ContainTableHint(plannercore.HintReadFromStorage) { + if _, ok := stmtNode.(*ast.SelectStmt); ok && !bindRecord.Bindings[0].Hint.ContainTableHint(plannercore.HintReadFromStorage) { sessVars.StmtCtx.StmtHints = originStmtHints defPlan, _, _, err := optimize(ctx, sctx, node, is) if err != nil { @@ -259,7 +268,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in defPlanHintsStr := hint.RestoreOptimizerHints(defPlanHints) binding := bindRecord.FindBinding(defPlanHintsStr) if binding == nil { - handleEvolveTasks(ctx, sctx, bindRecord, node.(ast.StmtNode), defPlanHintsStr) + handleEvolveTasks(ctx, sctx, bindRecord, stmtNode, defPlanHintsStr) } } } From 1cc20a2c173e2b9054f2db05cf79b057c5dc4bb0 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 16:29:49 +0800 Subject: [PATCH 06/11] fixup --- planner/optimize.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/planner/optimize.go b/planner/optimize.go index c29663bf08e6e..800e322080061 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -99,19 +99,6 @@ func GetExecuteForUpdateReadIS(node ast.Node, sctx sessionctx.Context) infoschem return nil } -func matchSQLBinding(stmtNode ast.StmtNode, sctx sessionctx.Context) (bindRecord *bindinfo.BindRecord, scope string, matched bool) { - useBinding := sctx.GetSessionVars().UsePlanBaselines - if !useBinding || stmtNode == nil { - return nil, "", false - } - var err error - bindRecord, scope, err = getBindRecord(sctx, stmtNode) - if err != nil || bindRecord == nil || len(bindRecord.Bindings) == 0 { - return nil, "", false - } - return bindRecord, scope, true -} - // Optimize does optimization and creates a Plan. // The node must be prepared first. func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is infoschema.InfoSchema) (plannercore.Plan, types.NameSlice, error) { From 38581f64802a586e89fa313ddc26ab44c0ff1188 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 16:32:18 +0800 Subject: [PATCH 07/11] fixup --- planner/optimize.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/planner/optimize.go b/planner/optimize.go index 800e322080061..25af98300f8a1 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -160,9 +160,11 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in useBinding = false } } - // add the extra Limit after matching the bind record - stmtNode = plannercore.TryAddExtraLimit(sctx, stmtNode) - node = stmtNode + if ok { + // add the extra Limit after matching the bind record + stmtNode = plannercore.TryAddExtraLimit(sctx, stmtNode) + node = stmtNode + } var names types.NameSlice var bestPlan, bestPlanFromBind plannercore.Plan @@ -278,7 +280,7 @@ func allowInReadOnlyMode(sctx sessionctx.Context, node ast.Node) (bool, error) { switch node.(type) { // allow change variables (otherwise can't unset read-only mode) case *ast.SetStmt, - // allow analyze table + // allow analyze table *ast.AnalyzeTableStmt, *ast.UseStmt, *ast.ShowStmt, From 526c9e22785d05fb13578a19548cfc85a2300da2 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 16:47:44 +0800 Subject: [PATCH 08/11] fixup --- planner/core/integration_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 812f18aad9e83..8fb6c65858989 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4724,19 +4724,19 @@ func (s *testIntegrationSuite) TestIssue27949(c *C) { tk.MustExec("use test") tk.MustExec("drop table if exists t27949") tk.MustExec("create table t27949 (a int, b int, key(b))") - tk.MustQuery("explain select * from t27949 where b=1").Check(testkit.Rows("IndexLookUp_10 10.00 root ", - "├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:t27949, index:b(b) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan_9(Probe) 10.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) + tk.MustQuery("explain format = 'brief' select * from t27949 where b=1").Check(testkit.Rows("IndexLookUp 10.00 root ", + "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t27949, index:b(b) range:[1,1], keep order:false, stats:pseudo", + "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) tk.MustExec("create global binding for select * from t27949 where b=1 using select * from t27949 ignore index(b) where b=1") - tk.MustQuery("explain select * from t27949 where b=1").Check(testkit.Rows("TableReader_7 10.00 root data:Selection_6", - "└─Selection_6 10.00 cop[tikv] eq(test.t27949.b, 1)", - " └─TableFullScan_5 10000.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) + tk.MustQuery("explain format = 'brief' select * from t27949 where b=1").Check(testkit.Rows("TableReader 10.00 root data:Selection", + "└─Selection 10.00 cop[tikv] eq(test.t27949.b, 1)", + " └─TableFullScan 10000.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) tk.MustExec("set @@sql_select_limit=100") - tk.MustQuery("explain select * from t27949 where b=1").Check(testkit.Rows("Limit_8 10.00 root offset:0, count:100", - "└─TableReader_13 10.00 root data:Limit_12", - " └─Limit_12 10.00 cop[tikv] offset:0, count:100", - " └─Selection_11 10.00 cop[tikv] eq(test.t27949.b, 1)", - " └─TableFullScan_10 10000.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) + tk.MustQuery("explain format = 'brief' select * from t27949 where b=1").Check(testkit.Rows("Limit 10.00 root offset:0, count:100", + "└─TableReader 10.00 root data:Limit", + " └─Limit 10.00 cop[tikv] offset:0, count:100", + " └─Selection 10.00 cop[tikv] eq(test.t27949.b, 1)", + " └─TableFullScan 10000.00 cop[tikv] table:t27949 keep order:false, stats:pseudo")) } func (s *testIntegrationSuite) TestIssue28154(c *C) { From 05f1b18bad2021d75ed649edaa290f8c067a7fd0 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 17:29:20 +0800 Subject: [PATCH 09/11] fixup --- planner/optimize.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/optimize.go b/planner/optimize.go index 25af98300f8a1..0771a0b66c1af 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -235,7 +235,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in defer func() { sessVars.StmtCtx.StmtHints = savedStmtHints }() - if sessVars.EvolvePlanBaselines && bestPlanFromBind != nil { + if sessVars.EvolvePlanBaselines && bestPlanFromBind != nil && sessVars.SelectLimit == math.MaxUint64 { // Check bestPlanFromBind firstly to avoid nil stmtNode. if _, ok := stmtNode.(*ast.SelectStmt); ok && !bindRecord.Bindings[0].Hint.ContainTableHint(plannercore.HintReadFromStorage) { sessVars.StmtCtx.StmtHints = originStmtHints @@ -280,7 +280,7 @@ func allowInReadOnlyMode(sctx sessionctx.Context, node ast.Node) (bool, error) { switch node.(type) { // allow change variables (otherwise can't unset read-only mode) case *ast.SetStmt, - // allow analyze table + // allow analyze table *ast.AnalyzeTableStmt, *ast.UseStmt, *ast.ShowStmt, From adef698b1a4b0c8d42b9d29dcbaba6bd980a285f Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 17:30:37 +0800 Subject: [PATCH 10/11] fixup --- planner/optimize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/optimize.go b/planner/optimize.go index 0771a0b66c1af..e473e428b957e 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -280,7 +280,7 @@ func allowInReadOnlyMode(sctx sessionctx.Context, node ast.Node) (bool, error) { switch node.(type) { // allow change variables (otherwise can't unset read-only mode) case *ast.SetStmt, - // allow analyze table + // allow analyze table *ast.AnalyzeTableStmt, *ast.UseStmt, *ast.ShowStmt, From 192d65f1d74bc69ed5dd7a09c60b016cfa5890e2 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 23 Nov 2021 17:33:04 +0800 Subject: [PATCH 11/11] fixup --- planner/optimize.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/planner/optimize.go b/planner/optimize.go index e473e428b957e..363c3e6f5374a 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -235,7 +235,8 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in defer func() { sessVars.StmtCtx.StmtHints = savedStmtHints }() - if sessVars.EvolvePlanBaselines && bestPlanFromBind != nil && sessVars.SelectLimit == math.MaxUint64 { + if sessVars.EvolvePlanBaselines && bestPlanFromBind != nil && + sessVars.SelectLimit == math.MaxUint64 { // do not evolve this query if sql_select_limit is enabled // Check bestPlanFromBind firstly to avoid nil stmtNode. if _, ok := stmtNode.(*ast.SelectStmt); ok && !bindRecord.Bindings[0].Hint.ContainTableHint(plannercore.HintReadFromStorage) { sessVars.StmtCtx.StmtHints = originStmtHints