Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`))
}
1 change: 1 addition & 0 deletions pkg/planner/core/task_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func (t *CopTask) convertToRootTaskImpl(ctx base.PlanContext) *RootTask {
proj.SetChildren(p)
newTask.SetPlan(proj)
}
t.handleRootTaskConds(ctx, newTask)
return newTask
}
if t.indexPlan != nil && t.tablePlan != nil {
Expand Down
12 changes: 6 additions & 6 deletions tests/integrationtest/r/index_merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ insert into t1(c1, c2) values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
explain select /*+ use_index_merge(t1) */ * from t1 where c1 < 10 or c2 < 10 and c3 < 10 order by 1;
id estRows task access object operator info
Sort_5 4060.74 root index_merge.t1.c1
└─Selection_12 2250.55 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), lt(index_merge.t1.c3, 10)))
└─Selection_13 913.89 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), lt(index_merge.t1.c3, 10))), or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), lt(index_merge.t1.c3, 10)))
└─IndexMerge_11 5542.21 root type: union
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand All @@ -253,7 +253,7 @@ c1 c2 c3
explain select /*+ use_index_merge(t1) */ * from t1 where c1 < 10 or c2 < 10 and c3 = c1 + c2 order by 1;
id estRows task access object operator info
Sort_5 5098.44 root index_merge.t1.c1
└─Selection_12 2825.66 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), eq(index_merge.t1.c3, plus(index_merge.t1.c1, index_merge.t1.c2))))
└─Selection_13 1440.65 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), eq(index_merge.t1.c3, plus(index_merge.t1.c1, index_merge.t1.c2)))), or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), eq(index_merge.t1.c3, plus(index_merge.t1.c1, index_merge.t1.c2))))
└─IndexMerge_11 5542.21 root type: union
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand All @@ -268,7 +268,7 @@ c1 c2 c3
explain select /*+ use_index_merge(t1) */ * from t1 where c1 < 10 or c2 < 10 and substring(c3, c2) order by 1;
id estRows task access object operator info
Sort_5 5098.44 root index_merge.t1.c1
└─Selection_12 2825.66 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), istrue_with_null(cast(substring(cast(index_merge.t1.c3, var_string(20)), index_merge.t1.c2), double BINARY))))
└─Selection_13 1440.65 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), istrue_with_null(cast(substring(cast(index_merge.t1.c3, var_string(20)), index_merge.t1.c2), double BINARY)))), or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), istrue_with_null(cast(substring(cast(index_merge.t1.c3, var_string(20)), index_merge.t1.c2), double BINARY))))
└─IndexMerge_11 5542.21 root type: union
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand All @@ -283,7 +283,7 @@ c1 c2 c3
explain select /*+ use_index_merge(t1) */ * from t1 where c1 < 10 or c2 < 10 and c3 order by 1;
id estRows task access object operator info
Sort_5 4800.37 root index_merge.t1.c1
└─Selection_12 2660.47 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), index_merge.t1.c3))
└─Selection_13 1277.12 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), index_merge.t1.c3)), or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), index_merge.t1.c3))
└─IndexMerge_11 5542.21 root type: union
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand All @@ -303,7 +303,7 @@ select /*+ use_index_merge(t1) */ * from t1 where c1 < 10 or c2 < 10 and c3 < 10
explain select * from t1 where c1 < 10 or c2 < 10 and c3 < 10 order by 1;
id estRows task access object operator info
Sort_5 4060.74 root index_merge.t1.c1
└─Selection_12 2250.55 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), lt(index_merge.t1.c3, 10)))
└─Selection_13 913.89 root or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), lt(index_merge.t1.c3, 10))), or(lt(index_merge.t1.c1, 10), and(lt(index_merge.t1.c2, 10), lt(index_merge.t1.c3, 10)))
└─IndexMerge_11 5542.21 root type: union
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand Down Expand Up @@ -656,7 +656,7 @@ c1 c2 c3 c4 c5
explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and greatest(c1, c2, c4) = 1 order by 1;
id estRows task access object operator info
Sort_5 4433.77 root index_merge.t1.c1
└─Selection_12 4433.77 root eq(greatest(index_merge.t1.c1, index_merge.t1.c2, index_merge.t1.c4), 1)
└─Selection_13 3547.02 root eq(greatest(index_merge.t1.c1, index_merge.t1.c2, index_merge.t1.c4), 1), eq(greatest(index_merge.t1.c1, index_merge.t1.c2, index_merge.t1.c4), 1)
└─IndexMerge_11 5542.21 root type: union
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'de' or c2 = '10' and fro
explain format=brief select /*+ use_index_merge(t1) */ 1 from t1 where c1 = 'ab' or c2 = '10' and char_length(left(c1, 10)) = 10;
id estRows task access object operator info
Projection 17.99 root 1->Column#5
└─Selection 0.04 root or(eq(planner__core__casetest__integration.t1.c1, "ab"), and(eq(planner__core__casetest__integration.t1.c2, "10"), eq(char_length(left(planner__core__casetest__integration.t1.c1, 10)), 10)))
└─Selection 0.00 root or(eq(planner__core__casetest__integration.t1.c1, "ab"), and(eq(planner__core__casetest__integration.t1.c2, "10"), eq(char_length(left(planner__core__casetest__integration.t1.c1, 10)), 10)))
└─IndexMerge 19.99 root type: union
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c1(c1) range:["ab","ab"], keep order:false, stats:pseudo
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c2(c2) range:["10","10"], keep order:false, stats:pseudo
Expand Down Expand Up @@ -1019,7 +1019,7 @@ select /*+ use_index_merge( tt2 ) */ 1 from tt2 where tt2.c1 in (-3896405) or tt
explain format=brief select /*+ use_index_merge(tt3) */ 1 from tt3 where c1 < -10 or c2 < 10 and reverse(c3) = '2';
id estRows task access object operator info
Projection 5098.44 root 1->Column#5
└─Selection 2825.66 root or(lt(planner__core__casetest__integration.tt3.c1, -10), and(lt(planner__core__casetest__integration.tt3.c2, 10), eq(reverse(cast(planner__core__casetest__integration.tt3.c3, var_string(20))), "2")))
└─Selection 1440.65 root or(lt(planner__core__casetest__integration.tt3.c1, -10), and(lt(planner__core__casetest__integration.tt3.c2, 10), eq(reverse(cast(planner__core__casetest__integration.tt3.c3, var_string(20))), "2")))
└─IndexMerge 5542.21 root type: union
├─IndexRangeScan(Build) 3323.33 cop[tikv] table:tt3, index:c1(c1) range:[-inf,-10), keep order:false, stats:pseudo
├─IndexRangeScan(Build) 3323.33 cop[tikv] table:tt3, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ Projection_14 6.40 root 1->Column#10, Column#9
└─Projection_15 6.40 root format(cast(planner__core__casetest__pushdown__push_down.t4a8656d1.col_74, double BINARY), 1)->Column#9
└─HashAgg_16 6.40 root group by:planner__core__casetest__pushdown__push_down.t4a8656d1.col_73, planner__core__casetest__pushdown__push_down.t4a8656d1.col_74, funcs:firstrow(planner__core__casetest__pushdown__push_down.t4a8656d1.col_74)->planner__core__casetest__pushdown__push_down.t4a8656d1.col_74
└─HashJoin_19 10.00 root inner join, equal:[eq(planner__core__casetest__pushdown__push_down.t4a8656d1.col_74, Column#13)]
├─Selection_20(Build) 8.00 root isnull(format(cast(planner__core__casetest__pushdown__push_down.t4a8656d1.col_74, double BINARY), 1)), json_overlaps(planner__core__casetest__pushdown__push_down.t4a8656d1.col_73, cast("[0.035131302371695955]", json BINARY))
├─Selection_20(Build) 8.00 root isnull(format(cast(planner__core__casetest__pushdown__push_down.t4a8656d1.col_74, double BINARY), 1)), isnull(format(cast(planner__core__casetest__pushdown__push_down.t4a8656d1.col_74, double BINARY), 1)), json_overlaps(planner__core__casetest__pushdown__push_down.t4a8656d1.col_73, cast("[0.035131302371695955]", json BINARY))
│ └─IndexMerge_27 10.00 root type: union
│ ├─Selection_25(Build) 0.00 cop[tikv]
│ │ └─IndexRangeScan_24 10.00 cop[tikv] table:t4a8656d1, index:idx_39(cast(`col_73` as double array), col_74) range:[0.035131302371695955,0.035131302371695955], keep order:false, stats:pseudo
│ └─TableRowIDScan_26(Probe) 10.00 cop[tikv] table:t4a8656d1 keep order:false, stats:pseudo
└─Projection_34(Probe) 10000.00 root cast(planner__core__casetest__pushdown__push_down.tld47bc815.col_1, datetime(6) BINARY)->Column#13
└─TableReader_36 10000.00 root data:TableFullScan_35
└─TableFullScan_35 10000.00 cop[tikv] table:tld47bc815 keep order:false, stats:pseudo
└─Projection_36(Probe) 10000.00 root cast(planner__core__casetest__pushdown__push_down.tld47bc815.col_1, datetime(6) BINARY)->Column#13
└─TableReader_38 10000.00 root data:TableFullScan_37
└─TableFullScan_37 10000.00 cop[tikv] table:tld47bc815 keep order:false, stats:pseudo