Files
tidb/tests/integrationtest/r/executor/index_merge_reader.result
2025-12-10 09:40:20 +00:00

535 lines
30 KiB
Plaintext

drop table if exists t1, t2;
create table t1(id int primary key, a int, b int, c int, d int);
create index t1a on t1(a);
create index t1b on t1(b);
insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5);
select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by id;
id a b c d
1 1 1 1 1
5 5 5 5 5
select /*+ use_index_merge(t1, primary, t1a) */ a from t1 where id < 2 or a > 4 order by a;
a
1
5
select /*+ use_index_merge(t1, primary, t1a) */ sum(a) from t1 where id < 2 or a > 4;
sum(a)
6
select /*+ use_index_merge(t1, t1a, t1b) */ * from t1 where a < 2 or b > 4 order by a;
id a b c d
1 1 1 1 1
5 5 5 5 5
select /*+ use_index_merge(t1, t1a, t1b) */ a from t1 where a < 2 or b > 4 order by a;
a
1
5
select /*+ use_index_merge(t1, t1a, t1b) */ sum(a) from t1 where a < 2 or b > 4;
sum(a)
6
drop table if exists t1, t2;
create table t1(id int primary key, a int, b int, c int, d int);
create index t1a on t1(a);
create index t1b on t1(b);
create table t2(id int primary key, a int);
create index t2a on t2(a);
insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5);
insert into t2 values(1,1),(5,5);
select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 4;
sum(t1.a)
6
select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 5;
sum(t1.a)
1
drop table if exists t0;
CREATE TABLE t0(c0 INT AS (1), c1 INT PRIMARY KEY);
INSERT INTO t0(c1) VALUES (0);
CREATE INDEX i0 ON t0(c0);
SELECT /*+ USE_INDEX_MERGE(t0, i0, PRIMARY)*/ t0.c0 FROM t0 WHERE t0.c1 OR t0.c0;
c0
1
SELECT t0.c0 FROM t0 WHERE t0.c1 OR t0.c0;
c0
1
drop table if exists t1;
create table t1(a int primary key, b int, c int, key(b), key(c));
INSERT INTO t1 VALUES (10, 10, 10), (11, 11, 11);
explain format='plan_tree' select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10);
id task access object operator info
IndexMerge root type: union
├─IndexRangeScan(Build) cop[tikv] table:t1, index:c(c) range:[10,10], keep order:false, stats:pseudo
├─TableRangeScan(Build) cop[tikv] table:t1 range:[10,10], keep order:false, stats:pseudo
└─Selection(Probe) cop[tikv] or(eq(executor__index_merge_reader.t1.c, 10), and(eq(executor__index_merge_reader.t1.b, 10), eq(executor__index_merge_reader.t1.a, 10)))
└─TableRowIDScan cop[tikv] table:t1 keep order:false, stats:pseudo
select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10);
a b c
10 10 10
drop table if exists t1, t2, t3;
create table t1 (a int not null, b tinyint not null, index (a), index (b)) partition by range (a) (partition p0 values less than (10),partition p1 values less than (20),partition p2 values less than (30),partition p3 values less than (40),partition p4 values less than MAXVALUE);
insert into t1 values(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100);
create table t2 (a int not null, b bigint not null, index (a), index (b)) partition by hash(a) partitions 10;
insert into t2 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23);
select /*+ USE_INDEX_MERGE(t1, a, b) */ * from t1 partition (p0) join t2 partition (p1) on t1.a = t2.a where t1.a < 40 or t1.b < 30;
a b a b
1 1 1 1
drop table if exists t;
set @@tidb_enable_index_merge = 1;
create table t (a int, b int, c int, primary key(a), key(b));
explain format='plan_tree' select /*+ inl_join(t2) */ * from t t1 join t t2 on t1.a = t2.a and t1.c = t2.c where t2.a = 1 or t2.b = 1;
id task access object operator info
Projection root executor__index_merge_reader.t.a, executor__index_merge_reader.t.b, executor__index_merge_reader.t.c, executor__index_merge_reader.t.a, executor__index_merge_reader.t.b, executor__index_merge_reader.t.c
└─IndexJoin root inner join, inner:TableReader, outer key:executor__index_merge_reader.t.a, inner key:executor__index_merge_reader.t.a, equal cond:eq(executor__index_merge_reader.t.a, executor__index_merge_reader.t.a), eq(executor__index_merge_reader.t.c, executor__index_merge_reader.t.c)
├─TableReader(Build) root data:Selection
│ └─Selection cop[tikv] not(isnull(executor__index_merge_reader.t.c))
│ └─TableFullScan cop[tikv] table:t1 keep order:false, stats:pseudo
└─TableReader(Probe) root data:Selection
└─Selection cop[tikv] not(isnull(executor__index_merge_reader.t.c)), or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1))
└─TableRangeScan cop[tikv] table:t2 range: decided by [executor__index_merge_reader.t.a], keep order:false, stats:pseudo
set @@tidb_enable_index_merge = default;
drop table if exists t1;
create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk));
begin;
explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10;
id estRows task access object operator info
IndexMerge_10 1841.86 root type: union
├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
└─Selection_9(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10)
└─TableRowIDScan_8 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10;
id estRows task access object operator info
IndexMerge_10 1106.67 root type: union
├─TableRangeScan_6(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
└─Selection_9(Probe) 1106.67 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10)
└─TableRowIDScan_8 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10;
id estRows task access object operator info
IndexMerge_10 367.05 root type: intersection
├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo
└─TableRowIDScan_9(Probe) 367.05 cop[tikv] table:t1 keep order:false, stats:pseudo
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
insert into t1 values(1, 1, 1, 1);
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
1 1 100 1
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10;
c1 c2 c3 pk
insert into t1 values(1, 1, 1, 1);
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
1 1 100 1
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
commit;
drop table if exists t1;
create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk));
set tx_isolation = 'READ-COMMITTED';
begin;
explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10;
id estRows task access object operator info
IndexMerge_10 1841.86 root type: union
├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
└─Selection_9(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10)
└─TableRowIDScan_8 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10;
id estRows task access object operator info
IndexMerge_10 1106.67 root type: union
├─TableRangeScan_6(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
└─Selection_9(Probe) 1106.67 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10)
└─TableRowIDScan_8 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10;
id estRows task access object operator info
IndexMerge_10 367.05 root type: intersection
├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo
├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo
└─TableRowIDScan_9(Probe) 367.05 cop[tikv] table:t1 keep order:false, stats:pseudo
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
insert into t1 values(1, 1, 1, 1);
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
1 1 100 1
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10;
c1 c2 c3 pk
insert into t1 values(1, 1, 1, 1);
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10;
c1 c2 c3 pk
1 1 1 1
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
1 1 100 1
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;
c1 c2 c3 pk
select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10;
c1 c2 c3 pk
commit;
set tx_isolation = 'REPEATABLE-READ';
drop table if exists t1;
create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk));
begin;
explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;
id estRows task access object operator info
SelectLock_7 1841.86 root for update 0
└─IndexMerge_12 1841.86 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
└─Selection_11(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10)
└─TableRowIDScan_10 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo
explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;
id estRows task access object operator info
SelectLock_7 1106.67 root for update 0
└─IndexMerge_12 1106.67 root type: union
├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t1 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
└─Selection_11(Probe) 1106.67 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10)
└─TableRowIDScan_10 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
insert into t1 values(1, 1, 1, 1);
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
1 1 1 1
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
insert into t1 values(1, 1, 1, 1);
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
1 1 1 1
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;
c1 c2 c3 pk
commit;
drop table if exists t1;
create table t1(c1 int, c2 int, c3 int, pk int, part int, key(c1), key(c2), key(c3), primary key(pk, part))
partition by range(part) (
partition p0 values less than (10),
partition p1 values less than (20),
partition p2 values less than (maxvalue));
begin;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
insert into t1 values(1, 1, 1, 1, 1);
insert into t1 values(11, 11, 11, 11, 11);
insert into t1 values(21, 21, 21, 21, 21);
insert into t1 values(31, 31, 31, 31, 31);
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
1 1 1 1 1
11 11 11 11 11
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20;
c1 c2 c3 pk part
1 1 1 1 1
11 11 11 11 11
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
1 1 1 1 1
11 11 11 11 11
select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20;
c1 c2 c3 pk part
1 1 1 1 1
11 11 11 11 11
update t1 set c3 = 100 where c3 = 1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
11 11 11 11 11
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20;
c1 c2 c3 pk part
11 11 11 11 11
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
11 11 11 11 11
select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20;
c1 c2 c3 pk part
11 11 11 11 11
delete from t1;
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20;
c1 c2 c3 pk part
select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20;
c1 c2 c3 pk part
select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20;
c1 c2 c3 pk part
commit;
set tx_isolation = default;
drop table if exists t1;
create table t1 (col_30 decimal default 0 ,
col_31 char(99) collate utf8_bin default 'sVgzHblmYYtEjVg' not null ,
col_37 int unsigned default 377206828 ,
primary key idx_16 ( col_37 ) , key idx_19 ( col_31) ) collate utf8mb4_general_ci ;
begin;
insert ignore into t1 values (388021, '', 416235653);
select /*+ use_index_merge( t1 ) */ 1 from t1 where ( t1.col_31 in ( 'OiOXzpCs' , 'oaVv' ) or t1.col_37 <= 4059907010 ) and t1.col_30 ;
1
1
commit;
drop table if exists tbl_3;
create table tbl_3 ( col_30 decimal , col_31 char(99) , col_32 smallint ,
col_33 tinyint unsigned not null , col_34 char(209) ,
col_35 char(110) , col_36 int unsigned , col_37 int unsigned ,
col_38 decimal(50,15) not null , col_39 char(104),
primary key ( col_37 ) , unique key ( col_33,col_30,col_36,col_39 ) ,
unique key ( col_32,col_35 ) , key ( col_31,col_38 ) ,
key ( col_31,col_33,col_32,col_35,col_36 ) ,
unique key ( col_38,col_34,col_33,col_31,col_30,col_36,col_35,col_37,col_39 ) ,
unique key ( col_39,col_32 ) , unique key ( col_30,col_35,col_31,col_38 ) ,
key ( col_38,col_32,col_33 ) );
begin;
insert ignore into tbl_3 values ( 71,'Fipc',-6676,30,'','FgfK',2464927398,4084082400,5602.5868,'' );
select /*+ use_index_merge( tbl_3 ) */ 1 from tbl_3 where ( tbl_3.col_37 not in ( 1626615245 , 2433569159 ) or tbl_3.col_38 = 0.06 ) ;
1
1
commit;
drop table if exists t1;
create table t1(c1 int, c2 int, c3 int, c4 int, primary key(c1, c2) /*T![clustered_index] CLUSTERED */, key(c3));
begin;
insert into t1 values(1, 1, 1, 1);
explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10;
id estRows task access object operator info
UnionScan_7 1841.86 root lt(executor__index_merge_reader.t1.c4, 10), or(lt(executor__index_merge_reader.t1.c1, -1), lt(executor__index_merge_reader.t1.c3, 10))
└─IndexMerge_12 1841.86 root type: union
├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t1 range:[-inf,-1), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo
└─Selection_11(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c4, 10)
└─TableRowIDScan_10 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10;
c1 c2 c3 c4
1 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c3 < -1) and c4 < 10;
c1 c2 c3 c4
1 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < -1) and c4 < 10;
c1 c2 c3 c4
commit;
drop table if exists t1;
create table t1(c1 varchar(100), c2 int, c3 int, c4 int, primary key(c1) /*T![clustered_index] CLUSTERED */, key(c3));
begin;
insert into t1 values('b', 1, 1, 1);
explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10;
id estRows task access object operator info
UnionScan_7 1841.86 root lt(executor__index_merge_reader.t1.c4, 10), or(lt(executor__index_merge_reader.t1.c1, "a"), lt(executor__index_merge_reader.t1.c3, 10))
└─IndexMerge_12 1841.86 root type: union
├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t1 range:[-inf,"a"), keep order:false, stats:pseudo
├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo
└─Selection_11(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c4, 10)
└─TableRowIDScan_10 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10;
c1 c2 c3 c4
b 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (c1 <= 'b' or c3 < -1) and c4 < 10;
c1 c2 c3 c4
b 1 1 1
select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < -1) and c4 < 10;
c1 c2 c3 c4
commit;
DROP TABLE IF EXISTS tab2;
CREATE TABLE tab2(pk INTEGER PRIMARY KEY, col0 INTEGER, col1 FLOAT, col2 TEXT, col3 INTEGER, col4 FLOAT, col5 TEXT);
CREATE INDEX idx_tab2_0 ON tab2 (col0 DESC,col3 DESC);
CREATE UNIQUE INDEX idx_tab2_3 ON tab2 (col4,col0 DESC);
CREATE INDEX idx_tab2_4 ON tab2 (col3,col1 DESC);
INSERT INTO tab2 VALUES(0,146,632.63,'shwwd',703,412.47,'xsppr');
INSERT INTO tab2 VALUES(1,81,536.29,'trhdh',49,726.3,'chuxv');
INSERT INTO tab2 VALUES(2,311,541.72,'txrvb',493,581.92,'xtrra');
INSERT INTO tab2 VALUES(3,669,293.27,'vcyum',862,415.14,'nbutk');
INSERT INTO tab2 VALUES(4,681,49.46,'odzhp',106,324.65,'deudp');
INSERT INTO tab2 VALUES(5,319,769.65,'aeqln',855,197.9,'apipa');
INSERT INTO tab2 VALUES(6,610,302.62,'bixap',184,840.31,'vggit');
INSERT INTO tab2 VALUES(7,253,453.21,'gjccm',107,104.5,'lvunv');
SPLIT TABLE tab2 BY (5);
TOTAL_SPLIT_REGION SCATTER_FINISH_RATIO
1 1
SELECT /*+ use_index_merge(tab2) */ pk FROM tab2 WHERE (col4 > 565.89 OR col0 > 68 ) and col0 > 10 order by 1;
pk
0
1
2
3
4
5
6
7
drop table if exists t;
create table t(a int, b int, c int, index idx(a, c), index idx2(b, c));
insert into t values(1, 1, 1), (2, 2, 2);
explain format='plan_tree' select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1;
id task access object operator info
IndexMerge root type: union, limit embedded(offset:0, count:1)
├─Limit(Build) cop[tikv] offset:0, count:1
│ └─IndexRangeScan cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo
├─Limit(Build) cop[tikv] offset:0, count:1
│ └─IndexRangeScan cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:false, stats:pseudo
└─TableRowIDScan(Probe) cop[tikv] table:t keep order:false, stats:pseudo
select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1;
a b c
1 1 1
drop table if exists t;
create table t(a int, b int, c int, index idx1(a, c), index idx2(b, c));
insert into t values(1, 1, 1), (1, 2, -1), (2, 1, -2);
begin;
insert into t values(1, 1, -3);
explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2;
id estRows task access object operator info
Limit_16 2.00 root offset:0, count:2
└─UnionScan_22 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1))
└─IndexMerge_26 2.00 root type: union
├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, stats:pseudo
├─IndexRangeScan_24(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo
└─TableRowIDScan_25(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo
select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2;
a b c
1 1 -3
2 1 -2
rollback;
begin;
insert into t values(1, 2, 4);
explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2;
id estRows task access object operator info
Limit_16 2.00 root offset:0, count:2
└─UnionScan_22 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1))
└─IndexMerge_26 2.00 root type: union
├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, desc, stats:pseudo
├─IndexRangeScan_24(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, desc, stats:pseudo
└─TableRowIDScan_25(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo
select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2;
a b c
1 2 4
1 1 1
rollback;
drop table if exists t1;
create table t1(pk varchar(100) primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));
insert into t1 values('TXwuGSfZfrgVbTksgvQBilqiUXlNEXzyXNqWRTCidzXFbrkpGFJalRMdVGQOAOojditwludthMcitNqNtvirGAudSNBtdIkpJIHQ', 1, 1), ('LSiKhgTNnuyjdBtuKKuRgzrcxbHrIlfxSkEuooaPYwfOBVQfNYAyatHiWvmUWRUvBLvXmpqAJUWRXXHFCLCjuJqFbVxQdUxqRuqW', 1, 1), ('qCOSFbvtmansHENQaAQbnyYOwCTPctlejpbpueHbtzskmPOazrMWdcMLaYjyfxYQUgDDjCnAnnExepNqwYIzHVjNVndlOzFaAOcf', 1, 1), ('qBqdtPyXIqLKynGNHnRlrufuUCZPqhxUYEqIrYERnQdqXRjVWcoYclxYXoqdpQboKydzhOHOWBwtmcXzGwCWQVdbpozvIaXxiBQj', 1, 1), ('TXZlGHnXOiSWGyRafAqworFmxuadHRTHcYyzLqZMzIMGUUBQmgiIJKQOqbHhoPEKbYBgfPDZJwwqgnCbMxZKaZfvGyVRRUOgRhoq', 1, 1), ('SwFEtKDfPDQpsyxTdTruPyNDLvEOLRdQtSttxJmgBuZiVKsflHCDZaGvkLHMqhHqLayfbZFrxUHzWHgfoPFCWCdCHScabWRNCHCL', 1, 1), ('BuZhnsTMGNtMJtrjjdMMrguutSpiLnZNCdgiNkWDPymzIymcujjBtsnKCAVRSErvbzPaOwLTTPWkGmbXltqOJXmkXnSWWlWaaBqe', 1, 1), ('LuJCpJrLUwDJutwBDtGEsGduteBWPHeGLVhmVJYVrmjunKNuplEeWDCMIAxHPoiRmdPnXneQEQWRvJkPBoXOPaGZhhFLFgGraLmH', 1, 1), ('JKJwMlPmymduJWOmKLFBmZyCFrcUvKcGQkzJmzGjuFoZweyCBptswEPHTkaIhWEEBMWzNBawtfYKKAugBNlxcwmpJSfuIAUSIxeG', 1, 1), ('IqQbehKwleoSUnwxrVLKSbzRqlEFfkwQtRtIfaVpEGfESyGjDJeAOWQPRYVQYvlPNPROQEraCqwQTzanPSrsnUvEXHSxcYjUJvzk', 1, 1), ('zNHmiBGCLUUEDgMAeIGuTgNJFPBtePpxcQrQlgnRlvosJfeYbhRfJdfMwXIRlXxVoOowhEvPhMQPlplzkUfjjmzdJKwGATvfDAiT', 1, 1), ('OjQvpfdsHSdZUAmGfmtQaYKYONAFHGNLeLKRYECqshxygiOzfKkqRwSYGgClqqnpHqPMZpqsjIYSalziqSfMbbtmmzxkOVgglVOh', 1, 1), ('dXXZaWDwdfhjIysLTNMSfwvoEBJhWOVpJnfXFofWSWMfMbUlRgAkobxoCxXPXNUWzAQczbQclQpvIvvATHHcQgdXUvwSTHqLXZny', 1, 1), ('haPqYVwFNUkedfIKPOPyUxIvbSkaUbsEWNvnDtXZsQQqafIhDXlajYpuXOSYiOwGJYAMVLUvXfwOIuyHKElzJHpOUdCiQiXRHubI', 1, 1), ('nQzOwSsVBjCpehVVmLeyYwyVEwYGAfkhCtkkaKyiXzYCRPRVZpNVnOXGbuWrQEgTuPEPFPApUaYLdCtyBEQulFEwyHlORrMfIJxr', 1, 1), ('ksGDopwNPvpjeCtAMaTrznDSgCLpRDQoCdsahWSjwumVEJITbNBPAAtkoxHuwmNQsryoILqCPBPiUSxAWjnFEdtxDIgEtqDiFvpO', 1, 1), ('AdWEZYzxCMhfcZseNVmNQpyqJrVKcKaZpKKcwZXfDPeIBMzkLzpJpOenidMBtBPBIbaiqfpSxBnGtRHAksBOgpigQTVomZzJhCFb', 1, 1), ('bVMNkLOAuRHqnCtGvVPLvmVSKihYFotmHTjObiAIARHawZTruAabGpFxeYxYTTFRxteFYyBfkBfiSEIFvOPquDnlVRNUUubssEMz', 1, 1), ('kXmcjqMYzGxvHBRRCovSTWavDnVajKLlxguJgniJeNkWQUxjHjYjBsveLfojybWkbqHBVzrOoqgXFrDnnRJPcybmnuAEUTPUoIjO', 1, 1), ('rVXzZDKudOpWCBuRCoQCpukHxenZnsaptDeJCCFzxMVvNucFwLKIiSceLsqUHHQuEfAIygjQCCkIbfInGthSnoLdNGWbsLDsxnrY', 1, 1);
explain format='plan_tree' select /*+ use_index_merge(t1, primary, idx1, idx2) */ c1 from t1 where c1 < 1024 and c2 < 1024;
id task access object operator info
Projection root executor__index_merge_reader.t1.c1
└─IndexMerge root type: intersection
├─IndexRangeScan(Build) cop[tikv] table:t1, index:idx1(c1) range:[-inf,1024), keep order:false, stats:pseudo
├─IndexRangeScan(Build) cop[tikv] table:t1, index:idx2(c2) range:[-inf,1024), keep order:false, stats:pseudo
└─TableRowIDScan(Probe) cop[tikv] table:t1 keep order:false, stats:pseudo
set global tidb_mem_oom_action='CANCEL';
set @@tidb_mem_quota_query = 3000;
select /*+ use_index_merge(t1, primary, idx1, idx2) */ c1 from t1 where c1 < 1024 and c2 < 1024;
Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=<num>]
set global tidb_mem_oom_action = DEFAULT;
set @@tidb_mem_quota_query = default;
drop table if exists t;
create table t(a int, b int, c int, index(b, a), index(c, a));
select * from t use index(b, c) where b=2 or c=3 order by a limit 10000000000000000;
a b c