Skip to content

Commit 67c7e69

Browse files
authored
planner: Fix the issue that may generate many plandigests when the inner table is clustered (#47952) (#48112)
close #47634
1 parent f3b75f4 commit 67c7e69

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

planner/core/casetest/plan_test.go

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

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

planner/core/casetest/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
{

planner/core/explain.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ func (p *PhysicalTableScan) ExplainNormalizedInfo() string {
183183
func (p *PhysicalTableScan) OperatorInfo(normalized bool) string {
184184
var buffer strings.Builder
185185
if len(p.rangeInfo) > 0 {
186-
// TODO: deal with normalized case
187-
buffer.WriteString("range: decided by ")
188-
buffer.WriteString(p.rangeInfo)
189-
buffer.WriteString(", ")
186+
if !normalized {
187+
buffer.WriteString("range: decided by ")
188+
buffer.WriteString(p.rangeInfo)
189+
buffer.WriteString(", ")
190+
}
190191
} else if p.haveCorCol() {
191192
if normalized {
192193
buffer.WriteString("range: decided by ")

0 commit comments

Comments
 (0)