Skip to content

Commit 2bdadae

Browse files
authored
planner: Fix the issue that may generate many plandigests when the inner table is clustered (#47952) (#48111)
close #47634
1 parent b7db604 commit 2bdadae

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

planner/core/explain.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ func (p *PhysicalTableScan) ExplainNormalizedInfo() string {
174174
func (p *PhysicalTableScan) OperatorInfo(normalized bool) string {
175175
var buffer strings.Builder
176176
if len(p.rangeInfo) > 0 {
177-
// TODO: deal with normalized case
178-
buffer.WriteString("range: decided by ")
179-
buffer.WriteString(p.rangeInfo)
180-
buffer.WriteString(", ")
177+
if !normalized {
178+
buffer.WriteString("range: decided by ")
179+
buffer.WriteString(p.rangeInfo)
180+
buffer.WriteString(", ")
181+
}
181182
} else if p.haveCorCol() {
182183
if normalized {
183184
buffer.WriteString("range: decided by ")

planner/core/plan_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,44 @@ func TestNormalizedPlan(t *testing.T) {
152152
}
153153
}
154154

155+
func TestIssue47634(t *testing.T) {
156+
store := testkit.CreateMockStore(t)
157+
tk := testkit.NewTestKit(t, store)
158+
tk.MustExec("use test")
159+
tk.MustExec("drop table if exists t3,t4")
160+
tk.MustExec("create table t3(a int, b int, c int);")
161+
tk.MustExec("create table t4(a int, b int, c int, primary key (a, b) clustered);")
162+
tk.MustExec("create table t5(a int, b int, c int, key idx_a_b (a, b));")
163+
tk.Session().GetSessionVars().PlanID = 0
164+
queriesGroup1 := []string{
165+
"explain select /*+ inl_join(t4) */ * from t3 join t4 on t3.b = t4.b where t4.a = 1;",
166+
"explain select /*+ inl_join(t5) */ * from t3 join t5 on t3.b = t5.b where t5.a = 1;",
167+
}
168+
queriesGroup2 := []string{
169+
"explain select /*+ inl_join(t4) */ * from t3 join t4 on t3.b = t4.b where t4.a = 2;",
170+
"explain select /*+ inl_join(t5) */ * from t3 join t5 on t3.b = t5.b where t5.a = 2;",
171+
}
172+
for i := 0; i < len(queriesGroup1); i++ {
173+
query1 := queriesGroup1[i]
174+
query2 := queriesGroup2[i]
175+
t.Run(query1+" vs "+query2, func(t *testing.T) {
176+
tk.MustExec(query1)
177+
info1 := tk.Session().ShowProcess()
178+
require.NotNil(t, info1)
179+
p1, ok := info1.Plan.(core.Plan)
180+
require.True(t, ok)
181+
_, digest1 := core.NormalizePlan(p1)
182+
tk.MustExec(query2)
183+
info2 := tk.Session().ShowProcess()
184+
require.NotNil(t, info2)
185+
p2, ok := info2.Plan.(core.Plan)
186+
require.True(t, ok)
187+
_, digest2 := core.NormalizePlan(p2)
188+
require.Equal(t, digest1, digest2)
189+
})
190+
}
191+
}
192+
155193
func TestNormalizedPlanForDiffStore(t *testing.T) {
156194
store, dom := testkit.CreateMockStoreAndDomain(t)
157195
tk := testkit.NewTestKit(t, store)

planner/core/testdata/plan_normalized_suite_out.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
" │ └─Selection cop gt(test.t1.c, ?)",
9696
" │ └─TableFullScan cop table:t1, range:[?,?], keep order:false",
9797
" └─TableReader root ",
98-
" └─TableRangeScan cop table:t2, range: decided by [test.t1.a], keep order:false"
98+
" └─TableRangeScan cop table:t2, keep order:false"
9999
]
100100
},
101101
{
@@ -128,7 +128,7 @@
128128
" │ └─Selection cop gt(test.t1.c, ?)",
129129
" │ └─TableFullScan cop table:t1, range:[?,?], keep order:false",
130130
" └─TableReader root ",
131-
" └─TableRangeScan cop table:t2, range: decided by [test.t1.a], keep order:false"
131+
" └─TableRangeScan cop table:t2, keep order:false"
132132
]
133133
},
134134
{

0 commit comments

Comments
 (0)