diff --git a/pkg/planner/core/testdata/index_merge_suite_out.json b/pkg/planner/core/testdata/index_merge_suite_out.json deleted file mode 100644 index 66cc33e82a435..0000000000000 --- a/pkg/planner/core/testdata/index_merge_suite_out.json +++ /dev/null @@ -1,593 +0,0 @@ -[ - { - "Name": "TestIndexMergePathGeneration", - "Cases": [ - "[]", - "[]", - "[{Idxs:[{c_d_e},{f,f_g}],TbFilters:[]}]", - "[{Idxs:[{c_d_e},{f,f_g}],TbFilters:[or(gt(test.t.c, 5), lt(test.t.f, 7))]},{Idxs:[{c_d_e},{f,f_g}],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2))]}]", - "[{Idxs:[{c_d_e},{f,f_g}],TbFilters:[or(gt(test.t.c, 5), lt(test.t.f, 7)),or(lt(test.t.c, 1), gt(test.t.g, 2))]},{Idxs:[{c_d_e},{f,f_g}],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2)),or(lt(test.t.c, 1), gt(test.t.g, 2))]},{Idxs:[{c_d_e},{g}],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2)),or(gt(test.t.c, 5), lt(test.t.f, 7))]}]", - "[{Idxs:[{c_d_e},{f,f_g}],TbFilters:[or(gt(test.t.c, 5), lt(test.t.f, 7)),or(lt(test.t.e, 1), gt(test.t.f, 2))]},{Idxs:[{c_d_e},{f,f_g}],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2)),or(lt(test.t.e, 1), gt(test.t.f, 2))]}]" - ] - }, - { - "Name": "TestHintForIntersectionIndexMerge", - "Cases": [ - { - "SQL": "set @@tidb_partition_prune_mode = 'dynamic'", - "Plan": null, - "Result": null - }, - { - "SQL": "select * from vh", - "Plan": [ - "IndexMerge 0.97 root partition:p0,p1,p2 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, index:ia(a) range:[10,10], keep order:false", - "├─IndexRangeScan(Build) 2.60 cop[tikv] table:t1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t1, index:id(d) range:[2,2], [5,5], keep order:false", - "└─TableRowIDScan(Probe) 0.97 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "IndexMerge 0.97 root partition:p0,p1,p2 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, index:ia(a) range:[10,10], keep order:false", - "├─IndexRangeScan(Build) 2.60 cop[tikv] table:t1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t1, index:id(d) range:[2,2], [5,5], keep order:false", - "└─TableRowIDScan(Probe) 0.97 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v@sel_1), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "IndexMerge 0.97 root partition:p0,p1,p2 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, index:ia(a) range:[10,10], keep order:false", - "├─IndexRangeScan(Build) 2.60 cop[tikv] table:t1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t1, index:id(d) range:[2,2], [5,5], keep order:false", - "└─TableRowIDScan(Probe) 0.97 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v@sel_1 .@sel_1), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "IndexMerge 0.97 root partition:p0,p1,p2 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, index:ia(a) range:[10,10], keep order:false", - "├─IndexRangeScan(Build) 2.60 cop[tikv] table:t1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t1, index:id(d) range:[2,2], [5,5], keep order:false", - "└─TableRowIDScan(Probe) 0.97 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v1@sel_1 .@sel_1), use_index_merge(@v t1, ia, ibc, id) */ * from v1 where c < 30 and d in (2,5)", - "Plan": [ - "IndexMerge 0.97 root partition:p0,p1,p2 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, index:ia(a) range:[10,10], keep order:false", - "├─IndexRangeScan(Build) 2.60 cop[tikv] table:t1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t1, index:id(d) range:[2,2], [5,5], keep order:false", - "└─TableRowIDScan(Probe) 0.97 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ use_index_merge(t2, ia, ibc, id, ie) */ * from t2 where a > 10 and b = 20 and c < 35 and d < 45 and e = 100", - "Plan": [ - "IndexMerge 0.89 root partition:p0,p1,p2 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:ia(a) range:(10,+inf], keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t2, index:id(d) range:[-inf,45), keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:ie(e) range:[100,100], keep order:false", - "└─TableRowIDScan(Probe) 0.89 cop[tikv] table:t2 keep order:false" - ], - "Result": [ - "20 20 20 5 100" - ] - }, - { - "SQL": "select /*+ use_index_merge(t3, ia, ibc, id, ie) */ * from t3 where a > 10 and b = 20 and c < 35 and d < 45 and e = 100", - "Plan": [ - "IndexMerge 0.44 root partition:p0 type: intersection", - "├─IndexRangeScan(Build) 1.00 cop[tikv] table:t3, index:ia(a) range:(10,+inf], keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t3, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t3, index:id(d) range:[-inf,45), keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t3, index:ie(e) range:[100,100], keep order:false", - "└─TableRowIDScan(Probe) 0.44 cop[tikv] table:t3 keep order:false" - ], - "Result": [ - "20 20 20 5 100" - ] - }, - { - "SQL": "select /*+ use_index_merge(t4, ia, ibc, id, ie) */ * from t4 where a > 10 and b = 20 and c < 35 and d in (1,3,8,9) and e = 100", - "Plan": [ - "IndexMerge 0.89 root partition:p0,p1 type: intersection", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t4, index:ia(a) range:(10,+inf], keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t4, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "├─IndexRangeScan(Build) 3.00 cop[tikv] table:t4, index:id(d) range:[1,1], [3,3], [8,8], [9,9], keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t4, index:ie(e) range:[100,100], keep order:false", - "└─TableRowIDScan(Probe) 0.89 cop[tikv] table:t4 keep order:false" - ], - "Result": [ - "30 20 5 8 100" - ] - }, - { - "SQL": "select /*+ use_index_merge(t5, is1, is2, is3, is4) */ * from t5 where s1 = 'Abc' and s2 > 'zzz' and s3 < 'B啊a' and s4 = 'CcC'", - "Plan": [ - "IndexMerge 0.00 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t5, index:is1(s1) range:[\"Abc\",\"Abc\"], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t5, index:is2(s2) range:(\"zzz\",+inf], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t5, index:is3(s3) range:[-inf,\"\\x0eJ\\xfb@\\xd5J\\x0e3\"), keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t5, index:is4(s4) range:[\"CCC\",\"CCC\"], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t5 keep order:false, stats:pseudo" - ], - "Result": [ - "Abc zzzz aa ccc" - ] - }, - { - "SQL": "select /*+ use_index_merge(t6, primary, is3, is4) */ * from t6 where s1 = 'Abc' and s2 > 'zzz' and s3 = 'A啊a' and s4 not like 'Cd_'", - "Plan": [ - "IndexMerge 0.03 root type: intersection", - "├─IndexRangeScan(Build) 33.33 cop[tikv] table:t6, index:PRIMARY(s1, s2) range:(\"Abc\" \"zzz\",\"Abc\" +inf], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t6, index:is3(s3) range:[\"\\x0e3\\xfb@\\xd5J\\x0e3\",\"\\x0e3\\xfb@\\xd5J\\x0e3\"], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.03 cop[tikv] gt(test.t6.s2, \"zzz\"), not(like(test.t6.s4, \"Cd_\", 92))", - " └─TableRowIDScan 0.03 cop[tikv] table:t6 keep order:false, stats:pseudo" - ], - "Result": [ - "Abc zzzz A啊A Cdaa" - ] - }, - { - "SQL": "select /*+ use_index_merge(t7, primary,ia,ib,ic,ie,iff,ig) */ * from t7 where a = 100 and b > 5 and c < 12.3 and d > 54.321 and e = '2022-11-22 17:00' and f > '2020-6-23 10:00' and g < 2025", - "Plan": [ - "IndexMerge 0.00 root type: intersection", - "├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t7, index:PRIMARY(d) range:(54.321,+inf], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t7, index:ia(a) range:[100,100], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t7, index:ib(b) range:(\"0x05\",+inf], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t7, index:ic(c) range:[-inf,12.3), keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t7, index:ie(e) range:[2022-11-22 17:00:00,2022-11-22 17:00:00], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t7, index:iff(f) range:(2020-06-23 10:00:00.00000,+inf], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t7, index:ig(g) range:[-inf,2025), keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t7 keep order:false, stats:pseudo" - ], - "Result": [ - "100 \u0006 12.2 56.000 2022-11-22 17:00:00 2022-12-21 00:00:00.00000 2021" - ] - }, - { - "SQL": "select /*+ use_index_merge(t8, primary,is2,is3,is4,is5) */ * from t8 where s1 like '啊A%' and s2 > 'abc' and s3 > 'cba' and s4 in ('aA', '??') and s5 = 'test,2'", - "Plan": [ - "Selection 0.04 root eq(test.t8.s5, \"test,2\")", - "└─IndexMerge 0.06 root type: intersection", - " ├─IndexRangeScan(Build) 250.00 cop[tikv] table:t8, index:PRIMARY(s1) range:[\"UJ\\x00A\",\"UJ\\x00B\"), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t8, index:is2(s2) range:(\"abc\",+inf], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t8, index:is3(s3) range:(\"cba\",+inf], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 20.00 cop[tikv] table:t8, index:is4(s4) range:[\"aA\",\"aA\"], [\"??\",\"??\"], keep order:false, stats:pseudo", - " └─Selection(Probe) 0.06 cop[tikv] gt(test.t8.s3, \"cba\"), like(test.t8.s1, \"啊A%\", 92)", - " └─TableRowIDScan 0.06 cop[tikv] table:t8 keep order:false, stats:pseudo" - ], - "Result": [ - "啊aabbccdd abcc cccc aA tEsT,2" - ] - }, - { - "SQL": "select (select /*+ use_index_merge(t1,ia,ibc,ic) */ a from t1 where t1.a > 10 and t1.b = 20 and t1.c = t2.a) from t2", - "Plan": [ - "Projection 3.00 root test.t1.a", - "└─Apply 3.00 root CARTESIAN left outer join", - " ├─IndexReader(Build) 3.00 root partition:all index:IndexFullScan", - " │ └─IndexFullScan 3.00 cop[tikv] table:t2, index:ia(a) keep order:false", - " └─MaxOneRow(Probe) 3.00 root ", - " └─IndexMerge 1.50 root partition:all type: intersection", - " ├─IndexRangeScan(Build) 6.00 cop[tikv] table:t1, index:ia(a) range:(10,+inf], keep order:false", - " ├─IndexRangeScan(Build) 4.00 cop[tikv] table:t1, index:ibc(b, c) range: decided by [eq(test.t1.b, 20) eq(test.t1.c, test.t2.a)], keep order:false", - " └─TableRowIDScan(Probe) 1.50 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "20", - "", - "" - ] - }, - { - "SQL": "select (select /*+ use_index_merge(t1,ia,ibc,ic) */ a from t1 where t1.a > 10 and t1.b = 20 and t1.c > t2.a) from t2", - "Plan": [ - "Projection 3.00 root test.t1.a", - "└─Apply 3.00 root CARTESIAN left outer join", - " ├─IndexReader(Build) 3.00 root partition:all index:IndexFullScan", - " │ └─IndexFullScan 3.00 cop[tikv] table:t2, index:ia(a) keep order:false", - " └─MaxOneRow(Probe) 3.00 root ", - " └─IndexMerge 3.60 root partition:all type: intersection", - " ├─IndexRangeScan(Build) 6.00 cop[tikv] table:t1, index:ia(a) range:(10,+inf], keep order:false", - " ├─Selection(Build) 7.20 cop[tikv] gt(test.t1.c, test.t2.a)", - " │ └─IndexRangeScan 9.00 cop[tikv] table:t1, index:ibc(b, c) range:[20,20], keep order:false", - " └─TableRowIDScan(Probe) 3.60 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "20", - "20", - "" - ] - }, - { - "SQL": "select (select /*+ use_index_merge(t1,ia,ibc,ic) */ a from t1 where t1.a > 10 and t1.b = 20 and t1.e > t2.a) from t2", - "Plan": [ - "Projection 3.00 root test.t1.a", - "└─Apply 3.00 root CARTESIAN left outer join", - " ├─IndexReader(Build) 3.00 root partition:all index:IndexFullScan", - " │ └─IndexFullScan 3.00 cop[tikv] table:t2, index:ia(a) keep order:false", - " └─MaxOneRow(Probe) 3.00 root ", - " └─IndexMerge 3.60 root partition:all type: intersection", - " ├─IndexRangeScan(Build) 6.00 cop[tikv] table:t1, index:ia(a) range:(10,+inf], keep order:false", - " ├─IndexRangeScan(Build) 9.00 cop[tikv] table:t1, index:ibc(b, c) range:[20,20], keep order:false", - " └─Selection(Probe) 3.60 cop[tikv] gt(test.t1.e, test.t2.a)", - " └─TableRowIDScan 4.50 cop[tikv] table:t1 keep order:false" - ], - "Result": [ - "20", - "20", - "20" - ] - }, - { - "SQL": "set @@tidb_partition_prune_mode = 'static'", - "Plan": null, - "Result": null - }, - { - "SQL": "select * from vh", - "Plan": [ - "PartitionUnion 1.50 root ", - "├─IndexMerge 0.50 root type: intersection", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, partition:p0, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 0.50 cop[tikv] table:t1, partition:p0 keep order:false", - "├─IndexMerge 1.00 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, partition:p2, index:ia(a) range:[10,10], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 33.23 cop[tikv] table:t1, partition:p2, index:ibc(b, c) range:[20 -inf,20 30), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 20.00 cop[tikv] table:t1, partition:p2, index:id(d) range:[2,2], [5,5], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "PartitionUnion 1.50 root ", - "├─IndexMerge 0.50 root type: intersection", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, partition:p0, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 0.50 cop[tikv] table:t1, partition:p0 keep order:false", - "├─IndexMerge 1.00 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, partition:p2, index:ia(a) range:[10,10], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 33.23 cop[tikv] table:t1, partition:p2, index:ibc(b, c) range:[20 -inf,20 30), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 20.00 cop[tikv] table:t1, partition:p2, index:id(d) range:[2,2], [5,5], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v@sel_1), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "PartitionUnion 1.50 root ", - "├─IndexMerge 0.50 root type: intersection", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, partition:p0, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 0.50 cop[tikv] table:t1, partition:p0 keep order:false", - "├─IndexMerge 1.00 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, partition:p2, index:ia(a) range:[10,10], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 33.23 cop[tikv] table:t1, partition:p2, index:ibc(b, c) range:[20 -inf,20 30), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 20.00 cop[tikv] table:t1, partition:p2, index:id(d) range:[2,2], [5,5], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v@sel_1 .@sel_1), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "PartitionUnion 1.50 root ", - "├─IndexMerge 0.50 root type: intersection", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, partition:p0, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 0.50 cop[tikv] table:t1, partition:p0 keep order:false", - "├─IndexMerge 1.00 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, partition:p2, index:ia(a) range:[10,10], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 33.23 cop[tikv] table:t1, partition:p2, index:ibc(b, c) range:[20 -inf,20 30), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 20.00 cop[tikv] table:t1, partition:p2, index:id(d) range:[2,2], [5,5], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ qb_name(v, v@sel_1 .@sel_1), use_index_merge(@v t1, ia, ibc, id) */ * from v", - "Plan": [ - "PartitionUnion 1.50 root ", - "├─IndexMerge 0.50 root type: intersection", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, partition:p0, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p0, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 0.50 cop[tikv] table:t1, partition:p0 keep order:false", - "├─IndexMerge 1.00 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ia(a) range:[10,10], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:ibc(b, c) range:[20 -inf,20 30), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:id(d) range:[2,2], [5,5], keep order:false", - "│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, partition:p2, index:ia(a) range:[10,10], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 33.23 cop[tikv] table:t1, partition:p2, index:ibc(b, c) range:[20 -inf,20 30), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 20.00 cop[tikv] table:t1, partition:p2, index:id(d) range:[2,2], [5,5], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo" - ], - "Result": [ - "10 20 5 5 3" - ] - }, - { - "SQL": "select /*+ use_index_merge(t2, ia, ibc, id, ie) */ * from t2 where a > 10 and b = 20 and c < 35 and d < 45 and e = 100", - "Plan": [ - "PartitionUnion 1.25 root ", - "├─IndexMerge 0.25 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p0, index:ia(a) range:(10,+inf], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p0, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, partition:p0, index:id(d) range:[-inf,45), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p0, index:ie(e) range:[100,100], keep order:false", - "│ └─TableRowIDScan(Probe) 0.25 cop[tikv] table:t2, partition:p0 keep order:false", - "├─IndexMerge 1.00 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p1, index:ia(a) range:(10,+inf], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p1, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p1, index:id(d) range:[-inf,45), keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t2, partition:p1, index:ie(e) range:[100,100], keep order:false", - "│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t2, partition:p1 keep order:false", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t2, partition:p2, index:ia(a) range:(10,+inf], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 33.23 cop[tikv] table:t2, partition:p2, index:ibc(b, c) range:[20 -inf,20 35), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t2, partition:p2, index:id(d) range:[-inf,45), keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, partition:p2, index:ie(e) range:[100,100], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo" - ], - "Result": [ - "20 20 20 5 100" - ] - }, - { - "SQL": "select /*+ use_index_merge(t3, ia, ibc, id, ie) */ * from t3 where a > 10 and b = 20 and c < 35 and d < 45 and e = 100", - "Plan": [ - "IndexMerge 0.50 root type: intersection", - "├─IndexRangeScan(Build) 1.00 cop[tikv] table:t3, partition:p0, index:ia(a) range:(10,+inf], keep order:false", - "├─IndexRangeScan(Build) 1.00 cop[tikv] table:t3, partition:p0, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t3, partition:p0, index:id(d) range:[-inf,45), keep order:false", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:t3, partition:p0, index:ie(e) range:[100,100], keep order:false", - "└─TableRowIDScan(Probe) 0.50 cop[tikv] table:t3, partition:p0 keep order:false" - ], - "Result": [ - "20 20 20 5 100" - ] - }, - { - "SQL": "select /*+ use_index_merge(t4, ia, ibc, id, ie) */ * from t4 where a > 10 and b = 20 and c < 35 and d in (1,3,8,9) and e = 100", - "Plan": [ - "PartitionUnion 1.25 root ", - "├─IndexMerge 0.25 root type: intersection", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p0, index:ia(a) range:(10,+inf], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p0, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - "│ ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t4, partition:p0, index:id(d) range:[1,1], [3,3], [8,8], [9,9], keep order:false", - "│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p0, index:ie(e) range:[100,100], keep order:false", - "│ └─TableRowIDScan(Probe) 0.25 cop[tikv] table:t4, partition:p0 keep order:false", - "└─IndexMerge 1.00 root type: intersection", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p1, index:ia(a) range:(10,+inf], keep order:false", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p1, index:ibc(b, c) range:[20 -inf,20 35), keep order:false", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p1, index:id(d) range:[1,1], [3,3], [8,8], [9,9], keep order:false", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t4, partition:p1, index:ie(e) range:[100,100], keep order:false", - " └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t4, partition:p1 keep order:false" - ], - "Result": [ - "30 20 5 8 100" - ] - } - ] - }, - { - "Name": "TestIndexMergeWithOrderProperty", - "Cases": [ - { - "SQL": "select * from t where a=1 or b=1 order by c; -- 1. auto pick the most suitable index ac and bc", - "Plan": [ - "Projection 19.99 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e", - "└─IndexMerge 19.99 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:bc(b, c) range:[1,1], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 19.99 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, ac, bc) */ * from t where a=1 or b=1 order by c; -- 2. hint instruction to pick the suitable index ac and bc", - "Plan": [ - "Projection 19.99 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e", - "└─IndexMerge 19.99 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:bc(b, c) range:[1,1], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 19.99 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t2 where a=1 or b=1 order by c; -- 3. if one of the index order path can't satisfied, back to normal choice", - "Plan": [ - "Sort 19.99 root test.t2.c", - "└─IndexMerge 19.99 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 19.99 cop[tikv] table:t2 keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, ac, b) */ * from t where a=1 or b=1 order by c; -- 4. hint to use ac strongly, but sort OP is still needed", - "Plan": [ - "Sort 19.99 root test.t.c", - "└─IndexMerge 19.99 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 19.99 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where a=1 or a=2 order by c; -- 5. duplicated column a's conditions and lack of column b's conditions", - "Plan": [ - "Sort 250.00 root test.t.c", - "└─TableReader 250.00 root data:Selection", - " └─Selection 250.00 cop[tikv] or(eq(test.t.a, 1), eq(test.t.a, 2))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t use index(a) where a=1 or a=2 order by c; -- 6. duplicated column a's conditions and lack of column b's conditions", - "Plan": [ - "Sort 250.00 root test.t.c", - "└─IndexLookUp 250.00 root ", - " ├─IndexRangeScan(Build) 250.00 cop[tikv] table:t, index:a(a) range:[1,2], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 250.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where a=1 or a=2 or b=3 order by c; -- 7. duplicate column a's conditions", - "Plan": [ - "Projection 259.75 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e", - "└─IndexMerge 259.75 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[2,2], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:bc(b, c) range:[3,3], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 259.75 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, ac, bc) */ * from t where a=1 or a=2 or b=3 order by c; -- 8. duplicate column a's conditions", - "Plan": [ - "Projection 259.75 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e", - "└─IndexMerge 259.75 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ac(a, c) range:[2,2], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:bc(b, c) range:[3,3], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 259.75 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where a=1 or b=1 or c=1 order by d; -- 9. more than 2 index related columns, here c condition is interference", - "Plan": [ - "Sort 29.97 root test.t.d", - "└─IndexMerge 29.97 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:c(c) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 29.97 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, a, b, c) */ * from t where a=1 or b=1 or c=1 order by d; -- 10. more than 2 index related columns, here c condition is interference", - "Plan": [ - "Sort 29.97 root test.t.d", - "└─IndexMerge 29.97 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:c(c) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 29.97 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where a=1 or b=1 or c=1 or d=1 order by e; -- 11. more index definition about idx(a,e), idx(b,e)", - "Plan": [ - "Sort 39.94 root test.t.e", - "└─TableReader 39.94 root data:Selection", - " └─Selection 39.94 cop[tikv] or(or(eq(test.t.a, 1), eq(test.t.b, 1)), or(eq(test.t.c, 1), eq(test.t.d, 1)))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, ae, be, c) */ * from t where a=1 or b=1 or c=1 order by e; -- 12. more index definition about idx(a,e), idx(b,e)", - "Plan": [ - "Sort 29.97 root test.t.e", - "└─IndexMerge 29.97 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:ae(a, e) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:be(b, e) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:c(c) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 29.97 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where (a=1 and b=1) or c=1 order by d; -- 13. composite predicates and more index defined, idx(a, b, d), idx(c, d)", - "Plan": [ - "Projection 10.10 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e", - "└─IndexMerge 10.10 root type: union", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:abd(a, b, d) range:[1 1,1 1], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:cd(c, d) range:[1,1], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 10.10 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where (a=1 and b=1) or (c=1 and d=2) order by d; -- 14. composite predicates and more index defined, idx(a, b, d), idx(c, d)", - "Plan": [ - "Projection 0.20 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e", - "└─IndexMerge 0.20 root type: union", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:abd(a, b, d) range:[1 1,1 1], keep order:true, stats:pseudo", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:cd(c, d) range:[1 2,1 2], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 0.20 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where (a=1 and b=1) or (c=1 and d=1) order by e", - "Plan": [ - "Sort 0.20 root test.t.e", - "└─IndexMerge 0.20 root type: union", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:cd(c, d) range:[1 1,1 1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:abd(a, b, d) range:[1 1,1 1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.20 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - } -]