From 29ca8c5a90b62a853309e985289f9ab4e88342a1 Mon Sep 17 00:00:00 2001 From: Jinlong Liu <50897894+King-Dylan@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:27:36 +0800 Subject: [PATCH] This is an automated cherry-pick of #47952 Signed-off-by: ti-chi-bot --- pkg/planner/core/casetest/BUILD.bazel | 32 ++++++++++++++++ planner/core/casetest/plan_test.go | 38 +++++++++++++++++++ .../testdata/plan_normalized_suite_out.json | 4 +- planner/core/explain.go | 9 +++-- 4 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 pkg/planner/core/casetest/BUILD.bazel diff --git a/pkg/planner/core/casetest/BUILD.bazel b/pkg/planner/core/casetest/BUILD.bazel new file mode 100644 index 0000000000000..a9cac84c4ba66 --- /dev/null +++ b/pkg/planner/core/casetest/BUILD.bazel @@ -0,0 +1,32 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +go_test( + name = "casetest_test", + timeout = "moderate", + srcs = [ + "integration_test.go", + "main_test.go", + "plan_test.go", + "stats_test.go", + "tiflash_selection_late_materialization_test.go", + ], + data = glob(["testdata/**"]), + flaky = True, + shard_count = 20, + deps = [ + "//pkg/domain", + "//pkg/parser", + "//pkg/parser/model", + "//pkg/planner/core", + "//pkg/planner/property", + "//pkg/testkit", + "//pkg/testkit/testdata", + "//pkg/testkit/testmain", + "//pkg/testkit/testsetup", + "//pkg/util/hint", + "//pkg/util/plancodec", + "@com_github_pingcap_failpoint//:failpoint", + "@com_github_stretchr_testify//require", + "@org_uber_go_goleak//:goleak", + ], +) diff --git a/planner/core/casetest/plan_test.go b/planner/core/casetest/plan_test.go index a1e855bea225d..3c2814d8b6721 100644 --- a/planner/core/casetest/plan_test.go +++ b/planner/core/casetest/plan_test.go @@ -154,6 +154,44 @@ func TestNormalizedPlan(t *testing.T) { } } +func TestIssue47634(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t3,t4") + tk.MustExec("create table t3(a int, b int, c int);") + tk.MustExec("create table t4(a int, b int, c int, primary key (a, b) clustered);") + tk.MustExec("create table t5(a int, b int, c int, key idx_a_b (a, b));") + tk.Session().GetSessionVars().PlanID.Store(0) + queriesGroup1 := []string{ + "explain select /*+ inl_join(t4) */ * from t3 join t4 on t3.b = t4.b where t4.a = 1;", + "explain select /*+ inl_join(t5) */ * from t3 join t5 on t3.b = t5.b where t5.a = 1;", + } + queriesGroup2 := []string{ + "explain select /*+ inl_join(t4) */ * from t3 join t4 on t3.b = t4.b where t4.a = 2;", + "explain select /*+ inl_join(t5) */ * from t3 join t5 on t3.b = t5.b where t5.a = 2;", + } + for i := 0; i < len(queriesGroup1); i++ { + query1 := queriesGroup1[i] + query2 := queriesGroup2[i] + t.Run(query1+" vs "+query2, func(t *testing.T) { + tk.MustExec(query1) + info1 := tk.Session().ShowProcess() + require.NotNil(t, info1) + p1, ok := info1.Plan.(core.Plan) + require.True(t, ok) + _, digest1 := core.NormalizePlan(p1) + tk.MustExec(query2) + info2 := tk.Session().ShowProcess() + require.NotNil(t, info2) + p2, ok := info2.Plan.(core.Plan) + require.True(t, ok) + _, digest2 := core.NormalizePlan(p2) + require.Equal(t, digest1, digest2) + }) + } +} + func TestNormalizedPlanForDiffStore(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) diff --git a/planner/core/casetest/testdata/plan_normalized_suite_out.json b/planner/core/casetest/testdata/plan_normalized_suite_out.json index c7435e182fcf5..5d6a70fdd8373 100644 --- a/planner/core/casetest/testdata/plan_normalized_suite_out.json +++ b/planner/core/casetest/testdata/plan_normalized_suite_out.json @@ -95,7 +95,7 @@ " │ └─Selection cop gt(test.t1.c, ?)", " │ └─TableFullScan cop table:t1, range:[?,?], keep order:false", " └─TableReader root ", - " └─TableRangeScan cop table:t2, range: decided by [test.t1.a], keep order:false" + " └─TableRangeScan cop table:t2, keep order:false" ] }, { @@ -128,7 +128,7 @@ " │ └─Selection cop gt(test.t1.c, ?)", " │ └─TableFullScan cop table:t1, range:[?,?], keep order:false", " └─TableReader root ", - " └─TableRangeScan cop table:t2, range: decided by [test.t1.a], keep order:false" + " └─TableRangeScan cop table:t2, keep order:false" ] }, { diff --git a/planner/core/explain.go b/planner/core/explain.go index 916947e916895..8d76fa33f1d34 100644 --- a/planner/core/explain.go +++ b/planner/core/explain.go @@ -183,10 +183,11 @@ func (p *PhysicalTableScan) ExplainNormalizedInfo() string { func (p *PhysicalTableScan) OperatorInfo(normalized bool) string { var buffer strings.Builder if len(p.rangeInfo) > 0 { - // TODO: deal with normalized case - buffer.WriteString("range: decided by ") - buffer.WriteString(p.rangeInfo) - buffer.WriteString(", ") + if !normalized { + buffer.WriteString("range: decided by ") + buffer.WriteString(p.rangeInfo) + buffer.WriteString(", ") + } } else if p.haveCorCol() { if normalized { buffer.WriteString("range: decided by ")