From 21a91db8ed91d905ea354e73acb9c9a48fffac69 Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Fri, 22 Sep 2023 17:45:22 +0800 Subject: [PATCH] tests, util: move IT in `util/` to `tests/integrationtest` (#47196) close pingcap/tidb#47177 --- tests/integrationtest/r/util/admin.result | 260 +++++++ tests/integrationtest/r/util/ranger.result | 590 ++++++++++++++++ tests/integrationtest/t/util/admin.test | 256 +++++++ tests/integrationtest/t/util/ranger.test | 219 ++++++ util/admin/BUILD.bazel | 2 - util/admin/admin_integration_test.go | 88 --- util/ranger/BUILD.bazel | 3 - util/ranger/main_test.go | 9 - util/ranger/ranger_test.go | 346 ---------- util/ranger/testdata/ranger_suite_in.json | 127 ---- util/ranger/testdata/ranger_suite_out.json | 760 --------------------- 11 files changed, 1325 insertions(+), 1335 deletions(-) create mode 100644 tests/integrationtest/r/util/admin.result create mode 100644 tests/integrationtest/r/util/ranger.result create mode 100644 tests/integrationtest/t/util/admin.test create mode 100644 tests/integrationtest/t/util/ranger.test delete mode 100644 util/ranger/testdata/ranger_suite_in.json delete mode 100644 util/ranger/testdata/ranger_suite_out.json diff --git a/tests/integrationtest/r/util/admin.result b/tests/integrationtest/r/util/admin.result new file mode 100644 index 0000000000000..9e633def68a0e --- /dev/null +++ b/tests/integrationtest/r/util/admin.result @@ -0,0 +1,260 @@ +drop table if exists t; +create table t(a bigint unsigned primary key, b int, c int, index idx(a, b)); +insert into t values(1, 1, 1); +admin check table t; + +drop table if exists t1; +CREATE TABLE t1 (c1 int); +INSERT INTO t1 SET c1 = 1; +ALTER TABLE t1 ADD COLUMN cc1 CHAR(36) NULL DEFAULT ''; +ALTER TABLE t1 ADD COLUMN cc2 VARCHAR(36) NULL DEFAULT ''; +ALTER TABLE t1 ADD INDEX idx1 (cc1); +ALTER TABLE t1 ADD INDEX idx2 (cc2); +ALTER TABLE t1 engine=innodb; +admin check table t1; + +drop table if exists t1; +create table t1 ( +a int as (JSON_EXTRACT(k,'$.a')), +c double as (JSON_EXTRACT(k,'$.c')), +d decimal(20,10) as (JSON_EXTRACT(k,'$.d')), +e char(10) as (JSON_EXTRACT(k,'$.e')), +f date as (JSON_EXTRACT(k,'$.f')), +g time as (JSON_EXTRACT(k,'$.g')), +h datetime as (JSON_EXTRACT(k,'$.h')), +i timestamp as (JSON_EXTRACT(k,'$.i')), +j year as (JSON_EXTRACT(k,'$.j')), +k json); +insert into t1 set k='{"a": 100,"c":1.234,"d":1.2340000000,"e":"abcdefg","f":"2018-09-28","g":"12:59:59","h":"2018-09-28 12:59:59","i":"2018-09-28 16:40:33","j":"2018"}'; +alter table t1 add index idx_a(a); +alter table t1 add index idx_c(c); +alter table t1 add index idx_d(d); +alter table t1 add index idx_e(e); +alter table t1 add index idx_f(f); +alter table t1 add index idx_g(g); +alter table t1 add index idx_h(h); +alter table t1 add index idx_j(j); +alter table t1 add index idx_i(i); +alter table t1 add index idx_m(a,c,d,e,f,g,h,i,j); +admin check table t1; + +drop table if exists t; +create table t (a bigint, b varchar(255), c int, primary key (a, b), index idx_0(a, b), index idx_1(b, c)); +insert into t values (1, '1', 1); +insert into t values (2, '2', 2); +admin check table t; + +insert into t values (3, '3', 3); +insert into t values (4, '4', 4); +insert into t values (5, '5', 5); +insert into t values (6, '6', 6); +insert into t values (7, '7', 7); +insert into t values (8, '8', 8); +insert into t values (9, '9', 9); +insert into t values (10, '10', 10); +insert into t values (11, '11', 11); +insert into t values (12, '12', 12); +insert into t values (13, '13', 13); +insert into t values (14, '14', 14); +insert into t values (15, '15', 15); +insert into t values (16, '16', 16); +insert into t values (17, '17', 17); +insert into t values (18, '18', 18); +insert into t values (19, '19', 19); +insert into t values (20, '20', 20); +insert into t values (21, '21', 21); +insert into t values (22, '22', 22); +insert into t values (23, '23', 23); +insert into t values (24, '24', 24); +insert into t values (25, '25', 25); +insert into t values (26, '26', 26); +insert into t values (27, '27', 27); +insert into t values (28, '28', 28); +insert into t values (29, '29', 29); +insert into t values (30, '30', 30); +insert into t values (31, '31', 31); +insert into t values (32, '32', 32); +insert into t values (33, '33', 33); +insert into t values (34, '34', 34); +insert into t values (35, '35', 35); +insert into t values (36, '36', 36); +insert into t values (37, '37', 37); +insert into t values (38, '38', 38); +insert into t values (39, '39', 39); +insert into t values (40, '40', 40); +insert into t values (41, '41', 41); +insert into t values (42, '42', 42); +insert into t values (43, '43', 43); +insert into t values (44, '44', 44); +insert into t values (45, '45', 45); +insert into t values (46, '46', 46); +insert into t values (47, '47', 47); +insert into t values (48, '48', 48); +insert into t values (49, '49', 49); +insert into t values (50, '50', 50); +insert into t values (51, '51', 51); +insert into t values (52, '52', 52); +insert into t values (53, '53', 53); +insert into t values (54, '54', 54); +insert into t values (55, '55', 55); +insert into t values (56, '56', 56); +insert into t values (57, '57', 57); +insert into t values (58, '58', 58); +insert into t values (59, '59', 59); +insert into t values (60, '60', 60); +insert into t values (61, '61', 61); +insert into t values (62, '62', 62); +insert into t values (63, '63', 63); +insert into t values (64, '64', 64); +insert into t values (65, '65', 65); +insert into t values (66, '66', 66); +insert into t values (67, '67', 67); +insert into t values (68, '68', 68); +insert into t values (69, '69', 69); +insert into t values (70, '70', 70); +insert into t values (71, '71', 71); +insert into t values (72, '72', 72); +insert into t values (73, '73', 73); +insert into t values (74, '74', 74); +insert into t values (75, '75', 75); +insert into t values (76, '76', 76); +insert into t values (77, '77', 77); +insert into t values (78, '78', 78); +insert into t values (79, '79', 79); +insert into t values (80, '80', 80); +insert into t values (81, '81', 81); +insert into t values (82, '82', 82); +insert into t values (83, '83', 83); +insert into t values (84, '84', 84); +insert into t values (85, '85', 85); +insert into t values (86, '86', 86); +insert into t values (87, '87', 87); +insert into t values (88, '88', 88); +insert into t values (89, '89', 89); +insert into t values (90, '90', 90); +insert into t values (91, '91', 91); +insert into t values (92, '92', 92); +insert into t values (93, '93', 93); +insert into t values (94, '94', 94); +insert into t values (95, '95', 95); +insert into t values (96, '96', 96); +insert into t values (97, '97', 97); +insert into t values (98, '98', 98); +insert into t values (99, '99', 99); +insert into t values (100, '100', 100); +insert into t values (101, '101', 101); +insert into t values (102, '102', 102); +insert into t values (103, '103', 103); +insert into t values (104, '104', 104); +insert into t values (105, '105', 105); +insert into t values (106, '106', 106); +insert into t values (107, '107', 107); +insert into t values (108, '108', 108); +insert into t values (109, '109', 109); +insert into t values (110, '110', 110); +insert into t values (111, '111', 111); +insert into t values (112, '112', 112); +insert into t values (113, '113', 113); +insert into t values (114, '114', 114); +insert into t values (115, '115', 115); +insert into t values (116, '116', 116); +insert into t values (117, '117', 117); +insert into t values (118, '118', 118); +insert into t values (119, '119', 119); +insert into t values (120, '120', 120); +insert into t values (121, '121', 121); +insert into t values (122, '122', 122); +insert into t values (123, '123', 123); +insert into t values (124, '124', 124); +insert into t values (125, '125', 125); +insert into t values (126, '126', 126); +insert into t values (127, '127', 127); +insert into t values (128, '128', 128); +insert into t values (129, '129', 129); +insert into t values (130, '130', 130); +insert into t values (131, '131', 131); +insert into t values (132, '132', 132); +insert into t values (133, '133', 133); +insert into t values (134, '134', 134); +insert into t values (135, '135', 135); +insert into t values (136, '136', 136); +insert into t values (137, '137', 137); +insert into t values (138, '138', 138); +insert into t values (139, '139', 139); +insert into t values (140, '140', 140); +insert into t values (141, '141', 141); +insert into t values (142, '142', 142); +insert into t values (143, '143', 143); +insert into t values (144, '144', 144); +insert into t values (145, '145', 145); +insert into t values (146, '146', 146); +insert into t values (147, '147', 147); +insert into t values (148, '148', 148); +insert into t values (149, '149', 149); +insert into t values (150, '150', 150); +insert into t values (151, '151', 151); +insert into t values (152, '152', 152); +insert into t values (153, '153', 153); +insert into t values (154, '154', 154); +insert into t values (155, '155', 155); +insert into t values (156, '156', 156); +insert into t values (157, '157', 157); +insert into t values (158, '158', 158); +insert into t values (159, '159', 159); +insert into t values (160, '160', 160); +insert into t values (161, '161', 161); +insert into t values (162, '162', 162); +insert into t values (163, '163', 163); +insert into t values (164, '164', 164); +insert into t values (165, '165', 165); +insert into t values (166, '166', 166); +insert into t values (167, '167', 167); +insert into t values (168, '168', 168); +insert into t values (169, '169', 169); +insert into t values (170, '170', 170); +insert into t values (171, '171', 171); +insert into t values (172, '172', 172); +insert into t values (173, '173', 173); +insert into t values (174, '174', 174); +insert into t values (175, '175', 175); +insert into t values (176, '176', 176); +insert into t values (177, '177', 177); +insert into t values (178, '178', 178); +insert into t values (179, '179', 179); +insert into t values (180, '180', 180); +insert into t values (181, '181', 181); +insert into t values (182, '182', 182); +insert into t values (183, '183', 183); +insert into t values (184, '184', 184); +insert into t values (185, '185', 185); +insert into t values (186, '186', 186); +insert into t values (187, '187', 187); +insert into t values (188, '188', 188); +insert into t values (189, '189', 189); +insert into t values (190, '190', 190); +insert into t values (191, '191', 191); +insert into t values (192, '192', 192); +insert into t values (193, '193', 193); +insert into t values (194, '194', 194); +insert into t values (195, '195', 195); +insert into t values (196, '196', 196); +insert into t values (197, '197', 197); +insert into t values (198, '198', 198); +insert into t values (199, '199', 199); +admin check table t; + +create index idx_2 on t (c); +admin check table t; + +create index idx_3 on t (a,c); +admin check table t; + +alter table t add column e char(36); +admin check table t; + +alter table t add column d char(36) NULL DEFAULT ''; +admin check table t; + +insert into t values (1000, '1000', 1000, '1000', '1000'); +admin check table t; + diff --git a/tests/integrationtest/r/util/ranger.result b/tests/integrationtest/r/util/ranger.result new file mode 100644 index 0000000000000..d68da2e9b6eff --- /dev/null +++ b/tests/integrationtest/r/util/ranger.result @@ -0,0 +1,590 @@ +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)); +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.10 cop[tikv] table:t, index:idx_ab(a, b) range:["kk" 1,"kk" 1], ["xx","xx"], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(util__ranger.t.c, 10) + └─TableRowIDScan 10.10 cop[tikv] table:t keep order:false, stats:pseudo +select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1)); +a b c +kk 1 10 +xx 4 10 +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))); +id estRows task access object operator info +IndexLookUp 0.02 root +├─IndexRangeScan(Build) 20.20 cop[tikv] table:t, index:idx_ab(a, b) range:["hh" 2,"hh" 2], ["kk" 1,"kk" 1], ["xx","xx"], ["yy","yy"], keep order:false, stats:pseudo +└─Selection(Probe) 0.02 cop[tikv] eq(util__ranger.t.c, 10) + └─TableRowIDScan 20.20 cop[tikv] table:t keep order:false, stats:pseudo +select * from t where c = 10 and ((a = 'xx' or a = 'yy') or ((a = 'kk' and b = 1) or (a = 'hh' and b = 2))); +a b c +hh 2 10 +kk 1 10 +xx 4 10 +yy 5 10 +set @@tidb_opt_fix_control = default; +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"; +id estRows task access object operator info +IndexLookUp 5.99 root +├─IndexRangeScan(Build) 5.99 cop[tikv] table:IDT_20755, index:u_m_col(COL1, COL2, COL3) range:["剮毵樍穋摻瀽鬦擀钟鷫" 39 -inf,"剮毵樍穋摻瀽鬦擀钟鷫" 39 2024-10-19 08:55:32), ("剮毵樍穋摻瀽鬦擀钟鷫" 39 2024-10-19 08:55:32,"剮毵樍穋摻瀽鬦擀钟鷫" 39 +inf], ["剮毵樍穋摻瀽鬦擀钟鷫" 72 -inf,"剮毵樍穋摻瀽鬦擀钟鷫" 72 2024-10-19 08:55:32), ("剮毵樍穋摻瀽鬦擀钟鷫" 72 2024-10-19 08:55:32,"剮毵樍穋摻瀽鬦擀钟鷫" 72 +inf], ["剮毵樍穋摻瀽鬦擀钟鷫" 73 -inf,"剮毵樍穋摻瀽鬦擀钟鷫" 73 2024-10-19 08:55:32), ("剮毵樍穋摻瀽鬦擀钟鷫" 73 2024-10-19 08:55:32,"剮毵樍穋摻瀽鬦擀钟鷫" 73 +inf], ["物碃貞枕騫摨聫嚣蜻禼" 39 -inf,"物碃貞枕騫摨聫嚣蜻禼" 39 2024-10-19 08:55:32), ("物碃貞枕騫摨聫嚣蜻禼" 39 2024-10-19 08:55:32,"物碃貞枕騫摨聫嚣蜻禼" 39 +inf], ["物碃貞枕騫摨聫嚣蜻禼" 72 -inf,"物碃貞枕騫摨聫嚣蜻禼" 72 2024-10-19 08:55:32), ("物碃貞枕騫摨聫嚣蜻禼" 72 2024-10-19 08:55:32,"物碃貞枕騫摨聫嚣蜻禼" 72 +inf], ["物碃貞枕騫摨聫嚣蜻禼" 73 -inf,"物碃貞枕騫摨聫嚣蜻禼" 73 2024-10-19 08:55:32), ("物碃貞枕騫摨聫嚣蜻禼" 73 2024-10-19 08:55:32,"物碃貞枕騫摨聫嚣蜻禼" 73 +inf], ["牾窓螎刳闌蜹瑦詬鍖湪" 39 -inf,"牾窓螎刳闌蜹瑦詬鍖湪" 39 2024-10-19 08:55:32), ("牾窓螎刳闌蜹瑦詬鍖湪" 39 2024-10-19 08:55:32,"牾窓螎刳闌蜹瑦詬鍖湪" 39 +inf], ["牾窓螎刳闌蜹瑦詬鍖湪" 72 -inf,"牾窓螎刳闌蜹瑦詬鍖湪" 72 2024-10-19 08:55:32), ("牾窓螎刳闌蜹瑦詬鍖湪" 72 2024-10-19 08:55:32,"牾窓螎刳闌蜹瑦詬鍖湪" 72 +inf], ["牾窓螎刳闌蜹瑦詬鍖湪" 73 -inf,"牾窓螎刳闌蜹瑦詬鍖湪" 73 2024-10-19 08:55:32), ("牾窓螎刳闌蜹瑦詬鍖湪" 73 2024-10-19 08:55:32,"牾窓螎刳闌蜹瑦詬鍖湪" 73 +inf], keep order:false, stats:pseudo +└─Selection(Probe) 5.99 cop[tikv] in(util__ranger.idt_20755.col1, "牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆", "物碃貞枕騫摨聫嚣蜻禼担堋黕詖蝒毎槒阆畒郒", "剮毵樍穋摻瀽鬦擀钟鷫產冖悄乮曙枱诠鑡轰砠") + └─TableRowIDScan 5.99 cop[tikv] table:IDT_20755 keep order:false, stats:pseudo +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"; +COL1 COL2 COL3 +牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆 73 2010-06-03 07:29:05 +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"; +id estRows task access object operator info +IndexLookUp 1.33 root +├─IndexRangeScan(Build) 1.33 cop[tikv] table:IDT_20755, index:u_m_col(COL1, COL2, COL3) range:["xxxxxxxxxx" 72 -inf,"xxxxxxxxxx" 72 2024-10-19 08:55:32), ("xxxxxxxxxx" 72 2024-10-19 08:55:32,"xxxxxxxxxx" 72 +inf], ["xxxxxxxxxx" 73 -inf,"xxxxxxxxxx" 73 2024-10-19 08:55:32), ("xxxxxxxxxx" 73 2024-10-19 08:55:32,"xxxxxxxxxx" 73 +inf], keep order:false, stats:pseudo +└─Selection(Probe) 1.33 cop[tikv] eq(util__ranger.idt_20755.col1, "xxxxxxxxxxxxxxx") + └─TableRowIDScan 1.33 cop[tikv] table:IDT_20755 keep order:false, stats:pseudo +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"; +COL1 COL2 COL3 +xxxxxxxxxxxxxxx 73 2010-06-03 07:29:05 +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"; +id estRows task access object operator info +IndexLookUp 2.00 root +├─IndexRangeScan(Build) 2.00 cop[tikv] table:IDT_20755, index:u_m_col(COL1, COL2, COL3) range:["xxxxxxxxxx" 72 -inf,"xxxxxxxxxx" 72 2024-10-19 08:55:32), ("xxxxxxxxxx" 72 2024-10-19 08:55:32,"xxxxxxxxxx" 72 +inf], ["xxxxxxxxxx" 73 -inf,"xxxxxxxxxx" 73 2024-10-19 08:55:32), ("xxxxxxxxxx" 73 2024-10-19 08:55:32,"xxxxxxxxxx" 73 +inf], ["xxxxxxxxxx" 74 -inf,"xxxxxxxxxx" 74 2024-10-19 08:55:32), ("xxxxxxxxxx" 74 2024-10-19 08:55:32,"xxxxxxxxxx" 74 +inf], keep order:false, stats:pseudo +└─Selection(Probe) 2.00 cop[tikv] eq(util__ranger.idt_20755.col1, "xxxxxxxxxxxxxxx") + └─TableRowIDScan 2.00 cop[tikv] table:IDT_20755 keep order:false, stats:pseudo +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"; +COL1 COL2 COL3 +xxxxxxxxxxxxxxx 73 2010-06-03 07:29:05 +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); +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t1, index:a(a) range:[0,0], keep order:false, stats:pseudo +select * from t1 use index(a) where a in (-1,0); +a +0 +explain format = 'brief' select * from t1 use index(a) where a = -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t1 use index(a) where a = -1; +a +explain format = 'brief' select * from t1 use index(a) where a > -1; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:a(a) range:[0,+inf], keep order:false, stats:pseudo +select * from t1 use index(a) where a > -1; +a +0 +explain format = 'brief' select * from t1 use index(a) where a < -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t1 use index(a) where a < -1; +a +explain format = 'brief' select * from t1 use index(a) where a <= -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t1 use index(a) where a <= -1; +a +explain format = 'brief' select * from t1 use index(a) where a >= -1; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:a(a) range:[0,+inf], keep order:false, stats:pseudo +select * from t1 use index(a) where a >= -1; +a +0 +explain format = 'brief' select * from t2 use index(idx) where a = 1 and b in (-1,0); +id estRows task access object operator info +IndexReader 0.10 root index:IndexRangeScan +└─IndexRangeScan 0.10 cop[tikv] table:t2, index:idx(a, b) range:[1 0,1 0], keep order:false, stats:pseudo +select * from t2 use index(idx) where a = 1 and b in (-1,0); +a b +1 0 +explain format = 'brief' select * from t2 use index(idx) where a = 1 and b = -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t2 use index(idx) where a = 1 and b = -1; +a b +explain format = 'brief' select * from t2 use index(idx) where a = 1 and b > -1; +id estRows task access object operator info +IndexReader 33.33 root index:IndexRangeScan +└─IndexRangeScan 33.33 cop[tikv] table:t2, index:idx(a, b) range:[1 0,1 +inf], keep order:false, stats:pseudo +select * from t2 use index(idx) where a = 1 and b > -1; +a b +1 0 +explain format = 'brief' select * from t2 use index(idx) where a = 1 and b < -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t2 use index(idx) where a = 1 and b < -1; +a b +explain format = 'brief' select * from t2 use index(idx) where a = 1 and b <= -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t2 use index(idx) where a = 1 and b <= -1; +a b +explain format = 'brief' select * from t2 use index(idx) where a = 1 and b >= -1; +id estRows task access object operator info +IndexReader 33.33 root index:IndexRangeScan +└─IndexRangeScan 33.33 cop[tikv] table:t2, index:idx(a, b) range:[1 0,1 +inf], keep order:false, stats:pseudo +select * from t2 use index(idx) where a = 1 and b >= -1; +a b +1 0 +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; +explain format='brief' select * from t; +id estRows task access object operator info +PartitionUnion 4.00 root +├─TableReader 1.00 root data:TableFullScan +│ └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 3.00 root data:TableFullScan + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t; +a b + 0 + -1 + 1 + 3 +explain format='brief' select * from t where a = 0; +id estRows task access object operator info +TableReader 1.00 root data:Selection +└─Selection 1.00 cop[tikv] eq(util__ranger.t.a, 0) + └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +select * from t where a = 0; +a b + 0 +explain format='brief' select * from t where a = 0 or a = 4; +id estRows task access object operator info +TableReader 1.00 root data:Selection +└─Selection 1.00 cop[tikv] or(eq(util__ranger.t.a, 0), eq(util__ranger.t.a, 4)) + └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +select * from t where a = 0 or a = 4; +a b + 0 +explain format='brief' select * from t where a = 1; +id estRows task access object operator info +TableReader 3.00 root data:Selection +└─Selection 3.00 cop[tikv] eq(util__ranger.t.a, 1) + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t where a = 1; +a b + -1 + 1 + 3 +explain format='brief' select * from t where a = -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t where a = -1; +a b +explain format='brief' select * from t where a = 3; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t where a = 3; +a b +explain format='brief' select * from t where a < 1; +id estRows task access object operator info +PartitionUnion 1.00 root +├─TableReader 1.00 root data:Selection +│ └─Selection 1.00 cop[tikv] lt(util__ranger.t.a, 1) +│ └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 0.00 root data:Selection + └─Selection 0.00 cop[tikv] lt(util__ranger.t.a, 1) + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t where a < 1; +a b + 0 +explain format='brief' select * from t where a < 3; +id estRows task access object operator info +PartitionUnion 4.00 root +├─TableReader 1.00 root data:Selection +│ └─Selection 1.00 cop[tikv] lt(util__ranger.t.a, 3) +│ └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 3.00 root data:Selection + └─Selection 3.00 cop[tikv] lt(util__ranger.t.a, 3) + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t where a < 3; +a b + 0 + -1 + 1 + 3 +explain format='brief' select * from t where a < -1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t where a < -1; +a b +explain format='brief' select * from t where a > 0; +id estRows task access object operator info +PartitionUnion 3.00 root +├─TableReader 0.00 root data:Selection +│ └─Selection 0.00 cop[tikv] gt(util__ranger.t.a, 0) +│ └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 3.00 root data:Selection + └─Selection 3.00 cop[tikv] gt(util__ranger.t.a, 0) + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t where a > 0; +a b + -1 + 1 + 3 +explain format='brief' select * from t where a > -1; +id estRows task access object operator info +PartitionUnion 4.00 root +├─TableReader 1.00 root data:Selection +│ └─Selection 1.00 cop[tikv] gt(util__ranger.t.a, -1) +│ └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 3.00 root data:Selection + └─Selection 3.00 cop[tikv] gt(util__ranger.t.a, -1) + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t where a > -1; +a b + 0 + -1 + 1 + 3 +explain format='brief' select * from t where a > 3; +id estRows task access object operator info +PartitionUnion 0.00 root +├─TableReader 0.00 root data:Selection +│ └─Selection 0.00 cop[tikv] gt(util__ranger.t.a, 3) +│ └─TableFullScan 1.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 0.00 root data:Selection + └─Selection 0.00 cop[tikv] gt(util__ranger.t.a, 3) + └─TableFullScan 3.00 cop[tikv] table:t, partition:p1 keep order:false +select * from t where a > 3; +a b +set @@tidb_partition_prune_mode = default; +set @@tidb_executor_concurrency = default; +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'; +id estRows task access object operator info +IndexLookUp 10.00 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:t(t) range:["aaa","aaa"], keep order:false, stats:pseudo +└─Selection(Probe) 10.00 cop[tikv] eq(util__ranger.t2.t, "aaaa") + └─TableRowIDScan 10.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select * from t2 where t='aaaa'; +id t +1 aaaa +explain format='brief' select * from t2 where t='aaaa' or t = 'a'; +id estRows task access object operator info +IndexLookUp 16.00 root +├─IndexRangeScan(Build) 20.00 cop[tikv] table:t2, index:t(t) range:["a","a"], ["aaa","aaa"], keep order:false, stats:pseudo +└─Selection(Probe) 16.00 cop[tikv] or(eq(util__ranger.t2.t, "aaaa"), eq(util__ranger.t2.t, "a")) + └─TableRowIDScan 20.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select * from t2 where t='aaaa' or t = 'a'; +id t +1 aaaa +2 a +analyze table t2; +explain format='brief' select * from t2 where t='aaaa'; +id estRows task access object operator info +TableReader 1.00 root data:Selection +└─Selection 1.00 cop[tikv] eq(util__ranger.t2.t, "aaaa") + └─TableFullScan 2.00 cop[tikv] table:t2 keep order:false +select * from t2 where t='aaaa'; +id t +1 aaaa +explain format='brief' select * from t2 where t='aaaa' or t = 'a'; +id estRows task access object operator info +TableReader 1.60 root data:Selection +└─Selection 1.60 cop[tikv] or(eq(util__ranger.t2.t, "aaaa"), eq(util__ranger.t2.t, "a")) + └─TableFullScan 2.00 cop[tikv] table:t2 keep order:false +select * from t2 where t='aaaa' or t = 'a'; +id t +1 aaaa +2 a +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; +id estRows task access object operator info +IndexLookUp 1.00 root +├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:idx(a, b, c) range:("t" 1 2,"t" 1 +inf], ("t" 2 2,"t" 2 +inf], ("w" 0 2,"w" 0 +inf], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo +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; +a b c d +t 1 3 3 +t 2 3 1 +w 0 3 3 +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; +id estRows task access object operator info +IndexLookUp 0.10 root +├─IndexRangeScan(Build) 0.30 cop[tikv] table:t, index:idx(a, b, c) range:["t" 1,"t" 1], ["t" 2,"t" 2], ["w" 0,"w" 0], keep order:false, stats:pseudo +└─Selection(Probe) 0.10 cop[tikv] gt(util__ranger.t.d, 2) + └─TableRowIDScan 0.30 cop[tikv] table:t keep order:false, stats:pseudo +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; +a b c d +t 1 3 3 +t 2 1 3 +w 0 3 3 +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)); +id estRows task access object operator info +Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b, c) keep order:false, desc:false +select * from t where a = 1 and (b,c) in ((1,1),(2,3)); +a b c +1 1 1 +explain format='brief' select * from t where a = 1 and ((b = 1 and c = 1) or (b = 2 and c = 3)); +id estRows task access object operator info +Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b, c) keep order:false, desc:false +select * from t where a = 1 and ((b = 1 and c = 1) or (b = 2 and c = 3)); +a b c +1 1 1 +explain format='brief' select * from t where a = 1 and ((b = 1) or (b = 2 and c = 3)); +id estRows task access object operator info +IndexReader 1.71 root index:IndexRangeScan +└─IndexRangeScan 1.71 cop[tikv] table:t, index:PRIMARY(a, b, c) range:[1 1,1 1], [1 2 3,1 2 3], keep order:false +select * from t where a = 1 and ((b = 1) or (b = 2 and c = 3)); +a b c +1 1 1 +explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c = 3; +id estRows task access object operator info +Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b, c) keep order:false, desc:false +select * from t where (a,b) in ((1,1),(2,2)) and c = 3; +a b c +2 2 3 +explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3; +id estRows task access object operator info +Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b, c) keep order:false, desc:false +select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3; +a b c +2 2 3 +explain format='brief' select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3; +id estRows task access object operator info +IndexReader 0.68 root index:Selection +└─Selection 0.68 cop[tikv] eq(util__ranger.t.c, 3), or(eq(util__ranger.t.a, 1), and(eq(util__ranger.t.a, 2), eq(util__ranger.t.b, 2))) + └─IndexRangeScan 2.00 cop[tikv] table:t, index:PRIMARY(a, b, c) range:[1,1], [2,2], keep order:false +select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3; +a b c +2 2 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)); +id estRows task access object operator info +Selection 0.58 root gt(util__ranger.t.c, 2), or(and(eq(util__ranger.t.a, 1), eq(util__ranger.t.b, 1)), and(eq(util__ranger.t.a, 2), eq(util__ranger.t.b, 2))) +└─Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b, c) keep order:false, desc:false +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)); +a b c +2 2 3 +explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c > 2; +id estRows task access object operator info +IndexReader 1.19 root index:IndexRangeScan +└─IndexRangeScan 1.19 cop[tikv] table:t, index:PRIMARY(a, b, c) range:(1 1 2,1 1 +inf], (2 2 2,2 2 +inf], keep order:false +select * from t where (a,b) in ((1,1),(2,2)) and c > 2; +a b c +2 2 3 +explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2; +id estRows task access object operator info +IndexReader 1.19 root index:IndexRangeScan +└─IndexRangeScan 1.19 cop[tikv] table:t, index:PRIMARY(a, b, c) range:(1 1 2,1 1 +inf], (2 2 2,2 2 +inf], keep order:false +select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2; +a b c +2 2 3 +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; +explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c = 3; +id estRows task access object operator info +Selection 1.00 root eq(util__ranger.t.c, 3) +└─Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b) keep order:false, desc:false +select * from t where (a,b) in ((1,1),(2,2)) and c = 3; +a b c +2 2 3 +explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3; +id estRows task access object operator info +Selection 1.00 root eq(util__ranger.t.c, 3) +└─Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b) keep order:false, desc:false +select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3; +a b c +2 2 3 +explain format='brief' select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3; +id estRows task access object operator info +IndexLookUp 0.75 root +├─Selection(Build) 2.00 cop[tikv] or(eq(util__ranger.t.a, 1), and(eq(util__ranger.t.a, 2), eq(util__ranger.t.b, 2))) +│ └─IndexRangeScan 2.00 cop[tikv] table:t, index:PRIMARY(a, b) range:[1,1], [2,2], keep order:false +└─Selection(Probe) 0.75 cop[tikv] eq(util__ranger.t.c, 3) + └─TableRowIDScan 2.00 cop[tikv] table:t keep order:false +select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3; +a b c +2 2 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); +id estRows task access object operator info +Selection 1.00 root eq(util__ranger.t.c, 3), or(eq(util__ranger.t.a, 1), eq(util__ranger.t.a, 2)) +└─Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b) keep order:false, desc:false +select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3 and (a = 1 or a = 2); +a b c +2 2 3 +explain format='brief' select * from t where (a,b) in ((1,1),(2,2)) and c > 2; +id estRows task access object operator info +Selection 1.00 root gt(util__ranger.t.c, 2) +└─Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b) keep order:false, desc:false +select * from t where (a,b) in ((1,1),(2,2)) and c > 2; +a b c +2 2 3 +explain format='brief' select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2; +id estRows task access object operator info +Selection 1.00 root gt(util__ranger.t.c, 2) +└─Batch_Point_Get 2.00 root table:t, index:PRIMARY(a, b) keep order:false, desc:false +select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2; +a b c +2 2 3 +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; +id estRows task access object operator info +IndexReader 0.67 root index:IndexRangeScan +└─IndexRangeScan 0.67 cop[tikv] table:t, index:a(a, b, c) range:(1 1 1,1 1 +inf], (1 2 1,1 2 +inf], keep order:false, stats:pseudo +select * from t where a = 1 and b in (1, 2) and c > 1; +a b c +1 2 2 +explain format='brief' select * from t where a = 1 and (b = 1 or b = 2) and c > 1; +id estRows task access object operator info +IndexReader 0.67 root index:IndexRangeScan +└─IndexRangeScan 0.67 cop[tikv] table:t, index:a(a, b, c) range:(1 1 1,1 1 +inf], (1 2 1,1 2 +inf], keep order:false, stats:pseudo +select * from t where a = 1 and (b = 1 or b = 2) and c > 1; +a b c +1 2 2 +explain format='brief' select * from t where a = 1 and (b = 1 or b in (2, 3)) and c > 1; +id estRows task access object operator info +IndexReader 1.00 root index:IndexRangeScan +└─IndexRangeScan 1.00 cop[tikv] table:t, index:a(a, b, c) range:(1 1 1,1 1 +inf], (1 2 1,1 2 +inf], (1 3 1,1 3 +inf], keep order:false, stats:pseudo +select * from t where a = 1 and (b = 1 or b in (2, 3)) and c > 1; +a b c +1 2 2 +explain format='brief' select * from t where a = 1 and (b = 1 or b = 2) and b = 3 and c > 1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t where a = 1 and (b = 1 or b = 2) and b = 3 and c > 1; +a b c +explain format='brief' select * from t where a = 1 and (b is null or b = 2); +id estRows task access object operator info +IndexReader 0.20 root index:IndexRangeScan +└─IndexRangeScan 0.20 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], [1 2,1 2], keep order:false, stats:pseudo +select * from t where a = 1 and (b is null or b = 2); +a b c +1 2 2 +explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1; +id estRows task access object operator info +IndexReader 0.07 root index:Selection +└─Selection 0.07 cop[tikv] gt(util__ranger.t.c, 1) + └─IndexRangeScan 0.20 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], [1 2,1 2], keep order:false, stats:pseudo +select * from t where a = 1 and (b is null or b = 2) and c > 1; +a b c +1 2 2 +explain format='brief' select * from t where a = 1 and b is null and c > 1; +id estRows task access object operator info +IndexReader 0.03 root index:Selection +└─Selection 0.03 cop[tikv] gt(util__ranger.t.c, 1) + └─IndexRangeScan 0.10 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], keep order:false, stats:pseudo +select * from t where a = 1 and b is null and c > 1; +a b c +explain format='brief' select * from t where a = 1 and b is null and b is null and c > 1; +id estRows task access object operator info +IndexReader 0.03 root index:Selection +└─Selection 0.03 cop[tikv] gt(util__ranger.t.c, 1) + └─IndexRangeScan 0.10 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], keep order:false, stats:pseudo +select * from t where a = 1 and b is null and b is null and c > 1; +a b c +explain format='brief' select * from t where a = 1 and b is null and b = 1 and c > 1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select * from t where a = 1 and b is null and b = 1 and c > 1; +a b c +set @@session.tidb_regard_null_as_point=default; +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; +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] util__ranger.t0.c0 + └─IndexFullScan 1.00 cop[tikv] table:t0, index:i0(c0) keep order:false +explain format = 'brief' select * from t0 where c0 and c0 > '123'; +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] util__ranger.t0.c0 + └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:("123",+inf], keep order:false +explain format = 'brief' select * from t0 where c0 and c0 <> '123'; +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] util__ranger.t0.c0 + └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:[-inf,"123"), ("123",+inf], keep order:false +explain format = 'brief' select * from t0 where c0 is true; +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] istrue(cast(util__ranger.t0.c0, double BINARY)) + └─IndexFullScan 1.00 cop[tikv] table:t0, index:i0(c0) keep order:false +explain format = 'brief' select * from t0 where c0 is false; +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] isfalse(cast(util__ranger.t0.c0, double BINARY)) + └─IndexFullScan 1.00 cop[tikv] table:t0, index:i0(c0) keep order:false +explain format = 'brief' select * from t0 where c0 and c0 in ('123','456','789'); +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] util__ranger.t0.c0 + └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:["123","123"], ["456","456"], ["789","789"], keep order:false +explain format = 'brief' select * FROM t0 WHERE ('a' != t0.c0) AND t0.c0; +id estRows task access object operator info +IndexReader 1.00 root index:Selection +└─Selection 1.00 cop[tikv] util__ranger.t0.c0 + └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:[-inf,"a"), ("a",+inf], keep order:false +set tidb_cost_model_version=default; +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; +id estRows task access object operator info +Projection 2.00 root Column#27 +└─Apply 2.00 root CARTESIAN left outer semi join, other cond:eq(util__ranger.t.e, Column#26) + ├─TableReader(Build) 2.00 root data:TableFullScan + │ └─TableFullScan 2.00 cop[tikv] table:t keep order:false + └─StreamAgg(Probe) 2.00 root funcs:count(1)->Column#26 + └─HashJoin 4.00 root inner join, equal:[eq(util__ranger.t.a, util__ranger.t.a)] + ├─IndexReader(Build) 4.00 root index:IndexFullScan + │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:idx(b, c, d) keep order:false + └─IndexReader(Probe) 4.00 root index:IndexRangeScan + └─IndexRangeScan 4.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(util__ranger.t.b, 1) in(util__ranger.t.c, 1, 2) eq(util__ranger.t.d, util__ranger.t.a)], keep order:false +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; +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) +1 +1 +set tidb_cost_model_version=default; +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; +id estRows task access object operator info +Union 2.00 root +├─IndexReader 1.00 root index:IndexRangeScan +│ └─IndexRangeScan 1.00 cop[tikv] table:t, index:PRIMARY(a, b) range:(0,+inf], keep order:false +└─IndexReader 1.00 root index:IndexRangeScan + └─IndexRangeScan 1.00 cop[tikv] table:t, index:PRIMARY(a, b) range:(0,+inf], keep order:false +select * from (select * from t union all select ifnull(a,b), b from t) sub where a > 0; +a b +1 2 +1 2 diff --git a/tests/integrationtest/t/util/admin.test b/tests/integrationtest/t/util/admin.test new file mode 100644 index 0000000000000..19afa81ef5131 --- /dev/null +++ b/tests/integrationtest/t/util/admin.test @@ -0,0 +1,256 @@ +# TestAdminCheckTable +drop table if exists t; +create table t(a bigint unsigned primary key, b int, c int, index idx(a, b)); +insert into t values(1, 1, 1); +admin check table t; +drop table if exists t1; +CREATE TABLE t1 (c1 int); +INSERT INTO t1 SET c1 = 1; +ALTER TABLE t1 ADD COLUMN cc1 CHAR(36) NULL DEFAULT ''; +ALTER TABLE t1 ADD COLUMN cc2 VARCHAR(36) NULL DEFAULT ''; +ALTER TABLE t1 ADD INDEX idx1 (cc1); +ALTER TABLE t1 ADD INDEX idx2 (cc2); +ALTER TABLE t1 engine=innodb; +admin check table t1; +drop table if exists t1; +create table t1 ( + a int as (JSON_EXTRACT(k,'$.a')), + c double as (JSON_EXTRACT(k,'$.c')), + d decimal(20,10) as (JSON_EXTRACT(k,'$.d')), + e char(10) as (JSON_EXTRACT(k,'$.e')), + f date as (JSON_EXTRACT(k,'$.f')), + g time as (JSON_EXTRACT(k,'$.g')), + h datetime as (JSON_EXTRACT(k,'$.h')), + i timestamp as (JSON_EXTRACT(k,'$.i')), + j year as (JSON_EXTRACT(k,'$.j')), + k json); +insert into t1 set k='{"a": 100,"c":1.234,"d":1.2340000000,"e":"abcdefg","f":"2018-09-28","g":"12:59:59","h":"2018-09-28 12:59:59","i":"2018-09-28 16:40:33","j":"2018"}'; +alter table t1 add index idx_a(a); +alter table t1 add index idx_c(c); +alter table t1 add index idx_d(d); +alter table t1 add index idx_e(e); +alter table t1 add index idx_f(f); +alter table t1 add index idx_g(g); +alter table t1 add index idx_h(h); +alter table t1 add index idx_j(j); +alter table t1 add index idx_i(i); +alter table t1 add index idx_m(a,c,d,e,f,g,h,i,j); +admin check table t1; + +# TestAdminCheckTableClusterIndex +drop table if exists t; +create table t (a bigint, b varchar(255), c int, primary key (a, b), index idx_0(a, b), index idx_1(b, c)); +insert into t values (1, '1', 1); +insert into t values (2, '2', 2); +admin check table t; +insert into t values (3, '3', 3); +insert into t values (4, '4', 4); +insert into t values (5, '5', 5); +insert into t values (6, '6', 6); +insert into t values (7, '7', 7); +insert into t values (8, '8', 8); +insert into t values (9, '9', 9); +insert into t values (10, '10', 10); +insert into t values (11, '11', 11); +insert into t values (12, '12', 12); +insert into t values (13, '13', 13); +insert into t values (14, '14', 14); +insert into t values (15, '15', 15); +insert into t values (16, '16', 16); +insert into t values (17, '17', 17); +insert into t values (18, '18', 18); +insert into t values (19, '19', 19); +insert into t values (20, '20', 20); +insert into t values (21, '21', 21); +insert into t values (22, '22', 22); +insert into t values (23, '23', 23); +insert into t values (24, '24', 24); +insert into t values (25, '25', 25); +insert into t values (26, '26', 26); +insert into t values (27, '27', 27); +insert into t values (28, '28', 28); +insert into t values (29, '29', 29); +insert into t values (30, '30', 30); +insert into t values (31, '31', 31); +insert into t values (32, '32', 32); +insert into t values (33, '33', 33); +insert into t values (34, '34', 34); +insert into t values (35, '35', 35); +insert into t values (36, '36', 36); +insert into t values (37, '37', 37); +insert into t values (38, '38', 38); +insert into t values (39, '39', 39); +insert into t values (40, '40', 40); +insert into t values (41, '41', 41); +insert into t values (42, '42', 42); +insert into t values (43, '43', 43); +insert into t values (44, '44', 44); +insert into t values (45, '45', 45); +insert into t values (46, '46', 46); +insert into t values (47, '47', 47); +insert into t values (48, '48', 48); +insert into t values (49, '49', 49); +insert into t values (50, '50', 50); +insert into t values (51, '51', 51); +insert into t values (52, '52', 52); +insert into t values (53, '53', 53); +insert into t values (54, '54', 54); +insert into t values (55, '55', 55); +insert into t values (56, '56', 56); +insert into t values (57, '57', 57); +insert into t values (58, '58', 58); +insert into t values (59, '59', 59); +insert into t values (60, '60', 60); +insert into t values (61, '61', 61); +insert into t values (62, '62', 62); +insert into t values (63, '63', 63); +insert into t values (64, '64', 64); +insert into t values (65, '65', 65); +insert into t values (66, '66', 66); +insert into t values (67, '67', 67); +insert into t values (68, '68', 68); +insert into t values (69, '69', 69); +insert into t values (70, '70', 70); +insert into t values (71, '71', 71); +insert into t values (72, '72', 72); +insert into t values (73, '73', 73); +insert into t values (74, '74', 74); +insert into t values (75, '75', 75); +insert into t values (76, '76', 76); +insert into t values (77, '77', 77); +insert into t values (78, '78', 78); +insert into t values (79, '79', 79); +insert into t values (80, '80', 80); +insert into t values (81, '81', 81); +insert into t values (82, '82', 82); +insert into t values (83, '83', 83); +insert into t values (84, '84', 84); +insert into t values (85, '85', 85); +insert into t values (86, '86', 86); +insert into t values (87, '87', 87); +insert into t values (88, '88', 88); +insert into t values (89, '89', 89); +insert into t values (90, '90', 90); +insert into t values (91, '91', 91); +insert into t values (92, '92', 92); +insert into t values (93, '93', 93); +insert into t values (94, '94', 94); +insert into t values (95, '95', 95); +insert into t values (96, '96', 96); +insert into t values (97, '97', 97); +insert into t values (98, '98', 98); +insert into t values (99, '99', 99); +insert into t values (100, '100', 100); +insert into t values (101, '101', 101); +insert into t values (102, '102', 102); +insert into t values (103, '103', 103); +insert into t values (104, '104', 104); +insert into t values (105, '105', 105); +insert into t values (106, '106', 106); +insert into t values (107, '107', 107); +insert into t values (108, '108', 108); +insert into t values (109, '109', 109); +insert into t values (110, '110', 110); +insert into t values (111, '111', 111); +insert into t values (112, '112', 112); +insert into t values (113, '113', 113); +insert into t values (114, '114', 114); +insert into t values (115, '115', 115); +insert into t values (116, '116', 116); +insert into t values (117, '117', 117); +insert into t values (118, '118', 118); +insert into t values (119, '119', 119); +insert into t values (120, '120', 120); +insert into t values (121, '121', 121); +insert into t values (122, '122', 122); +insert into t values (123, '123', 123); +insert into t values (124, '124', 124); +insert into t values (125, '125', 125); +insert into t values (126, '126', 126); +insert into t values (127, '127', 127); +insert into t values (128, '128', 128); +insert into t values (129, '129', 129); +insert into t values (130, '130', 130); +insert into t values (131, '131', 131); +insert into t values (132, '132', 132); +insert into t values (133, '133', 133); +insert into t values (134, '134', 134); +insert into t values (135, '135', 135); +insert into t values (136, '136', 136); +insert into t values (137, '137', 137); +insert into t values (138, '138', 138); +insert into t values (139, '139', 139); +insert into t values (140, '140', 140); +insert into t values (141, '141', 141); +insert into t values (142, '142', 142); +insert into t values (143, '143', 143); +insert into t values (144, '144', 144); +insert into t values (145, '145', 145); +insert into t values (146, '146', 146); +insert into t values (147, '147', 147); +insert into t values (148, '148', 148); +insert into t values (149, '149', 149); +insert into t values (150, '150', 150); +insert into t values (151, '151', 151); +insert into t values (152, '152', 152); +insert into t values (153, '153', 153); +insert into t values (154, '154', 154); +insert into t values (155, '155', 155); +insert into t values (156, '156', 156); +insert into t values (157, '157', 157); +insert into t values (158, '158', 158); +insert into t values (159, '159', 159); +insert into t values (160, '160', 160); +insert into t values (161, '161', 161); +insert into t values (162, '162', 162); +insert into t values (163, '163', 163); +insert into t values (164, '164', 164); +insert into t values (165, '165', 165); +insert into t values (166, '166', 166); +insert into t values (167, '167', 167); +insert into t values (168, '168', 168); +insert into t values (169, '169', 169); +insert into t values (170, '170', 170); +insert into t values (171, '171', 171); +insert into t values (172, '172', 172); +insert into t values (173, '173', 173); +insert into t values (174, '174', 174); +insert into t values (175, '175', 175); +insert into t values (176, '176', 176); +insert into t values (177, '177', 177); +insert into t values (178, '178', 178); +insert into t values (179, '179', 179); +insert into t values (180, '180', 180); +insert into t values (181, '181', 181); +insert into t values (182, '182', 182); +insert into t values (183, '183', 183); +insert into t values (184, '184', 184); +insert into t values (185, '185', 185); +insert into t values (186, '186', 186); +insert into t values (187, '187', 187); +insert into t values (188, '188', 188); +insert into t values (189, '189', 189); +insert into t values (190, '190', 190); +insert into t values (191, '191', 191); +insert into t values (192, '192', 192); +insert into t values (193, '193', 193); +insert into t values (194, '194', 194); +insert into t values (195, '195', 195); +insert into t values (196, '196', 196); +insert into t values (197, '197', 197); +insert into t values (198, '198', 198); +insert into t values (199, '199', 199); +admin check table t; +# Test back filled created index data. +create index idx_2 on t (c); +admin check table t; +create index idx_3 on t (a,c); +admin check table t; +# Test newly created columns. +alter table t add column e char(36); +admin check table t; +alter table t add column d char(36) NULL DEFAULT ''; +admin check table t; +insert into t values (1000, '1000', 1000, '1000', '1000'); +admin check table t; + diff --git a/tests/integrationtest/t/util/ranger.test b/tests/integrationtest/t/util/ranger.test new file mode 100644 index 0000000000000..9f455f2420995 --- /dev/null +++ b/tests/integrationtest/t/util/ranger.test @@ -0,0 +1,219 @@ +# 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; +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; +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; + diff --git a/util/admin/BUILD.bazel b/util/admin/BUILD.bazel index 34b45e5aebfc9..1df58edd205e1 100644 --- a/util/admin/BUILD.bazel +++ b/util/admin/BUILD.bazel @@ -35,10 +35,8 @@ go_test( ], embed = [":admin"], flaky = True, - shard_count = 3, deps = [ "//config", - "//sessionctx/variable", "//tablecodec", "//testkit", "//testkit/testsetup", diff --git a/util/admin/admin_integration_test.go b/util/admin/admin_integration_test.go index 484aeb74558a3..579fbe9fa9d1a 100644 --- a/util/admin/admin_integration_test.go +++ b/util/admin/admin_integration_test.go @@ -15,101 +15,13 @@ package admin_test import ( - "strconv" "testing" - "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/testkit" "github.com/stretchr/testify/require" ) -func TestAdminCheckTable(t *testing.T) { - store := testkit.CreateMockStore(t) - - // test NULL value. - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // test index column has pk-handle column - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a bigint unsigned primary key, b int, c int, index idx(a, b));") - tk.MustExec("insert into t values(1, 1, 1)") - tk.MustExec("admin check table t") - - // test for add index on the later added columns. - tk.MustExec("drop table if exists t1;") - tk.MustExec("CREATE TABLE t1 (c1 int);") - tk.MustExec("INSERT INTO t1 SET c1 = 1;") - tk.MustExec("ALTER TABLE t1 ADD COLUMN cc1 CHAR(36) NULL DEFAULT '';") - tk.MustExec("ALTER TABLE t1 ADD COLUMN cc2 VARCHAR(36) NULL DEFAULT ''") - tk.MustExec("ALTER TABLE t1 ADD INDEX idx1 (cc1);") - tk.MustExec("ALTER TABLE t1 ADD INDEX idx2 (cc2);") - tk.MustExec("ALTER TABLE t1 engine=innodb;") - tk.MustExec("admin check table t1;") - - // For add index on virtual column - tk.MustExec("drop table if exists t1;") - tk.MustExec(`create table t1 ( - a int as (JSON_EXTRACT(k,'$.a')), - c double as (JSON_EXTRACT(k,'$.c')), - d decimal(20,10) as (JSON_EXTRACT(k,'$.d')), - e char(10) as (JSON_EXTRACT(k,'$.e')), - f date as (JSON_EXTRACT(k,'$.f')), - g time as (JSON_EXTRACT(k,'$.g')), - h datetime as (JSON_EXTRACT(k,'$.h')), - i timestamp as (JSON_EXTRACT(k,'$.i')), - j year as (JSON_EXTRACT(k,'$.j')), - k json);`) - - tk.MustExec("insert into t1 set k='{\"a\": 100,\"c\":1.234,\"d\":1.2340000000,\"e\":\"abcdefg\",\"f\":\"2018-09-28\",\"g\":\"12:59:59\",\"h\":\"2018-09-28 12:59:59\",\"i\":\"2018-09-28 16:40:33\",\"j\":\"2018\"}';") - tk.MustExec("alter table t1 add index idx_a(a);") - tk.MustExec("alter table t1 add index idx_c(c);") - tk.MustExec("alter table t1 add index idx_d(d);") - tk.MustExec("alter table t1 add index idx_e(e);") - tk.MustExec("alter table t1 add index idx_f(f);") - tk.MustExec("alter table t1 add index idx_g(g);") - tk.MustExec("alter table t1 add index idx_h(h);") - tk.MustExec("alter table t1 add index idx_j(j);") - tk.MustExec("alter table t1 add index idx_i(i);") - tk.MustExec("alter table t1 add index idx_m(a,c,d,e,f,g,h,i,j);") - tk.MustExec("admin check table t1;") -} - -func TestAdminCheckTableClusterIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("drop database if exists admin_check_table_clustered_index;") - tk.MustExec("create database admin_check_table_clustered_index;") - tk.MustExec("use admin_check_table_clustered_index;") - - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - - tk.MustExec("create table t (a bigint, b varchar(255), c int, primary key (a, b), index idx_0(a, b), index idx_1(b, c));") - tk.MustExec("insert into t values (1, '1', 1);") - tk.MustExec("insert into t values (2, '2', 2);") - tk.MustExec("admin check table t;") - for i := 3; i < 200; i++ { - tk.MustExec("insert into t values (?, ?, ?);", i, strconv.Itoa(i), i) - } - tk.MustExec("admin check table t;") - - // Test back filled created index data. - tk.MustExec("create index idx_2 on t (c);") - tk.MustExec("admin check table t;") - tk.MustExec("create index idx_3 on t (a,c);") - tk.MustExec("admin check table t;") - - // Test newly created columns. - tk.MustExec("alter table t add column e char(36);") - tk.MustExec("admin check table t;") - tk.MustExec("alter table t add column d char(36) NULL DEFAULT '';") - tk.MustExec("admin check table t;") - - tk.MustExec("insert into t values (1000, '1000', 1000, '1000', '1000');") - tk.MustExec("admin check table t;") -} - func TestAdminCheckTableCorrupted(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/util/ranger/BUILD.bazel b/util/ranger/BUILD.bazel index 59bbbc6f8f3c3..91d81bbc56e42 100644 --- a/util/ranger/BUILD.bazel +++ b/util/ranger/BUILD.bazel @@ -44,7 +44,6 @@ go_test( "ranger_test.go", "types_test.go", ], - data = glob(["testdata/**"]), flaky = True, shard_count = 26, deps = [ @@ -58,9 +57,7 @@ go_test( "//planner/core", "//session", "//sessionctx", - "//sessionctx/variable", "//testkit", - "//testkit/testdata", "//testkit/testsetup", "//types", "//util/collate", diff --git a/util/ranger/main_test.go b/util/ranger/main_test.go index ebc0186b2add1..f5580dc4361ba 100644 --- a/util/ranger/main_test.go +++ b/util/ranger/main_test.go @@ -20,28 +20,19 @@ import ( "os" "testing" - "github.com/pingcap/tidb/testkit/testdata" "github.com/pingcap/tidb/testkit/testsetup" "go.uber.org/goleak" ) -var testDataMap = make(testdata.BookKeeper, 1) -var rangerSuiteData testdata.TestData - func TestMain(m *testing.M) { testsetup.SetupForCommonTest() flag.Parse() - testDataMap.LoadTestSuiteData("testdata", "ranger_suite") - rangerSuiteData = testDataMap["ranger_suite"] - if exitCode := m.Run(); exitCode != 0 { os.Exit(exitCode) } - testDataMap.GenerateOutputIfNeeded() - opts := []goleak.Option{ goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"), goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"), diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index db54c134b6cfd..8fcce6849910d 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -27,9 +27,7 @@ import ( plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx" - "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/testkit/testdata" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/ranger" @@ -838,260 +836,6 @@ func TestColumnRange(t *testing.T) { } } -func TestIndexRangeEliminatedProjection(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec("drop table if exists t") - testKit.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly - testKit.MustExec("create table t(a int not null, b int not null, primary key(a,b))") - testKit.MustExec("insert into t values(1,2)") - testKit.MustExec("analyze table t") - testKit.MustQuery("explain format = 'brief' select * from (select * from t union all select a, b from t) sub where a > 0").Check(testkit.Rows( - "Union 2.00 root ", - "├─IndexReader 1.00 root index:IndexRangeScan", - "│ └─IndexRangeScan 1.00 cop[tikv] table:t, index:PRIMARY(a, b) range:(0,+inf], keep order:false", - "└─IndexReader 1.00 root index:IndexRangeScan", - " └─IndexRangeScan 1.00 cop[tikv] table:t, index:PRIMARY(a, b) range:(0,+inf], keep order:false", - )) - testKit.MustQuery("select * from (select * from t union all select ifnull(a,b), b from t) sub where a > 0").Check(testkit.Rows( - "1 2", - "1 2", - )) -} - -func TestCompIndexInExprCorrCol(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec("set tidb_cost_model_version=2") - testKit.MustExec("drop table if exists t") - testKit.MustExec("create table t(a int primary key, b int, c int, d int, e int, index idx(b,c,d))") - testKit.MustExec("insert into t values(1,1,1,1,2),(2,1,2,1,0)") - testKit.MustExec("analyze table t") - - var input []string - var output []struct { - SQL string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestIndexStringIsTrueRange(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec("set tidb_cost_model_version=2") - testKit.MustExec("drop table if exists t0") - testKit.MustExec("CREATE TABLE t0(c0 TEXT(10));") - testKit.MustExec("INSERT INTO t0(c0) VALUES (1);") - testKit.MustExec("CREATE INDEX i0 ON t0(c0(255));") - testKit.MustExec("analyze table t0;") - - var input []string - var output []struct { - SQL string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestCompIndexDNFMatch(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec(`set @@session.tidb_regard_null_as_point=false`) - testKit.MustExec("drop table if exists t") - testKit.MustExec("create table t(a int, b int, c int, key(a,b,c));") - testKit.MustExec("insert into t values(1,2,2)") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestCompIndexMultiColDNF1(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - testKit.MustExec("drop table if exists t") - testKit.MustExec("create table t(a int, b int, c int, primary key(a,b));") - testKit.MustExec("insert into t values(1,1,1),(2,2,3)") - testKit.MustExec("analyze table t") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestCompIndexMultiColDNF2(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - testKit.MustExec("drop table if exists t") - testKit.MustExec("create table t(a int, b int, c int, primary key(a,b,c));") - testKit.MustExec("insert into t values(1,1,1),(2,2,3)") - testKit.MustExec("analyze table t") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestIssue41572(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec("drop table if exists t") - testKit.MustExec("create table t(a varchar(100), b int, c int, d int, index idx(a, b, c))") - testKit.MustExec("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)") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Sort().Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Result...)) - } -} - -func TestPrefixIndexMultiColDNF(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test;") - testKit.MustExec("drop table if exists t2;") - testKit.MustExec("create table t2 (id int unsigned not null auto_increment primary key, t text, index(t(3)));") - testKit.MustExec("insert into t2 (t) values ('aaaa'),('a');") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - inputLen := len(input) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - if i+1 == inputLen/2 { - testKit.MustExec("analyze table t2;") - } - } -} - -func TestIndexRangeForBit(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test;") - testKit.MustExec("set @@tidb_partition_prune_mode = 'static';") - testKit.MustExec("set @@tidb_executor_concurrency = 1;") - testKit.MustExec("drop table if exists t;") - testKit.MustExec("CREATE TABLE `t` (" + - "a bit(1) DEFAULT NULL," + - "b int(11) DEFAULT NULL" + - ") PARTITION BY HASH(a)" + - "PARTITIONS 3;") - testKit.MustExec("insert ignore into t values(-1, -1), (0, 0), (1, 1), (3, 3);") - testKit.MustExec("analyze table t;") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - func TestIndexRangeForYear(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1317,68 +1061,6 @@ func TestPrefixIndexRangeScan(t *testing.T) { } } -func TestIndexRangeForDecimal(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test;") - testKit.MustExec("drop table if exists t1, t2;") - testKit.MustExec("create table t1(a decimal unsigned, key(a));") - testKit.MustExec("insert into t1 values(0),(null);") - testKit.MustExec("create table t2(a int, b decimal unsigned, key idx(a,b));") - testKit.MustExec("insert into t2 values(1,0),(1,null);") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain format = 'brief' " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain format = 'brief' " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestPrefixIndexAppendPointRanges(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("USE test") - testKit.MustExec("DROP TABLE IF EXISTS IDT_20755") - testKit.MustExec("CREATE TABLE `IDT_20755` (\n" + - " `COL1` varchar(20) DEFAULT NULL,\n" + - " `COL2` tinyint(16) DEFAULT NULL,\n" + - " `COL3` timestamp NULL DEFAULT NULL,\n" + - " KEY `u_m_col` (`COL1`(10),`COL2`,`COL3`)\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - testKit.MustExec("INSERT INTO IDT_20755 VALUES(\"牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆\", 73, \"2010-06-03 07:29:05\")") - testKit.MustExec("INSERT INTO IDT_20755 VALUES(\"xxxxxxxxxxxxxxx\", 73, \"2010-06-03 07:29:05\")") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain format = 'brief' " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Rows()) - }) - testKit.MustQuery("explain format = 'brief' " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - func TestIndexRange(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2592,31 +2274,3 @@ create table t( require.Equal(t, tt.resultStr, got, fmt.Sprintf("different for expr %s", tt.exprStr)) } } - -func TestIssue44389(t *testing.T) { - store := testkit.CreateMockStore(t) - - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec("drop table if exists t") - testKit.MustExec("create table t(a varchar(100), b int, c int, index idx_ab(a, b))") - testKit.MustExec("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)") - testKit.MustExec("set @@tidb_opt_fix_control = '44389:ON'") - - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - rangerSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = testdata.ConvertRowsToStrings(testKit.MustQuery("explain " + tt).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(testKit.MustQuery(tt).Sort().Rows()) - }) - testKit.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...)) - testKit.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Result...)) - } -} diff --git a/util/ranger/testdata/ranger_suite_in.json b/util/ranger/testdata/ranger_suite_in.json deleted file mode 100644 index a862e85f2450e..0000000000000 --- a/util/ranger/testdata/ranger_suite_in.json +++ /dev/null @@ -1,127 +0,0 @@ -[ - { - "name": "TestCompIndexInExprCorrCol", - "cases": [ - "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" - ] - }, - { - "name": "TestIndexStringIsTrueRange", - "cases": [ - "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;" - ] - }, - { - "name": "TestCompIndexDNFMatch", - "cases": [ - "select * from t where a = 1 and b in (1, 2) and c > 1;", - "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 in (2, 3)) and c > 1;", - "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 is null or b = 2);", - "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 and c > 1;", - "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 = 1 and c > 1;" - ] - }, - { - "name": "TestCompIndexMultiColDNF1", - "cases": [ - "select * from t where (a,b) in ((1,1),(2,2)) and c = 3;", - "select * from t where ((a = 1 and b = 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;", - "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,b) in ((1,1),(2,2)) and c > 2;", - "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;" - ] - }, - { - "name": "TestCompIndexMultiColDNF2", - "cases": [ - // TODO: row count of BatchPointGet should be 1.00 instead of 2.00 actually, but getEqualCondSelectivity specially - // handles unique index, i.e, row count 1.00 is returned with CMSketch not checked at all. We should optimize this. - "select * from t where a = 1 and (b,c) in ((1,1),(2,3));", - "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) or (b = 2 and c = 3));", - "select * from t where (a,b) in ((1,1),(2,2)) and c = 3;", - "select * from t where ((a = 1 and b = 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;", - "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;", - "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;" - ] - }, - { - "name": "TestIssue41572", - "cases": [ - "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 d > 2" - ] - }, - { - "name": "TestPrefixIndexMultiColDNF", - "cases": [ - "select * from t2 where t='aaaa';", - "select * from t2 where t='aaaa' or t = 'a';", - "select * from t2 where t='aaaa';", - "select * from t2 where t='aaaa' or t = 'a';" - ] - }, - { - "name": "TestIndexRangeForBit", - "cases": [ - "select * from t;", - "select * from t where a = 0;", - "select * from t where a = 0 or a = 4;", - "select * from t where a = 1;", - "select * from t where a = -1;", - "select * from t where a = 3;", - "select * from t where a < 1;", - "select * from t where a < 3;", - "select * from t where a < -1;", - "select * from t where a > 0;", - "select * from t where a > -1;", - "select * from t where a > 3;" - ] - }, - { - "name": "TestIndexRangeForDecimal", - "cases": [ - "select * from t1 use index(a) where a in (-1,0);", - "select * from t1 use index(a) where a = -1;", - "select * from t1 use index(a) where a > -1;", - "select * from t1 use index(a) where a < -1;", - "select * from t1 use index(a) where a <= -1;", - "select * from t1 use index(a) where a >= -1;", - "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 = -1;", - "select * from t2 use index(idx) where a = 1 and b > -1;", - "select * from t2 use index(idx) where a = 1 and b < -1;", - "select * from t2 use index(idx) where a = 1 and b <= -1;", - "select * from t2 use index(idx) where a = 1 and b >= -1;" - ] - }, - { - "name": "TestPrefixIndexAppendPointRanges", - "cases": [ - "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 = \"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, 74) and col3 != \"2024-10-19 08:55:32\"" - ] - }, - { - "name": "TestIssue44389", - "cases": [ - "select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1))", - "select * from t where c = 10 and ((a = 'xx' or a = 'yy') or ((a = 'kk' and b = 1) or (a = 'hh' and b = 2)))" - ] - } -] diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json deleted file mode 100644 index 8e5385a843848..0000000000000 --- a/util/ranger/testdata/ranger_suite_out.json +++ /dev/null @@ -1,760 +0,0 @@ -[ - { - "Name": "TestCompIndexInExprCorrCol", - "Cases": [ - { - "SQL": "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", - "Result": [ - "Projection 2.00 root Column#27", - "└─Apply 2.00 root CARTESIAN left outer semi join, other cond:eq(test.t.e, Column#26)", - " ├─TableReader(Build) 2.00 root data:TableFullScan", - " │ └─TableFullScan 2.00 cop[tikv] table:t keep order:false", - " └─StreamAgg(Probe) 2.00 root funcs:count(1)->Column#26", - " └─HashJoin 4.00 root inner join, equal:[eq(test.t.a, test.t.a)]", - " ├─IndexReader(Build) 4.00 root index:IndexFullScan", - " │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:idx(b, c, d) keep order:false", - " └─IndexReader(Probe) 4.00 root index:IndexRangeScan", - " └─IndexRangeScan 4.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) in(test.t.c, 1, 2) eq(test.t.d, test.t.a)], keep order:false" - ] - }, - { - "SQL": "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", - "Result": [ - "1", - "1" - ] - } - ] - }, - { - "Name": "TestIndexStringIsTrueRange", - "Cases": [ - { - "SQL": "explain format = 'brief' select * from t0 where c0", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] test.t0.c0", - " └─IndexFullScan 1.00 cop[tikv] table:t0, index:i0(c0) keep order:false" - ] - }, - { - "SQL": "explain format = 'brief' select * from t0 where c0 and c0 > '123'", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] test.t0.c0", - " └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:(\"123\",+inf], keep order:false" - ] - }, - { - "SQL": "explain format = 'brief' select * from t0 where c0 and c0 <> '123'", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] test.t0.c0", - " └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:[-inf,\"123\"), (\"123\",+inf], keep order:false" - ] - }, - { - "SQL": "explain format = 'brief' select * from t0 where c0 is true", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] istrue(cast(test.t0.c0, double BINARY))", - " └─IndexFullScan 1.00 cop[tikv] table:t0, index:i0(c0) keep order:false" - ] - }, - { - "SQL": "explain format = 'brief' select * from t0 where c0 is false", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] isfalse(cast(test.t0.c0, double BINARY))", - " └─IndexFullScan 1.00 cop[tikv] table:t0, index:i0(c0) keep order:false" - ] - }, - { - "SQL": "explain format = 'brief' select * from t0 where c0 and c0 in ('123','456','789')", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] test.t0.c0", - " └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:[\"123\",\"123\"], [\"456\",\"456\"], [\"789\",\"789\"], keep order:false" - ] - }, - { - "SQL": "explain format = 'brief' select * FROM t0 WHERE ('a' != t0.c0) AND t0.c0;", - "Result": [ - "IndexReader 1.00 root index:Selection", - "└─Selection 1.00 cop[tikv] test.t0.c0", - " └─IndexRangeScan 1.00 cop[tikv] table:t0, index:i0(c0) range:[-inf,\"a\"), (\"a\",+inf], keep order:false" - ] - } - ] - }, - { - "Name": "TestCompIndexDNFMatch", - "Cases": [ - { - "SQL": "select * from t where a = 1 and b in (1, 2) and c > 1;", - "Plan": [ - "IndexReader_6 0.67 root index:IndexRangeScan_5", - "└─IndexRangeScan_5 0.67 cop[tikv] table:t, index:a(a, b, c) range:(1 1 1,1 1 +inf], (1 2 1,1 2 +inf], keep order:false, stats:pseudo" - ], - "Result": [ - "1 2 2" - ] - }, - { - "SQL": "select * from t where a = 1 and (b = 1 or b = 2) and c > 1;", - "Plan": [ - "IndexReader_6 0.67 root index:IndexRangeScan_5", - "└─IndexRangeScan_5 0.67 cop[tikv] table:t, index:a(a, b, c) range:(1 1 1,1 1 +inf], (1 2 1,1 2 +inf], keep order:false, stats:pseudo" - ], - "Result": [ - "1 2 2" - ] - }, - { - "SQL": "select * from t where a = 1 and (b = 1 or b in (2, 3)) and c > 1;", - "Plan": [ - "IndexReader_6 1.00 root index:IndexRangeScan_5", - "└─IndexRangeScan_5 1.00 cop[tikv] table:t, index:a(a, b, c) range:(1 1 1,1 1 +inf], (1 2 1,1 2 +inf], (1 3 1,1 3 +inf], keep order:false, stats:pseudo" - ], - "Result": [ - "1 2 2" - ] - }, - { - "SQL": "select * from t where a = 1 and (b = 1 or b = 2) and b = 3 and c > 1;", - "Plan": [ - "TableDual_5 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t where a = 1 and (b is null or b = 2);", - "Plan": [ - "IndexReader_6 0.20 root index:IndexRangeScan_5", - "└─IndexRangeScan_5 0.20 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], [1 2,1 2], keep order:false, stats:pseudo" - ], - "Result": [ - "1 2 2" - ] - }, - { - "SQL": "select * from t where a = 1 and (b is null or b = 2) and c > 1;", - "Plan": [ - "IndexReader_7 0.07 root index:Selection_6", - "└─Selection_6 0.07 cop[tikv] gt(test.t.c, 1)", - " └─IndexRangeScan_5 0.20 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], [1 2,1 2], keep order:false, stats:pseudo" - ], - "Result": [ - "1 2 2" - ] - }, - { - "SQL": "select * from t where a = 1 and b is null and c > 1;", - "Plan": [ - "IndexReader_7 0.03 root index:Selection_6", - "└─Selection_6 0.03 cop[tikv] gt(test.t.c, 1)", - " └─IndexRangeScan_5 0.10 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], keep order:false, stats:pseudo" - ], - "Result": null - }, - { - "SQL": "select * from t where a = 1 and b is null and b is null and c > 1;", - "Plan": [ - "IndexReader_7 0.03 root index:Selection_6", - "└─Selection_6 0.03 cop[tikv] gt(test.t.c, 1)", - " └─IndexRangeScan_5 0.10 cop[tikv] table:t, index:a(a, b, c) range:[1 NULL,1 NULL], keep order:false, stats:pseudo" - ], - "Result": null - }, - { - "SQL": "select * from t where a = 1 and b is null and b = 1 and c > 1;", - "Plan": [ - "TableDual_5 0.00 root rows:0" - ], - "Result": null - } - ] - }, - { - "Name": "TestCompIndexMultiColDNF1", - "Cases": [ - { - "SQL": "select * from t where (a,b) in ((1,1),(2,2)) and c = 3;", - "Plan": [ - "Selection_6 0.75 root eq(test.t.c, 3)", - "└─Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3;", - "Plan": [ - "Selection_6 0.75 root eq(test.t.c, 3)", - "└─Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3;", - "Plan": [ - "TableReader_7 0.75 root data:Selection_6", - "└─Selection_6 0.75 cop[tikv] eq(test.t.c, 3), or(eq(test.t.a, 1), and(eq(test.t.a, 2), eq(test.t.b, 2)))", - " └─TableRangeScan_5 2.00 cop[tikv] table:t range:[1,1], [2,2], keep order:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3 and (a = 1 or a = 2);", - "Plan": [ - "Selection_6 0.75 root eq(test.t.c, 3), or(eq(test.t.a, 1), eq(test.t.a, 2))", - "└─Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where (a,b) in ((1,1),(2,2)) and c > 2;", - "Plan": [ - "Selection_6 0.75 root gt(test.t.c, 2)", - "└─Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;", - "Plan": [ - "Selection_6 0.75 root gt(test.t.c, 2)", - "└─Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - } - ] - }, - { - "Name": "TestCompIndexMultiColDNF2", - "Cases": [ - { - "SQL": "select * from t where a = 1 and (b,c) in ((1,1),(2,3));", - "Plan": [ - "Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b, c) keep order:false, desc:false" - ], - "Result": [ - "1 1 1" - ] - }, - { - "SQL": "select * from t where a = 1 and ((b = 1 and c = 1) or (b = 2 and c = 3));", - "Plan": [ - "Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b, c) keep order:false, desc:false" - ], - "Result": [ - "1 1 1" - ] - }, - { - "SQL": "select * from t where a = 1 and ((b = 1) or (b = 2 and c = 3));", - "Plan": [ - "TableReader_6 1.71 root data:TableRangeScan_5", - "└─TableRangeScan_5 1.71 cop[tikv] table:t range:[1 1,1 1], [1 2 3,1 2 3], keep order:false" - ], - "Result": [ - "1 1 1" - ] - }, - { - "SQL": "select * from t where (a,b) in ((1,1),(2,2)) and c = 3;", - "Plan": [ - "Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b, c) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c = 3;", - "Plan": [ - "Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b, c) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t use index(primary) where ((a = 1) or (a = 2 and b = 2)) and c = 3;", - "Plan": [ - "TableReader_7 0.68 root data:Selection_6", - "└─Selection_6 0.68 cop[tikv] eq(test.t.c, 3), or(eq(test.t.a, 1), and(eq(test.t.a, 2), eq(test.t.b, 2)))", - " └─TableRangeScan_5 2.00 cop[tikv] table:t range:[1,1], [2,2], keep order:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "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));", - "Plan": [ - "Selection_6 0.44 root gt(test.t.c, 2), or(and(eq(test.t.a, 1), eq(test.t.b, 1)), and(eq(test.t.a, 2), eq(test.t.b, 2)))", - "└─Batch_Point_Get_5 2.00 root table:t, clustered index:PRIMARY(a, b, c) keep order:false, desc:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where (a,b) in ((1,1),(2,2)) and c > 2;", - "Plan": [ - "TableReader_6 1.19 root data:TableRangeScan_5", - "└─TableRangeScan_5 1.19 cop[tikv] table:t range:(1 1 2,1 1 +inf], (2 2 2,2 2 +inf], keep order:false" - ], - "Result": [ - "2 2 3" - ] - }, - { - "SQL": "select * from t where ((a = 1 and b = 1) or (a = 2 and b = 2)) and c > 2;", - "Plan": [ - "TableReader_6 1.19 root data:TableRangeScan_5", - "└─TableRangeScan_5 1.19 cop[tikv] table:t range:(1 1 2,1 1 +inf], (2 2 2,2 2 +inf], keep order:false" - ], - "Result": [ - "2 2 3" - ] - } - ] - }, - { - "Name": "TestIssue41572", - "Cases": [ - { - "SQL": "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", - "Plan": [ - "IndexLookUp_7 1.00 root ", - "├─IndexRangeScan_5(Build) 1.00 cop[tikv] table:t, index:idx(a, b, c) range:(\"t\" 1 2,\"t\" 1 +inf], (\"t\" 2 2,\"t\" 2 +inf], (\"w\" 0 2,\"w\" 0 +inf], keep order:false, stats:pseudo", - "└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Result": [ - "t 1 3 3", - "t 2 3 1", - "w 0 3 3" - ] - }, - { - "SQL": "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", - "Plan": [ - "IndexLookUp_8 0.10 root ", - "├─IndexRangeScan_5(Build) 0.30 cop[tikv] table:t, index:idx(a, b, c) range:[\"t\" 1,\"t\" 1], [\"t\" 2,\"t\" 2], [\"w\" 0,\"w\" 0], keep order:false, stats:pseudo", - "└─Selection_7(Probe) 0.10 cop[tikv] gt(test.t.d, 2)", - " └─TableRowIDScan_6 0.30 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Result": [ - "t 1 3 3", - "t 2 1 3", - "w 0 3 3" - ] - } - ] - }, - { - "Name": "TestPrefixIndexMultiColDNF", - "Cases": [ - { - "SQL": "select * from t2 where t='aaaa';", - "Plan": [ - "IndexLookUp_11 10.00 root ", - "├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:t2, index:t(t) range:[\"aaa\",\"aaa\"], keep order:false, stats:pseudo", - "└─Selection_10(Probe) 10.00 cop[tikv] eq(test.t2.t, \"aaaa\")", - " └─TableRowIDScan_9 10.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 aaaa" - ] - }, - { - "SQL": "select * from t2 where t='aaaa' or t = 'a';", - "Plan": [ - "IndexLookUp_11 16.00 root ", - "├─IndexRangeScan_8(Build) 20.00 cop[tikv] table:t2, index:t(t) range:[\"a\",\"a\"], [\"aaa\",\"aaa\"], keep order:false, stats:pseudo", - "└─Selection_10(Probe) 16.00 cop[tikv] or(eq(test.t2.t, \"aaaa\"), eq(test.t2.t, \"a\"))", - " └─TableRowIDScan_9 20.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 aaaa", - "2 a" - ] - }, - { - "SQL": "select * from t2 where t='aaaa';", - "Plan": [ - "TableReader_7 1.00 root data:Selection_6", - "└─Selection_6 1.00 cop[tikv] eq(test.t2.t, \"aaaa\")", - " └─TableFullScan_5 2.00 cop[tikv] table:t2 keep order:false" - ], - "Result": [ - "1 aaaa" - ] - }, - { - "SQL": "select * from t2 where t='aaaa' or t = 'a';", - "Plan": [ - "TableReader_7 1.60 root data:Selection_6", - "└─Selection_6 1.60 cop[tikv] or(eq(test.t2.t, \"aaaa\"), eq(test.t2.t, \"a\"))", - " └─TableFullScan_5 2.00 cop[tikv] table:t2 keep order:false" - ], - "Result": [ - "1 aaaa", - "2 a" - ] - } - ] - }, - { - "Name": "TestIndexRangeForBit", - "Cases": [ - { - "SQL": "select * from t;", - "Plan": [ - "PartitionUnion_8 4.00 root ", - "├─TableReader_10 1.00 root data:TableFullScan_9", - "│ └─TableFullScan_9 1.00 cop[tikv] table:t, partition:p0 keep order:false", - "└─TableReader_12 3.00 root data:TableFullScan_11", - " └─TableFullScan_11 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": [ - "\u0000 0", - "\u0001 -1", - "\u0001 1", - "\u0001 3" - ] - }, - { - "SQL": "select * from t where a = 0;", - "Plan": [ - "TableReader_9 1.00 root data:Selection_8", - "└─Selection_8 1.00 cop[tikv] eq(test.t.a, 0)", - " └─TableFullScan_7 1.00 cop[tikv] table:t, partition:p0 keep order:false" - ], - "Result": [ - "\u0000 0" - ] - }, - { - "SQL": "select * from t where a = 0 or a = 4;", - "Plan": [ - "TableReader_9 1.00 root data:Selection_8", - "└─Selection_8 1.00 cop[tikv] or(eq(test.t.a, 0), eq(test.t.a, 4))", - " └─TableFullScan_7 1.00 cop[tikv] table:t, partition:p0 keep order:false" - ], - "Result": [ - "\u0000 0" - ] - }, - { - "SQL": "select * from t where a = 1;", - "Plan": [ - "TableReader_9 3.00 root data:Selection_8", - "└─Selection_8 3.00 cop[tikv] eq(test.t.a, 1)", - " └─TableFullScan_7 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": [ - "\u0001 -1", - "\u0001 1", - "\u0001 3" - ] - }, - { - "SQL": "select * from t where a = -1;", - "Plan": [ - "TableDual_7 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t where a = 3;", - "Plan": [ - "TableDual_7 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t where a < 1;", - "Plan": [ - "PartitionUnion_9 1.00 root ", - "├─TableReader_12 1.00 root data:Selection_11", - "│ └─Selection_11 1.00 cop[tikv] lt(test.t.a, 1)", - "│ └─TableFullScan_10 1.00 cop[tikv] table:t, partition:p0 keep order:false", - "└─TableReader_15 0.00 root data:Selection_14", - " └─Selection_14 0.00 cop[tikv] lt(test.t.a, 1)", - " └─TableFullScan_13 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": [ - "\u0000 0" - ] - }, - { - "SQL": "select * from t where a < 3;", - "Plan": [ - "PartitionUnion_9 4.00 root ", - "├─TableReader_12 1.00 root data:Selection_11", - "│ └─Selection_11 1.00 cop[tikv] lt(test.t.a, 3)", - "│ └─TableFullScan_10 1.00 cop[tikv] table:t, partition:p0 keep order:false", - "└─TableReader_15 3.00 root data:Selection_14", - " └─Selection_14 3.00 cop[tikv] lt(test.t.a, 3)", - " └─TableFullScan_13 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": [ - "\u0000 0", - "\u0001 -1", - "\u0001 1", - "\u0001 3" - ] - }, - { - "SQL": "select * from t where a < -1;", - "Plan": [ - "TableDual_7 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t where a > 0;", - "Plan": [ - "PartitionUnion_9 3.00 root ", - "├─TableReader_12 0.00 root data:Selection_11", - "│ └─Selection_11 0.00 cop[tikv] gt(test.t.a, 0)", - "│ └─TableFullScan_10 1.00 cop[tikv] table:t, partition:p0 keep order:false", - "└─TableReader_15 3.00 root data:Selection_14", - " └─Selection_14 3.00 cop[tikv] gt(test.t.a, 0)", - " └─TableFullScan_13 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": [ - "\u0001 -1", - "\u0001 1", - "\u0001 3" - ] - }, - { - "SQL": "select * from t where a > -1;", - "Plan": [ - "PartitionUnion_9 4.00 root ", - "├─TableReader_12 1.00 root data:Selection_11", - "│ └─Selection_11 1.00 cop[tikv] gt(test.t.a, -1)", - "│ └─TableFullScan_10 1.00 cop[tikv] table:t, partition:p0 keep order:false", - "└─TableReader_15 3.00 root data:Selection_14", - " └─Selection_14 3.00 cop[tikv] gt(test.t.a, -1)", - " └─TableFullScan_13 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": [ - "\u0000 0", - "\u0001 -1", - "\u0001 1", - "\u0001 3" - ] - }, - { - "SQL": "select * from t where a > 3;", - "Plan": [ - "PartitionUnion_9 0.00 root ", - "├─TableReader_12 0.00 root data:Selection_11", - "│ └─Selection_11 0.00 cop[tikv] gt(test.t.a, 3)", - "│ └─TableFullScan_10 1.00 cop[tikv] table:t, partition:p0 keep order:false", - "└─TableReader_15 0.00 root data:Selection_14", - " └─Selection_14 0.00 cop[tikv] gt(test.t.a, 3)", - " └─TableFullScan_13 3.00 cop[tikv] table:t, partition:p1 keep order:false" - ], - "Result": null - } - ] - }, - { - "Name": "TestIndexRangeForDecimal", - "Cases": [ - { - "SQL": "select * from t1 use index(a) where a in (-1,0);", - "Plan": [ - "IndexReader 10.00 root index:IndexRangeScan", - "└─IndexRangeScan 10.00 cop[tikv] table:t1, index:a(a) range:[0,0], keep order:false, stats:pseudo" - ], - "Result": [ - "0" - ] - }, - { - "SQL": "select * from t1 use index(a) where a = -1;", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t1 use index(a) where a > -1;", - "Plan": [ - "IndexReader 3333.33 root index:IndexRangeScan", - "└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:a(a) range:[0,+inf], keep order:false, stats:pseudo" - ], - "Result": [ - "0" - ] - }, - { - "SQL": "select * from t1 use index(a) where a < -1;", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t1 use index(a) where a <= -1;", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t1 use index(a) where a >= -1;", - "Plan": [ - "IndexReader 3333.33 root index:IndexRangeScan", - "└─IndexRangeScan 3333.33 cop[tikv] table:t1, index:a(a) range:[0,+inf], keep order:false, stats:pseudo" - ], - "Result": [ - "0" - ] - }, - { - "SQL": "select * from t2 use index(idx) where a = 1 and b in (-1,0);", - "Plan": [ - "IndexReader 0.10 root index:IndexRangeScan", - "└─IndexRangeScan 0.10 cop[tikv] table:t2, index:idx(a, b) range:[1 0,1 0], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0" - ] - }, - { - "SQL": "select * from t2 use index(idx) where a = 1 and b = -1;", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t2 use index(idx) where a = 1 and b > -1;", - "Plan": [ - "IndexReader 33.33 root index:IndexRangeScan", - "└─IndexRangeScan 33.33 cop[tikv] table:t2, index:idx(a, b) range:[1 0,1 +inf], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0" - ] - }, - { - "SQL": "select * from t2 use index(idx) where a = 1 and b < -1;", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t2 use index(idx) where a = 1 and b <= -1;", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select * from t2 use index(idx) where a = 1 and b >= -1;", - "Plan": [ - "IndexReader 33.33 root index:IndexRangeScan", - "└─IndexRangeScan 33.33 cop[tikv] table:t2, index:idx(a, b) range:[1 0,1 +inf], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0" - ] - } - ] - }, - { - "Name": "TestPrefixIndexAppendPointRanges", - "Cases": [ - { - "SQL": "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\"", - "Plan": [ - "IndexLookUp 5.99 root ", - "├─IndexRangeScan(Build) 5.99 cop[tikv] table:IDT_20755, index:u_m_col(COL1, COL2, COL3) range:[\"剮毵樍穋摻瀽鬦擀钟鷫\" 39 -inf,\"剮毵樍穋摻瀽鬦擀钟鷫\" 39 2024-10-19 08:55:32), (\"剮毵樍穋摻瀽鬦擀钟鷫\" 39 2024-10-19 08:55:32,\"剮毵樍穋摻瀽鬦擀钟鷫\" 39 +inf], [\"剮毵樍穋摻瀽鬦擀钟鷫\" 72 -inf,\"剮毵樍穋摻瀽鬦擀钟鷫\" 72 2024-10-19 08:55:32), (\"剮毵樍穋摻瀽鬦擀钟鷫\" 72 2024-10-19 08:55:32,\"剮毵樍穋摻瀽鬦擀钟鷫\" 72 +inf], [\"剮毵樍穋摻瀽鬦擀钟鷫\" 73 -inf,\"剮毵樍穋摻瀽鬦擀钟鷫\" 73 2024-10-19 08:55:32), (\"剮毵樍穋摻瀽鬦擀钟鷫\" 73 2024-10-19 08:55:32,\"剮毵樍穋摻瀽鬦擀钟鷫\" 73 +inf], [\"物碃貞枕騫摨聫嚣蜻禼\" 39 -inf,\"物碃貞枕騫摨聫嚣蜻禼\" 39 2024-10-19 08:55:32), (\"物碃貞枕騫摨聫嚣蜻禼\" 39 2024-10-19 08:55:32,\"物碃貞枕騫摨聫嚣蜻禼\" 39 +inf], [\"物碃貞枕騫摨聫嚣蜻禼\" 72 -inf,\"物碃貞枕騫摨聫嚣蜻禼\" 72 2024-10-19 08:55:32), (\"物碃貞枕騫摨聫嚣蜻禼\" 72 2024-10-19 08:55:32,\"物碃貞枕騫摨聫嚣蜻禼\" 72 +inf], [\"物碃貞枕騫摨聫嚣蜻禼\" 73 -inf,\"物碃貞枕騫摨聫嚣蜻禼\" 73 2024-10-19 08:55:32), (\"物碃貞枕騫摨聫嚣蜻禼\" 73 2024-10-19 08:55:32,\"物碃貞枕騫摨聫嚣蜻禼\" 73 +inf], [\"牾窓螎刳闌蜹瑦詬鍖湪\" 39 -inf,\"牾窓螎刳闌蜹瑦詬鍖湪\" 39 2024-10-19 08:55:32), (\"牾窓螎刳闌蜹瑦詬鍖湪\" 39 2024-10-19 08:55:32,\"牾窓螎刳闌蜹瑦詬鍖湪\" 39 +inf], [\"牾窓螎刳闌蜹瑦詬鍖湪\" 72 -inf,\"牾窓螎刳闌蜹瑦詬鍖湪\" 72 2024-10-19 08:55:32), (\"牾窓螎刳闌蜹瑦詬鍖湪\" 72 2024-10-19 08:55:32,\"牾窓螎刳闌蜹瑦詬鍖湪\" 72 +inf], [\"牾窓螎刳闌蜹瑦詬鍖湪\" 73 -inf,\"牾窓螎刳闌蜹瑦詬鍖湪\" 73 2024-10-19 08:55:32), (\"牾窓螎刳闌蜹瑦詬鍖湪\" 73 2024-10-19 08:55:32,\"牾窓螎刳闌蜹瑦詬鍖湪\" 73 +inf], keep order:false, stats:pseudo", - "└─Selection(Probe) 5.99 cop[tikv] in(test.idt_20755.col1, \"牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆\", \"物碃貞枕騫摨聫嚣蜻禼担堋黕詖蝒毎槒阆畒郒\", \"剮毵樍穋摻瀽鬦擀钟鷫產冖悄乮曙枱诠鑡轰砠\")", - " └─TableRowIDScan 5.99 cop[tikv] table:IDT_20755 keep order:false, stats:pseudo" - ], - "Result": [ - "牾窓螎刳闌蜹瑦詬鍖湪槢壿玟瞏膍敗特森撇縆 73 2010-06-03 07:29:05" - ] - }, - { - "SQL": "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\"", - "Plan": [ - "IndexLookUp 1.33 root ", - "├─IndexRangeScan(Build) 1.33 cop[tikv] table:IDT_20755, index:u_m_col(COL1, COL2, COL3) range:[\"xxxxxxxxxx\" 72 -inf,\"xxxxxxxxxx\" 72 2024-10-19 08:55:32), (\"xxxxxxxxxx\" 72 2024-10-19 08:55:32,\"xxxxxxxxxx\" 72 +inf], [\"xxxxxxxxxx\" 73 -inf,\"xxxxxxxxxx\" 73 2024-10-19 08:55:32), (\"xxxxxxxxxx\" 73 2024-10-19 08:55:32,\"xxxxxxxxxx\" 73 +inf], keep order:false, stats:pseudo", - "└─Selection(Probe) 1.33 cop[tikv] eq(test.idt_20755.col1, \"xxxxxxxxxxxxxxx\")", - " └─TableRowIDScan 1.33 cop[tikv] table:IDT_20755 keep order:false, stats:pseudo" - ], - "Result": [ - "xxxxxxxxxxxxxxx 73 2010-06-03 07:29:05" - ] - }, - { - "SQL": "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\"", - "Plan": [ - "IndexLookUp 2.00 root ", - "├─IndexRangeScan(Build) 2.00 cop[tikv] table:IDT_20755, index:u_m_col(COL1, COL2, COL3) range:[\"xxxxxxxxxx\" 72 -inf,\"xxxxxxxxxx\" 72 2024-10-19 08:55:32), (\"xxxxxxxxxx\" 72 2024-10-19 08:55:32,\"xxxxxxxxxx\" 72 +inf], [\"xxxxxxxxxx\" 73 -inf,\"xxxxxxxxxx\" 73 2024-10-19 08:55:32), (\"xxxxxxxxxx\" 73 2024-10-19 08:55:32,\"xxxxxxxxxx\" 73 +inf], [\"xxxxxxxxxx\" 74 -inf,\"xxxxxxxxxx\" 74 2024-10-19 08:55:32), (\"xxxxxxxxxx\" 74 2024-10-19 08:55:32,\"xxxxxxxxxx\" 74 +inf], keep order:false, stats:pseudo", - "└─Selection(Probe) 2.00 cop[tikv] eq(test.idt_20755.col1, \"xxxxxxxxxxxxxxx\")", - " └─TableRowIDScan 2.00 cop[tikv] table:IDT_20755 keep order:false, stats:pseudo" - ], - "Result": [ - "xxxxxxxxxxxxxxx 73 2010-06-03 07:29:05" - ] - } - ] - }, - { - "Name": "TestIssue44389", - "Cases": [ - { - "SQL": "select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1))", - "Plan": [ - "IndexLookUp_11 0.01 root ", - "├─IndexRangeScan_8(Build) 10.10 cop[tikv] table:t, index:idx_ab(a, b) range:[\"kk\" 1,\"kk\" 1], [\"xx\",\"xx\"], keep order:false, stats:pseudo", - "└─Selection_10(Probe) 0.01 cop[tikv] eq(test.t.c, 10)", - " └─TableRowIDScan_9 10.10 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Result": [ - "kk 1 10", - "xx 4 10" - ] - }, - { - "SQL": "select * from t where c = 10 and ((a = 'xx' or a = 'yy') or ((a = 'kk' and b = 1) or (a = 'hh' and b = 2)))", - "Plan": [ - "IndexLookUp_11 0.02 root ", - "├─IndexRangeScan_8(Build) 20.20 cop[tikv] table:t, index:idx_ab(a, b) range:[\"hh\" 2,\"hh\" 2], [\"kk\" 1,\"kk\" 1], [\"xx\",\"xx\"], [\"yy\",\"yy\"], keep order:false, stats:pseudo", - "└─Selection_10(Probe) 0.02 cop[tikv] eq(test.t.c, 10)", - " └─TableRowIDScan_9 20.20 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Result": [ - "hh 2 10", - "kk 1 10", - "xx 4 10", - "yy 5 10" - ] - } - ] - } -]