diff --git a/planner/core/explain.go b/planner/core/explain.go index d0ae474b79e7f..0c68326b00a01 100644 --- a/planner/core/explain.go +++ b/planner/core/explain.go @@ -431,7 +431,7 @@ func (p *PhysicalIndexReader) ExplainInfo() string { // ExplainNormalizedInfo implements Plan interface. func (p *PhysicalIndexReader) ExplainNormalizedInfo() string { - return p.ExplainInfo() + return "index:" + p.indexPlan.TP() } func (p *PhysicalIndexReader) accessObject(sctx sessionctx.Context) string { diff --git a/planner/core/plan_test.go b/planner/core/plan_test.go index 288444c9f2c12..5dc6b8a5a1ac4 100644 --- a/planner/core/plan_test.go +++ b/planner/core/plan_test.go @@ -21,6 +21,7 @@ import ( "testing" . "github.com/pingcap/check" + "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" @@ -35,7 +36,7 @@ import ( "github.com/pingcap/tidb/util/testutil" ) -var _ = Suite(&testPlanNormalize{}) +var _ = SerialSuites(&testPlanNormalize{}) type testPlanNormalize struct { store kv.Storage @@ -286,6 +287,14 @@ func (s *testPlanNormalize) TestNormalizedDigest(c *C) { s_dist_10 char(24) DEFAULT NULL, PRIMARY KEY ( s_w_id , s_i_id ) );`) + + err := failpoint.Enable("github.com/pingcap/tidb/planner/mockRandomPlanID", "return(true)") + c.Assert(err, IsNil) + defer func() { + err = failpoint.Disable("github.com/pingcap/tidb/planner/mockRandomPlanID") + c.Assert(err, IsNil) + }() + normalizedDigestCases := []struct { sql1 string sql2 string @@ -404,7 +413,6 @@ func (s *testPlanNormalize) TestNormalizedDigest(c *C) { } func testNormalizeDigest(tk *testkit.TestKit, c *C, sql1, sql2 string, isSame bool) { - tk.Se.GetSessionVars().PlanID = 0 tk.MustQuery(sql1) info := tk.Se.ShowProcess() c.Assert(info, NotNil) @@ -412,7 +420,6 @@ func testNormalizeDigest(tk *testkit.TestKit, c *C, sql1, sql2 string, isSame bo c.Assert(ok, IsTrue) normalized1, digest1 := core.NormalizePlan(physicalPlan) - tk.Se.GetSessionVars().PlanID = 0 tk.MustQuery(sql2) info = tk.Se.ShowProcess() c.Assert(info, NotNil) diff --git a/planner/core/testdata/plan_normalized_suite_out.json b/planner/core/testdata/plan_normalized_suite_out.json index 8c656d9b60b40..ec97aea6b15b6 100644 --- a/planner/core/testdata/plan_normalized_suite_out.json +++ b/planner/core/testdata/plan_normalized_suite_out.json @@ -47,7 +47,7 @@ "SQL": "select a+1,b+2 from t1 use index(b) where b=3", "Plan": [ " Projection root plus(test.t1.a, ?), plus(test.t1.b, ?)", - " └─IndexReader root index:IndexRangeScan_5", + " └─IndexReader root index:IndexRangeScan", " └─IndexRangeScan cop table:t1, index:b(b), range:[?,?], keep order:false" ] }, diff --git a/planner/optimize.go b/planner/optimize.go index bd610664f4bd4..d111e078ab917 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math" + "math/rand" "runtime/trace" "strings" "sync" @@ -316,6 +317,10 @@ func optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in hintProcessor := &hint.BlockHintProcessor{Ctx: sctx} node.Accept(hintProcessor) + failpoint.Inject("mockRandomPlanID", func() { + sctx.GetSessionVars().PlanID = rand.Intn(1000) // nolint:gosec + }) + builder := planBuilderPool.Get().(*plannercore.PlanBuilder) defer planBuilderPool.Put(builder.ResetForReuse())