Skip to content

Commit 5e39597

Browse files
authored
planner: fix idxMergePartPlans forget to deal with RootTaskConds (#58507) (#58517)
close #58476
1 parent d1a0835 commit 5e39597

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

planner/core/issuetest/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ go_test(
66
srcs = ["planner_issue_test.go"],
77
flaky = True,
88
race = "on",
9-
shard_count = 8,
9+
shard_count = 9,
1010
deps = ["//testkit"],
1111
)

planner/core/issuetest/planner_issue_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,21 @@ func Test53726(t *testing.T) {
285285
" └─TableReader_11 2.00 root data:TableFullScan_10",
286286
" └─TableFullScan_10 2.00 cop[tikv] table:t7 keep order:false"))
287287
}
288+
289+
func TestIssue58476(t *testing.T) {
290+
store := testkit.CreateMockStore(t)
291+
tk := testkit.NewTestKit(t, store)
292+
tk.MustExec("use test;")
293+
tk.MustExec("CREATE TABLE t3 (id int PRIMARY KEY,c1 varchar(256),c2 varchar(256) GENERATED ALWAYS AS (concat(c1, c1)) VIRTUAL,KEY (id));")
294+
tk.MustExec("insert into t3(id, c1) values (50, 'c');")
295+
tk.MustQuery("SELECT /*+ USE_INDEX_MERGE(`t3`)*/ id FROM `t3` WHERE c2 BETWEEN 'a' AND 'b' GROUP BY id HAVING id < 100 or id > 0;").Check(testkit.Rows())
296+
tk.MustQuery("explain format='brief' SELECT /*+ USE_INDEX_MERGE(`t3`)*/ id FROM `t3` WHERE c2 BETWEEN 'a' AND 'b' GROUP BY id HAVING id < 100 or id > 0;").
297+
Check(testkit.Rows(
298+
`Projection 249.75 root test.t3.id`,
299+
`└─Selection 249.75 root ge(test.t3.c2, "a"), le(test.t3.c2, "b")`,
300+
` └─Projection 9990.00 root test.t3.id, test.t3.c2`,
301+
` └─IndexMerge 9990.00 root type: union`,
302+
` ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t3, index:id(id) range:[-inf,100), keep order:false, stats:pseudo`,
303+
` ├─TableRangeScan(Build) 3333.33 cop[tikv] table:t3 range:(0,+inf], keep order:false, stats:pseudo`,
304+
` └─TableRowIDScan(Probe) 9990.00 cop[tikv] table:t3 keep order:false, stats:pseudo`))
305+
}

planner/core/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,14 @@ func (t *copTask) convertToRootTaskImpl(ctx sessionctx.Context) *rootTask {
697697
p.PartitionInfo = t.partitionInfo
698698
setTableScanToTableRowIDScan(p.tablePlan)
699699
newTask.p = p
700-
t.handleRootTaskConds(ctx, newTask)
701700
if t.needExtraProj {
702701
schema := t.originSchema
703702
proj := PhysicalProjection{Exprs: expression.Column2Exprs(schema.Columns)}.Init(ctx, p.stats, t.idxMergePartPlans[0].SelectBlockOffset(), nil)
704703
proj.SetSchema(schema)
705704
proj.SetChildren(p)
706705
newTask.p = proj
707706
}
707+
t.handleRootTaskConds(ctx, newTask)
708708
return newTask
709709
}
710710
if t.indexPlan != nil && t.tablePlan != nil {

0 commit comments

Comments
 (0)