Skip to content

Commit

Permalink
planner: fix idxMergePartPlans forget to deal with RootTaskConds (#58507
Browse files Browse the repository at this point in the history
)

close #58476
  • Loading branch information
hawkingrei authored Dec 24, 2024
1 parent 6806af4 commit 0c22a2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_test(
data = glob(["testdata/**"]),
flaky = True,
race = "on",
shard_count = 5,
shard_count = 6,
deps = [
"//pkg/parser",
"//pkg/planner",
Expand Down
18 changes: 18 additions & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,21 @@ func TestIssues57583(t *testing.T) {
" └─Selection_20 9990.00 cop[tikv] not(isnull(test.t1.v1))",
" └─TableFullScan_19 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"))
}

func TestIssue58476(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("CREATE TABLE t3 (id int PRIMARY KEY,c1 varchar(256),c2 varchar(256) GENERATED ALWAYS AS (concat(c1, c1)) VIRTUAL,KEY (id));")
tk.MustExec("insert into t3(id, c1) values (50, 'c');")
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())
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;").
Check(testkit.Rows(
`Projection 249.75 root test.t3.id`,
`└─Selection 249.75 root ge(test.t3.c2, "a"), le(test.t3.c2, "b")`,
` └─Projection 9990.00 root test.t3.id, test.t3.c2`,
` └─IndexMerge 9990.00 root type: union`,
` ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t3, index:id(id) range:[-inf,100), keep order:false, stats:pseudo`,
` ├─TableRangeScan(Build) 3333.33 cop[tikv] table:t3 range:(0,+inf], keep order:false, stats:pseudo`,
` └─TableRowIDScan(Probe) 9990.00 cop[tikv] table:t3 keep order:false, stats:pseudo`))
}
2 changes: 1 addition & 1 deletion pkg/planner/core/task_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,14 @@ func (t *CopTask) convertToRootTaskImpl(ctx base.PlanContext) *RootTask {
p.PlanPartInfo = t.physPlanPartInfo
setTableScanToTableRowIDScan(p.tablePlan)
newTask.SetPlan(p)
t.handleRootTaskConds(ctx, newTask)
if t.needExtraProj {
schema := t.originSchema
proj := PhysicalProjection{Exprs: expression.Column2Exprs(schema.Columns)}.Init(ctx, p.StatsInfo(), t.idxMergePartPlans[0].QueryBlockOffset(), nil)
proj.SetSchema(schema)
proj.SetChildren(p)
newTask.SetPlan(proj)
}
t.handleRootTaskConds(ctx, newTask)
return newTask
}
if t.indexPlan != nil && t.tablePlan != nil {
Expand Down

0 comments on commit 0c22a2d

Please sign in to comment.