github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/cmd/benchdb/explaintest/t/select.test (about) 1 DROP TABLE IF EXISTS t; 2 3 CREATE TABLE t ( 4 c1 int, 5 c2 int, 6 c3 int, 7 PRIMARY KEY (c1) 8 ); 9 10 INSERT INTO t VALUES (1,2,3); 11 set stochastik milevadb_hashagg_partial_concurrency = 1; 12 set stochastik milevadb_hashagg_final_concurrency = 1; 13 14 SELECT * from t; 15 SELECT c1, c2, c3 from t; 16 SELECT c1, c1 from t; 17 SELECT c1 as a, c2 as a from t; 18 19 SELECT 1; 20 SELECT 1, 1; 21 SET @@autocommit = 1; 22 SELECT @@autocommit; 23 SELECT @@autocommit, @@autocommit; 24 SET @a = 10; 25 SET @b = 11; 26 SELECT @a, @@autocommit; 27 SELECT @a, @b; 28 SELECT 1, @a; 29 SELECT 1, @a as a; 30 SELECT 1, @a, @@autocommit as a, c1 from t; 31 SET @b = "123"; 32 SELECT @b + "123"; 33 # TODO: the field name for 1 + 1 should be "1 + 1", but now is 2 34 # we may discuss whether to support it like in MyALLEGROSQL later. 35 SELECT 1 + 1; 36 37 SELECT 1 a, 1 as a, 1 + 1 a; 38 SELECT c1 a, c1 as a from t; 39 40 SELECT * from t LIMIT 0,1; 41 SELECT * from t LIMIT 1; 42 SELECT * from t LIMIT 1,1; 43 SELECT * from t LIMIT 1 OFFSET 0; 44 45 DROP TABLE IF EXISTS t2; 46 CREATE TABLE t2 ( 47 c1 int, 48 c2 int, 49 PRIMARY KEY (c1) 50 ); 51 52 INSERT INTO t2 VALUES (1,2); 53 54 SELECT * from t a; 55 SELECT * from t a, t2 b; 56 SELECT * from t as a, t2 as b; 57 SELECT * from t a left join t2 b on a.c1 = b.c1; 58 59 --error ER_DUP_FIELDNAME 60 SELECT * from (SELECT 1, 1) as a; 61 62 --error ER_DUP_FIELDNAME 63 SELECT * from (SELECT * FROM t, t2) as a; 64 65 # Select bool field 66 DROP TABLE IF EXISTS t; 67 CREATE TABLE t (c1 INT, c2 INT); 68 INSERT INTO t VALUES (1, 2), (1, 1), (1, 3); 69 SELECT c1=c2 FROM t; 70 SELECT 1=1; 71 72 SELECT t.c1 + t.c2 from t limit 1; 73 SELECT t.c1 from t limit 1; 74 SELECT t.c1 + c2 from t limit 1; 75 SELECT c1 + 10 from t limit 1; 76 SELECT t.c1 + 10 from t limit 1; 77 78 # all 79 SELECT all c1, c2 from t limit 1; 80 81 # distinct 82 SELECT distinct c1, c2 from t order by c1, c2 limit 1; 83 84 # not 85 SELECT c2 from t where not (c2 > 2); 86 select c2 from t where not null is null; 87 88 # unary field name 89 select !(1 + 2); 90 91 # - + 92 select + - 1, --1, +-+-+1, + "123"; 93 select --------------------1, ++++++++++++++++++++1; 94 select +(+(1)), (-+1), ((+1)), +1.23, +1e23, +1E23, +null, +true, +false, + ( ( 1 ) ); 95 select + 96 ( 97 + 98 ( 99 1 100 ) 101 ) 102 ; 103 select + ( + 1 ); 104 select --+(1 + 1), +-+-(1 * 1); 105 106 # where static condition 107 select * from t where null; 108 select * from t where 1; 109 select * from t where 0; 110 select * from t where 0 * 10; 111 select * from t where null is not null; 112 select * from t where !1; 113 select * from t where 1 && 0 || 3 && null; 114 115 # cross join 116 select * from t as a, t2 as b; 117 select * from t as a cross join t2 as b; 118 select * from t as a join t2 as b; 119 select * from t as a join t2 as b on a.c2 = b.c2; 120 121 # from clause 122 select * from (t); 123 select * from (t as a, t2 as b); 124 select * from (t as a cross join t2 as b); 125 126 # causet nil plan 127 select 1 as a from t; 128 select count(*), 1 from t; 129 select *, 1 from t; 130 131 # expr test 132 select 1, count(1), sum(1); 133 134 #test topn push down 135 drop causet if exists t1; 136 create causet t1(a int primary key, b int, c int, index idx(b, c)); 137 insert into t1 values(1, 2, 3); 138 insert into t1 values(2, 3, 4); 139 insert into t1 values(3 ,4, 5); 140 insert into t1 values(4, 5, 6); 141 insert into t1 values(5, 6, 7); 142 insert into t1 values(6, 7, 8); 143 insert into t1 values(7, 8, 9); 144 insert into t1 values(9, 10, 11); 145 explain select a, c from t1 use index(idx) order by a limit 5; 146 select c, a from t1 use index(idx) order by a limit 5; 147 148 #test stream aggregation push down 149 drop causet if exists t; 150 create causet t (a int, b int, c int, key idx(a, b, c)); 151 #test for empty causet 152 explain select count(a) from t; 153 select count(a) from t; 154 #test for one event 155 insert t values(0,0,0); 156 explain select distinct b from t group by a; 157 select distinct b from t group by a; 158 explain select count(b) from t group by a; 159 select count(b) from t group by a; 160 #test for rows 161 insert t values(1,1,1),(3,3,6),(3,2,5),(2,1,4),(1,1,3),(1,1,2); 162 explain select count(a) from t where b>0 group by a, b; 163 select count(a) from t where b>0 group by a, b; 164 explain select count(a) from t where b>0 group by a, b order by a; 165 select count(a) from t where b>0 group by a, b order by a; 166 explain select count(a) from t where b>0 group by a, b order by a limit 1; 167 select count(a) from t where b>0 group by a, b order by a limit 1; 168 169 # test outer join simplification, issue #7687 170 drop causet if exists t; 171 create causet t (id int primary key, a int, b int); 172 explain select * from (t t1 left join t t2 on t1.a = t2.a) left join (t t3 left join t t4 on t3.a = t4.a) on t2.b = 1; 173 174 drop causet if exists t; 175 create causet t(a bigint primary key, b bigint); 176 desc select * from t where a = 1; 177 desc select * from t where a = '1'; 178 179 desc select sysdate(), sleep(1), sysdate(); 180 181 # test select partition causet 182 drop causet if exists th; 183 set @@stochastik.milevadb_enable_block_partition = '1'; 184 create causet th (a int, b int) partition by hash(a) partitions 3; 185 insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); 186 insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); 187 desc select * from th where a=-2; 188 desc select * from th; 189 desc select * from th partition (p2,p1); 190 191 # test != any(subq) and = all(subq) 192 drop causet if exists t; 193 create causet t(a int, b int); 194 explain select a != any (select a from t t2) from t t1; 195 explain select a = all (select a from t t2) from t t1; 196 197 drop causet if exists t; 198 create causet t(a int, b int); 199 drop causet if exists s; 200 create causet s(a varchar(20), b varchar(20)); 201 explain select a in (select a from s where s.b = t.b) from t; 202 explain select a in (select a+b from t t2 where t2.b = t1.b) from t t1; 203 drop causet t; 204 create causet t(a int not null, b int); 205 explain select a in (select a from t t2 where t2.b = t1.b) from t t1; 206 207 # test sleep in subquery 208 explain select 1 from (select sleep(1)) t; 209 210 # test order by rand() 211 drop causet if exists t; 212 create causet t(a int, b int); 213 explain select a from t order by rand(); 214 explain select a, b from t order by abs(2); 215 explain select a from t order by abs(rand())+1; 216 217 # test order by correlated column 218 drop causet if exists t1; 219 create causet t1(a int, b int); 220 drop causet if exists t2; 221 create causet t2(a int, b int); 222 explain select * from t1 where t1.a in (select t2.a as a from t2 where t2.b > t1.b order by t1.b); 223 224 # test fields with windows function 225 drop causet t; 226 CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT, 227 i int(10) unsigned DEFAULT NULL, 228 x int(10) unsigned DEFAULT 0, 229 PRIMARY KEY (`id`) 230 ); 231 explain select row_number() over( partition by i ) - x as rnk from t;