220 lines
13 KiB
Plaintext
220 lines
13 KiB
Plaintext
# TestIssue44389
|
|
drop table if exists t;
|
|
create table t(a varchar(100), b int, c int, index idx_ab(a, b));
|
|
insert into t values ('kk', 1, 10), ('kk', 1, 20), ('hh', 2, 10), ('hh', 3, 10), ('xx', 4, 10), ('yy', 5, 10), ('yy', 6, 20), ('zz', 7, 10);
|
|
set @@tidb_opt_fix_control = '44389:ON';
|
|
explain format='brief' select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1));
|
|
--sorted_result
|
|
select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1));
|
|
explain format='brief' select * from t where c = 10 and ((a = 'xx' or a = 'yy') or ((a = 'kk' and b = 1) or (a = 'hh' and b = 2)));
|
|
--sorted_result
|
|
select * from t where c = 10 and ((a = 'xx' or a = 'yy') or ((a = 'kk' and b = 1) or (a = 'hh' and b = 2)));
|
|
set @@tidb_opt_fix_control = default;
|
|
|
|
# TestPrefixIndexAppendPointRanges
|
|
DROP TABLE IF EXISTS IDT_20755;
|
|
CREATE TABLE `IDT_20755` (
|
|
`COL1` varchar(20) DEFAULT NULL,
|
|
`COL2` tinyint(16) DEFAULT NULL,
|
|
`COL3` timestamp NULL DEFAULT NULL,
|
|
KEY `u_m_col` (`COL1`(10),`COL2`,`COL3`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
|
INSERT INTO IDT_20755 VALUES("牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆", 73, "2010-06-03 07:29:05");
|
|
INSERT INTO IDT_20755 VALUES("xxxxxxxxxxxxxxx", 73, "2010-06-03 07:29:05");
|
|
explain format = 'brief' select * from IDT_20755 use index (u_m_col) where col1 in ("牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆", "物碃貞枕騫摨聫嚣蜻禼担堋黕詖蝒毎槒阆畒郒", "剮毵樍穋摻瀽鬦擀钟鷫產冖悄乮曙枱诠鑡轰砠") and col2 in (72, 39, 73) and col3 != "2024-10-19 08:55:32";
|
|
select * from IDT_20755 use index (u_m_col) where col1 in ("牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆", "物碃貞枕騫摨聫嚣蜻禼担堋黕詖蝒毎槒阆畒郒", "剮毵樍穋摻瀽鬦擀钟鷫產冖悄乮曙枱诠鑡轰砠") and col2 in (72, 39, 73) and col3 != "2024-10-19 08:55:32";
|
|
explain format = 'brief' select * from IDT_20755 use index (u_m_col) where col1 = "xxxxxxxxxxxxxxx" and col2 in (72, 73) and col3 != "2024-10-19 08:55:32";
|
|
select * from IDT_20755 use index (u_m_col) where col1 = "xxxxxxxxxxxxxxx" and col2 in (72, 73) and col3 != "2024-10-19 08:55:32";
|
|
explain format = 'brief' select * from IDT_20755 use index (u_m_col) where col1 = "xxxxxxxxxxxxxxx" and col2 in (72, 73, 74) and col3 != "2024-10-19 08:55:32";
|
|
select * from IDT_20755 use index (u_m_col) where col1 = "xxxxxxxxxxxxxxx" and col2 in (72, 73, 74) and col3 != "2024-10-19 08:55:32";
|
|
|
|
# TestIndexRangeForDecimal
|
|
drop table if exists t1, t2;
|
|
create table t1(a decimal unsigned, key(a));
|
|
insert into t1 values(0),(null);
|
|
create table t2(a int, b decimal unsigned, key idx(a,b));
|
|
insert into t2 values(1,0),(1,null);
|
|
explain format = 'brief' select * from t1 use index(a) where a in (-1,0);
|
|
select * from t1 use index(a) where a in (-1,0);
|
|
explain format = 'brief' select * from t1 use index(a) where a = -1;
|
|
select * from t1 use index(a) where a = -1;
|
|
explain format = 'brief' select * from t1 use index(a) where a > -1;
|
|
select * from t1 use index(a) where a > -1;
|
|
explain format = 'brief' select * from t1 use index(a) where a < -1;
|
|
select * from t1 use index(a) where a < -1;
|
|
explain format = 'brief' select * from t1 use index(a) where a <= -1;
|
|
select * from t1 use index(a) where a <= -1;
|
|
explain format = 'brief' select * from t1 use index(a) where a >= -1;
|
|
select * from t1 use index(a) where a >= -1;
|
|
explain format = 'brief' select * from t2 use index(idx) where a = 1 and b in (-1,0);
|
|
select * from t2 use index(idx) where a = 1 and b in (-1,0);
|
|
explain format = 'brief' select * from t2 use index(idx) where a = 1 and b = -1;
|
|
select * from t2 use index(idx) where a = 1 and b = -1;
|
|
explain format = 'brief' select * from t2 use index(idx) where a = 1 and b > -1;
|
|
select * from t2 use index(idx) where a = 1 and b > -1;
|
|
explain format = 'brief' select * from t2 use index(idx) where a = 1 and b < -1;
|
|
select * from t2 use index(idx) where a = 1 and b < -1;
|
|
explain format = 'brief' select * from t2 use index(idx) where a = 1 and b <= -1;
|
|
select * from t2 use index(idx) where a = 1 and b <= -1;
|
|
explain format = 'brief' select * from t2 use index(idx) where a = 1 and b >= -1;
|
|
select * from t2 use index(idx) where a = 1 and b >= -1;
|
|
|
|
# TestIndexRangeForBit
|
|
set @@tidb_partition_prune_mode = 'static';
|
|
set @@tidb_executor_concurrency = 1;
|
|
drop table if exists t;
|
|
CREATE TABLE `t` (a bit(1) DEFAULT NULL,b int(11) DEFAULT NULL) PARTITION BY HASH(a)PARTITIONS 3;
|
|
insert ignore into t values(-1, -1), (0, 0), (1, 1), (3, 3);
|
|
analyze table t all columns;
|
|
explain format='brief' select * from t;
|
|
select * from t;
|
|
explain format='brief' select * from t where a = 0;
|
|
select * from t where a = 0;
|
|
explain format='brief' select * from t where a = 0 or a = 4;
|
|
select * from t where a = 0 or a = 4;
|
|
explain format='brief' select * from t where a = 1;
|
|
select * from t where a = 1;
|
|
explain format='brief' select * from t where a = -1;
|
|
select * from t where a = -1;
|
|
explain format='brief' select * from t where a = 3;
|
|
select * from t where a = 3;
|
|
explain format='brief' select * from t where a < 1;
|
|
select * from t where a < 1;
|
|
explain format='brief' select * from t where a < 3;
|
|
select * from t where a < 3;
|
|
explain format='brief' select * from t where a < -1;
|
|
select * from t where a < -1;
|
|
explain format='brief' select * from t where a > 0;
|
|
select * from t where a > 0;
|
|
explain format='brief' select * from t where a > -1;
|
|
select * from t where a > -1;
|
|
explain format='brief' select * from t where a > 3;
|
|
select * from t where a > 3;
|
|
set @@tidb_partition_prune_mode = default;
|
|
set @@tidb_executor_concurrency = default;
|
|
|
|
# TestPrefixIndexMultiColDNF
|
|
drop table if exists t2;
|
|
create table t2 (id int unsigned not null auto_increment primary key, t text, index(t(3)));
|
|
insert into t2 (t) values ('aaaa'),('a');
|
|
explain format='brief' select * from t2 where t='aaaa';
|
|
select * from t2 where t='aaaa';
|
|
explain format='brief' select * from t2 where t='aaaa' or t = 'a';
|
|
select * from t2 where t='aaaa' or t = 'a';
|
|
analyze table t2;
|
|
explain format='brief' select * from t2 where t='aaaa';
|
|
select * from t2 where t='aaaa';
|
|
explain format='brief' select * from t2 where t='aaaa' or t = 'a';
|
|
select * from t2 where t='aaaa' or t = 'a';
|
|
|
|
# TestIssue41572
|
|
drop table if exists t;
|
|
create table t(a varchar(100), b int, c int, d int, index idx(a, b, c));
|
|
insert into t values ('t',1,1,1),('t',1,3,3),('t',2,1,3),('t',2,3,1),('w',0,3,3),('z',0,1,1);
|
|
explain format='brief' select * from t use index (idx) where ((a = 't' and b = 1) or (a = 't' and b = 2) or (a = 'w' and b = 0)) and c > 2;
|
|
select * from t use index (idx) where ((a = 't' and b = 1) or (a = 't' and b = 2) or (a = 'w' and b = 0)) and c > 2;
|
|
explain format='brief' select * from t use index (idx) where ((a = 't' and b = 1) or (a = 't' and b = 2) or (a = 'w' and b = 0)) and d > 2;
|
|
select * from t use index (idx) where ((a = 't' and b = 1) or (a = 't' and b = 2) or (a = 'w' and b = 0)) and d > 2;
|
|
|
|
# TestCompIndexMultiColDNF2
|
|
drop table if exists t;
|
|
create table t(a int, b int, c int, primary key(a,b,c));
|
|
insert into t values(1,1,1),(2,2,3);
|
|
analyze table t;
|
|
explain format='brief' select * from t where a = 1 and (b,c) in ((1,1),(2,3));
|
|
select * from t where a = 1 and (b,c) in ((1,1),(2,3));
|
|
explain format='brief' select * from t where a = 1 and ((b = 1 and c = 1) or (b = 2 and c = 3));
|
|
select * from t where a = 1 and ((b = 1 and c = 1) or (b = 2 and c = 3));
|
|
explain format='brief' select * from t where a = 1 and ((b = 1) or (b = 2 and c = 3));
|
|
select * from t where a = 1 and ((b = 1) or (b = 2 and c = 3));
|
|
explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c = 3;
|
|
select * from t where (a,b) in ((1,1),(2,2)) and c = 3;
|
|
explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3;
|
|
select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3;
|
|
explain format='brief' select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3;
|
|
select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3;
|
|
explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c > 2 and (a,b,c) in ((1,1,1),(2,2,3));
|
|
select * from t where (a,b) in ((1,1),(2,2)) and c > 2 and (a,b,c) in ((1,1,1),(2,2,3));
|
|
explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c > 2;
|
|
select * from t where (a,b) in ((1,1),(2,2)) and c > 2;
|
|
explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;
|
|
select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;
|
|
|
|
# TestCompIndexMultiColDNF1
|
|
drop table if exists t;
|
|
create table t(a int, b int, c int, primary key(a,b));
|
|
insert into t values(1,1,1),(2,2,3);
|
|
analyze table t all columns;
|
|
explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c = 3;
|
|
select * from t where (a,b) in ((1,1),(2,2)) and c = 3;
|
|
explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3;
|
|
select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3;
|
|
explain format='brief' select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3;
|
|
select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3;
|
|
explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3 and (a = 1 or a = 2);
|
|
select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3 and (a = 1 or a = 2);
|
|
explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c > 2;
|
|
select * from t where (a,b) in ((1,1),(2,2)) and c > 2;
|
|
explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;
|
|
select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;
|
|
|
|
# TestCompIndexDNFMatch
|
|
set @@session.tidb_regard_null_as_point=false;
|
|
drop table if exists t;
|
|
create table t(a int, b int, c int, key(a,b,c));
|
|
insert into t values(1,2,2);
|
|
explain format='brief' select * from t where a = 1 and b in (1, 2) and c > 1;
|
|
select * from t where a = 1 and b in (1, 2) and c > 1;
|
|
explain format='brief' select * from t where a = 1 and (b = 1 or b = 2) and c > 1;
|
|
select * from t where a = 1 and (b = 1 or b = 2) and c > 1;
|
|
explain format='brief' select * from t where a = 1 and (b = 1 or b in (2, 3)) and c > 1;
|
|
select * from t where a = 1 and (b = 1 or b in (2, 3)) and c > 1;
|
|
explain format='brief' select * from t where a = 1 and (b = 1 or b = 2) and b = 3 and c > 1;
|
|
select * from t where a = 1 and (b = 1 or b = 2) and b = 3 and c > 1;
|
|
explain format='brief' select * from t where a = 1 and (b is null or b = 2);
|
|
select * from t where a = 1 and (b is null or b = 2);
|
|
explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;
|
|
select * from t where a = 1 and (b is null or b = 2) and c > 1;
|
|
explain format='brief' select * from t where a = 1 and b is null and c > 1;
|
|
select * from t where a = 1 and b is null and c > 1;
|
|
explain format='brief' select * from t where a = 1 and b is null and b is null and c > 1;
|
|
select * from t where a = 1 and b is null and b is null and c > 1;
|
|
explain format='brief' select * from t where a = 1 and b is null and b = 1 and c > 1;
|
|
select * from t where a = 1 and b is null and b = 1 and c > 1;
|
|
set @@session.tidb_regard_null_as_point=default;
|
|
|
|
# TestIndexStringIsTrueRange
|
|
set tidb_cost_model_version=2;
|
|
drop table if exists t0;
|
|
CREATE TABLE t0(c0 TEXT(10));
|
|
INSERT INTO t0(c0) VALUES (1);
|
|
CREATE INDEX i0 ON t0(c0(255));
|
|
analyze table t0;
|
|
explain format = 'brief' select * from t0 where c0;
|
|
explain format = 'brief' select * from t0 where c0 and c0 > '123';
|
|
explain format = 'brief' select * from t0 where c0 and c0 <> '123';
|
|
explain format = 'brief' select * from t0 where c0 is true;
|
|
explain format = 'brief' select * from t0 where c0 is false;
|
|
explain format = 'brief' select * from t0 where c0 and c0 in ('123','456','789');
|
|
explain format = 'brief' select * FROM t0 WHERE ('a' != t0.c0) AND t0.c0;
|
|
set tidb_cost_model_version=default;
|
|
|
|
# TestCompIndexInExprCorrCol
|
|
set tidb_cost_model_version=2;
|
|
drop table if exists t;
|
|
create table t(a int primary key, b int, c int, d int, e int, index idx(b,c,d));
|
|
insert into t values(1,1,1,1,2),(2,1,2,1,0);
|
|
analyze table t;
|
|
explain format = 'brief' select t.e in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c in (1, 2) and s.d = t.a and s.a = t1.a) from t;
|
|
select t.e in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c in (1, 2) and s.d = t.a and s.a = t1.a) from t;
|
|
set tidb_cost_model_version=default;
|
|
|
|
# TestIndexRangeEliminatedProjection
|
|
drop table if exists t;
|
|
create table t(a int not null, b int not null, primary key(a,b));
|
|
insert into t values(1,2);
|
|
analyze table t;
|
|
explain format = 'brief' select * from (select * from t union all select a, b from t) sub where a > 0;
|
|
select * from (select * from t union all select ifnull(a,b), b from t) sub where a > 0;
|
|
|