Skip to content

Commit

Permalink
planner: fix idxMergePartPlans forget to deal with RootTaskConds (pin…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jan 23, 2025
1 parent d1a0835 commit 5e39597
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ go_test(
srcs = ["planner_issue_test.go"],
flaky = True,
race = "on",
shard_count = 8,
shard_count = 9,
deps = ["//testkit"],
)
18 changes: 18 additions & 0 deletions planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,21 @@ func Test53726(t *testing.T) {
" └─TableReader_11 2.00 root data:TableFullScan_10",
" └─TableFullScan_10 2.00 cop[tikv] table:t7 keep order:false"))
}

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 planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,14 @@ func (t *copTask) convertToRootTaskImpl(ctx sessionctx.Context) *rootTask {
p.PartitionInfo = t.partitionInfo
setTableScanToTableRowIDScan(p.tablePlan)
newTask.p = p
t.handleRootTaskConds(ctx, newTask)
if t.needExtraProj {
schema := t.originSchema
proj := PhysicalProjection{Exprs: expression.Column2Exprs(schema.Columns)}.Init(ctx, p.stats, t.idxMergePartPlans[0].SelectBlockOffset(), nil)
proj.SetSchema(schema)
proj.SetChildren(p)
newTask.p = proj
}
t.handleRootTaskConds(ctx, newTask)
return newTask
}
if t.indexPlan != nil && t.tablePlan != nil {
Expand Down

0 comments on commit 5e39597

Please sign in to comment.