diff --git a/tests/integrationtest/r/executor/executor.result b/tests/integrationtest/r/executor/executor.result deleted file mode 100644 index 5a61cfa41c802..0000000000000 --- a/tests/integrationtest/r/executor/executor.result +++ /dev/null @@ -1,4376 +0,0 @@ -select 1 + 2*3; -1 + 2*3 -7 -select _utf8"string"; -string -string -select 1 order by 1; -1 -1 -SELECT 'a' as f1 having f1 = 'a'; -f1 -a -SELECT (SELECT * FROM (SELECT 'a') t) AS f1 HAVING (f1 = 'a' OR TRUE); -f1 -a -SELECT (SELECT * FROM (SELECT 'a') t) + 1 AS f1 HAVING (f1 = 'a' OR TRUE); -f1 -1 -create table t (c1 int, c2 int, c3 varchar(20)); -insert into t values (1, 2, 'abc'), (2, 1, 'bcd'); -select c1 as a, c1 as b from t order by c1; -a b -1 1 -2 2 -select c1 as a, t.c1 as a from t order by a desc; -a a -2 2 -1 1 -select c1 as c2 from t order by c2; -c2 -1 -2 -select sum(c1) from t order by sum(c1); -sum(c1) -3 -select c1 as c2 from t order by c2 + 1; -c2 -2 -1 -select * from t order by 1; -c1 c2 c3 -1 2 abc -2 1 bcd -select * from t order by 2; -c1 c2 c3 -2 1 bcd -1 2 abc -select c1, c3 from t order by binary c1 desc; -c1 c3 -2 bcd -1 abc -select c1, c2 from t order by binary c3; -c1 c2 -1 2 -2 1 -create table t1(a int, b int); -create table t2(a int, b int); -insert into t1 value(1, 1), (2, 2); -insert into t2 value(1, 1), (2, 2); -select sum(c) from (select t1.a as a, t1.a as c, length(t1.b) from t1 union select a, b, b from t2) t; -sum(c) -5 -drop table if exists t; -create table t(a bigint, b bigint, c bigint); -insert into t values(1, 1, 1), (2, 2, 2), (3, 3, 3); -select cast(count(a) as signed), a as another, a from t group by a order by cast(count(a) as signed), a limit 10; -cast(count(a) as signed) another a -1 1 1 -1 2 2 -1 3 3 -drop table if exists t; -create table t (a int primary key auto_increment, b int, index idx (b)); -insert t (b) values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); -select b from t order by b desc; -b -9 -8 -7 -6 -5 -4 -3 -2 -1 -0 -select b from t where b <3 or (b >=6 and b < 8) order by b desc; -b -7 -6 -2 -1 -0 -drop table if exists t; -create table t (a int, b int, index idx (b, a)); -insert t values (0, 2), (1, 2), (2, 2), (0, 1), (1, 1), (2, 1), (0, 0), (1, 0), (2, 0); -select b, a from t order by b, a desc; -b a -0 2 -0 1 -0 0 -1 2 -1 1 -1 0 -2 2 -2 1 -2 0 -drop table if exists t; -create table t (a int primary key auto_increment, b int); -insert t (b) values (1), (2), (3), (4), (5), (6), (7), (8), (9); -select b from t order by a desc; -b -9 -8 -7 -6 -5 -4 -3 -2 -1 -select a from t where a <3 or (a >=6 and a < 8) order by a desc; -a -7 -6 -2 -1 -drop table if exists t; -create table t (a int unsigned primary key, b int, c int, key idx_ba (b, c, a)); -insert t values (1, 1, 1); -select * from t; -a b c -1 1 1 -update t set c=2 where a=1; -select * from t where b=1; -a b c -1 1 2 -CREATE TABLE test_mu (a int primary key, b int, c int); -INSERT INTO test_mu VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9); -INSERT INTO test_mu VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE b = 3, c = b; -SELECT * FROM test_mu ORDER BY a; -a b c -1 3 3 -4 5 6 -7 8 9 -INSERT INTO test_mu VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = 2, b = c+5; -SELECT * FROM test_mu ORDER BY a; -a b c -1 7 2 -4 5 6 -7 8 9 -UPDATE test_mu SET b = 0, c = b WHERE a = 4; -SELECT * FROM test_mu ORDER BY a; -a b c -1 7 2 -4 0 5 -7 8 9 -UPDATE test_mu SET c = 8, b = c WHERE a = 4; -SELECT * FROM test_mu ORDER BY a; -a b c -1 7 2 -4 5 8 -7 8 9 -UPDATE test_mu SET c = b, b = c WHERE a = 7; -SELECT * FROM test_mu ORDER BY a; -a b c -1 7 2 -4 5 8 -7 9 8 -drop table if exists tu; -CREATE TABLE tu(a int, b int, c int GENERATED ALWAYS AS (a + b) VIRTUAL, d int as (a * b) stored, e int GENERATED ALWAYS as (b * 2) VIRTUAL, PRIMARY KEY (a), UNIQUE KEY ukc (c), unique key ukd(d), key ke(e)); -insert into tu(a, b) values(1, 2); -insert into tu(a, b) values(5, 6); -select * from tu for update; -a b c d e -1 2 3 2 4 -5 6 11 30 12 -select * from tu where a = 1; -a b c d e -1 2 3 2 4 -select * from tu where a in (1, 2); -a b c d e -1 2 3 2 4 -select * from tu where c in (1, 2, 3); -a b c d e -1 2 3 2 4 -select * from tu where c = 3; -a b c d e -1 2 3 2 4 -select d, e from tu where c = 3; -d e -2 4 -select * from tu where d in (1, 2, 3); -a b c d e -1 2 3 2 4 -select * from tu where d = 2; -a b c d e -1 2 3 2 4 -select c, d from tu where d = 2; -c d -3 2 -select d, e from tu where e = 4; -d e -2 4 -select * from tu where e = 4; -a b c d e -1 2 3 2 4 -update tu set a = a + 1, b = b + 1 where c = 11; -select * from tu for update; -a b c d e -1 2 3 2 4 -6 7 13 42 14 -select * from tu where a = 6; -a b c d e -6 7 13 42 14 -select * from tu where c in (5, 6, 13); -a b c d e -6 7 13 42 14 -select b, c, e, d from tu where c = 13; -b c e d -7 13 14 42 -select a, e, d from tu where c in (5, 6, 13); -a e d -6 14 42 -drop table if exists tu; -drop table if exists t1,t2; -create table t1 (id int, i int, b bigint, d double, dd decimal); -create table t2 (id int, i int unsigned, b bigint unsigned, d double unsigned, dd decimal unsigned); -insert into t1 values(1, -1, -1, -1.1, -1); -insert into t2 values(2, 1, 1, 1.1, 1); -select * from t1 union select * from t2 order by id; -id i b d dd -1 -1 -1 -1.1 -1 -2 1 1 1.1 1 -select id, i, b, d, dd from t2 union select id, i, b, d, dd from t1 order by id; -id i b d dd -1 -1 -1 -1.1 -1 -2 1 1 1.1 1 -select id, i from t2 union select id, cast(i as unsigned int) from t1 order by id; -id i -1 18446744073709551615 -2 1 -select dd from t2 union all select dd from t2; -dd -1 -1 -drop table if exists t3,t4; -create table t3 (id int, v int); -create table t4 (id int, v double unsigned); -insert into t3 values (1, -1); -insert into t4 values (2, 1); -select id, v from t3 union select id, v from t4 order by id; -id v -1 -1 -2 1 -select id, v from t4 union select id, v from t3 order by id; -id v -1 -1 -2 1 -drop table if exists t5,t6,t7; -create table t5 (id int, v bigint unsigned); -create table t6 (id int, v decimal); -create table t7 (id int, v bigint); -insert into t5 values (1, 1); -insert into t6 values (2, -1); -insert into t7 values (3, -1); -select id, v from t5 union select id, v from t6 order by id; -id v -1 1 -2 -1 -select id, v from t5 union select id, v from t7 union select id, v from t6 order by id; -id v -1 1 -2 -1 -3 -1 -drop table if exists t1; -create table t1 (a int) partition by range (a) ( -partition p0 values less than (10), -partition p1 values less than (20), -partition p2 values less than (30), -partition p3 values less than (40), -partition p4 values less than MAXVALUE -); -insert into t1 values (1),(11),(21),(31); -delete from t1 partition (p4); -select * from t1 order by a; -a -1 -11 -21 -31 -delete from t1 partition (p0) where a > 10; -select * from t1 order by a; -a -1 -11 -21 -31 -delete from t1 partition (p0,p1,p2); -select * from t1; -a -31 -drop table if exists t_1; -create table t_1 (c1 int, c2 int, c3 int default 1, index (c1)) comment = 'test table'; -alter table `t_1` comment 'this is table comment'; -select table_comment from information_schema.tables where table_name = 't_1'; -table_comment -this is table comment -alter table `t_1` comment 'table t comment'; -select table_comment from information_schema.tables where table_name = 't_1'; -table_comment -table t comment -drop table if exists t; -create table t (c enum('a', 'b', 'c')); -insert into t values ('a'), (2), ('c'); -select * from t where c = 'a'; -c -a -select c + 1 from t where c = 2; -c + 1 -3 -delete from t; -insert into t values (); -insert into t values (null), ('1'); -select c + 1 from t where c = 1; -c + 1 -2 -delete from t; -insert into t values(1), (2), (3); -select * from t where c; -c -a -b -c -drop table if exists t; -create table t (c set('a', 'b', 'c')); -insert into t values ('a'), (2), ('c'), ('a,b'), ('b,a'); -select * from t where c = 'a'; -c -a -select * from t where c = 'a,b'; -c -a,b -a,b -select c + 1 from t where c = 2; -c + 1 -3 -delete from t; -insert into t values (); -insert into t values (null), ('1'); -select c + 1 from t where c = 1; -c + 1 -2 -delete from t; -insert into t values(3); -select * from t where c; -c -a,b -drop table if exists t; -create table t (id int, name varchar(20)); -drop table if exists t1; -create table t1 (gid int); -insert into t1 (gid) value (1); -insert into t (id, name) value ((select gid from t1) ,'asd'); -select * from t; -id name -1 asd -drop table if exists t; -create table t (a int primary key, b int); -insert into t values(1, 2), (2, 1); -select * from t where (a = 1 and b = 2) or (a = 2 and b = 1); -a b -1 2 -2 1 -select * from t where (a = 1 and b = 1) or (a = 2 and b = 2); -a b -drop table if exists t; -create table t(id int, PRIMARY KEY (id)); -insert into t values(1), (5), (10); -select * from t where id in(1, 2, 10); -id -1 -10 -drop table if exists admin_test; -create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)); -insert admin_test (c1, c2) values (1, 1), (2, 2), (NULL, NULL); -admin check table admin_test; -drop table if exists t; -create table t(a bigint, b bigint); -insert into t values(1, 1), (2, 2), (3, 30), (4, 40), (5, 5), (6, 6); -select * from t order by a limit 1, 1; -a b -2 2 -select * from t order by a limit 1, 2; -a b -2 2 -3 30 -select * from t order by a limit 1, 3; -a b -2 2 -3 30 -4 40 -select * from t order by a limit 1, 4; -a b -2 2 -3 30 -4 40 -5 5 -select a from t where a > 0 limit 1, 1; -a -2 -select a from t where a > 0 limit 1, 2; -a -2 -3 -select b from t where a > 0 limit 1, 3; -b -2 -30 -40 -select b from t where a > 0 limit 1, 4; -b -2 -30 -40 -5 -set @@tidb_init_chunk_size=2; -select * from t where a > 0 limit 2, 1; -a b -3 30 -select * from t where a > 0 limit 2, 2; -a b -3 30 -4 40 -select * from t where a > 0 limit 2, 3; -a b -3 30 -4 40 -5 5 -select * from t where a > 0 limit 2, 4; -a b -3 30 -4 40 -5 5 -6 6 -select a from t order by a limit 2, 1; -a -3 -select b from t order by a limit 2, 2; -b -30 -40 -select a from t order by a limit 2, 3; -a -3 -4 -5 -select b from t order by a limit 2, 4; -b -30 -40 -5 -6 -set @@tidb_init_chunk_size = default; -drop table if exists t; -create table t (a int unique); -insert t values (-1), (2), (3), (5), (6), (7), (8), (9); -select a from t where a < 0 or (a >= 2.1 and a < 5.1) or ( a > 5.9 and a <= 7.9) or a > '8.1'; -a --1 -3 -5 -6 -7 -9 -drop table if exists t; -create table t (a int unique); -insert t values (0); -select NULL from t ; -NULL -NULL -drop table if exists t; -create table t (a int unique, b int); -insert t values (5, 0); -insert t values (4, 0); -insert t values (3, 0); -insert t values (2, 0); -insert t values (1, 0); -insert t values (0, 0); -select * from t order by a limit 3; -a b -0 0 -1 0 -2 0 -drop table if exists t; -create table t (a int unique, b int); -insert t values (0, 1); -insert t values (1, 2); -insert t values (2, 1); -insert t values (3, 2); -insert t values (4, 1); -insert t values (5, 2); -select * from t where a < 5 and b = 1 limit 2; -a b -0 1 -2 1 -drop table if exists tab1; -CREATE TABLE tab1(pk INTEGER PRIMARY KEY, col0 INTEGER, col1 FLOAT, col3 INTEGER, col4 FLOAT); -CREATE INDEX idx_tab1_0 on tab1 (col0); -CREATE INDEX idx_tab1_1 on tab1 (col1); -CREATE INDEX idx_tab1_3 on tab1 (col3); -CREATE INDEX idx_tab1_4 on tab1 (col4); -INSERT INTO tab1 VALUES(1,37,20.85,30,10.69); -SELECT pk FROM tab1 WHERE ((col3 <= 6 OR col3 < 29 AND (col0 < 41)) OR col3 > 42) AND col1 >= 96.1 AND col3 = 30 AND col3 > 17 AND (col0 BETWEEN 36 AND 42); -pk -drop table if exists tab1; -CREATE TABLE tab1(pk INTEGER PRIMARY KEY, a INTEGER, b INTEGER); -CREATE INDEX idx_tab1_0 on tab1 (a); -INSERT INTO tab1 VALUES(1,1,1); -INSERT INTO tab1 VALUES(2,2,1); -INSERT INTO tab1 VALUES(3,1,2); -INSERT INTO tab1 VALUES(4,2,2); -SELECT * FROM tab1 WHERE pk <= 3 AND a = 1; -pk a b -1 1 1 -3 1 2 -SELECT * FROM tab1 WHERE pk <= 4 AND a = 1 AND b = 2; -pk a b -3 1 2 -CREATE INDEX idx_tab1_1 on tab1 (b, a); -SELECT pk FROM tab1 WHERE b > 1; -pk -3 -4 -drop table if exists t; -CREATE TABLE t (a varchar(3), index(a)); -insert t values('aaa'), ('aab'); -select * from t where a >= 'aaaa' and a < 'aabb'; -a -aab -drop table if exists t; -CREATE TABLE t (a int primary key, b int, c int, index(c)); -insert t values(1, 1, 1), (2, 2, 2), (4, 4, 4), (3, 3, 3), (5, 5, 5); -select a from t where c >= 2 order by b desc limit 1; -a -5 -drop table if exists t; -create table t(a varchar(50) primary key, b int, c int, index idx(b)); -insert into t values('aa', 1, 1); -select * from t use index(idx) where a > 'a'; -a b c -aa 1 1 -drop table if exists t; -CREATE TABLE `t` (a int, KEY (a)); -SELECT * FROM (SELECT * FROM (SELECT a as d FROM t WHERE a IN ('100')) AS x WHERE x.d < "123" ) tmp_count; -d -drop table if exists t1; -drop table if exists t2; -drop table if exists t3; -drop table if exists t4; -drop table if exists t5; -create table t1(k int, v int); -create table t2(k int, v int); -create table t3(id int auto_increment, k int, v int, primary key(id)); -create table t4(k int, v int); -create table t5(v int, k int, primary key(k)); -insert into t1 values (1, 1); -insert into t4 values (3, 3); -drop table if exists t6; -drop table if exists t7; -create table t6 (id int, v longtext); -create table t7 (x int, id int, v longtext, primary key(id)); -update t1 set v = 0 where k = 1; -select k, v from t1 where k = 1; -k v -1 0 -update t1 left join t3 on t1.k = t3.k set t1.v = 1; -select k, v from t1; -k v -1 1 -select id, k, v from t3; -id k v -update t1 left join t2 on t1.k = t2.k set t1.v = t2.v, t2.v = 3; -select k, v from t1; -k v -1 NULL -select k, v from t2; -k v -update t1 left join t2 on t1.k = t2.k set t2.v = 3, t1.v = t2.v; -select k, v from t1; -k v -1 NULL -select k, v from t2; -k v -update t2 right join t1 on t2.k = t1.k set t2.v = 4, t1.v = 0; -select k, v from t1; -k v -1 0 -select k, v from t2; -k v -update t1 left join t2 on t1.k = t2.k right join t4 on t4.k = t2.k set t1.v = 4, t2.v = 4, t4.v = 4; -select k, v from t1; -k v -1 0 -select k, v from t2; -k v -select k, v from t4; -k v -3 4 -insert t2 values (1, 10); -update t1 left join t2 on t1.k = t2.k set t2.v = 11; -select k, v from t2; -k v -1 11 -update t1 t11 left join t2 on t11.k = t2.k left join t1 t12 on t2.v = t12.k set t12.v = 233, t11.v = 111; -select k, v from t1; -k v -1 111 -select k, v from t2; -k v -1 11 -delete from t1; -delete from t2; -insert into t1 values (null, null); -update t1 left join t2 on t1.k = t2.k set t1.v = 1; -select k, v from t1; -k v -NULL 1 -insert t5 values(0, 0); -update t1 left join t5 on t1.k = t5.k set t1.v = 2; -select k, v from t1; -k v -NULL 2 -select k, v from t5; -k v -0 0 -insert into t6 values (1, NULL); -insert into t7 values (5, 1, 'a'); -update t6, t7 set t6.v = t7.v where t6.id = t7.id and t7.x = 5; -select v from t6; -v -a -drop table if exists t1, t2; -create table t1(id int primary key, v int, gv int GENERATED ALWAYS AS (v * 2) STORED); -create table t2(id int, v int); -update t1 tt1 inner join (select count(t1.id) a, t1.id from t1 left join t2 on t1.id = t2.id group by t1.id) x on tt1.id = x.id set tt1.v = tt1.v + x.a; -drop table if exists t; -create table t(a int primary key, b int, c int, index idx_b(b)); -insert into t values (1, 1, 1), (2, 1, 1), (3, 1, 2), (4, 2, 3); -select (select count(1) k from t s where s.b = t1.c) from t t1; -(select count(1) k from t s where s.b = t1.c) -3 -3 -1 -0 -drop table if exists t; -create table t(a int primary key, b int, c int); -insert into t values (1, 1, 1), (2, 1, 1), (3, 1, 2), (4, 2, 3); -select a from t; -a -1 -2 -3 -4 -select * from t where a = 4; -a b c -4 2 3 -select a from t limit 1; -a -1 -select a from t order by a desc; -a -4 -3 -2 -1 -select a from t order by a desc limit 1; -a -4 -select a from t order by b desc limit 1; -a -4 -select a from t where a < 3; -a -1 -2 -select a from t where b > 1; -a -4 -select a from t where b > 1 and a < 3; -a -select count(*) from t where b > 1 and a < 3; -count(*) -0 -select count(*) from t; -count(*) -4 -select count(*), c from t group by c order by c; -count(*) c -2 1 -1 2 -1 3 -select sum(c) as s from t group by b order by s; -s -3 -4 -select avg(a) as s from t group by b order by s; -s -2.0000 -4.0000 -select sum(distinct c) from t group by b; -sum(distinct c) -3 -3 -create index i on t(c,b); -select a from t where c = 1; -a -1 -2 -select a from t where c = 1 and a < 2; -a -1 -select a from t where c = 1 order by a limit 1; -a -1 -select count(*) from t where c = 1 ; -count(*) -2 -create index i1 on t(b); -select c from t where b = 2; -c -3 -select * from t where b = 2; -a b c -4 2 3 -select count(*) from t where b = 1; -count(*) -3 -select * from t where b = 1 and a > 1 limit 1; -a b c -2 1 1 -drop table if exists t; -create table t (id int, c1 datetime); -insert into t values (1, '2015-06-07 12:12:12'); -select id from t where c1 = '2015-06-07 12:12:12'; -id -1 -drop table if exists t0; -CREATE TABLE t0(c0 INT); -INSERT INTO t0 VALUES (100000); -SELECT * FROM t0 WHERE NOT SPACE(t0.c0); -c0 -100000 -drop table if exists t; -create table t(a int, primary key(a)); -insert into t(a) values(1); -alter table t add column b int default 1; -alter table t alter b set default 2; -select b from t where a = 1; -b -1 -drop table if exists t1; -create table t1 (a int, b int as (a + 1) virtual not null, unique index idx(b)); -REPLACE INTO `t1` (`a`) VALUES (2); -REPLACE INTO `t1` (`a`) VALUES (2); -select * from t1; -a b -2 3 -insert into `t1` (`a`) VALUES (2) on duplicate key update a = 3; -select * from t1; -a b -3 4 -drop table if exists t1; -create table t1 (c_int int, c_str varchar(40), key(c_str)); -drop table if exists t2; -create table t2 like t1; -insert into t1 values (1, 'a'), (2, 'b'), (3, 'c'); -insert into t2 select * from t1; -select (select t2.c_str from t2 where t2.c_str <= t1.c_str and t2.c_int in (1, 2) order by t2.c_str limit 1) x from t1 order by c_int; -x -a -a -a -drop table if exists t1, t2; -create table t1 (c1 int); -create table t2 (c1 int primary key, c2 int); -insert into t1 values(3); -insert into t2 values(2, 2); -insert into t2 values(0, 0); -delete from t1, t2 using t1 left join t2 on t1.c1 = t2.c2; -select * from t1 order by c1; -c1 -select * from t2 order by c1; -c1 c2 -0 0 -2 2 -drop table if exists t1, t2; -create table t1 (c1 int); -create table t2 (c2 int); -insert into t1 values(null); -insert into t2 values(null); -delete from t1, t2 using t1 join t2 where t1.c1 is null; -select * from t1; -c1 -select * from t2; -c2 -drop table if exists t1, t2; -create table t1 (pk int(11) primary key, a int(11) not null, b int(11), key idx_b(b), key idx_a(a)); -insert into `t1` values (1,1,0),(2,7,6),(3,2,null),(4,1,null),(5,4,5); -create table t2 (a int); -insert into t2 values (1),(null); -select (select a from t1 use index(idx_a) where b >= t2.a order by a limit 1) as field from t2; -field -4 -NULL -drop table if exists t, s; -create table t(a date, b float); -create table s(b float); -insert into t values(NULL,-37), ("2011-11-04",105), ("2013-03-02",-22), ("2006-07-02",-56), (NULL,124), (NULL,111), ("2018-03-03",-5); -insert into s values(-37),(105),(-22),(-56),(124),(105),(111),(-5); -select count(distinct t.a, t.b) from t join s on t.b= s.b; -count(distinct t.a, t.b) -4 -drop table if exists t; -create table t (a decimal(10,6), b decimal, index idx_b (b)); -set sql_mode = ''; -insert t values (1.1, 1.1); -insert t values (2.4, 2.4); -insert t values (3.3, 2.7); -select * from t where a < 2.399999; -a b -1.100000 1 -select * from t where a > 1.5; -a b -2.400000 2 -3.300000 3 -select * from t where a <= 1.1; -a b -1.100000 1 -select * from t where b >= 3; -a b -3.300000 3 -select * from t where not (b = 1); -a b -2.400000 2 -3.300000 3 -select * from t where b&1 = a|1; -a b -1.100000 1 -select * from t where b != 2 and b <=> 3; -a b -3.300000 3 -select * from t where b in (3); -a b -3.300000 3 -select * from t where b not in (1, 2); -a b -3.300000 3 -drop table if exists t; -create table t (a varchar(255), b int); -insert t values ('abc123', 1); -insert t values ('ab123', 2); -select * from t where a like 'ab%'; -a b -abc123 1 -ab123 2 -select * from t where a like 'ab_12'; -a b -drop table if exists t; -create table t (a int primary key); -insert t values (1); -insert t values (2); -select * from t where not (a = 1); -a -2 -select * from t where not(not (a = 1)); -a -1 -select * from t where not(a != 1 and a != 2); -a -1 -2 -set @@sql_mode = default; -drop table if exists t; -create table t (a decimal(10,6), b decimal, index idx_b (b)); -set sql_mode = ''; -insert t values (1.1, 1.1); -insert t values (2.2, 2.2); -insert t values (3.3, 2.7); -select * from t where a > 1.5; -a b -2.200000 2 -3.300000 3 -select * from t where b > 1.5; -a b -2.200000 2 -3.300000 3 -drop table if exists t; -create table t (a time(3), b time, index idx_a (a)); -insert t values ('11:11:11', '11:11:11'); -insert t values ('11:11:12', '11:11:12'); -insert t values ('11:11:13', '11:11:13'); -select * from t where a > '11:11:11.5'; -a b -11:11:12.000 11:11:12 -11:11:13.000 11:11:13 -select * from t where b > '11:11:11.5'; -a b -11:11:12.000 11:11:12 -11:11:13.000 11:11:13 -set @@sql_mode = default; -Select 1; -1 -1 -Select 1 from dual; -1 -1 -Select count(*) from dual; -count(*) -1 -Select 1 from dual where 1; -1 -1 -drop table if exists t; -create table t(a int primary key); -select t1.* from t t1, t t2 where t1.a=t2.a and 1=0; -a -drop table if exists t; -create table t (c int, d int); -insert t values (1, 1); -insert t values (1, 3); -insert t values (2, 1); -insert t values (2, 3); -select * from t where (c, d) < (2,2); -c d -1 1 -1 3 -2 1 -select * from t where (1,2,3) > (3,2,1); -c d -select * from t where row(1,2,3) > (3,2,1); -c d -select * from t where (c, d) = (select * from t where (c,d) = (1,1)); -c d -1 1 -select * from t where (c, d) = (select * from t k where (t.c,t.d) = (c,d)); -c d -1 1 -1 3 -2 1 -2 3 -select (1, 2, 3) < (2, 3, 4); -(1, 2, 3) < (2, 3, 4) -1 -select (2, 3, 4) <= (2, 3, 3); -(2, 3, 4) <= (2, 3, 3) -0 -select (2, 3, 4) <= (2, 3, 4); -(2, 3, 4) <= (2, 3, 4) -1 -select (2, 3, 4) <= (2, 1, 4); -(2, 3, 4) <= (2, 1, 4) -0 -select (2, 3, 4) >= (2, 3, 4); -(2, 3, 4) >= (2, 3, 4) -1 -select (2, 3, 4) = (2, 3, 4); -(2, 3, 4) = (2, 3, 4) -1 -select (2, 3, 4) != (2, 3, 4); -(2, 3, 4) != (2, 3, 4) -0 -select row(1, 1) in (row(1, 1)); -row(1, 1) in (row(1, 1)) -1 -select row(1, 0) in (row(1, 1)); -row(1, 0) in (row(1, 1)) -0 -select row(1, 1) in (select 1, 1); -row(1, 1) in (select 1, 1) -1 -select row(1, 1) > row(1, 0); -row(1, 1) > row(1, 0) -1 -select row(1, 1) > (select 1, 0); -row(1, 1) > (select 1, 0) -1 -select 1 > (select 1); -1 > (select 1) -0 -select (select 1); -(select 1) -1 -drop table if exists t1; -create table t1 (a int, b int); -insert t1 values (1,2),(1,null); -drop table if exists t2; -create table t2 (c int, d int); -insert t2 values (0,0); -select * from t2 where (1,2) in (select * from t1); -c d -0 0 -select * from t2 where (1,2) not in (select * from t1); -c d -select * from t2 where (1,1) not in (select * from t1); -c d -select * from t2 where (1,null) in (select * from t1); -c d -select * from t2 where (null,null) in (select * from t1); -c d -delete from t1 where a=1 and b=2; -select (1,1) in (select * from t2) from t1; -(1,1) in (select * from t2) -0 -select (1,1) not in (select * from t2) from t1; -(1,1) not in (select * from t2) -1 -select (1,1) in (select 1,1 from t2) from t1; -(1,1) in (select 1,1 from t2) -1 -select (1,1) not in (select 1,1 from t2) from t1; -(1,1) not in (select 1,1 from t2) -0 -select (1,null) not in (select 1,1 from t2) from t1; -(1,null) not in (select 1,1 from t2) -NULL -select (t1.a,null) not in (select 1,1 from t2) from t1; -(t1.a,null) not in (select 1,1 from t2) -NULL -select (1,null) in (select * from t1); -(1,null) in (select * from t1) -NULL -select (1,null) not in (select * from t1); -(1,null) not in (select * from t1) -NULL -select str_to_date('20190101','%Y%m%d%!') from dual; -str_to_date('20190101','%Y%m%d%!') -2019-01-01 -select str_to_date('20190101','%Y%m%d%f') from dual; -str_to_date('20190101','%Y%m%d%f') -2019-01-01 00:00:00.000000 -select str_to_date('20190101','%Y%m%d%H%i%s') from dual; -str_to_date('20190101','%Y%m%d%H%i%s') -2019-01-01 00:00:00 -select str_to_date('18/10/22','%y/%m/%d') from dual; -str_to_date('18/10/22','%y/%m/%d') -2018-10-22 -select str_to_date('a18/10/22','%y/%m/%d') from dual; -str_to_date('a18/10/22','%y/%m/%d') -NULL -select str_to_date('69/10/22','%y/%m/%d') from dual; -str_to_date('69/10/22','%y/%m/%d') -2069-10-22 -select str_to_date('70/10/22','%y/%m/%d') from dual; -str_to_date('70/10/22','%y/%m/%d') -1970-10-22 -select str_to_date('8/10/22','%y/%m/%d') from dual; -str_to_date('8/10/22','%y/%m/%d') -2008-10-22 -select str_to_date('8/10/22','%Y/%m/%d') from dual; -str_to_date('8/10/22','%Y/%m/%d') -2008-10-22 -select str_to_date('18/10/22','%Y/%m/%d') from dual; -str_to_date('18/10/22','%Y/%m/%d') -2018-10-22 -select str_to_date('a18/10/22','%Y/%m/%d') from dual; -str_to_date('a18/10/22','%Y/%m/%d') -NULL -select str_to_date('69/10/22','%Y/%m/%d') from dual; -str_to_date('69/10/22','%Y/%m/%d') -2069-10-22 -select str_to_date('70/10/22','%Y/%m/%d') from dual; -str_to_date('70/10/22','%Y/%m/%d') -1970-10-22 -select str_to_date('018/10/22','%Y/%m/%d') from dual; -str_to_date('018/10/22','%Y/%m/%d') -0018-10-22 -select str_to_date('2018/10/22','%Y/%m/%d') from dual; -str_to_date('2018/10/22','%Y/%m/%d') -2018-10-22 -select str_to_date('018/10/22','%y/%m/%d') from dual; -str_to_date('018/10/22','%y/%m/%d') -NULL -select str_to_date('18/10/22','%y0/%m/%d') from dual; -str_to_date('18/10/22','%y0/%m/%d') -NULL -select str_to_date('18/10/22','%Y0/%m/%d') from dual; -str_to_date('18/10/22','%Y0/%m/%d') -NULL -select str_to_date('18a/10/22','%y/%m/%d') from dual; -str_to_date('18a/10/22','%y/%m/%d') -NULL -select str_to_date('18a/10/22','%Y/%m/%d') from dual; -str_to_date('18a/10/22','%Y/%m/%d') -NULL -select str_to_date('20188/10/22','%Y/%m/%d') from dual; -str_to_date('20188/10/22','%Y/%m/%d') -NULL -select str_to_date('2018510522','%Y5%m5%d') from dual; -str_to_date('2018510522','%Y5%m5%d') -2018-10-22 -select str_to_date('2018^10^22','%Y^%m^%d') from dual; -str_to_date('2018^10^22','%Y^%m^%d') -2018-10-22 -select str_to_date('2018@10@22','%Y@%m@%d') from dual; -str_to_date('2018@10@22','%Y@%m@%d') -2018-10-22 -select str_to_date('2018%10%22','%Y%%m%%d') from dual; -str_to_date('2018%10%22','%Y%%m%%d') -NULL -select str_to_date('2018(10(22','%Y(%m(%d') from dual; -str_to_date('2018(10(22','%Y(%m(%d') -2018-10-22 -select str_to_date('2018\10\22','%Y\%m\%d') from dual; -str_to_date('2018\10\22','%Y\%m\%d') -NULL -select str_to_date('2018=10=22','%Y=%m=%d') from dual; -str_to_date('2018=10=22','%Y=%m=%d') -2018-10-22 -select str_to_date('2018+10+22','%Y+%m+%d') from dual; -str_to_date('2018+10+22','%Y+%m+%d') -2018-10-22 -select str_to_date('2018_10_22','%Y_%m_%d') from dual; -str_to_date('2018_10_22','%Y_%m_%d') -2018-10-22 -select str_to_date('69510522','%y5%m5%d') from dual; -str_to_date('69510522','%y5%m5%d') -2069-10-22 -select str_to_date('69^10^22','%y^%m^%d') from dual; -str_to_date('69^10^22','%y^%m^%d') -2069-10-22 -select str_to_date('18@10@22','%y@%m@%d') from dual; -str_to_date('18@10@22','%y@%m@%d') -2018-10-22 -select str_to_date('18%10%22','%y%%m%%d') from dual; -str_to_date('18%10%22','%y%%m%%d') -NULL -select str_to_date('18(10(22','%y(%m(%d') from dual; -str_to_date('18(10(22','%y(%m(%d') -2018-10-22 -select str_to_date('18\10\22','%y\%m\%d') from dual; -str_to_date('18\10\22','%y\%m\%d') -NULL -select str_to_date('18+10+22','%y+%m+%d') from dual; -str_to_date('18+10+22','%y+%m+%d') -2018-10-22 -select str_to_date('18=10=22','%y=%m=%d') from dual; -str_to_date('18=10=22','%y=%m=%d') -2018-10-22 -select str_to_date('18_10_22','%y_%m_%d') from dual; -str_to_date('18_10_22','%y_%m_%d') -2018-10-22 -SELECT STR_TO_DATE('2020-07-04 11:22:33 PM', '%Y-%m-%d %r'); -STR_TO_DATE('2020-07-04 11:22:33 PM', '%Y-%m-%d %r') -2020-07-04 23:22:33 -SELECT STR_TO_DATE('2020-07-04 12:22:33 AM', '%Y-%m-%d %r'); -STR_TO_DATE('2020-07-04 12:22:33 AM', '%Y-%m-%d %r') -2020-07-04 00:22:33 -SELECT STR_TO_DATE('2020-07-04 12:22:33', '%Y-%m-%d %T'); -STR_TO_DATE('2020-07-04 12:22:33', '%Y-%m-%d %T') -2020-07-04 12:22:33 -SELECT STR_TO_DATE('2020-07-04 00:22:33', '%Y-%m-%d %T'); -STR_TO_DATE('2020-07-04 00:22:33', '%Y-%m-%d %T') -2020-07-04 00:22:33 -drop table if exists pt; -create table pt (a int, b int, index i_b(b)) partition by range (a) (partition p1 values less than (2), partition p2 values less than (4), partition p3 values less than (6)); -insert into pt values(0, 0); -insert into pt values(1, 1); -insert into pt values(2, 2); -insert into pt values(3, 3); -insert into pt values(4, 4); -insert into pt values(5, 5); -select * from pt order by a; -a b -0 0 -1 1 -2 2 -3 3 -4 4 -5 5 -select b from pt where b = 3; -b -3 -select a from pt where b = 3; -a -3 -drop table if exists t1; -create table t1(i int, j int, k int); -insert into t1 VALUES (1,1,1),(2,2,2),(3,3,3),(4,4,4); -INSERT INTO t1 SELECT 10*i,j,5*j FROM t1 UNION SELECT 20*i,j,5*j FROM t1 UNION SELECT 30*i,j,5*j FROM t1; -set @@session.tidb_enable_window_function=1; -SELECT SUM(i) OVER W FROM t1 WINDOW w AS (PARTITION BY j ORDER BY i) ORDER BY 1+SUM(i) OVER w; -SUM(i) OVER W -1 -2 -3 -4 -11 -22 -31 -33 -44 -61 -62 -93 -122 -124 -183 -244 -set @@session.tidb_enable_window_function=default; -drop table if exists a; -create table a (f1 int, f2 varchar(32), primary key (f1)); -insert into a (f1,f2) values (1,'a'), (2,'b'), (3,'c'); -select /*+ inl_merge_join(a) */ a.* from a inner join (select 1 as k1,'k2-1' as k2) as k on a.f1=k.k1; -f1 f2 -1 a -drop table if exists t1, t2; -create table t1(a int); -create table t2(a int); -insert into t1(a) select 1; -select b.n from t1 left join (select a as a, null as n from t2) b on b.a = t1.a order by t1.a; -n -NULL -drop table if exists t; -drop table if exists s; -CREATE TABLE `t` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL); -CREATE TABLE `s` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL); -insert into t values(1,1),(2,2); -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into s values(3,3),(4,4),(1,null),(2,null),(null,null); -insert into s select * from s; -insert into s select * from s; -insert into s select * from s; -insert into s select * from s; -insert into s select * from s; -set @@tidb_max_chunk_size=32; -set @@tidb_enable_null_aware_anti_join=true; -select * from t where (a,b) not in (select a, b from s); -a b -set @@tidb_max_chunk_size=default; -set @@tidb_enable_null_aware_anti_join=default; -drop table if exists t; -create table t(id int primary key, a int); -insert into t values(1, 1); -begin PESSIMISTIC; -select a from t where id=1 for update; -a -1 -update t set a=a+1 where id=1; -commit; -select a from t where id=1; -a -2 -drop table if exists select_limit; -create table select_limit(id int not null default 1, name varchar(255), PRIMARY KEY(id)); -insert INTO select_limit VALUES (1, "hello"); -insert into select_limit values (2, "hello"); -insert INTO select_limit VALUES (3, "hello"); -insert INTO select_limit VALUES (4, "hello"); -select * from select_limit limit 1; -id name -1 hello -select id from (select * from select_limit limit 1) k where id != 1; -id -select * from select_limit limit 18446744073709551615 offset 0; -id name -1 hello -2 hello -3 hello -4 hello -select * from select_limit limit 18446744073709551615 offset 1; -id name -2 hello -3 hello -4 hello -select * from select_limit limit 18446744073709551615 offset 3; -id name -4 hello -select * from select_limit limit 18446744073709551616 offset 3; -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 53 near "18446744073709551616 offset 3;" -drop table if exists select_order_test; -create table select_order_test(id int not null default 1, name varchar(255), PRIMARY KEY(id)); -insert INTO select_order_test VALUES (1, "hello"); -insert into select_order_test values (2, "hello"); -select * from select_order_test where id = 1 order by id limit 1 offset 0; -id name -1 hello -select id from select_order_test order by id desc limit 1 ; -id -2 -select id from select_order_test order by id + 1 desc limit 1 ; -id -2 -select * from select_order_test order by name, id limit 1 offset 0; -id name -1 hello -select id as c1, name from select_order_test order by 2, id limit 1 offset 0; -c1 name -1 hello -select * from select_order_test order by name, id limit 100 offset 0; -id name -1 hello -2 hello -select * from select_order_test order by name, id limit 1 offset 100; -id name -select id from select_order_test order by name, id limit 18446744073709551615; -id -1 -2 -select id, name from select_order_test where id = 1 group by id, name limit 1 offset 0; -id name -1 hello -insert INTO select_order_test VALUES (3, "zz"); -insert INTO select_order_test VALUES (4, "zz"); -insert INTO select_order_test VALUES (5, "zz"); -insert INTO select_order_test VALUES (6, "zz"); -insert INTO select_order_test VALUES (7, "zz"); -insert INTO select_order_test VALUES (8, "zz"); -insert INTO select_order_test VALUES (9, "zz"); -insert INTO select_order_test VALUES (10, "zz"); -insert INTO select_order_test VALUES (10086, "hi"); -insert INTO select_order_test VALUES (11, "hh"); -insert INTO select_order_test VALUES (12, "hh"); -insert INTO select_order_test VALUES (13, "hh"); -insert INTO select_order_test VALUES (14, "hh"); -insert INTO select_order_test VALUES (15, "hh"); -insert INTO select_order_test VALUES (16, "hh"); -insert INTO select_order_test VALUES (17, "hh"); -insert INTO select_order_test VALUES (18, "hh"); -insert INTO select_order_test VALUES (19, "hh"); -insert INTO select_order_test VALUES (20, "hh"); -insert INTO select_order_test VALUES (21, "zz"); -insert INTO select_order_test VALUES (22, "zz"); -insert INTO select_order_test VALUES (23, "zz"); -insert INTO select_order_test VALUES (24, "zz"); -insert INTO select_order_test VALUES (25, "zz"); -insert INTO select_order_test VALUES (26, "zz"); -insert INTO select_order_test VALUES (27, "zz"); -insert INTO select_order_test VALUES (28, "zz"); -insert INTO select_order_test VALUES (29, "zz"); -insert INTO select_order_test VALUES (30, "zz"); -insert INTO select_order_test VALUES (1501, "aa"); -select * from select_order_test order by name, id limit 1 offset 3; -id name -11 hh -drop table if exists select_order_test; -drop table if exists t; -create table t (c int, d int); -insert t values (1, 1); -insert t values (1, 2); -insert t values (1, 3); -select 1-d as d from t order by d; -d --2 --1 -0 -select 1-d as d from t order by d + 1; -d -0 --1 --2 -select t.d from t order by d; -d -1 -2 -3 -drop table if exists t; -create table t (a int, b int, c int); -insert t values (1, 2, 3); -select b from (select a,b from t order by a,c) t; -b -2 -select b from (select a,b from t order by a,c limit 1) t; -b -2 -drop table if exists t; -create table t(a int, b int, index idx(a)); -insert into t values(1, 1), (2, 2); -select * from t where 1 order by b; -a b -1 1 -2 2 -select * from t where a between 1 and 2 order by a desc; -a b -2 2 -1 1 -drop table if exists t; -create table t(a int primary key, b int, c int, index idx(b)); -insert into t values(1, 3, 1); -insert into t values(2, 2, 2); -insert into t values(3, 1, 3); -select * from t use index(idx) order by a desc limit 1; -a b c -3 1 3 -drop table if exists t; -create table t(a int, b int, key b (b)); -set @@tidb_index_lookup_size = 3; -insert into t values(0, 10); -insert into t values(1, 9); -insert into t values(2, 8); -insert into t values(3, 7); -insert into t values(4, 6); -insert into t values(5, 5); -insert into t values(6, 4); -insert into t values(7, 3); -insert into t values(8, 2); -insert into t values(9, 1); -select a from t use index(b) order by b; -a -9 -8 -7 -6 -5 -4 -3 -2 -1 -0 -set @@tidb_index_lookup_size = default; -select row(1, 1) from test; -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select * from test group by row(1, 1); -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select * from test order by row(1, 1); -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select * from test having row(1, 1); -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select (select 1, 1) from test; -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select * from test group by (select 1, 1); -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select * from test order by (select 1, 1); -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -select * from test having (select 1, 1); -Error 1146 (42S02): Table 'executor__executor.test' doesn't exist -drop table if exists t; -create table t (c1 int primary key, c2 int, key c (c2)); -insert t values(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (26, 26), (27, 27), (28, 28), (29, 29), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (37, 37), (38, 38), (39, 39), (40, 40), (41, 41), (42, 42), (43, 43), (44, 44), (45, 45), (46, 46), (47, 47), (48, 48), (49, 49), (50, 50), (51, 51), (52, 52), (53, 53), (54, 54), (55, 55), (56, 56), (57, 57), (58, 58), (59, 59), (60, 60), (61, 61), (62, 62), (63, 63), (64, 64), (65, 65), (66, 66), (67, 67), (68, 68), (69, 69), (70, 70), (71, 71), (72, 72), (73, 73), (74, 74), (75, 75), (76, 76), (77, 77), (78, 78), (79, 79), (80, 80), (81, 81), (82, 82), (83, 83), (84, 84), (85, 85), (86, 86), (87, 87), (88, 88), (89, 89), (90, 90), (91, 91), (92, 92), (93, 93), (94, 94), (95, 95), (96, 96), (97, 97), (98, 98), (99, 99), (100, 100), (101, 101), (102, 102), (103, 103), (104, 104), (105, 105), (106, 106), (107, 107), (108, 108), (109, 109), (110, 110), (111, 111), (112, 112), (113, 113), (114, 114), (115, 115), (116, 116), (117, 117), (118, 118), (119, 119), (120, 120), (121, 121), (122, 122), (123, 123), (124, 124), (125, 125), (126, 126), (127, 127), (128, 128), (129, 129), (130, 130), (131, 131), (132, 132), (133, 133), (134, 134), (135, 135), (136, 136), (137, 137), (138, 138), (139, 139), (140, 140), (141, 141), (142, 142), (143, 143), (144, 144), (145, 145), (146, 146), (147, 147), (148, 148), (149, 149), (150, 150), (151, 151), (152, 152), (153, 153), (154, 154), (155, 155), (156, 156), (157, 157), (158, 158), (159, 159), (160, 160), (161, 161), (162, 162), (163, 163), (164, 164), (165, 165), (166, 166), (167, 167), (168, 168), (169, 169), (170, 170), (171, 171), (172, 172), (173, 173), (174, 174), (175, 175), (176, 176), (177, 177), (178, 178), (179, 179), (180, 180), (181, 181), (182, 182), (183, 183), (184, 184), (185, 185), (186, 186), (187, 187), (188, 188), (189, 189), (190, 190), (191, 191), (192, 192), (193, 193), (194, 194), (195, 195), (196, 196), (197, 197), (198, 198), (199, 199), (200, 200); -select c2 from t where c1 in ('7', '10', '112', '111', '98', '106', '100', '9', '18', '17') order by c2; -c2 -7 -9 -10 -17 -18 -98 -100 -106 -111 -112 -select c2 from t where c1 in ('7a'); -c2 -7 -drop table if exists t; -create table t (a int PRIMARY KEY AUTO_INCREMENT); -insert t values (),(); -insert t values (-100),(0); -select * from t; -a --100 -1 -2 -3 -select * from t where a = 1; -a -1 -select * from t where a != 1; -a --100 -2 -3 -select * from t where a >= '1.1'; -a -2 -3 -select * from t where a < '1.1'; -a --100 -1 -select * from t where a > '-100.1' and a < 2; -a --100 -1 -select * from t where a is null; -a -select * from t where a is true; -a --100 -1 -2 -3 -select * from t where a is false; -a -select * from t where a in (1, 2); -a -1 -2 -select * from t where a between 1 and 2; -a -1 -2 -drop table if exists t; -create table t (a int primary key auto_increment, b int default 1, c int); -insert t values (); -select * from t; -a b c -1 1 NULL -update t set b = NULL where a = 1; -select * from t; -a b c -1 NULL NULL -update t set c = 1; -select * from t ; -a b c -1 NULL 1 -delete from t where a = 1; -insert t (a) values (1); -select * from t; -a b c -1 1 NULL -drop table if exists test_json; -create table test_json (id int, a json); -insert into test_json (id, a) values (1, '{"a":[1,"2",{"aa":"bb"},4],"b":true}'); -insert into test_json (id, a) values (2, "null"); -insert into test_json (id, a) values (3, null); -insert into test_json (id, a) values (4, 'true'); -insert into test_json (id, a) values (5, '3'); -insert into test_json (id, a) values (5, '4.0'); -insert into test_json (id, a) values (6, '"string"'); -select tj.a from test_json tj order by tj.id; -a -{"a": [1, "2", {"aa": "bb"}, 4], "b": true} -null -NULL -true -3 -4 -"string" -select json_type(a) from test_json tj order by tj.id; -json_type(a) -OBJECT -NULL -NULL -BOOLEAN -INTEGER -DOUBLE -STRING -select a from test_json tj where a = 3; -a -3 -select a from test_json tj where a = 4.0; -a -4 -select a from test_json tj where a = true; -a -true -select a from test_json tj where a = "string"; -a -"string" -select cast(true as JSON); -cast(true as JSON) -true -select cast(false as JSON); -cast(false as JSON) -false -select a->>'$.a[2].aa' as x, a->'$.b' as y from test_json having x is not null order by id; -x y -bb true -select a->'$.a[2].aa' as x, a->>'$.b' as y from test_json having x is not null order by id; -x y -"bb" true -create table test_bad_json(a json default '{}'); -Error 1101 (42000): BLOB/TEXT/JSON column 'a' can't have a default value -create table test_bad_json(a blob default 'hello'); -Error 1101 (42000): BLOB/TEXT/JSON column 'a' can't have a default value -create table test_bad_json(a text default 'world'); -Error 1101 (42000): BLOB/TEXT/JSON column 'a' can't have a default value -create table test_bad_json(id int, a json, key (a)); -Error 3152 (42000): JSON column 'a' cannot be used in key specification. -select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON); -CAST('3' AS JSON) CAST('{}' AS JSON) CAST(null AS JSON) -3 {} NULL -select a, count(1) from test_json group by a order by a; -a count(1) -NULL 1 -null 1 -3 1 -4 1 -"string" 1 -{"a": [1, "2", {"aa": "bb"}, 4], "b": true} 1 -true 1 -drop table if exists test_json; -create table test_json ( a decimal(60,2) as (JSON_EXTRACT(b,'$.c')), b json ); -insert into test_json (b) values -('{"c": "1267.1"}'), -('{"c": "1267.01"}'), -('{"c": "1267.1234"}'), -('{"c": "1267.3456"}'), -('{"c": "1234567890123456789012345678901234567890123456789012345"}'), -('{"c": "1234567890123456789012345678901234567890123456789012345.12345"}'); -select a from test_json; -a -1267.10 -1267.01 -1267.12 -1267.35 -1234567890123456789012345678901234567890123456789012345.00 -1234567890123456789012345678901234567890123456789012345.12 -drop table if exists test_gc_write, test_gc_write_1; -CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (a+8) virtual); -Error 3109 (HY000): Generated column 'c' cannot refer to auto-increment column. -CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (b+8) virtual); -CREATE TABLE test_gc_write_1 (a int primary key, b int, c int); -insert into test_gc_write (a, b, c) values (1, 1, 1); -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -insert into test_gc_write values (1, 1, 1); -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -insert into test_gc_write select 1, 1, 1; -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -insert into test_gc_write (a, b) values (1, 1) on duplicate key update c = 1; -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -insert into test_gc_write set a = 1, b = 1, c = 1; -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -update test_gc_write set c = 1; -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -update test_gc_write, test_gc_write_1 set test_gc_write.c = 1; -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -insert into test_gc_write (a, b) values (1, 1); -insert into test_gc_write set a = 2, b = 2; -insert into test_gc_write (b) select c from test_gc_write; -update test_gc_write set b = 2 where a = 2; -update test_gc_write t1, test_gc_write_1 t2 set t1.b = 3, t2.b = 4; -insert into test_gc_write values (1, 1); -Error 1136 (21S01): Column count doesn't match value count at row 1 -insert into test_gc_write select 1, 1; -Error 1136 (21S01): Column count doesn't match value count at row 1 -insert into test_gc_write (c) select a, b from test_gc_write; -Error 1136 (21S01): Column count doesn't match value count at row 1 -insert into test_gc_write (b, c) select a, b from test_gc_write; -Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. -drop table if exists test_gc_read; -CREATE TABLE test_gc_read(a int primary key, b int, c int as (a+b), d int as (a*b) stored, e int as (c*2)); -SELECT generation_expression FROM information_schema.columns WHERE table_name = 'test_gc_read' AND column_name = 'd'; -generation_expression -`a` * `b` -INSERT INTO test_gc_read (a, b) VALUES (0,null),(1,2),(3,4); -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -INSERT INTO test_gc_read SET a = 5, b = 10; -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -5 10 15 50 30 -REPLACE INTO test_gc_read (a, b) VALUES (5, 6); -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -5 6 11 30 22 -INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE b = 9; -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -5 9 14 45 28 -SELECT c, d FROM test_gc_read; -c d -NULL NULL -3 2 -7 12 -14 45 -SELECT e FROM test_gc_read; -e -NULL -6 -14 -28 -INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE a = 6, b = a; -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -6 6 12 36 24 -INSERT INTO test_gc_read (a, b) VALUES (6, 8) ON DUPLICATE KEY UPDATE b = 8, a = b; -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -8 8 16 64 32 -SELECT * FROM test_gc_read WHERE c = 7; -a b c d e -3 4 7 12 14 -SELECT * FROM test_gc_read WHERE d = 64; -a b c d e -8 8 16 64 32 -SELECT * FROM test_gc_read WHERE e = 6; -a b c d e -1 2 3 2 6 -UPDATE test_gc_read SET a = a + 100 WHERE c = 7; -SELECT * FROM test_gc_read WHERE c = 107; -a b c d e -103 4 107 412 214 -UPDATE test_gc_read m SET m.a = m.a + 100 WHERE c = 107; -SELECT * FROM test_gc_read WHERE c = 207; -a b c d e -203 4 207 812 414 -UPDATE test_gc_read SET a = a - 200 WHERE d = 812; -SELECT * FROM test_gc_read WHERE d = 12; -a b c d e -3 4 7 12 14 -INSERT INTO test_gc_read set a = 4, b = d + 1; -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -3 4 7 12 14 -4 NULL NULL NULL NULL -8 8 16 64 32 -DELETE FROM test_gc_read where a = 4; -CREATE TABLE test_gc_help(a int primary key, b int, c int, d int, e int); -INSERT INTO test_gc_help(a, b, c, d, e) SELECT * FROM test_gc_read; -SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.c = t2.c ORDER BY t1.a; -a b c d e -1 2 3 2 6 -3 4 7 12 14 -8 8 16 64 32 -SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.d = t2.d ORDER BY t1.a; -a b c d e -1 2 3 2 6 -3 4 7 12 14 -8 8 16 64 32 -SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.e = t2.e ORDER BY t1.a; -a b c d e -1 2 3 2 6 -3 4 7 12 14 -8 8 16 64 32 -SELECT * FROM test_gc_read t WHERE t.a not in (SELECT t.a FROM test_gc_read t where t.c > 5); -a b c d e -0 NULL NULL NULL NULL -1 2 3 2 6 -SELECT * FROM test_gc_read t WHERE t.c in (SELECT t.c FROM test_gc_read t where t.c > 5); -a b c d e -3 4 7 12 14 -8 8 16 64 32 -SELECT tt.b FROM test_gc_read tt WHERE tt.a = (SELECT max(t.a) FROM test_gc_read t WHERE t.c = tt.c) ORDER BY b; -b -2 -4 -8 -SELECT c, sum(a) aa, max(d) dd, sum(e) ee FROM test_gc_read GROUP BY c ORDER BY aa; -c aa dd ee -NULL 0 NULL NULL -3 1 2 6 -7 3 12 14 -16 8 64 32 -SELECT a, sum(c), sum(d), sum(e) FROM test_gc_read GROUP BY a ORDER BY a; -a sum(c) sum(d) sum(e) -0 NULL NULL NULL -1 3 2 6 -3 7 12 14 -8 16 64 32 -UPDATE test_gc_read m, test_gc_read n SET m.b = m.b + 10, n.b = n.b + 10; -SELECT * FROM test_gc_read ORDER BY a; -a b c d e -0 NULL NULL NULL NULL -1 12 13 12 26 -3 14 17 42 34 -8 18 26 144 52 -drop table if exists t; -create table t(a int); -insert into t values(8); -update test_gc_read set a = a+1 where a in (select a from t); -select * from test_gc_read order by a; -a b c d e -0 NULL NULL NULL NULL -1 12 13 12 26 -3 14 17 42 34 -9 18 27 162 54 -CREATE TABLE test_gc_read_cast(a VARCHAR(255), b VARCHAR(255), c INT AS (JSON_EXTRACT(a, b)), d INT AS (JSON_EXTRACT(a, b)) STORED); -INSERT INTO test_gc_read_cast (a, b) VALUES ('{"a": "3"}', '$.a'); -SELECT c, d FROM test_gc_read_cast; -c d -3 3 -CREATE TABLE test_gc_read_cast_1(a VARCHAR(255), b VARCHAR(255), c ENUM("red", "yellow") AS (JSON_UNQUOTE(JSON_EXTRACT(a, b)))); -INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "yellow"}', '$.a'); -SELECT c FROM test_gc_read_cast_1; -c -yellow -CREATE TABLE test_gc_read_cast_2( a JSON, b JSON AS (a->>'$.a')); -INSERT INTO test_gc_read_cast_2(a) VALUES ('{"a": "{ \\\"key\\\": \\\"\\u6d4b\\\" }"}'); -SELECT b FROM test_gc_read_cast_2; -b -{"key": "测"} -CREATE TABLE test_gc_read_cast_3( a JSON, b JSON AS (a->>'$.a'), c INT AS (b * 3.14) ); -INSERT INTO test_gc_read_cast_3(a) VALUES ('{"a": "5"}'); -SELECT c FROM test_gc_read_cast_3; -c -16 -INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "invalid"}', '$.a'); -Error 1265 (01000): Data truncated for column 'c' at row 1 -DROP TABLE IF EXISTS test_gc_read_m; -CREATE TABLE test_gc_read_m (a int primary key, b int, c int as (a+1), d int as (c*2)); -INSERT INTO test_gc_read_m(a) values (1), (2); -ALTER TABLE test_gc_read_m DROP b; -SELECT * FROM test_gc_read_m; -a c d -1 2 4 -2 3 6 -CREATE TABLE test_gc_read_1(a int primary key, b int, c int as (a+b) not null, d int as (a*b) stored); -CREATE TABLE test_gc_read_2(a int primary key, b int, c int as (a+b), d int as (a*b) stored not null); -insert into test_gc_read_1(a, b) values (1, null); -Error 1048 (23000): Column 'c' cannot be null -insert into test_gc_read_2(a, b) values (1, null); -Error 1048 (23000): Column 'd' cannot be null -drop table if exists th, tr, tl; -create table th (a int, b int) partition by hash(a) partitions 3; -create table tr (a int, b int) -partition by range (a) ( -partition r0 values less than (4), -partition r1 values less than (7), -partition r3 values less than maxvalue); -create table tl (a int, b int, unique index idx(a)) partition by list (a) ( -partition p0 values in (3,5,6,9,17), -partition p1 values in (1,2,10,11,19,20), -partition p2 values in (4,12,13,14,18), -partition p3 values in (7,8,15,16,null)); -insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); -insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); -insert into tr values (-3,-3),(3,3),(4,4),(7,7),(8,8); -insert into tl values (3,3),(1,1),(4,4),(7,7),(8,8),(null,null); -select b from th partition (p0) order by a; -b --6 --3 -0 -3 -6 -select b from tr partition (r0) order by a; -b --3 -3 -select b from tl partition (p0) order by a; -b -3 -select b from th partition (p0,P0) order by a; -b --6 --3 -0 -3 -6 -select b from tr partition (r0,R0,r0) order by a; -b --3 -3 -select b from tl partition (p0,P0,p0) order by a; -b -3 -select b from th partition (P2,p0) order by a; -b --8 --6 --5 --3 --2 -0 -2 -3 -5 -6 -8 -select b from tr partition (r1,R3) order by a; -b -4 -7 -8 -select b from tl partition (p0,P3) order by a; -b -NULL -3 -7 -8 -select b from th partition (p0,p4); -Error 1735 (HY000): Unknown partition 'p4' in table 'th' -select b from tr partition (r1,r4); -Error 1735 (HY000): Unknown partition 'r4' in table 'tr' -select b from tl partition (p0,p4); -Error 1735 (HY000): Unknown partition 'p4' in table 'tl' -begin; -insert into th values (10,10),(11,11); -select a, b from th where b>10; -a b -11 11 -commit; -select a, b from th where b>10; -a b -11 11 -drop table if exists tscalar; -create table tscalar (c1 int) partition by range (c1 % 30) ( -partition p0 values less than (0), -partition p1 values less than (10), -partition p2 values less than (20), -partition pm values less than (maxvalue)); -insert into tscalar values(0), (10), (40), (50), (55); -insert into tscalar values(-0), (-10), (-40), (-50), (-55); -select * from tscalar where c1 in (55, 55); -c1 -55 -select * from tscalar where c1 in (40, 40); -c1 -40 -select * from tscalar where c1 in (40); -c1 -40 -select * from tscalar where c1 in (-40); -c1 --40 -select * from tscalar where c1 in (-40, -40); -c1 --40 -select * from tscalar where c1 in (-1); -c1 -prepare stmt from "load data local infile '/tmp/load_data_test.csv' into table test"; -Error 1295 (HY000): This command is not supported in the prepared statement protocol yet -prepare stmt from "import into test from 'xx' format 'delimited'"; -Error 1295 (HY000): This command is not supported in the prepared statement protocol yet -drop table if exists t; -create table t(a int, index idx(a)); -insert into t values(1), (2), (4); -begin; -update t set a = 3 where a = 4; -select * from t ignore index(idx); -a -1 -2 -3 -insert into t values(4); -select * from t use index(idx); -a -1 -2 -3 -4 -select * from t use index(idx) order by a desc; -a -4 -3 -2 -1 -update t set a = 5 where a = 3; -select * from t use index(idx); -a -1 -2 -4 -5 -commit; -drop table if exists t; -create table t(a int, b int, index idx(a)); -insert into t values(3, 3), (1, 1), (2, 2); -select * from t use index(idx) order by a; -a b -1 1 -2 2 -3 3 -drop table if exists t; -create table t(id bigint, PRIMARY KEY (id)); -insert into t values(9223372036854775807); -select * from t where id = 9223372036854775807; -id -9223372036854775807 -select * from t where id = 9223372036854775807; -id -9223372036854775807 -select * from t; -id -9223372036854775807 -insert into t values(9223372036854775807); -Error 1062 (23000): Duplicate entry '9223372036854775807' for key 't.PRIMARY' -delete from t where id = 9223372036854775807; -select * from t; -id -drop table if exists t; -create table t(id bigint unsigned primary key); -insert into t values(9223372036854775808), (9223372036854775809), (1), (2); -select * from t order by id; -id -1 -2 -9223372036854775808 -9223372036854775809 -select * from t where id not in (2); -id -9223372036854775808 -9223372036854775809 -1 -drop table if exists t; -create table t(a bigint unsigned primary key, b int, index idx(b)); -insert into t values(9223372036854775808, 1), (1, 1); -select * from t use index(idx) where b = 1 and a < 2; -a b -1 1 -select * from t use index(idx) where b = 1 order by b, a; -a b -1 1 -9223372036854775808 1 -set @@tidb_enable_clustered_index = 1; -drop table if exists t; -create table t(k1 int, k2 int, primary key(k1, k2)); -insert into t(k1, k2) value(-100, 1), (-50, 1), (0, 0), (1, 1), (3, 3); -select k1 from t order by k1; -k1 --100 --50 -0 -1 -3 -select k1 from t order by k1 desc; -k1 -3 -1 -0 --50 --100 -select k1 from t where k1 < -51; -k1 --100 -select k1 from t where k1 < -1; -k1 --100 --50 -select k1 from t where k1 <= 0; -k1 --100 --50 -0 -select k1 from t where k1 < 2; -k1 --100 --50 -0 -1 -select k1 from t where k1 < -1 and k1 > -90; -k1 --50 -set @@tidb_enable_clustered_index = default; -drop table if exists t1, t2, t3; -create table t1(t1.a char); -create table t2(a char, t2.b int); -create table t3(s.a char); -Error 1103 (42000): Incorrect table name 's' -set @@tidb_enable_clustered_index = 1; -drop table if exists admin_test; -create table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1, c2), index (c1), unique key(c2)); -insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3); -admin check table admin_test; -set @@tidb_enable_clustered_index = default; -drop table if exists t; -create table t(a bigint); -prepare stmt1 from 'select * from t limit ?'; -prepare stmt2 from 'select * from t limit ?, ?'; -set @a = -1; -set @b = 1; -execute stmt1 using @a; -Error 1210 (HY000): Incorrect arguments to LIMIT -execute stmt2 using @b, @a; -Error 1210 (HY000): Incorrect arguments to LIMIT -execute stmt2 using @a, @b; -Error 1210 (HY000): Incorrect arguments to LIMIT -execute stmt2 using @a, @a; -Error 1210 (HY000): Incorrect arguments to LIMIT -drop table if exists t; -create table t (e enum('Y', 'N')); -set sql_mode='STRICT_TRANS_TABLES'; -insert into t values (0); -Error 1265 (01000): Data truncated for column 'e' at row 1 -insert into t values ('abc'); -Error 1265 (01000): Data truncated for column 'e' at row 1 -set sql_mode=''; -insert into t values (0); -select * from t; -e - -insert into t values ('abc'); -select * from t; -e - - -insert into t values (null); -select * from t; -e - - -NULL -drop table if exists t; -create table t (id int auto_increment primary key, c1 enum('a', '', 'c')); -insert into t(c1) values (0); -select id, c1+0, c1 from t; -id c1+0 c1 -1 0 -alter table t change c1 c1 enum('a', '') not null; -select id, c1+0, c1 from t; -id c1+0 c1 -1 0 -insert into t(c1) values (0); -select id, c1+0, c1 from t; -id c1+0 c1 -1 0 -2 0 -set sql_mode=default; -drop table if exists t1; -create table t1(a int) partition by range (10 div a) (partition p0 values less than (10), partition p1 values less than maxvalue); -set @@sql_mode=''; -insert into t1 values (NULL), (0), (1); -set @@sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO'; -insert into t1 values (NULL), (0), (1); -Error 1365 (22012): Division by 0 -set @@sql_mode=default; -drop table if exists t1; -create table t1( -a int(11) DEFAULT NULL, -b varchar(10) DEFAULT NULL, -UNIQUE KEY idx_a (a)) PARTITION BY RANGE (a) -(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, -PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, -PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, -PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, -PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); -insert into t1 partition(p0) values(1, 'a'), (2, 'b'); -select * from t1 partition(p0) order by a; -a b -1 a -2 b -insert into t1 partition(p0, p1) values(3, 'c'), (4, 'd'); -select * from t1 partition(p1); -a b -insert into t1 values(1, 'a'); -Error 1062 (23000): Duplicate entry '1' for key 't1.idx_a' -insert into t1 partition(p0, p_non_exist) values(1, 'a'); -Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' -insert into t1 partition(p0, p1) values(40, 'a'); -Error 1748 (HY000): Found a row not matching the given partition set -replace into t1 partition(p0) values(1, 'replace'); -replace into t1 partition(p0, p1) values(3, 'replace'), (4, 'replace'); -replace into t1 values(1, 'a'); -select * from t1 partition (p0) order by a; -a b -1 a -2 b -3 replace -4 replace -replace into t1 partition(p0, p_non_exist) values(1, 'a'); -Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' -replace into t1 partition(p0, p1) values(40, 'a'); -Error 1748 (HY000): Found a row not matching the given partition set -truncate table t1; -drop table if exists t; -create table t(a int, b char(10)); -insert into t partition(p0, p1) values(1, 'a'); -Error 1747 (HY000): PARTITION () clause on non partitioned table -insert into t values(1, 'a'), (2, 'b'); -insert into t1 partition(p0) select * from t; -select * from t1 partition(p0) order by a; -a b -1 a -2 b -truncate table t; -insert into t values(3, 'c'), (4, 'd'); -insert into t1 partition(p0, p1) select * from t; -select * from t1 partition(p1) order by a; -a b -select * from t1 partition(p0) order by a; -a b -1 a -2 b -3 c -4 d -insert into t1 select 1, 'a'; -Error 1062 (23000): Duplicate entry '1' for key 't1.idx_a' -insert into t1 partition(p0, p_non_exist) select 1, 'a'; -Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' -insert into t1 partition(p0, p1) select 40, 'a'; -Error 1748 (HY000): Found a row not matching the given partition set -replace into t1 partition(p0) select 1, 'replace'; -truncate table t; -insert into t values(3, 'replace'), (4, 'replace'); -replace into t1 partition(p0, p1) select * from t; -replace into t1 select 1, 'a'; -select * from t1 partition (p0) order by a; -a b -1 a -2 b -3 replace -4 replace -replace into t1 partition(p0, p_non_exist) select 1, 'a'; -Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' -replace into t1 partition(p0, p1) select 40, 'a'; -Error 1748 (HY000): Found a row not matching the given partition set -drop table if exists t1, t2, t3; -create table t1( -a int(11), -b varchar(10) DEFAULT NULL, -primary key idx_a (a)) PARTITION BY RANGE (a) -(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, -PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, -PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, -PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, -PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); -create table t2( -a int(11) DEFAULT NULL, -b varchar(10) DEFAULT NULL) PARTITION BY RANGE (a) -(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, -PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, -PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, -PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, -PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); -create table t3 (a int(11), b varchar(10) default null); -insert into t3 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); -update t3 partition(p0) set a = 40 where a = 2; -Error 1747 (HY000): PARTITION () clause on non partitioned table -insert into t1 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); -update t1 partition(p0, p1) set a = 40; -Error 1748 (HY000): Found a row not matching the given partition set -update t1 partition(p0) set a = 40 where a = 2; -Error 1748 (HY000): Found a row not matching the given partition set -update t1 partition (p0, p_non_exist) set a = 40; -Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' -update t1 partition (p0), t3 set t1.a = 40 where t3.a = 2; -Error 1748 (HY000): Found a row not matching the given partition set -update t1 partition(p0) set a = 3 where a = 2; -update t1 partition(p0, p3) set a = 33 where a = 1; -insert into t2 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); -update t2 partition(p0, p1) set a = 40; -Error 1748 (HY000): Found a row not matching the given partition set -update t2 partition(p0) set a = 40 where a = 2; -Error 1748 (HY000): Found a row not matching the given partition set -update t2 partition(p0) set a = 3 where a = 2; -update t2 partition(p0, p3) set a = 33 where a = 1; -drop table if exists t4; -create table t4(a int primary key, b int) partition by hash(a) partitions 2; -insert into t4(a, b) values(1, 1),(2, 2),(3, 3); -update t4 partition(p0) set a = 5 where a = 2; -Error 1748 (HY000): Found a row not matching the given partition set -drop table if exists t; -CREATE TABLE t (a DATETIME); -INSERT INTO t VALUES('1988-04-17 01:59:59'); -SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t; -DATE_ADD(a, INTERVAL 1 SECOND) -1988-04-17 02:00:00 -select YEAR(0000-00-00), YEAR("0000-00-00"); -YEAR(0000-00-00) YEAR("0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select MONTH(0000-00-00), MONTH("0000-00-00"); -MONTH(0000-00-00) MONTH("0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select DAYOFMONTH(0000-00-00), DAYOFMONTH("0000-00-00"); -DAYOFMONTH(0000-00-00) DAYOFMONTH("0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select QUARTER(0000-00-00), QUARTER("0000-00-00"); -QUARTER(0000-00-00) QUARTER("0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select EXTRACT(DAY FROM 0000-00-00), EXTRACT(DAY FROM "0000-00-00"); -EXTRACT(DAY FROM 0000-00-00) EXTRACT(DAY FROM "0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select EXTRACT(MONTH FROM 0000-00-00), EXTRACT(MONTH FROM "0000-00-00"); -EXTRACT(MONTH FROM 0000-00-00) EXTRACT(MONTH FROM "0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select EXTRACT(YEAR FROM 0000-00-00), EXTRACT(YEAR FROM "0000-00-00"); -EXTRACT(YEAR FROM 0000-00-00) EXTRACT(YEAR FROM "0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select EXTRACT(WEEK FROM 0000-00-00), EXTRACT(WEEK FROM "0000-00-00"); -EXTRACT(WEEK FROM 0000-00-00) EXTRACT(WEEK FROM "0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select EXTRACT(QUARTER FROM 0000-00-00), EXTRACT(QUARTER FROM "0000-00-00"); -EXTRACT(QUARTER FROM 0000-00-00) EXTRACT(QUARTER FROM "0000-00-00") -0 NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select DAYOFWEEK(0000-00-00), DAYOFWEEK("0000-00-00"); -DAYOFWEEK(0000-00-00) DAYOFWEEK("0000-00-00") -NULL NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -select DAYOFYEAR(0000-00-00), DAYOFYEAR("0000-00-00"); -DAYOFYEAR(0000-00-00) DAYOFYEAR("0000-00-00") -NULL NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' -drop table if exists t; -create table t(v1 datetime, v2 datetime(3)); -insert ignore into t values(0,0); -select YEAR(v1), YEAR(v2) from t; -YEAR(v1) YEAR(v2) -0 0 -select MONTH(v1), MONTH(v2) from t; -MONTH(v1) MONTH(v2) -0 0 -select DAYOFMONTH(v1), DAYOFMONTH(v2) from t; -DAYOFMONTH(v1) DAYOFMONTH(v2) -0 0 -select QUARTER(v1), QUARTER(v2) from t; -QUARTER(v1) QUARTER(v2) -0 0 -select EXTRACT(DAY FROM v1), EXTRACT(DAY FROM v2) from t; -EXTRACT(DAY FROM v1) EXTRACT(DAY FROM v2) -0 0 -select EXTRACT(MONTH FROM v1), EXTRACT(MONTH FROM v2) from t; -EXTRACT(MONTH FROM v1) EXTRACT(MONTH FROM v2) -0 0 -select EXTRACT(YEAR FROM v1), EXTRACT(YEAR FROM v2) from t; -EXTRACT(YEAR FROM v1) EXTRACT(YEAR FROM v2) -0 0 -select EXTRACT(WEEK FROM v1), EXTRACT(WEEK FROM v2) from t; -EXTRACT(WEEK FROM v1) EXTRACT(WEEK FROM v2) -0 0 -select EXTRACT(QUARTER FROM v1), EXTRACT(QUARTER FROM v2) from t; -EXTRACT(QUARTER FROM v1) EXTRACT(QUARTER FROM v2) -0 0 -select DAYOFWEEK(v1), DAYOFWEEK(v2) from t; -DAYOFWEEK(v1) DAYOFWEEK(v2) -NULL NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000' -select DAYOFYEAR(v1), DAYOFYEAR(v2) from t; -DAYOFYEAR(v1) DAYOFYEAR(v2) -NULL NULL -Level Code Message -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' -Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000' -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE'; -create table t (a datetime default '2999-00-00 00:00:00'); -Error 1067 (42000): Invalid default value for 'a' -create table t (a datetime); -alter table t modify column a datetime default '2999-00-00 00:00:00'; -Error 1067 (42000): Invalid default value for 'a' -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE'; -create table t (a datetime default '0000-00-00 00:00:00'); -Error 1067 (42000): Invalid default value for 'a' -create table t (a datetime); -alter table t modify column a datetime default '0000-00-00 00:00:00'; -Error 1067 (42000): Invalid default value for 'a' -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES'; -create table t (a datetime default '2999-00-00 00:00:00'); -drop table if exists t; -create table t (a datetime default '0000-00-00 00:00:00'); -drop table if exists t; -create table t (a datetime); -alter table t modify column a datetime default '2999-00-00 00:00:00'; -alter table t modify column a datetime default '0000-00-00 00:00:00'; -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES'; -create table t (a datetime default '2999-02-30 00:00:00'); -Error 1067 (42000): Invalid default value for 'a' -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE'; -create table t (a datetime default '2999-02-30 00:00:00'); -Error 1067 (42000): Invalid default value for 'a' -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES'; -create table t (a datetime default '2999-02-30 00:00:00'); -drop table if exists t; -create table t (a datetime); -alter table t modify column a datetime default '2999-02-30 00:00:00'; -drop table if exists t; -set @@sql_mode=default; -drop table if exists `enum-set`; -CREATE TABLE `enum-set` (`set` SET('x00','x01','x02','x03','x04','x05','x06','x07','x08','x09','x10','x11','x12','x13','x14','x15','x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31','x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47','x48','x49','x50','x51','x52','x53','x54','x55','x56','x57','x58','x59','x60','x61','x62','x63')NOT NULL PRIMARY KEY); -INSERT INTO `enum-set` VALUES ("x00,x59"); -select `set` from `enum-set` use index(PRIMARY); -set -x00,x59 -admin check table `enum-set`; -drop table if exists t; -create table t(a YEAR, PRIMARY KEY(a)); -insert into t set a = '2151'; -delete from t; -admin check table t; -drop table if exists t; -set @@tidb_enable_clustered_index = 'int_only'; -create table t(a varchar(10), b varchar(10), c varchar(1), index idx(a, b, c)); -insert into t values('a', 'b', 'c'); -insert into t values('a', 'b', 'c'); -select b, _tidb_rowid from t use index(idx) where a = 'a'; -b _tidb_rowid -b 1 -b 2 -begin; -select * from t for update; -a b c -a b c -a b c -select distinct b from t use index(idx) where a = 'a'; -b -b -commit; -drop table if exists t; -create table t(a varchar(5) primary key); -insert into t values('a'); -select *, _tidb_rowid from t use index(`primary`) where _tidb_rowid=1; -a _tidb_rowid -a 1 -set @@tidb_enable_clustered_index = default; -drop table if exists t; -set sql_mode = ''; -select a, b from (select 1 a) ``, (select 2 b) ``; -Error 1248 (42000): Every derived table must have its own alias -select a, b from (select 1 a) `x`, (select 2 b) `x`; -Error 1066 (42000): Not unique table/alias: 'x' -select a, b from (select 1 a), (select 2 b); -Error 1248 (42000): Every derived table must have its own alias -select a from (select 1 a) ``, (select 2 a) ``; -Error 1248 (42000): Every derived table must have its own alias -select a from (select 1 a) `x`, (select 2 a) `x`; -Error 1066 (42000): Not unique table/alias: 'x' -select x.a from (select 1 a) `x`, (select 2 a) `x`; -Error 1066 (42000): Not unique table/alias: 'x' -select a from (select 1 a), (select 2 a); -Error 1248 (42000): Every derived table must have its own alias -set sql_mode = 'oracle'; -select a, b from (select 1 a) ``, (select 2 b) ``; -a b -1 2 -select a, b from (select 1 a) `x`, (select 2 b) `x`; -a b -1 2 -select a, b from (select 1 a), (select 2 b); -a b -1 2 -select a from (select 1 a) ``, (select 2 a) ``; -Error 1052 (23000): Column 'a' in field list is ambiguous -select a from (select 1 a) `x`, (select 2 a) `x`; -Error 1052 (23000): Column 'a' in field list is ambiguous -select x.a from (select 1 a) `x`, (select 2 a) `x`; -Error 1052 (23000): Column 'a' in field list is ambiguous -select a from (select 1 a), (select 2 a); -Error 1052 (23000): Column 'a' in field list is ambiguous -set sql_mode = default; -drop table if exists th; -create table th (a int, b int) partition by hash(a) partitions 3; -insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); -insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); -select b from th order by a; -b --8 --7 --6 --5 --4 --3 --2 --1 -0 -1 -2 -3 -4 -5 -6 -7 -8 -select * from th where a=-2; -a b --2 -2 -select * from th where a=5; -a b -5 5 -drop table if exists th; -drop table if exists view_t; -create table view_t (a int,b int); -insert into view_t values(1,2); -create definer='root'@'localhost' view view1 as select * from view_t; -create definer='root'@'localhost' view view2(c,d) as select * from view_t; -create definer='root'@'localhost' view view3(c,d) as select a,b from view_t; -create definer='root'@'localhost' view view4 as select * from (select * from (select * from view_t) tb1) tb; -select * from view1; -a b -1 2 -select * from view2; -c d -1 2 -select * from view3; -c d -1 2 -select * from view4; -a b -1 2 -drop table view_t; -create table view_t(c int,d int); -select * from view1; -Error 1356 (HY000): View 'executor__executor.view1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them -select * from view2; -Error 1356 (HY000): View 'executor__executor.view2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them -select * from view3; -Error 1356 (HY000): View 'executor__executor.view3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them -drop table view_t; -create table view_t(a int,b int,c int); -insert into view_t values(1,2,3); -select * from view1; -a b -1 2 -select * from view2; -c d -1 2 -select * from view3; -c d -1 2 -select * from view4; -a b -1 2 -alter table view_t drop column a; -alter table view_t add column a int after b; -update view_t set a=1; -select * from view1; -a b -1 2 -select * from view2; -c d -1 2 -select * from view3; -c d -1 2 -select * from view4; -a b -1 2 -drop table view_t; -drop view view1,view2,view3,view4; -set @@tidb_enable_window_function = 1; -create table t(a int, b int); -insert into t values (1,1),(1,2),(2,1),(2,2); -create definer='root'@'localhost' view v as select a, first_value(a) over(rows between 1 preceding and 1 following), last_value(a) over(rows between 1 preceding and 1 following) from t; -select * from v; -a first_value(a) over(rows between 1 preceding and 1 following) last_value(a) over(rows between 1 preceding and 1 following) -1 1 1 -1 1 2 -2 1 2 -2 2 2 -drop view v; -set @@tidb_enable_window_function = default; -drop table if exists t; -create table t(a varbinary(10)); -insert into t values ('123.12'); -select 1+a from t; -1+a -124.12 -select a-1 from t; -a-1 -122.12 -select -10*a from t; --10*a --1231.2 -select a/-2 from t; -a/-2 --61.56 -drop table if exists t1, t2, t3; -create table t1(a int, b int); -create table t2(a int, b varchar(20)); -create table t3(a int, b decimal(30,10)); -insert into t1 values (1,1),(1,1),(2,2),(3,3),(null,null); -insert into t2 values (1,'1'),(2,'2'),(null,null),(null,'3'); -insert into t3 values (2,2.1),(3,3); -explain format = 'brief' select * from t3 union select * from t1; -id estRows task access object operator info -HashAgg 16000.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#7, funcs:firstrow(Column#8)->Column#8 -└─Union 20000.00 root - ├─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo - └─Projection 10000.00 root executor__executor.t1.a->Column#7, cast(executor__executor.t1.b, decimal(30,10) BINARY)->Column#8 - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t3 union select * from t1; -a b -NULL NULL -1 1.0000000000 -2 2.0000000000 -2 2.1000000000 -3 3.0000000000 -explain format = 'brief' select * from t2 union all select * from t1; -id estRows task access object operator info -Union 20000.00 root -├─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─Projection 10000.00 root executor__executor.t1.a->Column#7, cast(executor__executor.t1.b, varchar(20) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#8 - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t2 union all select * from t1; -a b -NULL NULL -NULL NULL -NULL 3 -1 1 -1 1 -1 1 -2 2 -2 2 -3 3 -explain format = 'brief' select * from t1 except select * from t3; -id estRows task access object operator info -HashJoin 6400.00 root anti semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t3.a)], other cond:nulleq(cast(executor__executor.t1.b, decimal(10,0) BINARY), executor__executor.t3.b) -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, executor__executor.t1.b, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a, funcs:firstrow(executor__executor.t1.b)->executor__executor.t1.b - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, executor__executor.t1.b, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 except select * from t3; -a b -NULL NULL -1 1 -2 2 -explain format = 'brief' select * from t1 intersect select * from t2; -id estRows task access object operator info -HashJoin 6400.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)], other cond:nulleq(cast(executor__executor.t1.b, double BINARY), cast(executor__executor.t2.b, double BINARY)) -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, executor__executor.t1.b, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a, funcs:firstrow(executor__executor.t1.b)->executor__executor.t1.b - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, executor__executor.t1.b, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 intersect select * from t2; -a b -NULL NULL -1 1 -2 2 -explain format = 'brief' select * from t1 union all select * from t2 union all select * from t3; -id estRows task access object operator info -Union 30000.00 root -├─Projection 10000.00 root executor__executor.t1.a->Column#10, cast(executor__executor.t1.b, varchar(30) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#11 -│ └─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -├─Projection 10000.00 root executor__executor.t2.a->Column#10, cast(executor__executor.t2.b, varchar(30) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#11 -│ └─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─Projection 10000.00 root executor__executor.t3.a->Column#10, cast(executor__executor.t3.b, varchar(30) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#11 - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -select * from t1 union all select * from t2 union all select * from t3; -a b -NULL NULL -NULL NULL -NULL 3 -1 1 -1 1 -1 1 -2 2 -2 2 -2 2.1000000000 -3 3 -3 3.0000000000 -explain format = 'brief' select * from t1 union all select * from t2 except select * from t3; -id estRows task access object operator info -HashJoin 12800.00 root anti semi join, equal:[nulleq(Column#10, executor__executor.t3.a)], other cond:nulleq(cast(Column#11, double BINARY), cast(executor__executor.t3.b, double BINARY)) -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -└─HashAgg(Probe) 16000.00 root group by:Column#10, Column#11, funcs:firstrow(Column#10)->Column#10, funcs:firstrow(Column#11)->Column#11 - └─Union 20000.00 root - ├─Projection 10000.00 root executor__executor.t1.a->Column#10, cast(executor__executor.t1.b, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#11 - │ └─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -select * from t1 union all select * from t2 except select * from t3; -a b -NULL NULL -NULL 3 -1 1 -2 2 -explain format = 'brief' select * from t1 intersect select * from t2 intersect select * from t1; -id estRows task access object operator info -HashJoin 5120.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t1.a) nulleq(executor__executor.t1.b, executor__executor.t1.b)] -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─HashJoin(Probe) 6400.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)], other cond:nulleq(cast(executor__executor.t1.b, double BINARY), cast(executor__executor.t2.b, double BINARY)) - ├─TableReader(Build) 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, executor__executor.t1.b, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a, funcs:firstrow(executor__executor.t1.b)->executor__executor.t1.b - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, executor__executor.t1.b, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 intersect select * from t2 intersect select * from t1; -a b -NULL NULL -1 1 -2 2 -explain format = 'brief' select * from t1 union all select * from t2 intersect select * from t3; -id estRows task access object operator info -Union 16400.00 root -├─Projection 10000.00 root executor__executor.t1.a->Column#10, cast(executor__executor.t1.b, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#11 -│ └─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─HashJoin 6400.00 root semi join, equal:[nulleq(executor__executor.t2.a, executor__executor.t3.a)], other cond:nulleq(cast(executor__executor.t2.b, double BINARY), cast(executor__executor.t3.b, double BINARY)) - ├─TableReader(Build) 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo - └─HashAgg(Probe) 8000.00 root group by:executor__executor.t2.a, executor__executor.t2.b, funcs:firstrow(executor__executor.t2.a)->executor__executor.t2.a, funcs:firstrow(executor__executor.t2.b)->executor__executor.t2.b - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t2.a, executor__executor.t2.b, - └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -select * from t1 union all select * from t2 intersect select * from t3; -a b -NULL NULL -1 1 -1 1 -2 2 -3 3 -explain format = 'brief' select * from t1 except select * from t2 intersect select * from t3; -id estRows task access object operator info -HashJoin 6400.00 root anti semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)], other cond:nulleq(cast(executor__executor.t1.b, double BINARY), cast(executor__executor.t2.b, double BINARY)) -├─HashJoin(Build) 6400.00 root semi join, equal:[nulleq(executor__executor.t2.a, executor__executor.t3.a)], other cond:nulleq(cast(executor__executor.t2.b, double BINARY), cast(executor__executor.t3.b, double BINARY)) -│ ├─TableReader(Build) 10000.00 root data:TableFullScan -│ │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -│ └─HashAgg(Probe) 8000.00 root group by:executor__executor.t2.a, executor__executor.t2.b, funcs:firstrow(executor__executor.t2.a)->executor__executor.t2.a, funcs:firstrow(executor__executor.t2.b)->executor__executor.t2.b -│ └─TableReader 8000.00 root data:HashAgg -│ └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t2.a, executor__executor.t2.b, -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, executor__executor.t1.b, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a, funcs:firstrow(executor__executor.t1.b)->executor__executor.t1.b - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, executor__executor.t1.b, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 except select * from t2 intersect select * from t3; -a b -NULL NULL -1 1 -2 2 -3 3 -set tidb_cost_model_version=2; -drop table if exists t; -create table t (c1 year(4), c2 int, key(c1)); -insert into t values(2001, 1); -explain format = 'brief' select t1.c1, t2.c1 from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -id estRows task access object operator info -MergeJoin 0.00 root inner join, left key:executor__executor.t.c1, right key:executor__executor.t.c1 -├─TableDual(Build) 0.00 root rows:0 -└─TableDual(Probe) 0.00 root rows:0 -select t1.c1, t2.c1 from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -c1 c1 -explain format = 'brief' select * from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -id estRows task access object operator info -MergeJoin 0.00 root inner join, left key:executor__executor.t.c1, right key:executor__executor.t.c1 -├─TableDual(Build) 0.00 root rows:0 -└─TableDual(Probe) 0.00 root rows:0 -select * from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -c1 c2 c1 c2 -explain format = 'brief' select count(*) from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#7 -└─MergeJoin 0.00 root inner join, left key:executor__executor.t.c1, right key:executor__executor.t.c1 - ├─TableDual(Build) 0.00 root rows:0 - └─TableDual(Probe) 0.00 root rows:0 -select count(*) from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -count(*) -0 -explain format = 'brief' select t1.c1, t2.c1 from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -id estRows task access object operator info -MergeJoin 0.00 root left outer join, left key:executor__executor.t.c1, right key:executor__executor.t.c1 -├─TableDual(Build) 0.00 root rows:0 -└─TableDual(Probe) 0.00 root rows:0 -select t1.c1, t2.c1 from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -c1 c1 -explain format = 'brief' select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -id estRows task access object operator info -MergeJoin 0.00 root left outer join, left key:executor__executor.t.c1, right key:executor__executor.t.c1 -├─TableDual(Build) 0.00 root rows:0 -└─TableDual(Probe) 0.00 root rows:0 -select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -c1 c2 c1 c2 -explain format = 'brief' select count(*) from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -id estRows task access object operator info -StreamAgg 1.00 root funcs:count(1)->Column#7 -└─MergeJoin 0.00 root left outer join, left key:executor__executor.t.c1, right key:executor__executor.t.c1 - ├─TableDual(Build) 0.00 root rows:0 - └─TableDual(Probe) 0.00 root rows:0 -select count(*) from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -count(*) -0 -explain format = 'brief' select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 is not NULL; -id estRows task access object operator info -HashJoin 12487.50 root left outer join, equal:[eq(executor__executor.t.c1, executor__executor.t.c1)] -├─TableReader(Build) 9990.00 root data:Selection -│ └─Selection 9990.00 cop[tikv] not(isnull(executor__executor.t.c1)) -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader(Probe) 9990.00 root data:Selection - └─Selection 9990.00 cop[tikv] not(isnull(executor__executor.t.c1)) - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 is not NULL; -c1 c2 c1 c2 -2001 1 2001 1 -set tidb_cost_model_version=2; -drop table if exists t1, t2, t3; -create table t1(a int); -create table t2 like t1; -create table t3 like t1; -insert into t1 values (1),(1),(2),(3),(null); -insert into t2 values (1),(2),(null),(null); -insert into t3 values (2),(3); -explain format='brief' select * from t3 union select * from t1; -id estRows task access object operator info -HashAgg 16000.00 root group by:Column#5, funcs:firstrow(Column#5)->Column#5 -└─Union 20000.00 root - ├─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t3 union select * from t1; -a -NULL -1 -2 -3 -explain format='brief' select * from t2 union all select * from t1; -id estRows task access object operator info -Union 20000.00 root -├─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t2 union all select * from t1; -a -NULL -NULL -NULL -1 -1 -1 -2 -2 -3 -explain format='brief' select * from t1 except select * from t3; -id estRows task access object operator info -HashJoin 6400.00 root anti semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t3.a)] -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 except select * from t3; -a -NULL -1 -explain format='brief' select * from t1 intersect select * from t2; -id estRows task access object operator info -HashJoin 6400.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)] -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 intersect select * from t2; -a -NULL -1 -2 -explain format='brief' select * from t1 union all select * from t2 union all select * from t3; -id estRows task access object operator info -Union 30000.00 root -├─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -├─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -select * from t1 union all select * from t2 union all select * from t3; -a -NULL -NULL -NULL -1 -1 -1 -2 -2 -2 -3 -3 -explain format='brief' select * from t1 union all select * from t2 except select * from t3; -id estRows task access object operator info -HashJoin 12800.00 root anti semi join, equal:[nulleq(Column#7, executor__executor.t3.a)] -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -└─HashAgg(Probe) 16000.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#7 - └─Union 20000.00 root - ├─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -select * from t1 union all select * from t2 except select * from t3; -a -NULL -1 -explain format='brief' select * from t1 intersect select * from t2 intersect select * from t1; -id estRows task access object operator info -HashJoin 5120.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t1.a)] -├─TableReader(Build) 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─HashJoin(Probe) 6400.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)] - ├─TableReader(Build) 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 intersect select * from t2 intersect select * from t1; -a -NULL -1 -2 -explain format='brief' select * from t1 union all select * from t2 intersect select * from t3; -id estRows task access object operator info -Union 16400.00 root -├─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─HashJoin 6400.00 root semi join, equal:[nulleq(executor__executor.t2.a, executor__executor.t3.a)] - ├─TableReader(Build) 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo - └─HashAgg(Probe) 8000.00 root group by:executor__executor.t2.a, funcs:firstrow(executor__executor.t2.a)->executor__executor.t2.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t2.a, - └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -select * from t1 union all select * from t2 intersect select * from t3; -a -NULL -1 -1 -2 -2 -3 -explain format='brief' select * from t1 except select * from t2 intersect select * from t3; -id estRows task access object operator info -HashJoin 6400.00 root anti semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)] -├─HashJoin(Build) 6400.00 root semi join, equal:[nulleq(executor__executor.t2.a, executor__executor.t3.a)] -│ ├─TableReader(Build) 10000.00 root data:TableFullScan -│ │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -│ └─HashAgg(Probe) 8000.00 root group by:executor__executor.t2.a, funcs:firstrow(executor__executor.t2.a)->executor__executor.t2.a -│ └─TableReader 8000.00 root data:HashAgg -│ └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t2.a, -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 except select * from t2 intersect select * from t3; -a -NULL -1 -3 -explain format='brief' select * from t1 intersect (select * from t2 except (select * from t3)); -id estRows task access object operator info -HashJoin 6400.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t2.a)] -├─HashJoin(Build) 6400.00 root anti semi join, equal:[nulleq(executor__executor.t2.a, executor__executor.t3.a)] -│ ├─TableReader(Build) 10000.00 root data:TableFullScan -│ │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -│ └─HashAgg(Probe) 8000.00 root group by:executor__executor.t2.a, funcs:firstrow(executor__executor.t2.a)->executor__executor.t2.a -│ └─TableReader 8000.00 root data:HashAgg -│ └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t2.a, -│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -select * from t1 intersect (select * from t2 except (select * from t3)); -a -NULL -1 -explain format='brief' select * from t1 union all (select * from t2 except select * from t3); -id estRows task access object operator info -Union 16400.00 root -├─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -└─HashJoin 6400.00 root anti semi join, equal:[nulleq(executor__executor.t2.a, executor__executor.t3.a)] - ├─TableReader(Build) 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo - └─HashAgg(Probe) 8000.00 root group by:executor__executor.t2.a, funcs:firstrow(executor__executor.t2.a)->executor__executor.t2.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t2.a, - └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -select * from t1 union all (select * from t2 except select * from t3); -a -NULL -NULL -1 -1 -1 -2 -3 -explain format='brief' select * from t1 union (select * from t2 union all select * from t3); -id estRows task access object operator info -HashAgg 24000.00 root group by:Column#8, funcs:firstrow(Column#8)->Column#8 -└─Union 30000.00 root - ├─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─Union 20000.00 root - ├─TableReader 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─TableReader 10000.00 root data:TableFullScan - └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -select * from t1 union (select * from t2 union all select * from t3); -a -NULL -1 -2 -3 -explain format='brief' (select * from t1 intersect select * from t1) except (select * from t2 union select * from t3); -id estRows task access object operator info -HashJoin 5120.00 root anti semi join, equal:[nulleq(executor__executor.t1.a, Column#9)] -├─HashAgg(Build) 16000.00 root group by:Column#9, funcs:firstrow(Column#9)->Column#9 -│ └─Union 20000.00 root -│ ├─TableReader 10000.00 root data:TableFullScan -│ │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -│ └─TableReader 10000.00 root data:TableFullScan -│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo -└─HashJoin(Probe) 6400.00 root semi join, equal:[nulleq(executor__executor.t1.a, executor__executor.t1.a)] - ├─TableReader(Build) 10000.00 root data:TableFullScan - │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─HashAgg(Probe) 8000.00 root group by:executor__executor.t1.a, funcs:firstrow(executor__executor.t1.a)->executor__executor.t1.a - └─TableReader 8000.00 root data:HashAgg - └─HashAgg 8000.00 cop[tikv] group by:executor__executor.t1.a, - └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -(select * from t1 intersect select * from t1) except (select * from t2 union select * from t3); -a -drop table if exists issue40279; -CREATE TABLE `issue40279` (`a` char(155) NOT NULL DEFAULT 'on1unvbxp5sko6mbetn3ku26tuiyju7w3wc0olzto9ew7gsrx',`b` mediumint(9) NOT NULL DEFAULT '2525518',PRIMARY KEY (`b`,`a`) /*T![clustered_index] CLUSTERED */); -insert into `issue40279` values (); -( select `issue40279`.`b` as r0 , from_base64( `issue40279`.`a` ) as r1 from `issue40279` ) except ( select `issue40279`.`a` as r0 , elt(2, `issue40279`.`a` , `issue40279`.`a` ) as r1 from `issue40279`); -r0 r1 -2525518 NULL -drop table if exists t2; -CREATE TABLE `t2` ( `a` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; -insert into t2 values(0xCED2); -(select elt(2,t2.a,t2.a) from t2) except (select 0xCED2 from t2); -elt(2,t2.a,t2.a) -drop table if exists t; -create table t(a datetime, b bigint, c bigint); -insert into t values(cast('2023-08-09 00:00:00' as datetime), 20230809, 20231310); -select a > 20230809 from t; -a > 20230809 -0 -select a = 20230809 from t; -a = 20230809 -1 -select a < 20230810 from t; -a < 20230810 -1 -select a < 20231310 from t; -a < 20231310 -0 -select 20230809 < a from t; -20230809 < a -0 -select 20230809 = a from t; -20230809 = a -1 -select 20230810 > a from t; -20230810 > a -1 -select 20231310 > a from t; -20231310 > a -0 -select cast('2023-08-09 00:00:00' as datetime) > 20230809 from t; -cast('2023-08-09 00:00:00' as datetime) > 20230809 -1 -select cast('2023-08-09 00:00:00' as datetime) = 20230809 from t; -cast('2023-08-09 00:00:00' as datetime) = 20230809 -0 -select cast('2023-08-09 00:00:00' as datetime) < 20230810 from t; -cast('2023-08-09 00:00:00' as datetime) < 20230810 -0 -select cast('2023-08-09 00:00:00' as datetime) < 20231310 from t; -cast('2023-08-09 00:00:00' as datetime) < 20231310 -0 -select 20230809 < cast('2023-08-09 00:00:00' as datetime) from t; -20230809 < cast('2023-08-09 00:00:00' as datetime) -1 -select 20230809 = cast('2023-08-09 00:00:00' as datetime) from t; -20230809 = cast('2023-08-09 00:00:00' as datetime) -0 -select 20230810 > cast('2023-08-09 00:00:00' as datetime) from t; -20230810 > cast('2023-08-09 00:00:00' as datetime) -0 -select 20231310 > cast('2023-08-09 00:00:00' as datetime) from t; -20231310 > cast('2023-08-09 00:00:00' as datetime) -0 -select a > b from t; -a > b -1 -select a = b from t; -a = b -0 -select a < b + 1 from t; -a < b + 1 -0 -select a < c from t; -a < c -0 -select b < a from t; -b < a -1 -select b = a from t; -b = a -0 -select b > a from t; -b > a -0 -select c > a from t; -c > a -0 -load stats; -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 11 near ";" -load stats ./xxx.json; -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 12 near "./xxx.json;" -drop database if exists test_show; -create database test_show; -use test_show; -show engines; -Engine Support Comment Transactions XA Savepoints -InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES -drop table if exists t; -create table t(a int primary key); -show index in t; -Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global -t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES NO -show index from t; -Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global -t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES NO -show master status; -File Position Binlog_Do_DB Binlog_Ignore_DB Executed_Gtid_Set -tidb-binlog 0 -show create database test_show; -Database Create Database -test_show CREATE DATABASE `test_show` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ -show privileges; -Privilege Context Comment -Alter Tables To alter the table -Alter routine Functions,Procedures To alter or drop stored functions/procedures -Config Server Admin To use SHOW CONFIG and SET CONFIG statements -Create Databases,Tables,Indexes To create new databases and tables -Create routine Databases To use CREATE FUNCTION/PROCEDURE -Create role Server Admin To create new roles -Create temporary tables Databases To use CREATE TEMPORARY TABLE -Create view Tables To create new views -Create user Server Admin To create new users -Delete Tables To delete existing rows -Drop Databases,Tables To drop databases, tables, and views -Drop role Server Admin To drop roles -Event Server Admin To create, alter, drop and execute events -Execute Functions,Procedures To execute stored routines -File File access on server To read and write files on the server -Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess -Index Tables To create or drop indexes -Insert Tables To insert data into tables -Lock tables Databases To use LOCK TABLES (together with SELECT privilege) -Process Server Admin To view the plain text of currently executing queries -Proxy Server Admin To make proxy user possible -References Databases,Tables To have references on tables -Reload Server Admin To reload or refresh tables, logs and privileges -Replication client Server Admin To ask where the slave or master servers are -Replication slave Server Admin To read binary log events from the master -Select Tables To retrieve rows from table -Show databases Server Admin To see all databases with SHOW DATABASES -Show view Tables To see views with SHOW CREATE VIEW -Shutdown Server Admin To shut down the server -Super Server Admin To use KILL thread, SET GLOBAL, CHANGE MASTER, etc. -Trigger Tables To use triggers -Create tablespace Server Admin To create/alter/drop tablespaces -Update Tables To update existing rows -Usage Server Admin No privileges - allow connect only -BACKUP_ADMIN Server Admin -RESTORE_ADMIN Server Admin -SYSTEM_USER Server Admin -SYSTEM_VARIABLES_ADMIN Server Admin -ROLE_ADMIN Server Admin -CONNECTION_ADMIN Server Admin -PLACEMENT_ADMIN Server Admin -DASHBOARD_CLIENT Server Admin -RESTRICTED_TABLES_ADMIN Server Admin -RESTRICTED_STATUS_ADMIN Server Admin -RESTRICTED_VARIABLES_ADMIN Server Admin -RESTRICTED_USER_ADMIN Server Admin -RESTRICTED_CONNECTION_ADMIN Server Admin -RESTRICTED_REPLICA_WRITER_ADMIN Server Admin -RESOURCE_GROUP_ADMIN Server Admin -RESOURCE_GROUP_USER Server Admin -show table status; -Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t InnoDB 10 Compact 0 0 0 0 0 0 NULL 0 NULL NULL utf8mb4_bin -drop database test_show; -use executor__executor; -select \N; -NULL -NULL -select "\N"; -N -N -drop table if exists test; -create table test (`\N` int); -insert into test values (1); -select * from test; -\N -1 -select \N from test; -NULL -NULL -select (\N) from test; -NULL -NULL -select `\N` from test; -\N -1 -select (`\N`) from test; -\N -1 -select '\N' from test; -N -N -select ('\N') from test; -N -N -select nUll; -NULL -NULL -select (null); -NULL -NULL -select null+NULL; -null+NULL -NULL -select 'abc'; -abc -abc -select (('abc')); -abc -abc -select 'abc'+'def'; -'abc'+'def' -0 -select '\n'; - - - -select '\t col'; -col - col -select '\t Col'; -Col - Col -select '\n\t 中文 col'; -中文 col - - 中文 col -select ' \r\n .col'; -.col - - .col -select ' 😆col'; -😆col - 😆col -select 'abc '; -abc -abc -select ' abc 123 '; -abc 123 - abc 123 -select 'a' ' ' 'string'; -a -a string -select 'a' " " "string"; -a -a string -select 'string' 'string'; -string -stringstring -select "ss" "a"; -ss -ssa -select "ss" "a" "b"; -ss -ssab -select "ss" "a" ' ' "b"; -ss -ssa b -select "ss" "a" ' ' "b" ' ' "d"; -ss -ssa b d -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; -select * from b; -a k1 k2 v -2 3 4 100 -select * from a; -k1 k2 v -2 3 20 -3 4 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -2 3 4 100 -select * from a; -k1 k2 v -2 3 20 -3 4 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -22 23 24 100 -select * from a; -k1 k2 v -12 13 20 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -22 23 24 100 -select * from a; -k1 k2 v -12 13 20 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -22 23 24 100 -select * from a; -k1 k2 v -11 11 11 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); -select * from b; -a k1 k2 v -22 22 22 22 -select * from a; -k1 k2 v -11 11 11 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; -select * from b; -a k1 k2 v -2 3 4 100 -select * from a; -k1 k2 v -2 3 20 -3 4 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -2 3 4 100 -select * from a; -k1 k2 v -2 3 20 -3 4 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -22 23 24 100 -select * from a; -k1 k2 v -12 13 20 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -22 23 24 100 -select * from a; -k1 k2 v -12 13 20 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -a k1 k2 v -22 23 24 100 -select * from a; -k1 k2 v -11 11 11 -23 24 20 -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); -select * from b; -a k1 k2 v -22 22 22 22 -select * from a; -k1 k2 v -11 11 11 -23 24 20 -admin check table a; -admin check table b; -set @@tidb_enable_clustered_index=On; -drop table if exists t; -create table t (a int, b int, c int, primary key(a,b)); -explain format = 'brief' select t1.a from t t1 left join t t2 on t1.a = t2.a and t1.b = t2.b; -id estRows task access object operator info -TableReader 10000.00 root data:TableFullScan -└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo -set @@tidb_enable_clustered_index=default; -drop table if exists t; -create table t (c1 bit(2)); -insert into t values (0), (1), (2), (3); -insert into t values (4); -Error 1406 (22001): Data too long for column 'c1' at row 1 -insert into t values ('a'); -Error 1406 (22001): Data too long for column 'c1' at row 1 -select hex(c1) from t where c1 = 2; -hex(c1) -2 -drop table if exists t; -create table t (c1 bit(31)); -insert into t values (0x7fffffff); -insert into t values (0x80000000); -Error 1406 (22001): Data too long for column 'c1' at row 1 -insert into t values (0xffffffff); -Error 1406 (22001): Data too long for column 'c1' at row 1 -insert into t values ('123'); -insert into t values ('1234'); -insert into t values ('12345); -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 30 near "'12345);" -drop table if exists t; -create table t (c1 bit(62)); -insert into t values ('12345678'); -drop table if exists t; -create table t (c1 bit(61)); -insert into t values ('12345678'); -Error 1406 (22001): Data too long for column 'c1' at row 1 -drop table if exists t; -create table t (c1 bit(32)); -insert into t values (0x7fffffff); -insert into t values (0xffffffff); -insert into t values (0x1ffffffff); -Error 1406 (22001): Data too long for column 'c1' at row 1 -insert into t values ('1234'); -insert into t values ('12345'); -Error 1406 (22001): Data too long for column 'c1' at row 1 -drop table if exists t; -create table t (c1 bit(64)); -insert into t values (0xffffffffffffffff); -insert into t values ('12345678'); -insert into t values ('123456789'); -Error 1366 (HY000): Incorrect bit value: '123456789' for column 'c1' at row 1 -drop table if exists t; -create table t (c1 bit(64)); -insert into t values (0xffffffffffffffff); -insert into t values ('12345678'); -select hex(c1) from t where c1; -hex(c1) -FFFFFFFFFFFFFFFF -3132333435363738 -drop table if exists t, t1; -create table t (ts timestamp); -set time_zone = '+00:00'; -insert into t values ('2017-04-27 22:40:42'); -set time_zone = '+10:00'; -select * from t; -ts -2017-04-28 08:40:42 -set time_zone = '-6:00'; -select * from t; -ts -2017-04-27 16:40:42 -drop table if exists t1; -CREATE TABLE t1 ( -id bigint(20) NOT NULL AUTO_INCREMENT, -uid int(11) DEFAULT NULL, -datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -ip varchar(128) DEFAULT NULL, -PRIMARY KEY (id), -KEY i_datetime (datetime), -KEY i_userid (uid) -); -INSERT INTO t1 VALUES (123381351,1734,"2014-03-31 08:57:10","127.0.0.1"); -select datetime from t1; -datetime -2014-03-31 08:57:10 -select datetime from t1 where datetime='2014-03-31 08:57:10'; -datetime -2014-03-31 08:57:10 -select * from t1 where datetime='2014-03-31 08:57:10'; -id uid datetime ip -123381351 1734 2014-03-31 08:57:10 127.0.0.1 -set time_zone = 'Asia/Shanghai'; -drop table if exists t1; -CREATE TABLE t1 ( -id bigint(20) NOT NULL AUTO_INCREMENT, -datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -PRIMARY KEY (id) -); -INSERT INTO t1 VALUES (123381351,"2014-03-31 08:57:10"); -select * from t1 where datetime="2014-03-31 08:57:10"; -id datetime -123381351 2014-03-31 08:57:10 -alter table t1 add key i_datetime (datetime); -select * from t1 where datetime="2014-03-31 08:57:10"; -id datetime -123381351 2014-03-31 08:57:10 -select * from t1; -id datetime -123381351 2014-03-31 08:57:10 -select datetime from t1 where datetime='2014-03-31 08:57:10'; -datetime -2014-03-31 08:57:10 -set time_zone=default; -drop table if exists t2; -create table t2(a int, b int, c int); -insert into t2 values (11, 8, (select not b)); -Error 1054 (42S22): Unknown column 'b' in 'field list' -insert into t2 set a = 11, b = 8, c = (select b)); -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 49 near ");" -insert into t2 values(1, 1, (select b from t2)); -select * from t2; -a b c -1 1 NULL -insert into t2 set a = 1, b = 1, c = (select b+1 from t2); -select * from t2; -a b c -1 1 NULL -1 1 2 -delete from t2; -insert into t2 values(2, 4, a); -select * from t2; -a b c -2 4 2 -insert into t2 set a = 3, b = 5, c = b; -select * from t2; -a b c -2 4 2 -3 5 5 -drop table if exists t; -create table t(a int, b int); -insert into t values ( 81, ( select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ) ); -Error 1105 (HY000): Insert's SET operation or VALUES_LIST doesn't support complex subqueries now -insert into t set a = 81, b = (select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ); -Error 1105 (HY000): Insert's SET operation or VALUES_LIST doesn't support complex subqueries now -drop table if exists t2; -drop table if exists t; -create table t (id bit(16), key id(id)); -insert into t values (65); -select * from t where id not in (-1,2); -id -A -select * from t where id in (-1, -2); -Error 1582 (42000): Incorrect parameter count in the call to native function 'in' -drop table if exists t; -drop table if exists t1; -create table t(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) clustered); -create table t1(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) nonclustered); -insert into t(k1) select 1; -insert into t1(k1) select 1; -set @@tidb_enable_vectorized_expression = 0; -(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); -k1 hex(v) -1 1D5E4CF7F -(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); -k1 hex(v) -1 1D5E4CF7F -set @@tidb_enable_vectorized_expression = 1; -(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); -k1 hex(v) -1 1D5E4CF7F -(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); -k1 hex(v) -1 1D5E4CF7F -set @@tidb_enable_vectorized_expression = default; -drop table if exists t; -drop view if exists v; -create table t(a int); -insert into t values(1), (2), (3); -create definer='root'@'localhost' view v as select count(*) as c1 from t; -select * from v; -c1 -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select count(*) from t) s; -select * from v order by 1; -count(*) -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select avg(a) from t group by a) s; -select * from v order by 1; -avg(a) -1.0000 -2.0000 -3.0000 -drop view v; -create definer='root'@'localhost' view v as select * from (select sum(a) from t group by a) s; -select * from v order by 1; -sum(a) -1 -2 -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select group_concat(a) from t group by a) s; -select * from v order by 1; -group_concat(a) -1 -2 -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select count(0) as c1 from t) s; -select * from v order by 1; -c1 -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select count(*) as c1 from t) s; -select * from v order by 1; -c1 -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select group_concat(a) as `concat(a)` from t group by a) s; -select * from v order by 1; -concat(a) -1 -2 -3 -drop view v; -create definer='root'@'localhost' view v as select * from (select a from t group by a) s; -select * from v order by 1; -a -1 -2 -3 -SELECT `s`.`count(a)` FROM (SELECT COUNT(`a`) FROM `executor__executor`.`t`) AS `s`; -Error 1054 (42S22): Unknown column 's.count(a)' in 'field list' -drop view v; -create definer='root'@'localhost' view v as select * from (select count(a) from t) s; -select * from v; -count(a) -3 -drop table if exists t; -create table t(c1 int); -insert into t values(111), (222), (333); -drop view if exists v; -create definer='root'@'localhost' view v as (select * from (select row_number() over (order by c1) from t) s); -select * from v; -row_number() over (order by c1) -1 -2 -3 -drop view if exists v; -create definer='root'@'localhost' view v as (select * from (select c1, row_number() over (order by c1) from t) s); -select * from v; -c1 row_number() over (order by c1) -111 1 -222 2 -333 3 -drop view if exists v; -create definer='root'@'localhost' view v as (select * from (select c1 or 0 from t) s); -select * from v; -c1 or 0 -1 -1 -1 -select `c1 or 0` from v; -c1 or 0 -1 -1 -1 -drop view v; -drop table if exists t, t1, t2; -create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b)); -create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); -create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -DROP TABLE IF EXISTS admin_checksum_partition_test; -CREATE TABLE admin_checksum_partition_test (a INT) PARTITION BY HASH(a) PARTITIONS 4; -INSERT INTO admin_checksum_partition_test VALUES (1), (2); -ADMIN CHECKSUM TABLE admin_checksum_partition_test; -drop table if exists t; -create table t (a tinyint not null); -set sql_mode = 'STRICT_TRANS_TABLES'; -insert t values (); -Error 1364 (HY000): Field 'a' doesn't have a default value -insert t values ('1000'); -Error 1264 (22003): Out of range value for column 'a' at row 1 -create table if not exists tdouble (a double(3,2)); -insert tdouble values (10.23); -Error 1264 (22003): Out of range value for column 'a' at row 1 -set sql_mode = ''; -insert t values (); -show warnings; -Level Code Message -Warning 1364 Field 'a' doesn't have a default value -insert t values (null); -Error 1048 (23000): Column 'a' cannot be null -insert ignore t values (null); -show warnings; -Level Code Message -Warning 1048 Column 'a' cannot be null -insert t select null; -show warnings; -Level Code Message -Warning 1048 Column 'a' cannot be null -insert t values (1000); -select * from t order by a; -a -0 -0 -0 -127 -insert tdouble values (10.23); -select * from tdouble; -a -9.99 -set sql_mode = 'STRICT_TRANS_TABLES'; -set @@global.sql_mode = ''; -drop table if exists t2; -create table t2 (a varchar(3)); -insert t2 values ('abcd'); -select * from t2; -a -abc -insert t2 values ('abcd'); -Error 1406 (22001): Data too long for column 'a' at row 1 -set sql_mode = default; -set @@global.sql_mode = default; -use information_schema; -select count(*)>=4 from schemata; -count(*)>=4 -1 -create database mytest; -use information_schema; -select * from schemata where schema_name = 'mysql'; -CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH TIDB_PLACEMENT_POLICY_NAME -def mysql utf8mb4 utf8mb4_bin NULL NULL -select * from schemata where schema_name like 'my%'; -CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH TIDB_PLACEMENT_POLICY_NAME -def mysql utf8mb4 utf8mb4_bin NULL NULL -def mytest utf8mb4 utf8mb4_bin NULL NULL -select 1 from tables limit 1; -1 -1 -use executor__executor; -set @@sql_mode='NO_ZERO_DATE'; -select date_add('2001-01-00', interval -2 hour); -date_add('2001-01-00', interval -2 hour) -NULL -show warnings; -Level Code Message -Warning 1292 Incorrect datetime value: '2001-01-00' -set @@sql_mode=default; -set @@sql_mode='NO_ZERO_DATE'; -drop table if exists t1; -SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d'); -STR_TO_DATE('0000-1-01', '%Y-%m-%d') -NULL -show warnings; -Level Code Message -Warning 1411 Incorrect datetime value: '0000-1-01' for function str_to_date -SELECT CAST('4#,8?Q' AS DATE); -CAST('4#,8?Q' AS DATE) -NULL -show warnings; -Level Code Message -Warning 8034 Incorrect datetime value: '4#,8?Q' -CREATE TABLE t1 (c1 INT, c2 TEXT); -INSERT INTO t1 VALUES (1833458842, '0.3503490908550797'); -SELECT CAST(t1.c2 AS DATE) FROM t1; -CAST(t1.c2 AS DATE) -NULL -show warnings; -Level Code Message -Warning 1292 Incorrect datetime value: '0.3503490908550797' -set @@sql_mode=default; -drop table if exists t; -create table t(a decimal(10,2) unsigned); -insert into t values (-1); -Error 1264 (22003): Out of range value for column 'a' at row 1 -insert into t values ("-1.1e-1"); -Error 1264 (22003): Out of range value for column 'a' at row 1 -insert into t values (-1.1); -Error 1264 (22003): Out of range value for column 'a' at row 1 -insert into t values (-0); -set sql_mode=''; -delete from t; -insert into t values (-1); -select a from t limit 1; -a -0.00 -set sql_mode=default; -drop table if exists t; -create table t(a int); -do 1 in (select * from t); -insert into t values(1); -do 1 in (select * from t); -drop table if exists t; -create table t(j JSON); -insert into t values('2010'); -insert into t values('2011'); -insert into t values('2012'); -insert into t values('2010.000'); -insert into t values(cast(18446744073709551615 as JSON)); -insert into t values(cast(18446744073709551616.000000 as JSON)); -select count(distinct j) from t; -count(distinct j) -5 -drop table if exists t; -create table t(id int(11), j JSON, d DOUBLE); -insert into t values(0, '2010', 2010); -insert into t values(1, '2011', 2011); -insert into t values(2, '2012', 2012); -insert into t values(3, cast(18446744073709551615 as JSON), 18446744073709551616.000000); -select /*+inl_hash_join(t2)*/ t1.id, t2.id from t t1 join t t2 on t1.j = t2.d; -id id -0 0 -1 1 -2 2 -drop table if exists catalog_sales, store_sales, date_dim; -create table catalog_sales -( -cs_sold_date_sk int , -cs_sold_time_sk int , -cs_ship_date_sk int , -cs_bill_customer_sk int , -cs_bill_cdemo_sk int , -cs_bill_hdemo_sk int , -cs_bill_addr_sk int , -cs_ship_customer_sk int , -cs_ship_cdemo_sk int , -cs_ship_hdemo_sk int , -cs_ship_addr_sk int , -cs_call_center_sk int , -cs_catalog_page_sk int , -cs_ship_mode_sk int , -cs_warehouse_sk int , -cs_item_sk int not null, -cs_promo_sk int , -cs_order_number int not null, -cs_quantity int , -cs_wholesale_cost decimal(7,2) , -cs_list_price decimal(7,2) , -cs_sales_price decimal(7,2) , -cs_ext_discount_amt decimal(7,2) , -cs_ext_sales_price decimal(7,2) , -cs_ext_wholesale_cost decimal(7,2) , -cs_ext_list_price decimal(7,2) , -cs_ext_tax decimal(7,2) , -cs_coupon_amt decimal(7,2) , -cs_ext_ship_cost decimal(7,2) , -cs_net_paid decimal(7,2) , -cs_net_paid_inc_tax decimal(7,2) , -cs_net_paid_inc_ship decimal(7,2) , -cs_net_paid_inc_ship_tax decimal(7,2) , -cs_net_profit decimal(7,2) , -primary key (cs_item_sk, cs_order_number) -); -create table store_sales -( -ss_sold_date_sk int , -ss_sold_time_sk int , -ss_item_sk int not null, -ss_customer_sk int , -ss_cdemo_sk int , -ss_hdemo_sk int , -ss_addr_sk int , -ss_store_sk int , -ss_promo_sk int , -ss_ticket_number int not null, -ss_quantity int , -ss_wholesale_cost decimal(7,2) , -ss_list_price decimal(7,2) , -ss_sales_price decimal(7,2) , -ss_ext_discount_amt decimal(7,2) , -ss_ext_sales_price decimal(7,2) , -ss_ext_wholesale_cost decimal(7,2) , -ss_ext_list_price decimal(7,2) , -ss_ext_tax decimal(7,2) , -ss_coupon_amt decimal(7,2) , -ss_net_paid decimal(7,2) , -ss_net_paid_inc_tax decimal(7,2) , -ss_net_profit decimal(7,2) , -primary key (ss_item_sk, ss_ticket_number) -); -create table date_dim -( -d_date_sk int not null, -d_date_id char(16) not null, -d_date date , -d_month_seq int , -d_week_seq int , -d_quarter_seq int , -d_year int , -d_dow int , -d_moy int , -d_dom int , -d_qoy int , -d_fy_year int , -d_fy_quarter_seq int , -d_fy_week_seq int , -d_day_name char(9) , -d_quarter_name char(6) , -d_holiday char(1) , -d_weekend char(1) , -d_following_holiday char(1) , -d_first_dom int , -d_last_dom int , -d_same_day_ly int , -d_same_day_lq int , -d_current_day char(1) , -d_current_week char(1) , -d_current_month char(1) , -d_current_quarter char(1) , -d_current_year char(1) , -primary key (d_date_sk) -); -plan replayer dump explain with ssci as ( -select ss_customer_sk customer_sk -,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk -and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk -,ss_item_sk), -csci as( -select cs_bill_customer_sk customer_sk -,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk -and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk -,cs_item_sk) -select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only -,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only -,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci left join csci on (ssci.customer_sk=csci.customer_sk -and ssci.item_sk = csci.item_sk) -UNION -select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only -,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only -,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci right join csci on (ssci.customer_sk=csci.customer_sk -and ssci.item_sk = csci.item_sk) -limit 100; -admin show bdr role; -BDR_ROLE - -admin set bdr role primary; -admin show bdr role; -BDR_ROLE -primary -admin set bdr role secondary; -admin show bdr role; -BDR_ROLE -secondary -admin unset bdr role; -admin show bdr role; -BDR_ROLE - -admin set bdr role test_err; -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 27 near "test_err;" -admin show bdr role; -BDR_ROLE - -admin unset bdr role; -set global tidb_mem_oom_action='CANCEL'; -drop table if exists t, t1; -create table t(a int, b int, index idx(a)); -create table t1(a int, c int, index idx(a)); -set tidb_mem_quota_query=10; -select t.a, t1.a from t use index(idx), t1 use index(idx) where t.a = t1.a; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -set global tidb_mem_oom_action=default; -set tidb_mem_quota_query=default; -drop table if exists t, t1; -create table t (a int primary key, b double); -insert into t values (1,1); -SET GLOBAL tidb_mem_oom_action='CANCEL'; -set @@tidb_mem_quota_query=1; -select sum(b) from t group by a; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -drop table if exists t,t1; -create table t (a bigint); -create table t1 (a bigint); -set @@tidb_mem_quota_query=200; -insert into t1 values (1),(2),(3),(4),(5); -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -replace into t1 values (1),(2),(3),(4),(5); -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -set @@tidb_mem_quota_query=10000; -insert into t1 values (1),(2),(3),(4),(5); -set @@tidb_mem_quota_query=10; -insert into t select a from t1 order by a desc; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -replace into t select a from t1 order by a desc; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -set @@tidb_mem_quota_query=10000; -insert into t values (1),(2),(3),(4),(5); -set @@tidb_mem_quota_query=244; -delete from t; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -set @@tidb_mem_quota_query=10000; -delete from t1; -insert into t1 values(1); -insert into t values (1),(2),(3),(4),(5); -set @@tidb_mem_quota_query=244; -delete t, t1 from t join t1 on t.a = t1.a; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -set @@tidb_mem_quota_query=100000; -truncate table t; -insert into t values(1),(2),(3); -set @@tidb_mem_quota_query=244; -update t set a = 4; -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -SET GLOBAL tidb_mem_oom_action = DEFAULT; -set @@tidb_mem_quota_query=DEFAULT; -drop table if exists t; -create table t(a int); -insert into t values(1); -set tidb_track_aggregate_memory_usage = off; -explain analyze select /*+ HASH_AGG() */ sum(a) from t; -id estRows actRows task access object execution info operator info memory disk -HashAgg_9 1.00 1 root funcs:sum(Column#4)->Column#3 N/A N/A -└─TableReader_10 1.00 1 root data:HashAgg_5 Bytes N/A - └─HashAgg_5 1.00 1 cop[tikv] funcs:sum(executor__executor.t.a)->Column#4 N/A N/A - └─TableFullScan_8 10000.00 1 cop[tikv] keep order:false, stats:pseudo N/A N/A -explain analyze select /*+ STREAM_AGG() */ sum(a) from t; -id estRows actRows task access object execution info operator info memory disk -StreamAgg_14 1.00 1 root funcs:sum(Column#4)->Column#3 N/A N/A -└─TableReader_15 1.00 1 root data:StreamAgg_8 Bytes N/A - └─StreamAgg_8 1.00 1 cop[tikv] funcs:sum(executor__executor.t.a)->Column#4 N/A N/A - └─TableFullScan_13 10000.00 1 cop[tikv] keep order:false, stats:pseudo N/A N/A -set tidb_track_aggregate_memory_usage = on; -explain analyze select /*+ HASH_AGG() */ sum(a) from t; -id estRows actRows task access object execution info operator info memory disk -HashAgg_9 1.00 1 root funcs:sum(Column#4)->Column#3 KB Bytes -└─TableReader_10 1.00 1 root data:HashAgg_5 Bytes N/A - └─HashAgg_5 1.00 1 cop[tikv] funcs:sum(executor__executor.t.a)->Column#4 N/A N/A - └─TableFullScan_8 10000.00 1 cop[tikv] keep order:false, stats:pseudo N/A N/A -explain analyze select /*+ STREAM_AGG() */ sum(a) from t; -id estRows actRows task access object execution info operator info memory disk -StreamAgg_14 1.00 1 root funcs:sum(Column#4)->Column#3 KB N/A -└─TableReader_15 1.00 1 root data:StreamAgg_8 Bytes N/A - └─StreamAgg_8 1.00 1 cop[tikv] funcs:sum(executor__executor.t.a)->Column#4 N/A N/A - └─TableFullScan_13 10000.00 1 cop[tikv] keep order:false, stats:pseudo N/A N/A -set tidb_track_aggregate_memory_usage = default; -drop table if exists testbind; -create table testbind(i int, s varchar(20)); -create index index_t on testbind(i,s); -create global binding for select * from testbind using select * from testbind use index for join(index_t); -show global bindings where default_db='executor__executor'; -Original_sql Bind_sql Default_db Status Create_time Update_time Charset Collation Source Sql_digest Plan_digest -select * from `executor__executor` . `testbind` SELECT * FROM `executor__executor`.`testbind` USE INDEX FOR JOIN (`index_t`) executor__executor enabled utf8mb4 utf8mb4_general_ci manual a2fa907992be17801e5976df09b5b3a0d205f4c4aff39a14ab3bc8642026f527 -create session binding for select * from testbind using select * from testbind use index for join(index_t); -show session bindings where default_db='executor__executor'; -Original_sql Bind_sql Default_db Status Create_time Update_time Charset Collation Source Sql_digest Plan_digest -select * from `executor__executor` . `testbind` SELECT * FROM `executor__executor`.`testbind` USE INDEX FOR JOIN (`index_t`) executor__executor enabled utf8mb4 utf8mb4_general_ci manual a2fa907992be17801e5976df09b5b3a0d205f4c4aff39a14ab3bc8642026f527 -drop session binding for select * from testbind using select * from testbind use index for join(index_t); -drop global binding for select * from testbind using select * from testbind use index for join(index_t); -drop table if EXISTS t1; -create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); -insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); -explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; -id estRows actRows task access object execution info operator info memory disk -IndexMerge_8 3334.67 2 root NULL .*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.* type: union KB N/A -├─TableRangeScan_5(Build) 3333.33 1 cop[tikv] table:t1 .*time:.*loops:.*cop_task:.* range:[-inf,2), keep order:false, stats:pseudo Bytes N/A -├─IndexRangeScan_6(Build) 3333.33 1 cop[tikv] table:t1, index:t1a(a) .*time:.*loops:.*cop_task:.* range:(4,+inf], keep order:false, stats:pseudo N/A N/A -└─TableRowIDScan_7(Probe) 3334.67 2 cop[tikv] table:t1 .*time:.*loops:.*cop_task:.* keep order:false, stats:pseudo N/A N/A -set @@tidb_enable_collect_execution_info=0; -select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; -id a b c d -1 1 1 1 1 -5 5 5 5 5 -set @@tidb_enable_collect_execution_info=default; -drop table if exists t1; -create table t1 (a int, b int, index(a)); -insert into t1 values (1,2),(2,3),(3,4); -explain analyze select * from t1 use index(a) where a > 1; -id estRows actRows task access object execution info operator info memory disk -IndexLookUp_7 3333.33 2 root NULL .*time:.*loops:.*index_task:.*table_task: {total_time.*num.*concurrency.*}.* NULL KB N/A -├─IndexRangeScan_5(Build) 3333.33 2 cop[tikv] table:t1, index:a(a) .*time:.*loops:.*cop_task:.* range:(1,+inf], keep order:false, stats:pseudo N/A N/A -└─TableRowIDScan_6(Probe) 3333.33 2 cop[tikv] table:t1 .*time:.*loops:.*cop_task:.* keep order:false, stats:pseudo N/A N/A -drop table if exists t1; -create table t1 (a int, b int); -insert into t1 values (1,2),(2,3),(3,4); -explain analyze SELECT /*+ HASH_AGG() */ count(*) FROM t1 WHERE a < 10; -id estRows actRows task access object execution info operator info memory disk -HashAgg_11 1.00 1 root NULL .*time:.*loops:.*partial_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*final_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.* funcs:count(Column#5)->Column#4 KB Bytes -└─TableReader_12 1.00 1 root NULL time.*loops.*cop_task.* data:HashAgg_6 Bytes N/A - └─HashAgg_6 1.00 1 cop[tikv] NULL tikv_task:.* funcs:count(1)->Column#5 N/A N/A - └─Selection_10 3323.33 3 cop[tikv] NULL tikv_task:.* lt(executor__executor.t1.a, 10) N/A N/A - └─TableFullScan_9 10000.00 3 cop[tikv] table:t1 tikv_task:.* keep order:false, stats:pseudo N/A N/A -set global tidb_txn_mode=''; -drop table if exists t, t1; -create table t (c1 int, c2 int, c3 int); -insert t values (11, 2, 3); -insert t values (12, 2, 3); -insert t values (13, 2, 3); -create table t1 (c1 int); -insert t1 values (11); -begin; -select * from t where c1=11 for update; -c1 c2 c3 -11 2 3 -begin; -update t set c2=211 where c1=11; -commit; -commit; -Error 9007 (HY000): Write conflict, reason=Optimistic [try again later] -begin; -select * from t where exists(select null from t1 where t1.c1=t.c1) for update; -c1 c2 c3 -11 211 3 -begin; -update t set c2=211 where c1=12; -commit; -commit; -begin; -select * from t where c1=11 for update; -c1 c2 c3 -11 211 3 -begin; -update t set c2=22 where c1=12; -commit; -commit; -set @@autocommit=1; -select * from t where c1=11 for update; -c1 c2 c3 -11 211 3 -begin; -update t set c2=211 where c1=11; -commit; -commit; -begin; -select * from (select * from t for update) t join t1 for update; -c1 c2 c3 c1 -11 211 3 11 -12 22 3 11 -13 2 3 11 -begin; -update t1 set c1 = 13; -commit; -commit; -Error 9007 (HY000): Write conflict, reason=Optimistic [try again later] -set global tidb_txn_mode=pessimistic; -drop table if exists t, t1; -create table t (i int); -create table t1 (i int); -insert t values (1); -insert t1 values (1); -begin pessimistic; -select * from t, t1 where t.i = t1.i for update of t; -i i -1 1 -begin pessimistic; -select * from t1 for update; -i -1 -select * from t for update nowait; -Error 3572 (HY000): Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set. -rollback; -select * from t for update nowait; -i -1 -rollback; -set session tidb_txn_mode=''; -drop table if exists t; -create table t(a int); -insert into t values (1); -begin; -select 1 as a union select a from t for update; -a -1 -set session tidb_txn_mode=''; -update t set a = a + 1; -commit; -Error 9007 (HY000): Write conflict, reason=Optimistic [try again later] -begin; -select 1 as a union select a from t limit 5 for update; -a -1 -2 -select 1 as a union select a from t order by a for update; -a -1 -2 -update t set a = a + 1; -commit; -Error 9007 (HY000): Write conflict, reason=Optimistic [try again later] -set session tidb_txn_mode=pessimistic; -drop table if exists t; -create table t (id bigint key,b int); -split table t by (10),(20),(30); -TOTAL_SPLIT_REGION SCATTER_FINISH_RATIO -3 1 -insert into t values (0,0),(10,10),(20,20),(30,30); -alter table t add index idx1(b); -admin show ddl jobs 1; -JOB_ID DB_NAME TABLE_NAME JOB_TYPE SCHEMA_STATE SCHEMA_ID TABLE_ID ROW_COUNT CREATE_TIME START_TIME END_TIME STATE - executor__executor t public 4 synced -insert into t values (1,0),(2,10),(3,20),(4,30); -alter table t add index idx2(b); -admin show ddl jobs 1; -JOB_ID DB_NAME TABLE_NAME JOB_TYPE SCHEMA_STATE SCHEMA_ID TABLE_ID ROW_COUNT CREATE_TIME START_TIME END_TIME STATE - executor__executor t public 8 synced -drop table if exists t; -create table t(a int, b int as(-a)); -insert into t(a) values(1), (3), (7); -SET GLOBAL tidb_mem_oom_action='CANCEL'; -set @@tidb_mem_quota_query=1; -update t set t.a = t.a - 1 where t.a in (select a from t where a < 4); -Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] -set @@tidb_mem_quota_query=1000000000; -select stmt_type from information_schema.statements_summary where digest_text = 'update `t` set `t` . `a` = `t` . `a` - ? where `t` . `a` in ( select `a` from `t` where `a` < ? )'; -stmt_type -Update -set @@tidb_mem_quota_query=default; -set global tidb_mem_oom_action=default; -drop table if exists t; -drop user if exists 'testuser'@'localhost'; -create table t(a int); -create user 'testuser'@'localhost'; -LOCK TABLE executor__executor.t WRITE; -Error 1044 (42000): Access denied for user 'testuser'@'localhost' to database 'executor__executor' -GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; -LOCK TABLE executor__executor.t WRITE; -Error 1142 (42000): SELECT command denied to user 'testuser'@'localhost' for table 't' -REVOKE ALL ON executor__executor.* FROM 'testuser'@'localhost'; -GRANT SELECT ON executor__executor.* to 'testuser'@'localhost'; -LOCK TABLE executor__executor.t WRITE; -Error 1044 (42000): Access denied for user 'testuser'@'localhost' to database 'executor__executor' -GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; -LOCK TABLE executor__executor.t WRITE; -drop database if exists test2; -create database test2; -create table test2.t2(a int); -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; -Error 1044 (42000): Access denied for user 'testuser'@'localhost' to database 'test2' -GRANT LOCK TABLES ON test2.* to 'testuser'@'localhost'; -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; -Error 1142 (42000): SELECT command denied to user 'testuser'@'localhost' for table 't2' -GRANT SELECT ON test2.* to 'testuser'@'localhost'; -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; -Error 8020 (HY000): Table 't' was locked in WRITE by server: session: -unlock tables; -unlock tables; -drop user 'testuser'@'localhost'; diff --git a/tests/integrationtest/r/executor/insert.result b/tests/integrationtest/r/executor/insert.result deleted file mode 100644 index a2250b63e7478..0000000000000 --- a/tests/integrationtest/r/executor/insert.result +++ /dev/null @@ -1,2180 +0,0 @@ -set tidb_enable_clustered_index = on; -drop table if exists t; -create table t(a char(20), b int, primary key(a)); -insert into t values('aa', 1), ('bb', 1); -insert into t values('aa', 2); -Error 1062 (23000): Duplicate entry 'aa' for key 't.PRIMARY' -drop table t; -create table t(a char(20), b varchar(30), c varchar(10), primary key(a, b, c)); -insert into t values ('a', 'b', 'c'), ('b', 'a', 'c'); -insert into t values ('a', 'b', 'c'); -Error 1062 (23000): Duplicate entry 'a-b-c' for key 't.PRIMARY' -set tidb_enable_clustered_index = default; -set tidb_enable_clustered_index = on; -drop table if exists t1; -create table t1(c1 decimal(6,4), primary key(c1)); -insert into t1 set c1 = 0.1; -insert into t1 set c1 = 0.1 on duplicate key update c1 = 1; -select * from t1; -c1 -1.0000 -set tidb_enable_clustered_index = default; -drop table if exists t1; -create table t1(c1 year); -insert into t1 set c1 = '2004'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 year); -insert into t1 set c1 = 2004; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 bit); -insert into t1 set c1 = 1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 smallint unsigned); -insert into t1 set c1 = 1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 int unsigned); -insert into t1 set c1 = 1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 smallint); -insert into t1 set c1 = -1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 int); -insert into t1 set c1 = -1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 decimal(6,4)); -insert into t1 set c1 = '1.1'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 decimal); -insert into t1 set c1 = 1.1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 numeric); -insert into t1 set c1 = -1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 float); -insert into t1 set c1 = 1.2; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 double); -insert into t1 set c1 = 1.2; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 double); -insert into t1 set c1 = 1.3; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 real); -insert into t1 set c1 = 1.4; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 date); -insert into t1 set c1 = '2020-01-01'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 time); -insert into t1 set c1 = '20:00:00'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 datetime); -insert into t1 set c1 = '2020-01-01 22:22:22'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 timestamp); -insert into t1 set c1 = '2020-01-01 22:22:22'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 year); -insert into t1 set c1 = '2020'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 char(15)); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 varchar(15)); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 binary(3)); -insert into t1 set c1 = 'a'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 varbinary(3)); -insert into t1 set c1 = 'b'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 blob); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1(3)); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 text); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1(3)); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 enum('a', 'b')); -insert into t1 set c1 = 'a'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 set('a', 'b')); -insert into t1 set c1 = 'a,b'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists c; -create table c(i int,j int,k int,primary key(i,j,k)); -insert into c values(1,2,3); -insert into c values(1,2,4); -update c set i=1,j=2,k=4 where i=1 and j=2 and k=3; -Error 1062 (23000): Duplicate entry '1-2-4' for key 'c.PRIMARY' -drop table if exists t1, t2; -create table t1 (a int(11) ,b varchar(100) ,primary key (a)); -create table t2 (c int(11) ,d varchar(100) ,primary key (c)); -prepare in1 from 'insert into t1 (a,b) select c,null from t2 t on duplicate key update b=t.d'; -execute in1; -drop table if exists t1; -create table t1(a bigint); -insert into t1 values("asfasdfsajhlkhlksdaf"); -Error 1366 (HY000): Incorrect bigint value: 'asfasdfsajhlkhlksdaf' for column 'a' at row 1 -drop table if exists t1; -create table t1(a varchar(10)) charset ascii; -insert into t1 values('我'); -Error 1366 (HY000): Incorrect string value '\xE6\x88\x91' for column 'a' -drop table if exists t1; -create table t1(a char(10) charset utf8); -insert into t1 values('我'); -alter table t1 add column b char(10) charset ascii as ((a)); -select * from t1; -a b -我 ? -drop table if exists t; -create table t (a year); -insert into t values(2156); -Error 1264 (22003): Out of range value for column 'a' at row 1 -DROP TABLE IF EXISTS ts; -CREATE TABLE ts (id int DEFAULT NULL, time1 TIMESTAMP NULL DEFAULT NULL); -SET @@sql_mode=''; -INSERT INTO ts (id, time1) VALUES (1, TIMESTAMP '1018-12-23 00:00:00'); -SHOW WARNINGS; -Level Code Message -Warning 1292 Incorrect timestamp value: '1018-12-23 00:00:00' for column 'time1' at row 1 -SELECT * FROM ts ORDER BY id; -id time1 -1 0000-00-00 00:00:00 -SET @@sql_mode='STRICT_TRANS_TABLES'; -INSERT INTO ts (id, time1) VALUES (2, TIMESTAMP '1018-12-24 00:00:00'); -Error 1292 (22007): Incorrect timestamp value: '1018-12-24 00:00:00' for column 'time1' at row 1 -DROP TABLE ts; -CREATE TABLE t0(c0 SMALLINT AUTO_INCREMENT PRIMARY KEY); -INSERT IGNORE INTO t0(c0) VALUES (194626268); -INSERT IGNORE INTO t0(c0) VALUES ('*'); -SHOW WARNINGS; -Level Code Message -Warning 1366 Incorrect smallint value: '*' for column 'c0' at row 1 -Warning 1690 constant 32768 overflows smallint -Warning 1467 Failed to read auto-increment value from storage engine -SET @@sql_mode=default; -drop table if exists t1; -create table t1(a decimal(15,2)); -insert into t1 values (1111111111111.01); -select * from t1; -a -1111111111111.01 -select cast(a as decimal) from t1; -cast(a as decimal) -9999999999 -drop table if exists t1; -create table t1(a json, b int, unique index idx((cast(a as signed array)))); -insert into t1 values ('[1,11]', 1); -insert into t1 values ('[2, 22]', 2); -select * from t1; -a b -[1, 11] 1 -[2, 22] 2 -insert into t1 values ('[2, 222]', 2); -Error 1062 (23000): Duplicate entry '2' for key 't1.idx' -replace into t1 values ('[1, 10]', 10); -select * from t1; -a b -[2, 22] 2 -[1, 10] 10 -replace into t1 values ('[1, 2]', 1); -select * from t1; -a b -[1, 2] 1 -replace into t1 values ('[1, 11]', 1); -insert into t1 values ('[2, 22]', 2); -select * from t1; -a b -[1, 11] 1 -[2, 22] 2 -insert ignore into t1 values ('[1]', 2); -select * from t1; -a b -[1, 11] 1 -[2, 22] 2 -insert ignore into t1 values ('[1, 2]', 2); -select * from t1; -a b -[1, 11] 1 -[2, 22] 2 -insert into t1 values ('[2]', 2) on duplicate key update b = 10; -select * from t1; -a b -[1, 11] 1 -[2, 22] 10 -insert into t1 values ('[2, 1]', 2) on duplicate key update a = '[1,2]'; -Error 1062 (23000): Duplicate entry '[1, 2]' for key 't1.idx' -insert into t1 values ('[1,2]', 2) on duplicate key update a = '[1,2]'; -Error 1062 (23000): Duplicate entry '[1, 2]' for key 't1.idx' -insert into t1 values ('[11, 22]', 2) on duplicate key update a = '[1,2]'; -Error 1062 (23000): Duplicate entry '[1, 2]' for key 't1.idx' -set time_zone="+09:00"; -drop table if exists t; -create table t (id int, c1 datetime not null default CURRENT_TIMESTAMP); -set TIMESTAMP = 1234; -insert t (id) values (1); -select * from t; -id c1 -1 1970-01-01 09:20:34 -drop table if exists t; -create table t (dt datetime); -set @@time_zone='+08:00'; -delete from t; -insert into t values ('2020-10-22'); -select * from t; -dt -2020-10-22 00:00:00 -delete from t; -insert into t values ('2020-10-22-16'); -select * from t; -dt -2020-10-22 16:00:00 -delete from t; -insert into t values ('2020-10-22 16-31'); -select * from t; -dt -2020-10-22 16:31:00 -delete from t; -insert into t values ('2020-10-22 16:31-15'); -select * from t; -dt -2020-10-22 16:31:15 -delete from t; -insert into t values ('2020-10-22T16:31:15-10'); -select * from t; -dt -2020-10-23 10:31:15 -delete from t; -insert into t values ('2020.10-22'); -select * from t; -dt -2020-10-22 00:00:00 -delete from t; -insert into t values ('2020-10.22-16'); -select * from t; -dt -2020-10-22 16:00:00 -delete from t; -insert into t values ('2020-10-22.16-31'); -select * from t; -dt -2020-10-22 16:31:00 -delete from t; -insert into t values ('2020-10-22 16.31-15'); -select * from t; -dt -2020-10-22 16:31:15 -delete from t; -insert into t values ('2020-10-22T16.31.15+14'); -select * from t; -dt -2020-10-22 10:31:15 -delete from t; -insert into t values ('2020-10:22'); -select * from t; -dt -2020-10-22 00:00:00 -delete from t; -insert into t values ('2020-10-22:16'); -select * from t; -dt -2020-10-22 16:00:00 -delete from t; -insert into t values ('2020-10-22-16:31'); -select * from t; -dt -2020-10-22 16:31:00 -delete from t; -insert into t values ('2020-10-22 16-31:15'); -select * from t; -dt -2020-10-22 16:31:15 -delete from t; -insert into t values ('2020-10-22T16.31.15+09:30'); -select * from t; -dt -2020-10-22 15:01:15 -delete from t; -insert into t values ('2020.10-22:16'); -select * from t; -dt -2020-10-22 16:00:00 -delete from t; -insert into t values ('2020-10.22-16:31'); -select * from t; -dt -2020-10-22 16:31:00 -delete from t; -insert into t values ('2020-10-22.16-31:15'); -select * from t; -dt -2020-10-22 16:31:15 -delete from t; -insert into t values ('2020-10-22T16:31.15+09:30'); -select * from t; -dt -2020-10-22 15:01:15 -drop table if exists t; -create table t (dt datetime, ts timestamp); -delete from t; -set @@time_zone='+08:00'; -insert into t values ('2020-10-22T16:53:40Z', '2020-10-22T16:53:40Z'); -set @@time_zone='+00:00'; -select * from t; -dt ts -2020-10-23 00:53:40 2020-10-22 16:53:40 -delete from t; -set @@time_zone='-08:00'; -insert into t values ('2020-10-22T16:53:40Z', '2020-10-22T16:53:40Z'); -set @@time_zone='+08:00'; -select * from t; -dt ts -2020-10-22 08:53:40 2020-10-23 00:53:40 -delete from t; -set @@time_zone='-03:00'; -insert into t values ('2020-10-22T16:53:40+03:00', '2020-10-22T16:53:40+03:00'); -set @@time_zone='+08:00'; -select * from t; -dt ts -2020-10-22 10:53:40 2020-10-22 21:53:40 -delete from t; -set @@time_zone='+08:00'; -insert into t values ('2020-10-22T16:53:40+08:00', '2020-10-22T16:53:40+08:00'); -set @@time_zone='+08:00'; -select * from t; -dt ts -2020-10-22 16:53:40 2020-10-22 16:53:40 -drop table if exists t; -create table t (ts timestamp); -insert into t values ('2020-10-22T12:00:00Z'), ('2020-10-22T13:00:00Z'), ('2020-10-22T14:00:00Z'); -select count(*) from t where ts > '2020-10-22T12:00:00Z'; -count(*) -2 -set @@time_zone='+08:00'; -drop table if exists t; -create table t (dt datetime(2), ts timestamp(2)); -insert into t values ('2020-10-27T14:39:10.10+00:00', '2020-10-27T14:39:10.10+00:00'); -select * from t; -dt ts -2020-10-27 22:39:10.10 2020-10-27 22:39:10.10 -drop table if exists t; -create table t (dt datetime(1), ts timestamp(1)); -insert into t values ('2020-10-27T14:39:10.3+0200', '2020-10-27T14:39:10.3+0200'); -select * from t; -dt ts -2020-10-27 20:39:10.3 2020-10-27 20:39:10.3 -drop table if exists t; -create table t (dt datetime(6), ts timestamp(6)); -insert into t values ('2020-10-27T14:39:10.3-02', '2020-10-27T14:39:10.3-02'); -select * from t; -dt ts -2020-10-28 00:39:10.300000 2020-10-28 00:39:10.300000 -drop table if exists t; -create table t (dt datetime(2), ts timestamp(2)); -insert into t values ('2020-10-27T14:39:10.10Z', '2020-10-27T14:39:10.10Z'); -select * from t; -dt ts -2020-10-27 22:39:10.10 2020-10-27 22:39:10.10 -set time_zone=default; -set timestamp=default; -drop table if exists t1; -create table t1(a year(4)); -insert into t1 values(0000),(00),("0000"),("000"), ("00"), ("0"), (79), ("79"); -select * from t1; -a -0000 -0000 -0000 -2000 -2000 -2000 -1979 -1979 -drop table if exists t; -create table t(f_year year NOT NULL DEFAULT '0000')ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; -insert into t values(); -select * from t; -f_year -0000 -insert into t values('0000'); -select * from t; -f_year -0000 -0000 -drop table if exists t1, t2, t3, t4; -create table t1(d date); -create table t2(d datetime); -create table t3(d date); -create table t4(d datetime); -set sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES'; -insert into t1 values ('0000-00-00'); -insert into t2 values ('0000-00-00'); -insert into t1 values ('2019-00-00'); -insert into t2 values ('2019-00-00'); -insert into t1 values ('2019-01-00'); -insert into t2 values ('2019-01-00'); -insert into t1 values ('2019-00-01'); -insert into t2 values ('2019-00-01'); -insert into t1 values ('2019-02-31'); -insert into t2 values ('2019-02-31'); -select year(d), month(d), day(d) from t1; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -select year(d), month(d), day(d) from t2; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -insert t3 select d from t1; -select year(d), month(d), day(d) from t3; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -insert t4 select d from t2; -select year(d), month(d), day(d) from t4; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -truncate t1;truncate t2;truncate t3;truncate t4; -set sql_mode='ALLOW_INVALID_DATES'; -insert into t1 values ('0000-00-00'); -insert into t2 values ('0000-00-00'); -insert into t1 values ('2019-00-00'); -insert into t2 values ('2019-00-00'); -insert into t1 values ('2019-01-00'); -insert into t2 values ('2019-01-00'); -insert into t1 values ('2019-00-01'); -insert into t2 values ('2019-00-01'); -insert into t1 values ('2019-02-31'); -insert into t2 values ('2019-02-31'); -select year(d), month(d), day(d) from t1; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -select year(d), month(d), day(d) from t2; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -insert t3 select d from t1; -select year(d), month(d), day(d) from t3; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -insert t4 select d from t2; -select year(d), month(d), day(d) from t4; -year(d) month(d) day(d) -0 0 0 -2019 0 0 -2019 1 0 -2019 0 1 -2019 2 31 -set sql_mode=default; -drop table if exists t1, t2, t3; -create table t1 (a int,b int,primary key(a,b)) partition by range(a) (partition p0 values less than (100),partition p1 values less than (1000)); -insert into t1 set a=1, b=1; -insert into t1 set a=1,b=1 on duplicate key update a=1,b=1; -select * from t1; -a b -1 1 -create table t2 (a int,b int,primary key(a,b)) partition by hash(a) partitions 4; -insert into t2 set a=1,b=1; -insert into t2 set a=1,b=1 on duplicate key update a=1,b=1; -select * from t2; -a b -1 1 -CREATE TABLE t3 (a int, b int, c int, d int, e int, -PRIMARY KEY (a,b), -UNIQUE KEY (b,c,d) -) PARTITION BY RANGE ( b ) ( -PARTITION p0 VALUES LESS THAN (4), -PARTITION p1 VALUES LESS THAN (7), -PARTITION p2 VALUES LESS THAN (11) -); -insert into t3 values (1,2,3,4,5); -insert into t3 values (1,2,3,4,5),(6,2,3,4,6) on duplicate key update e = e + values(e); -select * from t3; -a b c d e -1 2 3 4 16 -drop table if exists t1; -create table t1 (a bit(3)); -insert into t1 values(-1); -Error 1406 (22001): Data too long for column 'a' at row 1 -insert into t1 values(9); -Error 1406 (22001): Data too long for column 'a' at row 1 -create table t64 (a bit(64)); -insert into t64 values(-1); -insert into t64 values(18446744073709551615); -insert into t64 values(18446744073709551616); -Error 1264 (22003): Out of range value for column 'a' at row 1 -drop table if exists bug; -create table bug (a varchar(100)); -insert into bug select ifnull(JSON_UNQUOTE(JSON_EXTRACT('[{"amount":2000,"feeAmount":0,"merchantNo":"20190430140319679394","shareBizCode":"20160311162_SECOND"}]', '$[0].merchantNo')),'') merchant_no union SELECT '20180531557' merchant_no; -select * from bug; -a -20180531557 -20190430140319679394 -drop table if exists t; -create table t (a int, b double); -insert into t values (ifnull('',0)+0, 0); -insert into t values (0, ifnull('',0)+0); -select * from t; -a b -0 0 -0 0 -insert into t values ('', 0); -Error 1366 (HY000): Incorrect int value: '' for column 'a' at row 1 -insert into t values (0, ''); -Error 1366 (HY000): Incorrect double value: '' for column 'b' at row 1 -update t set a = ''; -Error 1292 (22007): Truncated incorrect DOUBLE value: '' -update t set b = ''; -Error 1292 (22007): Truncated incorrect DOUBLE value: '' -update t set a = ifnull('',0)+0; -update t set b = ifnull('',0)+0; -delete from t where a = ''; -select * from t; -a b -drop table if exists t,t1; -create table t(col1 FLOAT, col2 FLOAT(10,2), col3 DOUBLE, col4 DOUBLE(10,2), col5 DECIMAL, col6 DECIMAL(10,2)); -insert into t values (-3.402823466E+68, -34028234.6611, -1.7976931348623157E+308, -17976921.34, -9999999999, -99999999.99); -Error 1264 (22003): Out of range value for column 'col1' at row 1 -insert into t values (-34028234.6611, -3.402823466E+68, -1.7976931348623157E+308, -17976921.34, -9999999999, -99999999.99); -Error 1264 (22003): Out of range value for column 'col2' at row 1 -create table t1(id1 float,id2 float); -insert ignore into t1 values(999999999999999999999999999999999999999,-999999999999999999999999999999999999999); -select @@warning_count; -@@warning_count -2 -select convert(id1,decimal(65)),convert(id2,decimal(65)) from t1; -convert(id1,decimal(65)) convert(id2,decimal(65)) -340282346638528860000000000000000000000 -340282346638528860000000000000000000000 -set sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; -drop table if exists t1; -CREATE TABLE t1(c1 TINYTEXT CHARACTER SET utf8mb4); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 128)); -Error 1406 (22001): Data too long for column 'c1' at row 1 -drop table if exists t1; -CREATE TABLE t1(c1 Text CHARACTER SET utf8mb4); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 32768)); -Error 1406 (22001): Data too long for column 'c1' at row 1 -drop table if exists t1; -CREATE TABLE t1(c1 mediumtext); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 8777215)); -Error 1406 (22001): Data too long for column 'c1' at row 1 -set sql_mode = 'ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; -drop table if exists t1; -CREATE TABLE t1(c1 TINYTEXT CHARACTER SET utf8mb4); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 128)); -select length(c1) from t1; -length(c1) -254 -drop table if exists t1; -CREATE TABLE t1(c1 Text CHARACTER SET utf8mb4); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 32768)); -select length(c1) from t1; -length(c1) -65534 -set sql_mode = default; -set @@allow_auto_random_explicit_insert = true; -drop table if exists ar; -create table ar (id bigint key clustered auto_random, name char(10)); -insert into ar(id) values (1); -select id from ar; -id -1 -select last_insert_id(); -last_insert_id() -0 -delete from ar; -insert into ar(id) values (1), (2); -select id from ar; -id -1 -2 -select last_insert_id(); -last_insert_id() -0 -delete from ar; -drop table ar; -set @@allow_auto_random_explicit_insert = default; -drop table if exists t, t1; -create table t (a int primary key, b datetime, d date); -insert into t values (1, '2019-02-11 30:00:00', '2019-01-31'); -Error 1292 (22007): Incorrect datetime value: '2019-02-11 30:00:00' for column 'b' at row 1 -CREATE TABLE t1 (a BINARY(16) PRIMARY KEY); -INSERT INTO t1 VALUES (AES_ENCRYPT('a','a')); -INSERT INTO t1 VALUES (AES_ENCRYPT('a','a')); -Error 1062 (23000): Duplicate entry '{ W]\xA1\x06u\x9D\xBD\xB1\xA3.\xE2\xD9\xA7t' for key 't1.PRIMARY' -INSERT INTO t1 VALUES (AES_ENCRYPT('b','b')); -INSERT INTO t1 VALUES (AES_ENCRYPT('b','b')); -Error 1062 (23000): Duplicate entry '\x0C\x1E\x8DG`\xEB\x93 F&BC\xF0\xB5\xF4\xB7' for key 't1.PRIMARY' -drop table if exists t1; -create table t1 (a bit primary key) engine=innodb; -insert into t1 values (b'0'); -insert into t1 values (b'0'); -Error 1062 (23000): Duplicate entry '\x00' for key 't1.PRIMARY' -drop table if exists t; -create table t(c numeric primary key); -insert ignore into t values(null); -insert into t values(0); -Error 1062 (23000): Duplicate entry '0' for key 't.PRIMARY' -set tidb_enable_clustered_index = on; -drop table if exists t1pk; -create table t1pk(id varchar(200) primary key, v int); -insert into t1pk(id, v) values('abc', 1); -select * from t1pk; -id v -abc 1 -set @@tidb_constraint_check_in_place=true; -insert into t1pk(id, v) values('abc', 2); -Error 1062 (23000): Duplicate entry 'abc' for key 't1pk.PRIMARY' -set @@tidb_constraint_check_in_place=false; -insert into t1pk(id, v) values('abc', 3); -Error 1062 (23000): Duplicate entry 'abc' for key 't1pk.PRIMARY' -select v, id from t1pk; -v id -1 abc -select id from t1pk where id = 'abc'; -id -abc -select v, id from t1pk where id = 'abc'; -v id -1 abc -drop table if exists t3pk; -create table t3pk(id1 varchar(200), id2 varchar(200), v int, id3 int, primary key(id1, id2, id3)); -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 100, 1); -select * from t3pk; -id1 id2 v id3 -abc xyz 1 100 -set @@tidb_constraint_check_in_place=true; -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 100, 2); -Error 1062 (23000): Duplicate entry 'abc-xyz-100' for key 't3pk.PRIMARY' -set @@tidb_constraint_check_in_place=false; -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 100, 3); -Error 1062 (23000): Duplicate entry 'abc-xyz-100' for key 't3pk.PRIMARY' -select v, id3, id2, id1 from t3pk; -v id3 id2 id1 -1 100 xyz abc -select id3, id2, id1 from t3pk where id3 = 100 and id2 = 'xyz' and id1 = 'abc'; -id3 id2 id1 -100 xyz abc -select id3, id2, id1, v from t3pk where id3 = 100 and id2 = 'xyz' and id1 = 'abc'; -id3 id2 id1 v -100 xyz abc 1 -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 101, 1); -insert into t3pk(id1, id2, id3, v) values('abc', 'zzz', 101, 1); -drop table if exists t1pku; -create table t1pku(id varchar(200) primary key, uk int, v int, unique key ukk(uk)); -insert into t1pku(id, uk, v) values('abc', 1, 2); -select * from t1pku where id = 'abc'; -id uk v -abc 1 2 -insert into t1pku(id, uk, v) values('aaa', 1, 3); -Error 1062 (23000): Duplicate entry '1' for key 't1pku.ukk' -select * from t1pku; -id uk v -abc 1 2 -select * from t3pk where (id1, id2, id3) in (('abc', 'xyz', 100), ('abc', 'xyz', 101), ('abc', 'zzz', 101)); -id1 id2 v id3 -abc xyz 1 100 -abc xyz 1 101 -abc zzz 1 101 -set @@tidb_constraint_check_in_place=default; -set tidb_enable_clustered_index = default; -set tidb_enable_clustered_index = on; -drop table if exists it1pk; -create table it1pk(id varchar(200) primary key, v int); -insert into it1pk(id, v) values('abc', 1); -insert ignore into it1pk(id, v) values('abc', 2); -select * from it1pk where id = 'abc'; -id v -abc 1 -drop table if exists it2pk; -create table it2pk(id1 varchar(200), id2 varchar(200), v int, primary key(id1, id2)); -insert into it2pk(id1, id2, v) values('abc', 'cba', 1); -select * from it2pk where id1 = 'abc' and id2 = 'cba'; -id1 id2 v -abc cba 1 -insert ignore into it2pk(id1, id2, v) values('abc', 'cba', 2); -select * from it2pk where id1 = 'abc' and id2 = 'cba'; -id1 id2 v -abc cba 1 -drop table if exists it1pku; -create table it1pku(id varchar(200) primary key, uk int, v int, unique key ukk(uk)); -insert into it1pku(id, uk, v) values('abc', 1, 2); -select * from it1pku where id = 'abc'; -id uk v -abc 1 2 -insert ignore into it1pku(id, uk, v) values('aaa', 1, 3), ('bbb', 2, 1); -select * from it1pku; -id uk v -abc 1 2 -bbb 2 1 -set tidb_enable_clustered_index = default; -set tidb_enable_clustered_index = on; -drop table if exists dt1pi; -create table dt1pi(id varchar(200) primary key, v int); -insert into dt1pi(id, v) values('abb', 1),('acc', 2); -insert into dt1pi(id, v) values('abb', 2) on duplicate key update v = v + 1; -select * from dt1pi; -id v -abb 2 -acc 2 -insert into dt1pi(id, v) values('abb', 2) on duplicate key update v = v + 1, id = 'xxx'; -select * from dt1pi; -id v -acc 2 -xxx 3 -drop table if exists dt1piu; -create table dt1piu(id varchar(200) primary key, uk int, v int, unique key uuk(uk)); -insert into dt1piu(id, uk, v) values('abb', 1, 10),('acc', 2, 20); -insert into dt1piu(id, uk, v) values('xyz', 1, 100) on duplicate key update v = v + 1; -select * from dt1piu; -id uk v -abb 1 11 -acc 2 20 -insert into dt1piu(id, uk, v) values('abb', 1, 2) on duplicate key update v = v + 1, id = 'xxx'; -select * from dt1piu; -id uk v -acc 2 20 -xxx 1 12 -drop table if exists ts1pk; -create table ts1pk(id1 timestamp, id2 timestamp, v int, primary key(id1, id2)); -insert into ts1pk (id1, id2, v) values('2018-01-01 11:11:11', '2018-01-01 11:11:11', 1); -select id1, id2, v from ts1pk; -id1 id2 v -2018-01-01 11:11:11 2018-01-01 11:11:11 1 -insert into ts1pk (id1, id2, v) values('2018-01-01 11:11:11', '2018-01-01 11:11:11', 2) on duplicate key update v = values(v); -select id1, id2, v from ts1pk; -id1 id2 v -2018-01-01 11:11:11 2018-01-01 11:11:11 2 -insert into ts1pk (id1, id2, v) values('2018-01-01 11:11:11', '2018-01-01 11:11:11', 2) on duplicate key update v = values(v), id1 = '2018-01-01 11:11:12'; -select id1, id2, v from ts1pk; -id1 id2 v -2018-01-01 11:11:12 2018-01-01 11:11:11 2 -set tidb_enable_clustered_index = default; -set tidb_enable_clustered_index = on; -drop table if exists pkt1; -CREATE TABLE pkt1 (a varchar(255), b int, index idx(b), primary key(a,b)); -insert into pkt1 values ('aaa',1); -select b from pkt1 where b = 1; -b -1 -drop table if exists pkt2; -CREATE TABLE pkt2 (a varchar(255), b int, unique index idx(b), primary key(a,b)); -insert into pkt2 values ('aaa',1); -select b from pkt2 where b = 1; -b -1 -drop table if exists issue_18232; -create table issue_18232 (a int, b int, c int, d int, primary key (a, b), index idx(c)); -select a from issue_18232 use index (idx); -a -select b from issue_18232 use index (idx); -b -select a,b from issue_18232 use index (idx); -a b -select c from issue_18232 use index (idx); -c -select a,c from issue_18232 use index (idx); -a c -select b,c from issue_18232 use index (idx); -b c -select a,b,c from issue_18232 use index (idx); -a b c -select d from issue_18232 use index (idx); -d -select a,d from issue_18232 use index (idx); -a d -select b,d from issue_18232 use index (idx); -b d -select a,b,d from issue_18232 use index (idx); -a b d -select c,d from issue_18232 use index (idx); -c d -select a,c,d from issue_18232 use index (idx); -a c d -select b,c,d from issue_18232 use index (idx); -b c d -select a,b,c,d from issue_18232 use index (idx); -a b c d -set tidb_enable_clustered_index = default; -drop table if exists t1, t2; -create table t1(a year, primary key(a)); -insert ignore into t1 values(null); -create table t2(a int, key(a)); -insert into t2 values(0); -select /*+ hash_join(t1) */ * from t1 join t2 on t1.a = t2.a; -a a -0000 0 -select /*+ inl_join(t1) */ * from t1 join t2 on t1.a = t2.a; -a a -0000 0 -select /*+ inl_join(t2) */ * from t1 join t2 on t1.a = t2.a; -a a -0000 0 -select /*+ inl_hash_join(t1) */ * from t1 join t2 on t1.a = t2.a; -a a -0000 0 -select /*+ inl_merge_join(t1) */ * from t1 join t2 on t1.a = t2.a; -a a -0000 0 -select /*+ merge_join(t1) */ * from t1 join t2 on t1.a = t2.a; -a a -0000 0 -drop table if exists vctt; -create table vctt (v varchar(4), c char(4)); -insert into vctt values ('ab ', 'ab '); -select * from vctt; -v c -ab ab -delete from vctt; -insert into vctt values ('ab\n\n\n', 'ab\n\n\n'), ('ab\t\t\t', 'ab\t\t\t'), ('ab ', 'ab '), ('ab\r\r\r', 'ab\r\r\r'); -show warnings; -Level Code Message -Warning 1265 Data truncated for column 'v' at row 1 -Warning 1265 Data truncated for column 'v' at row 2 -Warning 1265 Data truncated for column 'v' at row 3 -Warning 1265 Data truncated for column 'v' at row 4 -select * from vctt; -v c -ab - - ab - - -ab ab -ab ab -ab ab -select length(v), length(c) from vctt; -length(v) length(c) -4 4 -4 4 -4 2 -4 4 -drop table if exists t1; -create table t1(a int, b varchar(20), primary key(a,b(3)) clustered); -insert into t1 values(1,'aaaaa'); -insert into t1 values(1,'aaaaa'); -Error 1062 (23000): Duplicate entry '1-aaa' for key 't1.PRIMARY' -insert into t1 select 1, 'aaa'; -Error 1062 (23000): Duplicate entry '1-aaa' for key 't1.PRIMARY' -insert into t1 select 1, 'bb'; -insert into t1 select 1, 'bb'; -Error 1062 (23000): Duplicate entry '1-bb' for key 't1.PRIMARY' -drop table if exists bintest; -create table bintest (h enum(0x61, '1', 'b')) character set utf8mb4; -insert into bintest(h) values(0x61); -select * from bintest; -h -a -drop table if exists bintest; -create table bintest (h set(0x61, '1', 'b')) character set utf8mb4; -insert into bintest(h) values(0x61); -select * from bintest; -h -a -drop table if exists temp_test; -create global temporary table temp_test(id int primary key auto_increment) on commit delete rows; -insert into temp_test(id) values(0); -select * from temp_test; -id -begin; -insert into temp_test(id) values(0); -select * from temp_test; -id -1 -commit; -begin; -insert into temp_test(id) values(0); -select * from temp_test; -id -1 -insert into temp_test(id) values(0); -select id from temp_test order by id; -id -1 -2 -commit; -begin; -insert into temp_test(id) values(0), (0); -select id from temp_test order by id; -id -1 -2 -insert into temp_test(id) values(0), (0); -select id from temp_test order by id; -id -1 -2 -3 -4 -commit; -begin; -insert into temp_test(id) values(10); -insert into temp_test(id) values(0); -select id from temp_test order by id; -id -10 -11 -insert into temp_test(id) values(20), (30); -insert into temp_test(id) values(0), (0); -select id from temp_test order by id; -id -10 -11 -20 -30 -31 -32 -commit; -drop table if exists temp_test; -drop table if exists temp_test; -create global temporary table temp_test(id int) on commit delete rows; -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test; -_tidb_rowid -begin; -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test; -_tidb_rowid -1 -commit; -begin; -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test; -_tidb_rowid -1 -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test order by _tidb_rowid; -_tidb_rowid -1 -2 -commit; -begin; -insert into temp_test(id) values(0), (0); -select _tidb_rowid from temp_test order by _tidb_rowid; -_tidb_rowid -1 -2 -insert into temp_test(id) values(0), (0); -select _tidb_rowid from temp_test order by _tidb_rowid; -_tidb_rowid -1 -2 -3 -4 -commit; -drop table if exists temp_test; -drop table if exists t1; -create table t1(c1 date); -insert into t1 values('2020-02-31'); -Error 1292 (22007): Incorrect date value: '2020-02-31' for column 'c1' at row 1 -set @@sql_mode='ALLOW_INVALID_DATES'; -insert into t1 values('2020-02-31'); -select * from t1; -c1 -2020-02-31 -set @@sql_mode='STRICT_TRANS_TABLES'; -insert into t1 values('2020-02-31'); -Error 1292 (22007): Incorrect date value: '2020-02-31' for column 'c1' at row 1 -set sql_mode=default; -drop table if exists t; -create table t (id decimal(10)); -insert into t values('1sdf'); -Error 1366 (HY000): Incorrect decimal value: '1sdf' for column 'id' at row 1 -insert into t values('1edf'); -Error 1366 (HY000): Incorrect decimal value: '1edf' for column 'id' at row 1 -insert into t values('12Ea'); -Error 1366 (HY000): Incorrect decimal value: '12Ea' for column 'id' at row 1 -insert into t values('1E'); -Error 1366 (HY000): Incorrect decimal value: '1E' for column 'id' at row 1 -insert into t values('1e'); -Error 1366 (HY000): Incorrect decimal value: '1e' for column 'id' at row 1 -insert into t values('1.2A'); -Error 1366 (HY000): Incorrect decimal value: '1.2A' for column 'id' at row 1 -insert into t values('1.2.3.4.5'); -Error 1366 (HY000): Incorrect decimal value: '1.2.3.4.5' for column 'id' at row 1 -insert into t values('1.2.'); -Error 1366 (HY000): Incorrect decimal value: '1.2.' for column 'id' at row 1 -insert into t values('1,999.00'); -Error 1366 (HY000): Incorrect decimal value: '1,999.00' for column 'id' at row 1 -insert into t values('12e-3'); -show warnings; -Level Code Message -Warning 1366 Incorrect decimal value: '12e-3' for column 'id' at row 1 -select id from t; -id -0 -drop table if exists t; -SET sql_mode='NO_ENGINE_SUBSTITUTION'; -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (a tinyint not null auto_increment primary key, b char(20)); -INSERT INTO t1 VALUES (127,'maxvalue'); -REPLACE INTO t1 VALUES (0,'newmaxvalue'); -Error 1467 (HY000): Failed to read auto-increment value from storage engine -set sql_mode=default; -DROP TABLE IF EXISTS t1; -CREATE TABLE t1(a INT) ENGINE = InnoDB; -INSERT IGNORE into t1(SELECT SLEEP(NULL)); -SHOW WARNINGS; -Level Code Message -Warning 1210 Incorrect arguments to sleep -INSERT IGNORE into t1(SELECT SLEEP(-1)); -SHOW WARNINGS; -Level Code Message -Warning 1210 Incorrect arguments to sleep -INSERT IGNORE into t1(SELECT SLEEP(1)); -SELECT * FROM t1; -a -0 -0 -0 -DROP TABLE t1; -drop table if exists t1; -create table t1(c1 float); -insert into t1 values(999.99); -select cast(t1.c1 as decimal(4, 1)) from t1; -cast(t1.c1 as decimal(4, 1)) -999.9 -select cast(t1.c1 as decimal(5, 1)) from t1; -cast(t1.c1 as decimal(5, 1)) -1000.0 -drop table if exists t1; -create table t1(c1 decimal(6, 4)); -insert into t1 values(99.9999); -select cast(t1.c1 as decimal(5, 3)) from t1; -cast(t1.c1 as decimal(5, 3)) -99.999 -select cast(t1.c1 as decimal(6, 3)) from t1; -cast(t1.c1 as decimal(6, 3)) -100.000 -drop table if exists t1; -create table t1(id int, a int); -set @@SQL_MODE='STRICT_TRANS_TABLES'; -insert into t1 values(1, '1e100'); -Error 1264 (22003): Out of range value for column 'a' at row 1 -insert into t1 values(2, '-1e100'); -Error 1264 (22003): Out of range value for column 'a' at row 1 -select id, a from t1; -id a -set @@SQL_MODE=''; -insert into t1 values(1, '1e100'); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'a' at row 1 -insert into t1 values(2, '-1e100'); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'a' at row 1 -select id, a from t1 order by id asc; -id a -1 2147483647 -2 -2147483648 -set sql_mode=default; -drop table if exists tf; -create table tf(a float(1, 0) unsigned); -insert into tf values('-100'); -Error 1264 (22003): Out of range value for column 'a' at row 1 -set @@sql_mode=''; -insert into tf values('-100'); -select * from tf; -a -0 -set @@sql_mode=default; -drop table if exists tt1; -create table tt1 (c1 decimal(64)); -insert into tt1 values(89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); -Error 1264 (22003): Out of range value for column 'c1' at row 1 -insert into tt1 values(89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000); -Error 1264 (22003): Out of range value for column 'c1' at row 1 -insert ignore into tt1 values(89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'c1' at row 1 -Warning 1292 Truncated incorrect DECIMAL value: '789012345678901234567890123456789012345678901234567890123456789012345678900000000' -select c1 from tt1; -c1 -9999999999999999999999999999999999999999999999999999999999999999 -update tt1 set c1 = 89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000; -Error 1264 (22003): Out of range value for column 'c1' at row 1 -drop table if exists tt1; -insert into tt1 values(4556414e723532); -Error 1367 (22007): Illegal double '4556414e723532' value found during parsing -select 888888888888888888888888888888888888888888888888888888888888888888888888888888888888; -888888888888888888888888888888888888888888888888888888888888888888888888888888888888 -99999999999999999999999999999999999999999999999999999999999999999 -show warnings; -Level Code Message -Warning 1292 Truncated incorrect DECIMAL value: '888888888888888888888888888888888888888888888888888888888888888888888888888888888' -drop table if exists t; -create table t (id smallint auto_increment primary key); -alter table t add column c1 int default 1; -insert ignore into t(id) values (194626268); -affected rows: 1 -info: -select * from t; -id c1 -32767 1 -insert ignore into t(id) values ('*') on duplicate key update c1 = 2; -affected rows: 2 -info: -select * from t; -id c1 -32767 2 -drop table if exists t; -create table t (i int not null primary key, j int unique key); -insert into t values (1, 1), (2, 2); -affected rows: 2 -info: Records: 2 Duplicates: 0 Warnings: 0 -insert ignore into t values(1, 1) on duplicate key update i = 2; -affected rows: 0 -info: -select * from t; -i j -1 1 -2 2 -insert ignore into t values(1, 1) on duplicate key update j = 2; -affected rows: 0 -info: -select * from t; -i j -1 1 -2 2 -drop table if exists t2; -create table t2(`col_25` set('Alice','Bob','Charlie','David') NOT NULL,`col_26` date NOT NULL DEFAULT '2016-04-15', PRIMARY KEY (`col_26`) clustered, UNIQUE KEY `idx_9` (`col_25`,`col_26`),UNIQUE KEY `idx_10` (`col_25`)); -insert into t2(col_25, col_26) values('Bob', '1989-03-23'),('Alice', '2023-11-24'), ('Charlie', '2023-12-05'); -insert ignore into t2 (col_25,col_26) values ( 'Bob','1977-11-23' ) on duplicate key update col_25 = 'Alice', col_26 = '2036-12-13'; -show warnings; -Level Code Message -Warning 1062 Duplicate entry 'Alice' for key 't2.idx_10' -select * from t2; -col_25 col_26 -Alice 2023-11-24 -Bob 1989-03-23 -Charlie 2023-12-05 -drop table if exists t4; -create table t4(id int primary key clustered, k int, v int, unique key uk1(k)); -insert into t4 values (1, 10, 100), (3, 30, 300); -insert ignore into t4 (id, k, v) values(1, 0, 0) on duplicate key update id = 2, k = 30; -show warnings; -Level Code Message -Warning 1062 Duplicate entry '30' for key 't4.uk1' -select * from t4; -id k v -1 10 100 -3 30 300 -drop table if exists t5; -create table t5(k1 varchar(100), k2 varchar(100), uk1 int, v int, primary key(k1, k2) clustered, unique key ukk1(uk1), unique key ukk2(v)); -insert into t5(k1, k2, uk1, v) values('1', '1', 1, '100'), ('1', '3', 2, '200'); -update ignore t5 set k2 = '2', uk1 = 2 where k1 = '1' and k2 = '1'; -show warnings; -Level Code Message -Warning 1062 Duplicate entry '2' for key 't5.ukk1' -select * from t5; -k1 k2 uk1 v -1 1 1 100 -1 3 2 200 -drop table if exists t6; -create table t6 (a int, b int, c int, primary key(a, b) clustered, unique key idx_14(b), unique key idx_15(b), unique key idx_16(a, b)); -insert into t6 select 10, 10, 20; -insert ignore into t6 set a = 20, b = 10 on duplicate key update a = 100; -select * from t6; -a b c -100 10 20 -insert ignore into t6 set a = 200, b= 10 on duplicate key update c = 1000; -select * from t6; -a b c -100 10 1000 -drop table if exists insert_autoinc_test; -create table insert_autoinc_test (id int primary key auto_increment, c1 int); -insert into insert_autoinc_test(c1) values (1), (2); -begin; -select * from insert_autoinc_test; -id c1 -1 1 -2 2 -commit; -begin; -insert into insert_autoinc_test(id, c1) values (5,5); -insert into insert_autoinc_test(c1) values (6); -commit; -begin; -select * from insert_autoinc_test; -id c1 -1 1 -2 2 -5 5 -6 6 -commit; -begin; -insert into insert_autoinc_test(id, c1) values (3,3); -commit; -begin; -select * from insert_autoinc_test; -id c1 -1 1 -2 2 -3 3 -5 5 -6 6 -commit; -begin; -insert into insert_autoinc_test(c1) values (7); -commit; -begin; -select * from insert_autoinc_test; -id c1 -1 1 -2 2 -3 3 -5 5 -6 6 -7 7 -commit; -drop table if exists insert_autoinc_test; -create table insert_autoinc_test (id int primary key auto_increment, c1 int); -insert into insert_autoinc_test(id, c1) values (0.3, 1); -select * from insert_autoinc_test; -id c1 -1 1 -insert into insert_autoinc_test(id, c1) values (-0.3, 2); -select * from insert_autoinc_test; -id c1 -1 1 -2 2 -insert into insert_autoinc_test(id, c1) values (-3.3, 3); -select * from insert_autoinc_test; -id c1 --3 3 -1 1 -2 2 -insert into insert_autoinc_test(id, c1) values (4.3, 4); -select * from insert_autoinc_test; -id c1 --3 3 -1 1 -2 2 -4 4 -insert into insert_autoinc_test(c1) values (5); -select * from insert_autoinc_test; -id c1 --3 3 -1 1 -2 2 -4 4 -5 5 -insert into insert_autoinc_test(id, c1) values (null, 6); -select * from insert_autoinc_test; -id c1 --3 3 -1 1 -2 2 -4 4 -5 5 -6 6 -drop table if exists insert_autoinc_test; -create table insert_autoinc_test (id int primary key auto_increment, c1 int); -insert into insert_autoinc_test(id, c1) values (5, 1); -select * from insert_autoinc_test; -id c1 -5 1 -insert into insert_autoinc_test(id, c1) values (0, 2); -select * from insert_autoinc_test; -id c1 -5 1 -6 2 -insert into insert_autoinc_test(id, c1) values (0, 3); -select * from insert_autoinc_test; -id c1 -5 1 -6 2 -7 3 -set SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -insert into insert_autoinc_test(id, c1) values (0, 4); -select * from insert_autoinc_test; -id c1 -0 4 -5 1 -6 2 -7 3 -insert into insert_autoinc_test(id, c1) values (0, 5); -Error 1062 (23000): Duplicate entry '0' for key 'insert_autoinc_test.PRIMARY' -insert into insert_autoinc_test(c1) values (6); -select * from insert_autoinc_test; -id c1 -0 4 -5 1 -6 2 -7 3 -8 6 -insert into insert_autoinc_test(id, c1) values (null, 7); -select * from insert_autoinc_test; -id c1 -0 4 -5 1 -6 2 -7 3 -8 6 -9 7 -set SQL_MODE=''; -insert into insert_autoinc_test(id, c1) values (0, 8); -select * from insert_autoinc_test; -id c1 -0 4 -5 1 -6 2 -7 3 -8 6 -9 7 -10 8 -insert into insert_autoinc_test(id, c1) values (null, 9); -select * from insert_autoinc_test; -id c1 -0 4 -5 1 -6 2 -7 3 -8 6 -9 7 -10 8 -11 9 -set sql_mode = default; -drop table if exists insert_test; -create table insert_test (id int PRIMARY KEY AUTO_INCREMENT, c1 int, c2 int, c3 int default 1); -insert insert_test (c1) values (1),(2),(NULL); -affected rows: 3 -info: Records: 3 Duplicates: 0 Warnings: 0 -begin; -insert insert_test (c1) values (); -Error 1136 (21S01): Column count doesn't match value count at row 1 -rollback; -begin; -insert insert_test (c1, c2) values (1,2),(1); -Error 1136 (21S01): Column count doesn't match value count at row 2 -rollback; -begin; -insert insert_test (xxx) values (3); -Error 1054 (42S22): Unknown column 'xxx' in 'field list' -rollback; -begin; -insert insert_test_xxx (c1) values (); -Error 1146 (42S02): Table 'executor__insert.insert_test_xxx' doesn't exist -rollback; -insert insert_test set c1 = 3; -affected rows: 1 -info: -begin; -insert insert_test set c1 = 4, c1 = 5; -Error 1110 (42000): Column 'c1' specified twice -rollback; -begin; -insert insert_test set xxx = 6; -Error 1054 (42S22): Unknown column 'xxx' in 'field list' -rollback; -drop table if exists insert_test_1, insert_test_2; -create table insert_test_1 (id int, c1 int); -insert insert_test_1 select id, c1 from insert_test; -affected rows: 4 -info: Records: 4 Duplicates: 0 Warnings: 0 -create table insert_test_2 (id int, c1 int); -insert insert_test_1 select id, c1 from insert_test union select id * 10, c1 * 10 from insert_test; -affected rows: 8 -info: Records: 8 Duplicates: 0 Warnings: 0 -begin; -insert insert_test_1 select c1 from insert_test; -Error 1136 (21S01): Column count doesn't match value count at row 1 -rollback; -begin; -insert insert_test_1 values(default, default, default, default, default); -Error 1136 (21S01): Column count doesn't match value count at row 1 -rollback; -select * from insert_test where id = 1; -id c1 c2 c3 -1 1 NULL 1 -insert into insert_test (id, c3) values (1, 2) on duplicate key update id=values(id), c2=10; -affected rows: 2 -info: -select * from insert_test where id = 1; -id c1 c2 c3 -1 1 10 1 -insert into insert_test (id, c2) values (1, 1) on duplicate key update insert_test.c2=10; -affected rows: 0 -info: -insert into insert_test (id, c2) values(1, 1) on duplicate key update t.c2 = 10; -Error 1054 (42S22): Unknown column 't.c2' in 'field list' -INSERT INTO insert_test (id, c3) VALUES (1, 2) ON DUPLICATE KEY UPDATE c3=values(c3)+c3+3; -affected rows: 2 -info: -select * from insert_test where id = 1; -id c1 c2 c3 -1 1 10 6 -INSERT IGNORE INTO insert_test (id, c3) VALUES (1, 2) ON DUPLICATE KEY UPDATE c3=values(c3)+c3+3; -affected rows: 2 -info: -select * from insert_test where id = 1; -id c1 c2 c3 -1 1 10 11 -drop table if exists insert_err; -create table insert_err (id int, c1 varchar(8)); -insert insert_err values (1, 'abcdabcdabcd'); -Error 1406 (22001): Data too long for column 'c1' at row 1 -insert insert_err values (1, '你好,世界'); -create table TEST1 (ID INT NOT NULL, VALUE INT DEFAULT NULL, PRIMARY KEY (ID)); -INSERT INTO TEST1(id,value) VALUE(3,3) on DUPLICATE KEY UPDATE VALUE=4; -affected rows: 1 -info: -drop table if exists t; -create table t (id int); -insert into t values(1); -update t t1 set id = (select count(*) + 1 from t t2 where t1.id = t2.id); -select * from t; -id -2 -drop table if exists t; -create table t(c decimal(5, 5)); -insert into t value(0); -insert into t value(1); -Error 1264 (22003): Out of range value for column 'c' at row 1 -drop table if exists t; -create table t(c binary(255)); -insert into t value(1); -select length(c) from t; -length(c) -255 -drop table if exists t; -create table t(c varbinary(255)); -insert into t value(1); -select length(c) from t; -length(c) -1 -drop table if exists t; -create table t(c int); -set @@time_zone = '+08:00'; -insert into t value(Unix_timestamp('2002-10-27 01:00')); -select * from t; -c -1035651600 -set @@time_zone = default; -drop table if exists t1; -create table t1 (b char(0)); -insert into t1 values (""); -DROP TABLE IF EXISTS t; -CREATE TABLE t(a DECIMAL(4,2)); -INSERT INTO t VALUES (1.000001); -SHOW WARNINGS; -Level Code Message -Warning 1366 Incorrect decimal value: '1.000001' for column 'a' at row 1 -INSERT INTO t VALUES (1.000000); -SHOW WARNINGS; -Level Code Message -DROP TABLE IF EXISTS t; -CREATE TABLE t(a datetime); -INSERT INTO t VALUES('2017-00-00'); -Error 1292 (22007): Incorrect datetime value: '2017-00-00' for column 'a' at row 1 -set sql_mode = ''; -INSERT INTO t VALUES('2017-00-00'); -SELECT * FROM t; -a -2017-00-00 00:00:00 -set sql_mode = 'strict_all_tables'; -SELECT * FROM t; -a -2017-00-00 00:00:00 -set sql_mode = default; -drop table if exists test; -CREATE TABLE test(id int(10) UNSIGNED NOT NULL AUTO_INCREMENT, p int(10) UNSIGNED NOT NULL, PRIMARY KEY(p), KEY(id)); -insert into test(p) value(1); -select * from test; -id p -1 1 -select * from test use index (id) where id = 1; -id p -1 1 -insert into test values(NULL, 2); -select * from test use index (id) where id = 2; -id p -2 2 -insert into test values(2, 3); -select * from test use index (id) where id = 2; -id p -2 2 -2 3 -drop table if exists t; -create table t(a bigint unsigned); -set @@sql_mode = 'strict_all_tables'; -insert into t value (-1); -Error 1264 (22003): Out of range value for column 'a' at row 1 -set @@sql_mode = ''; -insert into t value (-1); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'a' at row 1 -insert into t select -1; -show warnings; -Level Code Message -Warning 1690 constant -1 overflows bigint -insert into t select cast(-1 as unsigned); -insert into t value (-1.111); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'a' at row 1 -insert into t value ('-1.111'); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'a' at row 1 -update t set a = -1 limit 1; -show warnings; -Level Code Message -Warning 1690 constant -1 overflows bigint -select * from t; -a -0 -0 -18446744073709551615 -0 -0 -set @@sql_mode = default; -drop table if exists t; -create table t(a time(6)); -insert into t value('20070219173709.055870'), ('20070219173709.055'), ('20070219173709.055870123'); -select * from t; -a -17:37:09.055870 -17:37:09.055000 -17:37:09.055870 -truncate table t; -insert into t value(20070219173709.055870), (20070219173709.055), (20070219173709.055870123); -select * from t; -a -17:37:09.055870 -17:37:09.055000 -17:37:09.055870 -insert into t value(-20070219173709.055870); -Error 1292 (22007): Incorrect time value: '-20070219173709.055870' for column 'a' at row 1 -drop table if exists t; -set @@sql_mode=''; -create table t(a float unsigned, b double unsigned); -insert into t value(-1.1, -1.1), (-2.1, -2.1), (0, 0), (1.1, 1.1); -show warnings; -Level Code Message -Warning 1264 Out of range value for column 'a' at row 1 -Warning 1264 Out of range value for column 'b' at row 1 -Warning 1264 Out of range value for column 'a' at row 2 -Warning 1264 Out of range value for column 'b' at row 2 -select * from t; -a b -0 0 -0 0 -0 0 -1.1 1.1 -set @@sql_mode=default; -drop table if exists t; -create table t(a int default 1, b int default 2); -insert into t values(default, default); -select * from t; -a b -1 2 -truncate table t; -insert into t values(default(b), default(a)); -select * from t; -a b -2 1 -truncate table t; -insert into t (b) values(default); -select * from t; -a b -1 2 -truncate table t; -insert into t (b) values(default(a)); -select * from t; -a b -1 1 -drop view if exists v; -create view v as select * from t; -insert into v values(1,2); -Error 1105 (HY000): insert into view v is not supported now -replace into v values(1,2); -Error 1105 (HY000): replace into view v is not supported now -drop view v; -drop sequence if exists seq; -create sequence seq; -insert into seq values(); -Error 1105 (HY000): insert into sequence seq is not supported now -replace into seq values(); -Error 1105 (HY000): replace into sequence seq is not supported now -drop sequence seq; -drop table if exists t; -create table t(name varchar(255), b int, c int, primary key(name(2))); -insert into t(name, b) values("cha", 3); -insert into t(name, b) values("chb", 3); -Error 1062 (23000): Duplicate entry 'ch' for key 't.PRIMARY' -insert into t(name, b) values("测试", 3); -insert into t(name, b) values("测试", 3); -Error 1062 (23000): Duplicate entry 'æµ' for key 't.PRIMARY' -drop table if exists t; -create table t (i int unique key); -insert into t values (1),(2); -affected rows: 2 -info: Records: 2 Duplicates: 0 Warnings: 0 -select * from t; -i -1 -2 -insert into t values (1), (2) on duplicate key update i = values(i); -affected rows: 0 -info: Records: 2 Duplicates: 0 Warnings: 0 -select * from t; -i -1 -2 -insert into t values (2), (3) on duplicate key update i = 3; -affected rows: 2 -info: Records: 2 Duplicates: 1 Warnings: 0 -select * from t; -i -1 -3 -drop table if exists t; -create table t (i int primary key, j int unique key); -insert into t values (-1, 1); -affected rows: 1 -info: -select * from t; -i j --1 1 -insert into t values (1, 1) on duplicate key update j = values(j); -affected rows: 0 -info: -select * from t; -i j --1 1 -drop table if exists test; -create table test (i int primary key, j int unique); -begin; -insert into test values (1,1); -insert into test values (2,1) on duplicate key update i = -i, j = -j; -commit; -select * from test; -i j --1 -1 -delete from test; -insert into test values (1, 1); -begin; -delete from test where i = 1; -insert into test values (2, 1) on duplicate key update i = -i, j = -j; -commit; -select * from test; -i j -2 1 -delete from test; -insert into test values (1, 1); -begin; -update test set i = 2, j = 2 where i = 1; -insert into test values (1, 3) on duplicate key update i = -i, j = -j; -insert into test values (2, 4) on duplicate key update i = -i, j = -j; -commit; -select * from test order by i; -i j --2 -2 -1 3 -delete from test; -begin; -insert into test values (1, 3), (1, 3) on duplicate key update i = values(i), j = values(j); -commit; -select * from test order by i; -i j -1 3 -create table tmp (id int auto_increment, code int, primary key(id, code)); -create table m (id int primary key auto_increment, code int unique); -insert tmp (code) values (1); -insert tmp (code) values (1); -set tidb_init_chunk_size=1; -insert m (code) select code from tmp on duplicate key update code = values(code); -select * from m; -id code -1 1 -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT AUTO_INCREMENT PRIMARY KEY, -f2 VARCHAR(5) NOT NULL UNIQUE); -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); -affected rows: 1 -info: -SELECT LAST_INSERT_ID(); -LAST_INSERT_ID() -1 -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); -affected rows: 0 -info: -SELECT LAST_INSERT_ID(); -LAST_INSERT_ID() -1 -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT AUTO_INCREMENT UNIQUE, -f2 VARCHAR(5) NOT NULL UNIQUE); -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); -affected rows: 1 -info: -SELECT LAST_INSERT_ID(); -LAST_INSERT_ID() -1 -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); -affected rows: 0 -info: -SELECT LAST_INSERT_ID(); -LAST_INSERT_ID() -1 -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = 2; -affected rows: 2 -info: -SELECT LAST_INSERT_ID(); -LAST_INSERT_ID() -1 -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT); -INSERT t1 VALUES (1) ON DUPLICATE KEY UPDATE f1 = 1; -affected rows: 1 -info: -SELECT * FROM t1; -f1 -1 -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT NOT NULL UNIQUE); -INSERT t1 VALUES (1, 1); -affected rows: 1 -info: -INSERT t1 VALUES (1, 1), (1, 1) ON DUPLICATE KEY UPDATE f1 = 2, f2 = 2; -affected rows: 3 -info: Records: 2 Duplicates: 1 Warnings: 0 -SELECT * FROM t1 order by f1; -f1 f2 -1 1 -2 2 -INSERT t1 VALUES (1, 1) ON DUPLICATE KEY UPDATE f2 = null; -Error 1048 (23000): Column 'f2' cannot be null -INSERT IGNORE t1 VALUES (1, 1) ON DUPLICATE KEY UPDATE f2 = null; -affected rows: 2 -info: -show warnings; -Level Code Message -Warning 1048 Column 'f2' cannot be null -SELECT * FROM t1 order by f1; -f1 f2 -1 0 -2 2 -SET sql_mode=''; -INSERT t1 VALUES (1, 1) ON DUPLICATE KEY UPDATE f2 = null; -Error 1048 (23000): Column 'f2' cannot be null -SELECT * FROM t1 order by f1; -f1 f2 -1 0 -2 2 -set sql_mode=default; -set tidb_init_chunk_size=default; -drop table if exists t1, t2; -create table t1(a1 bigint primary key, b1 bigint); -create table t2(a2 bigint primary key, b2 bigint); -insert into t1 values(1, 100); -affected rows: 1 -info: -insert into t2 values(1, 200); -affected rows: 1 -info: -insert into t1 select a2, b2 from t2 on duplicate key update b1 = a2; -affected rows: 2 -info: Records: 1 Duplicates: 1 Warnings: 0 -select * from t1; -a1 b1 -1 1 -insert into t1 select a2, b2 from t2 on duplicate key update b1 = b2; -affected rows: 2 -info: Records: 1 Duplicates: 1 Warnings: 0 -select * from t1; -a1 b1 -1 200 -insert into t1 select a2, b2 from t2 on duplicate key update a1 = a2; -affected rows: 0 -info: Records: 1 Duplicates: 0 Warnings: 0 -select * from t1; -a1 b1 -1 200 -insert into t1 select a2, b2 from t2 on duplicate key update b1 = 300; -affected rows: 2 -info: Records: 1 Duplicates: 1 Warnings: 0 -select * from t1; -a1 b1 -1 300 -insert into t1 values(1, 1) on duplicate key update b1 = 400; -affected rows: 2 -info: -select * from t1; -a1 b1 -1 400 -insert into t1 select 1, 500 from t2 on duplicate key update b1 = 400; -affected rows: 0 -info: Records: 1 Duplicates: 0 Warnings: 0 -select * from t1; -a1 b1 -1 400 -drop table if exists t1, t2; -create table t1(a bigint primary key, b bigint); -create table t2(a bigint primary key, b bigint); -insert into t1 select * from t2 on duplicate key update c = t2.b; -Error 1054 (42S22): Unknown column 'c' in 'field list' -drop table if exists t1, t2; -create table t1(a bigint primary key, b bigint); -create table t2(a bigint primary key, b bigint); -insert into t1 select * from t2 on duplicate key update a = b; -Error 1052 (23000): Column 'b' in field list is ambiguous -drop table if exists t1, t2; -create table t1(a bigint primary key, b bigint); -create table t2(a bigint primary key, b bigint); -insert into t1 select * from t2 on duplicate key update c = b; -Error 1054 (42S22): Unknown column 'c' in 'field list' -drop table if exists t1, t2; -create table t1(a1 bigint primary key, b1 bigint); -create table t2(a2 bigint primary key, b2 bigint); -insert into t1 select * from t2 on duplicate key update a1 = values(b2); -Error 1054 (42S22): Unknown column 'b2' in 'field list' -drop table if exists t1, t2; -create table t1(a1 bigint primary key, b1 bigint); -create table t2(a2 bigint primary key, b2 bigint); -insert into t1 values(1, 100); -affected rows: 1 -info: -insert into t2 values(1, 200); -affected rows: 1 -info: -insert into t1 select * from t2 on duplicate key update b1 = values(b1) + b2; -affected rows: 2 -info: Records: 1 Duplicates: 1 Warnings: 0 -select * from t1; -a1 b1 -1 400 -insert into t1 select * from t2 on duplicate key update b1 = values(b1) + b2; -affected rows: 0 -info: Records: 1 Duplicates: 0 Warnings: 0 -select * from t1; -a1 b1 -1 400 -drop table if exists t; -create table t(k1 bigint, k2 bigint, val bigint, primary key(k1, k2)); -insert into t (val, k1, k2) values (3, 1, 2); -affected rows: 1 -info: -select * from t; -k1 k2 val -1 2 3 -insert into t (val, k1, k2) select c, a, b from (select 1 as a, 2 as b, 4 as c) tmp on duplicate key update val = tmp.c; -affected rows: 2 -info: Records: 1 Duplicates: 1 Warnings: 0 -select * from t; -k1 k2 val -1 2 4 -drop table if exists t; -create table t(k1 double, k2 double, v double, primary key(k1, k2)); -insert into t (v, k1, k2) select c, a, b from (select "3" c, "1" a, "2" b) tmp on duplicate key update v=c; -affected rows: 1 -info: Records: 1 Duplicates: 0 Warnings: 0 -select * from t; -k1 k2 v -1 2 3 -insert into t (v, k1, k2) select c, a, b from (select "3" c, "1" a, "2" b) tmp on duplicate key update v=c; -affected rows: 0 -info: Records: 1 Duplicates: 0 Warnings: 0 -select * from t; -k1 k2 v -1 2 3 -drop table if exists t1, t2; -create table t1(id int, a int, b int); -insert into t1 values (1, 1, 1); -affected rows: 1 -info: -insert into t1 values (2, 2, 1); -affected rows: 1 -info: -insert into t1 values (3, 3, 1); -affected rows: 1 -info: -create table t2(a int primary key, b int, unique(b)); -insert into t2 select a, b from t1 order by id on duplicate key update a=t1.a, b=t1.b; -affected rows: 5 -info: Records: 3 Duplicates: 2 Warnings: 0 -select * from t2 order by a; -a b -3 1 -drop table if exists t1, t2; -create table t1(id int, a int, b int); -insert into t1 values (1, 1, 1); -affected rows: 1 -info: -insert into t1 values (2, 1, 2); -affected rows: 1 -info: -insert into t1 values (3, 3, 1); -affected rows: 1 -info: -create table t2(a int primary key, b int, unique(b)); -insert into t2 select a, b from t1 order by id on duplicate key update a=t1.a, b=t1.b; -affected rows: 4 -info: Records: 3 Duplicates: 1 Warnings: 0 -select * from t2 order by a; -a b -1 2 -3 1 -drop table if exists t1, t2; -create table t1(id int, a int, b int, c int); -insert into t1 values (1, 1, 1, 1); -affected rows: 1 -info: -insert into t1 values (2, 2, 1, 2); -affected rows: 1 -info: -insert into t1 values (3, 3, 2, 2); -affected rows: 1 -info: -insert into t1 values (4, 4, 2, 2); -affected rows: 1 -info: -create table t2(a int primary key, b int, c int, unique(b), unique(c)); -insert into t2 select a, b, c from t1 order by id on duplicate key update b=t2.b, c=t2.c; -affected rows: 2 -info: Records: 4 Duplicates: 0 Warnings: 0 -select * from t2 order by a; -a b c -1 1 1 -3 2 2 -drop table if exists t1; -create table t1(a int primary key, b int); -insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5); -affected rows: 5 -info: Records: 5 Duplicates: 0 Warnings: 0 -insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18) on duplicate key update b=b+10; -affected rows: 7 -info: Records: 5 Duplicates: 2 Warnings: 0 -drop table if exists a, b; -create table a(x int primary key); -create table b(x int, y int); -insert into a values(1); -affected rows: 1 -info: -insert into b values(1, 2); -affected rows: 1 -info: -insert into a select x from b ON DUPLICATE KEY UPDATE a.x=b.y; -affected rows: 2 -info: Records: 1 Duplicates: 1 Warnings: 0 -select * from a; -x -2 -## Test issue 28078. -## Use different types of columns so that there's likely to be error if the types mismatches. -drop table if exists a, b; -create table a(id int, a1 timestamp, a2 varchar(10), a3 float, unique(id)); -create table b(id int, b1 time, b2 varchar(10), b3 int); -insert into a values (1, '2022-01-04 07:02:04', 'a', 1.1), (2, '2022-01-04 07:02:05', 'b', 2.2); -affected rows: 2 -info: Records: 2 Duplicates: 0 Warnings: 0 -insert into b values (2, '12:34:56', 'c', 10), (3, '01:23:45', 'd', 20); -affected rows: 2 -info: Records: 2 Duplicates: 0 Warnings: 0 -insert into a (id) select id from b on duplicate key update a.a2 = b.b2, a.a3 = 3.3; -affected rows: 3 -info: Records: 2 Duplicates: 1 Warnings: 0 -select * from a; -id a1 a2 a3 -1 2022-01-04 07:02:04 a 1.1 -2 2022-01-04 07:02:05 c 3.3 -3 NULL NULL NULL -insert into a (id) select 4 from b where b3 = 20 on duplicate key update a.a3 = b.b3; -affected rows: 1 -info: Records: 1 Duplicates: 0 Warnings: 0 -select * from a; -id a1 a2 a3 -1 2022-01-04 07:02:04 a 1.1 -2 2022-01-04 07:02:05 c 3.3 -3 NULL NULL NULL -4 NULL NULL NULL -insert into a (a2, a3) select 'x', 1.2 from b on duplicate key update a.a2 = b.b3; -affected rows: 2 -info: Records: 2 Duplicates: 0 Warnings: 0 -select * from a; -id a1 a2 a3 -1 2022-01-04 07:02:04 a 1.1 -2 2022-01-04 07:02:05 c 3.3 -3 NULL NULL NULL -4 NULL NULL NULL -NULL NULL x 1.2 -NULL NULL x 1.2 -## reproduce insert on duplicate key update bug under new row format. -drop table if exists t1; -create table t1(c1 decimal(6,4), primary key(c1)); -insert into t1 set c1 = 0.1; -insert into t1 set c1 = 0.1 on duplicate key update c1 = 1; -select * from t1 use index(primary); -c1 -1.0000 -drop table if exists t; -create table t (d int); -insert into t values (cast('18446744073709551616' as unsigned)); -Error 1690 (22003): BIGINT UNSIGNED value is out of range in '18446744073709551616' -set sql_mode=''; -insert into t values (cast('18446744073709551616' as unsigned)); -Level Code Message -Warning 1264 Out of range value for column 'd' at row 1 -Warning 1292 Truncated incorrect INTEGER value: '18446744073709551616' -set sql_mode=DEFAULT; -drop table if exists parent, child; -create table parent (id int primary key, ref int, key(ref)); -create table child (id int primary key, ref int, foreign key (ref) references parent(ref)); -insert into parent values (1, 1), (2, 2); -insert into child values (1, 1); -insert into child values (1, 2) on duplicate key update ref = 2; -insert into child values (1, 3) on duplicate key update ref = 3; -Error 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`executor__insert`.`child`, CONSTRAINT `fk_1` FOREIGN KEY (`ref`) REFERENCES `parent` (`ref`)) -insert ignore into child values (1, 3) on duplicate key update ref = 3; -Level Code Message -Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`executor__insert`.`child`, CONSTRAINT `fk_1` FOREIGN KEY (`ref`) REFERENCES `parent` (`ref`)) -insert into parent values (2, 3) on duplicate key update ref = 3; -Error 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`executor__insert`.`child`, CONSTRAINT `fk_1` FOREIGN KEY (`ref`) REFERENCES `parent` (`ref`)) -insert ignore into parent values (2, 3) on duplicate key update ref = 3; -drop table if exists t1, t2; -create table t1 (id int primary key, col1 varchar(10) not null default ''); -create table t2 (id int primary key, col1 varchar(10)); -insert into t2 values (1, null); -insert ignore into t1 values(5, null); -set session sql_mode = ''; -insert into t1 values(1, null); -Error 1048 (23000): Column 'col1' cannot be null -insert into t1 set id = 1, col1 = null; -Error 1048 (23000): Column 'col1' cannot be null -insert t1 VALUES (5, 5) ON DUPLICATE KEY UPDATE col1 = null; -Error 1048 (23000): Column 'col1' cannot be null -insert t1 VALUES (5, 5), (6, null) ON DUPLICATE KEY UPDATE col1 = null; -select * from t1; -id col1 -5 -6 -insert into t1 select * from t2; -show warnings; -Level Code Message -Warning 1048 Column 'col1' cannot be null -insert into t1 values(2, null), (3, 3), (4, 4); -show warnings; -Level Code Message -Warning 1048 Column 'col1' cannot be null -update t1 set col1 = null where id = 3; -show warnings; -Level Code Message -Warning 1048 Column 'col1' cannot be null -insert ignore t1 VALUES (4, 4) ON DUPLICATE KEY UPDATE col1 = null; -select * from t1; -id col1 -1 -2 -3 -4 -5 -6 diff --git a/tests/integrationtest/t/executor/executor.test b/tests/integrationtest/t/executor/executor.test deleted file mode 100644 index fae9c4c4b9b2a..0000000000000 --- a/tests/integrationtest/t/executor/executor.test +++ /dev/null @@ -1,2713 +0,0 @@ -# TestSelectWithoutFrom -select 1 + 2*3; -select _utf8"string"; -select 1 order by 1; -SELECT 'a' as f1 having f1 = 'a'; -SELECT (SELECT * FROM (SELECT 'a') t) AS f1 HAVING (f1 = 'a' OR TRUE); -SELECT (SELECT * FROM (SELECT 'a') t) + 1 AS f1 HAVING (f1 = 'a' OR TRUE); - -# TestOrderBy -create table t (c1 int, c2 int, c3 varchar(20)); -insert into t values (1, 2, 'abc'), (2, 1, 'bcd'); -## Fix issue https://github.com/pingcap/tidb/issues/337 -select c1 as a, c1 as b from t order by c1; -select c1 as a, t.c1 as a from t order by a desc; -select c1 as c2 from t order by c2; -select sum(c1) from t order by sum(c1); -select c1 as c2 from t order by c2 + 1; -## Order by position. -select * from t order by 1; -select * from t order by 2; -## Order by binary. -select c1, c3 from t order by binary c1 desc; -select c1, c2 from t order by binary c3; - -# TestNeighbouringProj -create table t1(a int, b int); -create table t2(a int, b int); -insert into t1 value(1, 1), (2, 2); -insert into t2 value(1, 1), (2, 2); -select sum(c) from (select t1.a as a, t1.a as c, length(t1.b) from t1 union select a, b, b from t2) t; -drop table if exists t; -create table t(a bigint, b bigint, c bigint); -insert into t values(1, 1, 1), (2, 2, 2), (3, 3, 3); -select cast(count(a) as signed), a as another, a from t group by a order by cast(count(a) as signed), a limit 10; - -# TestIndexReverseOrder -drop table if exists t; -create table t (a int primary key auto_increment, b int, index idx (b)); -insert t (b) values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); -select b from t order by b desc; -select b from t where b <3 or (b >=6 and b < 8) order by b desc; -drop table if exists t; -create table t (a int, b int, index idx (b, a)); -insert t values (0, 2), (1, 2), (2, 2), (0, 1), (1, 1), (2, 1), (0, 0), (1, 0), (2, 0); -select b, a from t order by b, a desc; - -# TestTableReverseOrder -drop table if exists t; -create table t (a int primary key auto_increment, b int); -insert t (b) values (1), (2), (3), (4), (5), (6), (7), (8), (9); -select b from t order by a desc; -select a from t where a <3 or (a >=6 and a < 8) order by a desc; - -# TestUnsignedPKColumn -drop table if exists t; -create table t (a int unsigned primary key, b int, c int, key idx_ba (b, c, a)); -insert t values (1, 1, 1); -select * from t; -update t set c=2 where a=1; -select * from t where b=1; - -# TestMultiUpdate -CREATE TABLE test_mu (a int primary key, b int, c int); -INSERT INTO test_mu VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9); -INSERT INTO test_mu VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE b = 3, c = b; -SELECT * FROM test_mu ORDER BY a; -INSERT INTO test_mu VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = 2, b = c+5; -SELECT * FROM test_mu ORDER BY a; -UPDATE test_mu SET b = 0, c = b WHERE a = 4; -SELECT * FROM test_mu ORDER BY a; -UPDATE test_mu SET c = 8, b = c WHERE a = 4; -SELECT * FROM test_mu ORDER BY a; -UPDATE test_mu SET c = b, b = c WHERE a = 7; -SELECT * FROM test_mu ORDER BY a; - -# TestGeneratedColumnPointGet -drop table if exists tu; -CREATE TABLE tu(a int, b int, c int GENERATED ALWAYS AS (a + b) VIRTUAL, d int as (a * b) stored, e int GENERATED ALWAYS as (b * 2) VIRTUAL, PRIMARY KEY (a), UNIQUE KEY ukc (c), unique key ukd(d), key ke(e)); -insert into tu(a, b) values(1, 2); -insert into tu(a, b) values(5, 6); -select * from tu for update; -select * from tu where a = 1; -select * from tu where a in (1, 2); -select * from tu where c in (1, 2, 3); -select * from tu where c = 3; -select d, e from tu where c = 3; -select * from tu where d in (1, 2, 3); -select * from tu where d = 2; -select c, d from tu where d = 2; -select d, e from tu where e = 4; -select * from tu where e = 4; -update tu set a = a + 1, b = b + 1 where c = 11; -select * from tu for update; -select * from tu where a = 6; -select * from tu where c in (5, 6, 13); -select b, c, e, d from tu where c = 13; -select a, e, d from tu where c in (5, 6, 13); -drop table if exists tu; - -# TestUnionAutoSignedCast -drop table if exists t1,t2; -create table t1 (id int, i int, b bigint, d double, dd decimal); -create table t2 (id int, i int unsigned, b bigint unsigned, d double unsigned, dd decimal unsigned); -insert into t1 values(1, -1, -1, -1.1, -1); -insert into t2 values(2, 1, 1, 1.1, 1); -select * from t1 union select * from t2 order by id; -select id, i, b, d, dd from t2 union select id, i, b, d, dd from t1 order by id; -select id, i from t2 union select id, cast(i as unsigned int) from t1 order by id; -select dd from t2 union all select dd from t2; -drop table if exists t3,t4; -create table t3 (id int, v int); -create table t4 (id int, v double unsigned); -insert into t3 values (1, -1); -insert into t4 values (2, 1); -select id, v from t3 union select id, v from t4 order by id; -select id, v from t4 union select id, v from t3 order by id; -drop table if exists t5,t6,t7; -create table t5 (id int, v bigint unsigned); -create table t6 (id int, v decimal); -create table t7 (id int, v bigint); -insert into t5 values (1, 1); -insert into t6 values (2, -1); -insert into t7 values (3, -1); -select id, v from t5 union select id, v from t6 order by id; -select id, v from t5 union select id, v from t7 union select id, v from t6 order by id; - -# TestDeletePartition -drop table if exists t1; -create table t1 (a int) partition by range (a) ( - partition p0 values less than (10), - partition p1 values less than (20), - partition p2 values less than (30), - partition p3 values less than (40), - partition p4 values less than MAXVALUE - ); -insert into t1 values (1),(11),(21),(31); -delete from t1 partition (p4); -select * from t1 order by a; -delete from t1 partition (p0) where a > 10; -select * from t1 order by a; -delete from t1 partition (p0,p1,p2); -select * from t1; - -# TestAlterTableComment -drop table if exists t_1; -create table t_1 (c1 int, c2 int, c3 int default 1, index (c1)) comment = 'test table'; -alter table `t_1` comment 'this is table comment'; -select table_comment from information_schema.tables where table_name = 't_1'; -alter table `t_1` comment 'table t comment'; -select table_comment from information_schema.tables where table_name = 't_1'; - -# TestExecutorEnum -drop table if exists t; -create table t (c enum('a', 'b', 'c')); -insert into t values ('a'), (2), ('c'); -select * from t where c = 'a'; -select c + 1 from t where c = 2; -delete from t; -insert into t values (); -insert into t values (null), ('1'); -select c + 1 from t where c = 1; -delete from t; -insert into t values(1), (2), (3); -select * from t where c; - -# TestExecutorSet -drop table if exists t; -create table t (c set('a', 'b', 'c')); -insert into t values ('a'), (2), ('c'), ('a,b'), ('b,a'); -select * from t where c = 'a'; -select * from t where c = 'a,b'; -select c + 1 from t where c = 2; -delete from t; -insert into t values (); -insert into t values (null), ('1'); -select c + 1 from t where c = 1; -delete from t; -insert into t values(3); -select * from t where c; - -# TestSubQueryInValues -drop table if exists t; -create table t (id int, name varchar(20)); -drop table if exists t1; -create table t1 (gid int); -insert into t1 (gid) value (1); -insert into t (id, name) value ((select gid from t1) ,'asd'); -select * from t; - -# TestEnhancedRangeAccess -drop table if exists t; -create table t (a int primary key, b int); -insert into t values(1, 2), (2, 1); -select * from t where (a = 1 and b = 2) or (a = 2 and b = 1); -select * from t where (a = 1 and b = 1) or (a = 2 and b = 2); - -# TestTableScanWithPointRanges -drop table if exists t; -create table t(id int, PRIMARY KEY (id)); -insert into t values(1), (5), (10); -select * from t where id in(1, 2, 10); - -# TestCheckTable -drop table if exists admin_test; -create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)); -insert admin_test (c1, c2) values (1, 1), (2, 2), (NULL, NULL); -admin check table admin_test; - -# TestExecutorLimit -drop table if exists t; -create table t(a bigint, b bigint); -insert into t values(1, 1), (2, 2), (3, 30), (4, 40), (5, 5), (6, 6); -select * from t order by a limit 1, 1; -select * from t order by a limit 1, 2; -select * from t order by a limit 1, 3; -select * from t order by a limit 1, 4; -select a from t where a > 0 limit 1, 1; -select a from t where a > 0 limit 1, 2; -select b from t where a > 0 limit 1, 3; -select b from t where a > 0 limit 1, 4; -set @@tidb_init_chunk_size=2; -select * from t where a > 0 limit 2, 1; -select * from t where a > 0 limit 2, 2; -select * from t where a > 0 limit 2, 3; -select * from t where a > 0 limit 2, 4; -select a from t order by a limit 2, 1; -select b from t order by a limit 2, 2; -select a from t order by a limit 2, 3; -select b from t order by a limit 2, 4; -set @@tidb_init_chunk_size = default; - -# TestIndexScan -drop table if exists t; -create table t (a int unique); -insert t values (-1), (2), (3), (5), (6), (7), (8), (9); -select a from t where a < 0 or (a >= 2.1 and a < 5.1) or ( a > 5.9 and a <= 7.9) or a > '8.1'; -drop table if exists t; -create table t (a int unique); -insert t values (0); -select NULL from t ; -drop table if exists t; -create table t (a int unique, b int); -insert t values (5, 0); -insert t values (4, 0); -insert t values (3, 0); -insert t values (2, 0); -insert t values (1, 0); -insert t values (0, 0); -select * from t order by a limit 3; -drop table if exists t; -create table t (a int unique, b int); -insert t values (0, 1); -insert t values (1, 2); -insert t values (2, 1); -insert t values (3, 2); -insert t values (4, 1); -insert t values (5, 2); -select * from t where a < 5 and b = 1 limit 2; -drop table if exists tab1; -CREATE TABLE tab1(pk INTEGER PRIMARY KEY, col0 INTEGER, col1 FLOAT, col3 INTEGER, col4 FLOAT); -CREATE INDEX idx_tab1_0 on tab1 (col0); -CREATE INDEX idx_tab1_1 on tab1 (col1); -CREATE INDEX idx_tab1_3 on tab1 (col3); -CREATE INDEX idx_tab1_4 on tab1 (col4); -INSERT INTO tab1 VALUES(1,37,20.85,30,10.69); -SELECT pk FROM tab1 WHERE ((col3 <= 6 OR col3 < 29 AND (col0 < 41)) OR col3 > 42) AND col1 >= 96.1 AND col3 = 30 AND col3 > 17 AND (col0 BETWEEN 36 AND 42); -drop table if exists tab1; -CREATE TABLE tab1(pk INTEGER PRIMARY KEY, a INTEGER, b INTEGER); -CREATE INDEX idx_tab1_0 on tab1 (a); -INSERT INTO tab1 VALUES(1,1,1); -INSERT INTO tab1 VALUES(2,2,1); -INSERT INTO tab1 VALUES(3,1,2); -INSERT INTO tab1 VALUES(4,2,2); -SELECT * FROM tab1 WHERE pk <= 3 AND a = 1; -SELECT * FROM tab1 WHERE pk <= 4 AND a = 1 AND b = 2; -CREATE INDEX idx_tab1_1 on tab1 (b, a); -SELECT pk FROM tab1 WHERE b > 1; -drop table if exists t; -CREATE TABLE t (a varchar(3), index(a)); -insert t values('aaa'), ('aab'); -select * from t where a >= 'aaaa' and a < 'aabb'; -drop table if exists t; -CREATE TABLE t (a int primary key, b int, c int, index(c)); -insert t values(1, 1, 1), (2, 2, 2), (4, 4, 4), (3, 3, 3), (5, 5, 5); -select a from t where c >= 2 order by b desc limit 1; -drop table if exists t; -create table t(a varchar(50) primary key, b int, c int, index idx(b)); -insert into t values('aa', 1, 1); -select * from t use index(idx) where a > 'a'; -drop table if exists t; -CREATE TABLE `t` (a int, KEY (a)); -SELECT * FROM (SELECT * FROM (SELECT a as d FROM t WHERE a IN ('100')) AS x WHERE x.d < "123" ) tmp_count; - -# TestUpdateJoin -drop table if exists t1; -drop table if exists t2; -drop table if exists t3; -drop table if exists t4; -drop table if exists t5; -create table t1(k int, v int); -create table t2(k int, v int); -create table t3(id int auto_increment, k int, v int, primary key(id)); -create table t4(k int, v int); -create table t5(v int, k int, primary key(k)); -insert into t1 values (1, 1); -insert into t4 values (3, 3); -drop table if exists t6; -drop table if exists t7; -create table t6 (id int, v longtext); -create table t7 (x int, id int, v longtext, primary key(id)); -update t1 set v = 0 where k = 1; -select k, v from t1 where k = 1; -update t1 left join t3 on t1.k = t3.k set t1.v = 1; -select k, v from t1; -select id, k, v from t3; -update t1 left join t2 on t1.k = t2.k set t1.v = t2.v, t2.v = 3; -select k, v from t1; -select k, v from t2; -update t1 left join t2 on t1.k = t2.k set t2.v = 3, t1.v = t2.v; -select k, v from t1; -select k, v from t2; -update t2 right join t1 on t2.k = t1.k set t2.v = 4, t1.v = 0; -select k, v from t1; -select k, v from t2; -update t1 left join t2 on t1.k = t2.k right join t4 on t4.k = t2.k set t1.v = 4, t2.v = 4, t4.v = 4; -select k, v from t1; -select k, v from t2; -select k, v from t4; -insert t2 values (1, 10); -update t1 left join t2 on t1.k = t2.k set t2.v = 11; -select k, v from t2; -update t1 t11 left join t2 on t11.k = t2.k left join t1 t12 on t2.v = t12.k set t12.v = 233, t11.v = 111; -select k, v from t1; -select k, v from t2; -delete from t1; -delete from t2; -insert into t1 values (null, null); -update t1 left join t2 on t1.k = t2.k set t1.v = 1; -select k, v from t1; -insert t5 values(0, 0); -update t1 left join t5 on t1.k = t5.k set t1.v = 2; -select k, v from t1; -select k, v from t5; -insert into t6 values (1, NULL); -insert into t7 values (5, 1, 'a'); -update t6, t7 set t6.v = t7.v where t6.id = t7.id and t7.x = 5; -select v from t6; -drop table if exists t1, t2; -create table t1(id int primary key, v int, gv int GENERATED ALWAYS AS (v * 2) STORED); -create table t2(id int, v int); -update t1 tt1 inner join (select count(t1.id) a, t1.id from t1 left join t2 on t1.id = t2.id group by t1.id) x on tt1.id = x.id set tt1.v = tt1.v + x.a; - -# TestScanControlSelection -drop table if exists t; -create table t(a int primary key, b int, c int, index idx_b(b)); -insert into t values (1, 1, 1), (2, 1, 1), (3, 1, 2), (4, 2, 3); -select (select count(1) k from t s where s.b = t1.c) from t t1; - -# TestSimpleDAG -drop table if exists t; -create table t(a int primary key, b int, c int); -insert into t values (1, 1, 1), (2, 1, 1), (3, 1, 2), (4, 2, 3); -select a from t; -select * from t where a = 4; -select a from t limit 1; -select a from t order by a desc; -select a from t order by a desc limit 1; -select a from t order by b desc limit 1; -select a from t where a < 3; -select a from t where b > 1; -select a from t where b > 1 and a < 3; -select count(*) from t where b > 1 and a < 3; -select count(*) from t; -select count(*), c from t group by c order by c; -select sum(c) as s from t group by b order by s; -select avg(a) as s from t group by b order by s; -select sum(distinct c) from t group by b; -create index i on t(c,b); -select a from t where c = 1; -select a from t where c = 1 and a < 2; -select a from t where c = 1 order by a limit 1; -select count(*) from t where c = 1 ; -create index i1 on t(b); -select c from t where b = 2; -select * from t where b = 2; -select count(*) from t where b = 1; -select * from t where b = 1 and a > 1 limit 1; -drop table if exists t; -create table t (id int, c1 datetime); -insert into t values (1, '2015-06-07 12:12:12'); -select id from t where c1 = '2015-06-07 12:12:12'; -drop table if exists t0; -CREATE TABLE t0(c0 INT); -INSERT INTO t0 VALUES (100000); -SELECT * FROM t0 WHERE NOT SPACE(t0.c0); - -# TestAlterDefaultValue -drop table if exists t; -create table t(a int, primary key(a)); -insert into t(a) values(1); -alter table t add column b int default 1; -alter table t alter b set default 2; -select b from t where a = 1; - -# TestGenerateColumnReplace -## For issue 17256 -drop table if exists t1; -create table t1 (a int, b int as (a + 1) virtual not null, unique index idx(b)); -REPLACE INTO `t1` (`a`) VALUES (2); -REPLACE INTO `t1` (`a`) VALUES (2); -select * from t1; -insert into `t1` (`a`) VALUES (2) on duplicate key update a = 3; -select * from t1; - -# TestIssue19372 -drop table if exists t1; -create table t1 (c_int int, c_str varchar(40), key(c_str)); -drop table if exists t2; -create table t2 like t1; -insert into t1 values (1, 'a'), (2, 'b'), (3, 'c'); -insert into t2 select * from t1; -select (select t2.c_str from t2 where t2.c_str <= t1.c_str and t2.c_int in (1, 2) order by t2.c_str limit 1) x from t1 order by c_int; - -# TestDeleteWithMulTbl -## Delete multiple tables from left joined table. -## The result of left join is (3, null, null). -## Because rows in t2 are not matched, so no row will be deleted in t2. -## But row in t1 is matched, so it should be deleted. -drop table if exists t1, t2; -create table t1 (c1 int); -create table t2 (c1 int primary key, c2 int); -insert into t1 values(3); -insert into t2 values(2, 2); -insert into t2 values(0, 0); -delete from t1, t2 using t1 left join t2 on t1.c1 = t2.c2; -select * from t1 order by c1; -select * from t2 order by c1; -## Rows in both t1 and t2 are matched, so will be deleted even if it's null. -## NOTE: The null values are not generated by join. -drop table if exists t1, t2; -create table t1 (c1 int); -create table t2 (c2 int); -insert into t1 values(null); -insert into t2 values(null); -delete from t1, t2 using t1 join t2 where t1.c1 is null; -select * from t1; -select * from t2; - -# TestIssue13758 -drop table if exists t1, t2; -create table t1 (pk int(11) primary key, a int(11) not null, b int(11), key idx_b(b), key idx_a(a)); -insert into `t1` values (1,1,0),(2,7,6),(3,2,null),(4,1,null),(5,4,5); -create table t2 (a int); -insert into t2 values (1),(null); -select (select a from t1 use index(idx_a) where b >= t2.a order by a limit 1) as field from t2; - -# TestIssue20237 -drop table if exists t, s; -create table t(a date, b float); -create table s(b float); -insert into t values(NULL,-37), ("2011-11-04",105), ("2013-03-02",-22), ("2006-07-02",-56), (NULL,124), (NULL,111), ("2018-03-03",-5); -insert into s values(-37),(105),(-22),(-56),(124),(105),(111),(-5); -select count(distinct t.a, t.b) from t join s on t.b= s.b; - -# TestToPBExpr -drop table if exists t; -create table t (a decimal(10,6), b decimal, index idx_b (b)); -set sql_mode = ''; -insert t values (1.1, 1.1); -insert t values (2.4, 2.4); -insert t values (3.3, 2.7); -select * from t where a < 2.399999; -select * from t where a > 1.5; -select * from t where a <= 1.1; -select * from t where b >= 3; -select * from t where not (b = 1); -select * from t where b&1 = a|1; -select * from t where b != 2 and b <=> 3; -select * from t where b in (3); -select * from t where b not in (1, 2); -drop table if exists t; -create table t (a varchar(255), b int); -insert t values ('abc123', 1); -insert t values ('ab123', 2); -select * from t where a like 'ab%'; -select * from t where a like 'ab_12'; -drop table if exists t; -create table t (a int primary key); -insert t values (1); -insert t values (2); -select * from t where not (a = 1); -select * from t where not(not (a = 1)); -select * from t where not(a != 1 and a != 2); -set @@sql_mode = default; - -# TestDatumXAPI -drop table if exists t; -create table t (a decimal(10,6), b decimal, index idx_b (b)); -set sql_mode = ''; -insert t values (1.1, 1.1); -insert t values (2.2, 2.2); -insert t values (3.3, 2.7); -select * from t where a > 1.5; -select * from t where b > 1.5; -drop table if exists t; -create table t (a time(3), b time, index idx_a (a)); -insert t values ('11:11:11', '11:11:11'); -insert t values ('11:11:12', '11:11:12'); -insert t values ('11:11:13', '11:11:13'); -select * from t where a > '11:11:11.5'; -select * from t where b > '11:11:11.5'; -set @@sql_mode = default; - -# TestTableDual -Select 1; -Select 1 from dual; -Select count(*) from dual; -Select 1 from dual where 1; -drop table if exists t; -create table t(a int primary key); -select t1.* from t t1, t t2 where t1.a=t2.a and 1=0; - -# TestRow -drop table if exists t; -create table t (c int, d int); -insert t values (1, 1); -insert t values (1, 3); -insert t values (2, 1); -insert t values (2, 3); -select * from t where (c, d) < (2,2); -select * from t where (1,2,3) > (3,2,1); -select * from t where row(1,2,3) > (3,2,1); -select * from t where (c, d) = (select * from t where (c,d) = (1,1)); -select * from t where (c, d) = (select * from t k where (t.c,t.d) = (c,d)); -select (1, 2, 3) < (2, 3, 4); -select (2, 3, 4) <= (2, 3, 3); -select (2, 3, 4) <= (2, 3, 4); -select (2, 3, 4) <= (2, 1, 4); -select (2, 3, 4) >= (2, 3, 4); -select (2, 3, 4) = (2, 3, 4); -select (2, 3, 4) != (2, 3, 4); -select row(1, 1) in (row(1, 1)); -select row(1, 0) in (row(1, 1)); -select row(1, 1) in (select 1, 1); -select row(1, 1) > row(1, 0); -select row(1, 1) > (select 1, 0); -select 1 > (select 1); -select (select 1); -drop table if exists t1; -create table t1 (a int, b int); -insert t1 values (1,2),(1,null); -drop table if exists t2; -create table t2 (c int, d int); -insert t2 values (0,0); -select * from t2 where (1,2) in (select * from t1); -select * from t2 where (1,2) not in (select * from t1); -select * from t2 where (1,1) not in (select * from t1); -select * from t2 where (1,null) in (select * from t1); -select * from t2 where (null,null) in (select * from t1); -delete from t1 where a=1 and b=2; -select (1,1) in (select * from t2) from t1; -select (1,1) not in (select * from t2) from t1; -select (1,1) in (select 1,1 from t2) from t1; -select (1,1) not in (select 1,1 from t2) from t1; -## MySQL 5.7 returns 1 for these 2 queries, which is wrong. -select (1,null) not in (select 1,1 from t2) from t1; -select (t1.a,null) not in (select 1,1 from t2) from t1; -select (1,null) in (select * from t1); -select (1,null) not in (select * from t1); - -# TestStrToDateBuiltin -select str_to_date('20190101','%Y%m%d%!') from dual; -select str_to_date('20190101','%Y%m%d%f') from dual; -select str_to_date('20190101','%Y%m%d%H%i%s') from dual; -select str_to_date('18/10/22','%y/%m/%d') from dual; -select str_to_date('a18/10/22','%y/%m/%d') from dual; -select str_to_date('69/10/22','%y/%m/%d') from dual; -select str_to_date('70/10/22','%y/%m/%d') from dual; -select str_to_date('8/10/22','%y/%m/%d') from dual; -select str_to_date('8/10/22','%Y/%m/%d') from dual; -select str_to_date('18/10/22','%Y/%m/%d') from dual; -select str_to_date('a18/10/22','%Y/%m/%d') from dual; -select str_to_date('69/10/22','%Y/%m/%d') from dual; -select str_to_date('70/10/22','%Y/%m/%d') from dual; -select str_to_date('018/10/22','%Y/%m/%d') from dual; -select str_to_date('2018/10/22','%Y/%m/%d') from dual; -select str_to_date('018/10/22','%y/%m/%d') from dual; -select str_to_date('18/10/22','%y0/%m/%d') from dual; -select str_to_date('18/10/22','%Y0/%m/%d') from dual; -select str_to_date('18a/10/22','%y/%m/%d') from dual; -select str_to_date('18a/10/22','%Y/%m/%d') from dual; -select str_to_date('20188/10/22','%Y/%m/%d') from dual; -select str_to_date('2018510522','%Y5%m5%d') from dual; -select str_to_date('2018^10^22','%Y^%m^%d') from dual; -select str_to_date('2018@10@22','%Y@%m@%d') from dual; -select str_to_date('2018%10%22','%Y%%m%%d') from dual; -select str_to_date('2018(10(22','%Y(%m(%d') from dual; -select str_to_date('2018\10\22','%Y\%m\%d') from dual; -select str_to_date('2018=10=22','%Y=%m=%d') from dual; -select str_to_date('2018+10+22','%Y+%m+%d') from dual; -select str_to_date('2018_10_22','%Y_%m_%d') from dual; -select str_to_date('69510522','%y5%m5%d') from dual; -select str_to_date('69^10^22','%y^%m^%d') from dual; -select str_to_date('18@10@22','%y@%m@%d') from dual; -select str_to_date('18%10%22','%y%%m%%d') from dual; -select str_to_date('18(10(22','%y(%m(%d') from dual; -select str_to_date('18\10\22','%y\%m\%d') from dual; -select str_to_date('18+10+22','%y+%m+%d') from dual; -select str_to_date('18=10=22','%y=%m=%d') from dual; -select str_to_date('18_10_22','%y_%m_%d') from dual; -SELECT STR_TO_DATE('2020-07-04 11:22:33 PM', '%Y-%m-%d %r'); -SELECT STR_TO_DATE('2020-07-04 12:22:33 AM', '%Y-%m-%d %r'); -SELECT STR_TO_DATE('2020-07-04 12:22:33', '%Y-%m-%d %T'); -SELECT STR_TO_DATE('2020-07-04 00:22:33', '%Y-%m-%d %T'); - -# TestReadPartitionedTable -drop table if exists pt; -create table pt (a int, b int, index i_b(b)) partition by range (a) (partition p1 values less than (2), partition p2 values less than (4), partition p3 values less than (6)); -insert into pt values(0, 0); -insert into pt values(1, 1); -insert into pt values(2, 2); -insert into pt values(3, 3); -insert into pt values(4, 4); -insert into pt values(5, 5); -## Table reader -select * from pt order by a; -## Index reader -select b from pt where b = 3; -## Index lookup -select a from pt where b = 3; - -# TestIssue10435 -drop table if exists t1; -create table t1(i int, j int, k int); -insert into t1 VALUES (1,1,1),(2,2,2),(3,3,3),(4,4,4); -INSERT INTO t1 SELECT 10*i,j,5*j FROM t1 UNION SELECT 20*i,j,5*j FROM t1 UNION SELECT 30*i,j,5*j FROM t1; -set @@session.tidb_enable_window_function=1; -SELECT SUM(i) OVER W FROM t1 WINDOW w AS (PARTITION BY j ORDER BY i) ORDER BY 1+SUM(i) OVER w; -set @@session.tidb_enable_window_function=default; - -# TestIndexJoinTableDualPanic -drop table if exists a; -create table a (f1 int, f2 varchar(32), primary key (f1)); -insert into a (f1,f2) values (1,'a'), (2,'b'), (3,'c'); -## TODO here: index join cause the data race of txn. -select /*+ inl_merge_join(a) */ a.* from a inner join (select 1 as k1,'k2-1' as k2) as k on a.f1=k.k1; - -# TestSortLeftJoinWithNullColumnInRightChildPanic -drop table if exists t1, t2; -create table t1(a int); -create table t2(a int); -insert into t1(a) select 1; -select b.n from t1 left join (select a as a, null as n from t2) b on b.a = t1.a order by t1.a; - -# TestIssue39211 -drop table if exists t; -drop table if exists s; -CREATE TABLE `t` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL); -CREATE TABLE `s` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL); -insert into t values(1,1),(2,2); -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into t select * from t; -insert into s values(3,3),(4,4),(1,null),(2,null),(null,null); -insert into s select * from s; -insert into s select * from s; -insert into s select * from s; -insert into s select * from s; -insert into s select * from s; -set @@tidb_max_chunk_size=32; -set @@tidb_enable_null_aware_anti_join=true; -select * from t where (a,b) not in (select a, b from s); -set @@tidb_max_chunk_size=default; -set @@tidb_enable_null_aware_anti_join=default; - -# TestPessimisticSelectForUpdate -drop table if exists t; -create table t(id int primary key, a int); -insert into t values(1, 1); -begin PESSIMISTIC; -select a from t where id=1 for update; -update t set a=a+1 where id=1; -commit; -select a from t where id=1; - -# TestSelectLimit -drop table if exists select_limit; -create table select_limit(id int not null default 1, name varchar(255), PRIMARY KEY(id)); -insert INTO select_limit VALUES (1, "hello"); -insert into select_limit values (2, "hello"); -insert INTO select_limit VALUES (3, "hello"); -insert INTO select_limit VALUES (4, "hello"); -select * from select_limit limit 1; -select id from (select * from select_limit limit 1) k where id != 1; -select * from select_limit limit 18446744073709551615 offset 0; -select * from select_limit limit 18446744073709551615 offset 1; -select * from select_limit limit 18446744073709551615 offset 3; ---error 1064 -select * from select_limit limit 18446744073709551616 offset 3; - -# TestSelectOrderBy -drop table if exists select_order_test; -create table select_order_test(id int not null default 1, name varchar(255), PRIMARY KEY(id)); -insert INTO select_order_test VALUES (1, "hello"); -insert into select_order_test values (2, "hello"); -select * from select_order_test where id = 1 order by id limit 1 offset 0; -select id from select_order_test order by id desc limit 1 ; -select id from select_order_test order by id + 1 desc limit 1 ; -select * from select_order_test order by name, id limit 1 offset 0; -select id as c1, name from select_order_test order by 2, id limit 1 offset 0; -select * from select_order_test order by name, id limit 100 offset 0; -select * from select_order_test order by name, id limit 1 offset 100; -select id from select_order_test order by name, id limit 18446744073709551615; -select id, name from select_order_test where id = 1 group by id, name limit 1 offset 0; -insert INTO select_order_test VALUES (3, "zz"); -insert INTO select_order_test VALUES (4, "zz"); -insert INTO select_order_test VALUES (5, "zz"); -insert INTO select_order_test VALUES (6, "zz"); -insert INTO select_order_test VALUES (7, "zz"); -insert INTO select_order_test VALUES (8, "zz"); -insert INTO select_order_test VALUES (9, "zz"); -insert INTO select_order_test VALUES (10, "zz"); -insert INTO select_order_test VALUES (10086, "hi"); -insert INTO select_order_test VALUES (11, "hh"); -insert INTO select_order_test VALUES (12, "hh"); -insert INTO select_order_test VALUES (13, "hh"); -insert INTO select_order_test VALUES (14, "hh"); -insert INTO select_order_test VALUES (15, "hh"); -insert INTO select_order_test VALUES (16, "hh"); -insert INTO select_order_test VALUES (17, "hh"); -insert INTO select_order_test VALUES (18, "hh"); -insert INTO select_order_test VALUES (19, "hh"); -insert INTO select_order_test VALUES (20, "hh"); -insert INTO select_order_test VALUES (21, "zz"); -insert INTO select_order_test VALUES (22, "zz"); -insert INTO select_order_test VALUES (23, "zz"); -insert INTO select_order_test VALUES (24, "zz"); -insert INTO select_order_test VALUES (25, "zz"); -insert INTO select_order_test VALUES (26, "zz"); -insert INTO select_order_test VALUES (27, "zz"); -insert INTO select_order_test VALUES (28, "zz"); -insert INTO select_order_test VALUES (29, "zz"); -insert INTO select_order_test VALUES (30, "zz"); -insert INTO select_order_test VALUES (1501, "aa"); -select * from select_order_test order by name, id limit 1 offset 3; -drop table if exists select_order_test; -drop table if exists t; -create table t (c int, d int); -insert t values (1, 1); -insert t values (1, 2); -insert t values (1, 3); -select 1-d as d from t order by d; -select 1-d as d from t order by d + 1; -select t.d from t order by d; -drop table if exists t; -create table t (a int, b int, c int); -insert t values (1, 2, 3); -select b from (select a,b from t order by a,c) t; -select b from (select a,b from t order by a,c limit 1) t; -drop table if exists t; -create table t(a int, b int, index idx(a)); -insert into t values(1, 1), (2, 2); -select * from t where 1 order by b; -select * from t where a between 1 and 2 order by a desc; -drop table if exists t; -create table t(a int primary key, b int, c int, index idx(b)); -insert into t values(1, 3, 1); -insert into t values(2, 2, 2); -insert into t values(3, 1, 3); -select * from t use index(idx) order by a desc limit 1; -drop table if exists t; -create table t(a int, b int, key b (b)); -set @@tidb_index_lookup_size = 3; -insert into t values(0, 10); -insert into t values(1, 9); -insert into t values(2, 8); -insert into t values(3, 7); -insert into t values(4, 6); -insert into t values(5, 5); -insert into t values(6, 4); -insert into t values(7, 3); -insert into t values(8, 2); -insert into t values(9, 1); -select a from t use index(b) order by b; -set @@tidb_index_lookup_size = default; - -# TestSelectErrorRow ---error 1146 -select row(1, 1) from test; ---error 1146 -select * from test group by row(1, 1); ---error 1146 -select * from test order by row(1, 1); ---error 1146 -select * from test having row(1, 1); ---error 1146 -select (select 1, 1) from test; ---error 1146 -select * from test group by (select 1, 1); ---error 1146 -select * from test order by (select 1, 1); ---error 1146 -select * from test having (select 1, 1); - -# TestIn -drop table if exists t; -create table t (c1 int primary key, c2 int, key c (c2)); -insert t values(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (26, 26), (27, 27), (28, 28), (29, 29), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (37, 37), (38, 38), (39, 39), (40, 40), (41, 41), (42, 42), (43, 43), (44, 44), (45, 45), (46, 46), (47, 47), (48, 48), (49, 49), (50, 50), (51, 51), (52, 52), (53, 53), (54, 54), (55, 55), (56, 56), (57, 57), (58, 58), (59, 59), (60, 60), (61, 61), (62, 62), (63, 63), (64, 64), (65, 65), (66, 66), (67, 67), (68, 68), (69, 69), (70, 70), (71, 71), (72, 72), (73, 73), (74, 74), (75, 75), (76, 76), (77, 77), (78, 78), (79, 79), (80, 80), (81, 81), (82, 82), (83, 83), (84, 84), (85, 85), (86, 86), (87, 87), (88, 88), (89, 89), (90, 90), (91, 91), (92, 92), (93, 93), (94, 94), (95, 95), (96, 96), (97, 97), (98, 98), (99, 99), (100, 100), (101, 101), (102, 102), (103, 103), (104, 104), (105, 105), (106, 106), (107, 107), (108, 108), (109, 109), (110, 110), (111, 111), (112, 112), (113, 113), (114, 114), (115, 115), (116, 116), (117, 117), (118, 118), (119, 119), (120, 120), (121, 121), (122, 122), (123, 123), (124, 124), (125, 125), (126, 126), (127, 127), (128, 128), (129, 129), (130, 130), (131, 131), (132, 132), (133, 133), (134, 134), (135, 135), (136, 136), (137, 137), (138, 138), (139, 139), (140, 140), (141, 141), (142, 142), (143, 143), (144, 144), (145, 145), (146, 146), (147, 147), (148, 148), (149, 149), (150, 150), (151, 151), (152, 152), (153, 153), (154, 154), (155, 155), (156, 156), (157, 157), (158, 158), (159, 159), (160, 160), (161, 161), (162, 162), (163, 163), (164, 164), (165, 165), (166, 166), (167, 167), (168, 168), (169, 169), (170, 170), (171, 171), (172, 172), (173, 173), (174, 174), (175, 175), (176, 176), (177, 177), (178, 178), (179, 179), (180, 180), (181, 181), (182, 182), (183, 183), (184, 184), (185, 185), (186, 186), (187, 187), (188, 188), (189, 189), (190, 190), (191, 191), (192, 192), (193, 193), (194, 194), (195, 195), (196, 196), (197, 197), (198, 198), (199, 199), (200, 200); -select c2 from t where c1 in ('7', '10', '112', '111', '98', '106', '100', '9', '18', '17') order by c2; -select c2 from t where c1 in ('7a'); - -# TestTablePKisHandleScan -drop table if exists t; -create table t (a int PRIMARY KEY AUTO_INCREMENT); -insert t values (),(); -insert t values (-100),(0); -select * from t; -select * from t where a = 1; -select * from t where a != 1; -select * from t where a >= '1.1'; -select * from t where a < '1.1'; -select * from t where a > '-100.1' and a < 2; -select * from t where a is null; -select * from t where a is true; -select * from t where a is false; -select * from t where a in (1, 2); -select * from t where a between 1 and 2; - -# TestDefaultNull -drop table if exists t; -create table t (a int primary key auto_increment, b int default 1, c int); -insert t values (); -select * from t; -update t set b = NULL where a = 1; -select * from t; -update t set c = 1; -select * from t ; -delete from t where a = 1; -insert t (a) values (1); -select * from t; - -# TestJSON -drop table if exists test_json; -create table test_json (id int, a json); -insert into test_json (id, a) values (1, '{"a":[1,"2",{"aa":"bb"},4],"b":true}'); -insert into test_json (id, a) values (2, "null"); -insert into test_json (id, a) values (3, null); -insert into test_json (id, a) values (4, 'true'); -insert into test_json (id, a) values (5, '3'); -insert into test_json (id, a) values (5, '4.0'); -insert into test_json (id, a) values (6, '"string"'); -select tj.a from test_json tj order by tj.id; -select json_type(a) from test_json tj order by tj.id; -select a from test_json tj where a = 3; -select a from test_json tj where a = 4.0; -select a from test_json tj where a = true; -select a from test_json tj where a = "string"; -select cast(true as JSON); -select cast(false as JSON); -select a->>'$.a[2].aa' as x, a->'$.b' as y from test_json having x is not null order by id; -select a->'$.a[2].aa' as x, a->>'$.b' as y from test_json having x is not null order by id; --- error 1101 -create table test_bad_json(a json default '{}'); --- error 1101 -create table test_bad_json(a blob default 'hello'); --- error 1101 -create table test_bad_json(a text default 'world'); --- error 3152 -create table test_bad_json(id int, a json, key (a)); -select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON); -select a, count(1) from test_json group by a order by a; -drop table if exists test_json; -create table test_json ( a decimal(60,2) as (JSON_EXTRACT(b,'$.c')), b json ); -insert into test_json (b) values - ('{"c": "1267.1"}'), - ('{"c": "1267.01"}'), - ('{"c": "1267.1234"}'), - ('{"c": "1267.3456"}'), - ('{"c": "1234567890123456789012345678901234567890123456789012345"}'), - ('{"c": "1234567890123456789012345678901234567890123456789012345.12345"}'); -select a from test_json; - -# TestGeneratedColumnWrite -drop table if exists test_gc_write, test_gc_write_1; --- error 3109 -CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (a+8) virtual); -CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (b+8) virtual); -CREATE TABLE test_gc_write_1 (a int primary key, b int, c int); --- error 3105 -insert into test_gc_write (a, b, c) values (1, 1, 1); --- error 3105 -insert into test_gc_write values (1, 1, 1); --- error 3105 -insert into test_gc_write select 1, 1, 1; --- error 3105 -insert into test_gc_write (a, b) values (1, 1) on duplicate key update c = 1; --- error 3105 -insert into test_gc_write set a = 1, b = 1, c = 1; --- error 3105 -update test_gc_write set c = 1; --- error 3105 -update test_gc_write, test_gc_write_1 set test_gc_write.c = 1; -insert into test_gc_write (a, b) values (1, 1); -insert into test_gc_write set a = 2, b = 2; -insert into test_gc_write (b) select c from test_gc_write; -update test_gc_write set b = 2 where a = 2; -update test_gc_write t1, test_gc_write_1 t2 set t1.b = 3, t2.b = 4; --- error 1136 -insert into test_gc_write values (1, 1); --- error 1136 -insert into test_gc_write select 1, 1; --- error 1136 -insert into test_gc_write (c) select a, b from test_gc_write; --- error 3105 -insert into test_gc_write (b, c) select a, b from test_gc_write; - -# TestGeneratedColumnRead -drop table if exists test_gc_read; -CREATE TABLE test_gc_read(a int primary key, b int, c int as (a+b), d int as (a*b) stored, e int as (c*2)); -SELECT generation_expression FROM information_schema.columns WHERE table_name = 'test_gc_read' AND column_name = 'd'; -INSERT INTO test_gc_read (a, b) VALUES (0,null),(1,2),(3,4); -SELECT * FROM test_gc_read ORDER BY a; -INSERT INTO test_gc_read SET a = 5, b = 10; -SELECT * FROM test_gc_read ORDER BY a; -REPLACE INTO test_gc_read (a, b) VALUES (5, 6); -SELECT * FROM test_gc_read ORDER BY a; -INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE b = 9; -SELECT * FROM test_gc_read ORDER BY a; -SELECT c, d FROM test_gc_read; -SELECT e FROM test_gc_read; -INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE a = 6, b = a; -SELECT * FROM test_gc_read ORDER BY a; -INSERT INTO test_gc_read (a, b) VALUES (6, 8) ON DUPLICATE KEY UPDATE b = 8, a = b; -SELECT * FROM test_gc_read ORDER BY a; -SELECT * FROM test_gc_read WHERE c = 7; -SELECT * FROM test_gc_read WHERE d = 64; -SELECT * FROM test_gc_read WHERE e = 6; -UPDATE test_gc_read SET a = a + 100 WHERE c = 7; -SELECT * FROM test_gc_read WHERE c = 107; -UPDATE test_gc_read m SET m.a = m.a + 100 WHERE c = 107; -SELECT * FROM test_gc_read WHERE c = 207; -UPDATE test_gc_read SET a = a - 200 WHERE d = 812; -SELECT * FROM test_gc_read WHERE d = 12; -INSERT INTO test_gc_read set a = 4, b = d + 1; -SELECT * FROM test_gc_read ORDER BY a; -DELETE FROM test_gc_read where a = 4; -CREATE TABLE test_gc_help(a int primary key, b int, c int, d int, e int); -INSERT INTO test_gc_help(a, b, c, d, e) SELECT * FROM test_gc_read; -SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.c = t2.c ORDER BY t1.a; -SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.d = t2.d ORDER BY t1.a; -SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.e = t2.e ORDER BY t1.a; ---sorted_result -SELECT * FROM test_gc_read t WHERE t.a not in (SELECT t.a FROM test_gc_read t where t.c > 5); ---sorted_result -SELECT * FROM test_gc_read t WHERE t.c in (SELECT t.c FROM test_gc_read t where t.c > 5); -SELECT tt.b FROM test_gc_read tt WHERE tt.a = (SELECT max(t.a) FROM test_gc_read t WHERE t.c = tt.c) ORDER BY b; -SELECT c, sum(a) aa, max(d) dd, sum(e) ee FROM test_gc_read GROUP BY c ORDER BY aa; -SELECT a, sum(c), sum(d), sum(e) FROM test_gc_read GROUP BY a ORDER BY a; -UPDATE test_gc_read m, test_gc_read n SET m.b = m.b + 10, n.b = n.b + 10; -SELECT * FROM test_gc_read ORDER BY a; -drop table if exists t; -create table t(a int); -insert into t values(8); -update test_gc_read set a = a+1 where a in (select a from t); -select * from test_gc_read order by a; -CREATE TABLE test_gc_read_cast(a VARCHAR(255), b VARCHAR(255), c INT AS (JSON_EXTRACT(a, b)), d INT AS (JSON_EXTRACT(a, b)) STORED); -INSERT INTO test_gc_read_cast (a, b) VALUES ('{"a": "3"}', '$.a'); -SELECT c, d FROM test_gc_read_cast; -CREATE TABLE test_gc_read_cast_1(a VARCHAR(255), b VARCHAR(255), c ENUM("red", "yellow") AS (JSON_UNQUOTE(JSON_EXTRACT(a, b)))); -INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "yellow"}', '$.a'); -SELECT c FROM test_gc_read_cast_1; -CREATE TABLE test_gc_read_cast_2( a JSON, b JSON AS (a->>'$.a')); -INSERT INTO test_gc_read_cast_2(a) VALUES ('{"a": "{ \\\"key\\\": \\\"\\u6d4b\\\" }"}'); -SELECT b FROM test_gc_read_cast_2; -CREATE TABLE test_gc_read_cast_3( a JSON, b JSON AS (a->>'$.a'), c INT AS (b * 3.14) ); -INSERT INTO test_gc_read_cast_3(a) VALUES ('{"a": "5"}'); -SELECT c FROM test_gc_read_cast_3; ---error 1265 -INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "invalid"}', '$.a'); -DROP TABLE IF EXISTS test_gc_read_m; -CREATE TABLE test_gc_read_m (a int primary key, b int, c int as (a+1), d int as (c*2)); -INSERT INTO test_gc_read_m(a) values (1), (2); -ALTER TABLE test_gc_read_m DROP b; -SELECT * FROM test_gc_read_m; -CREATE TABLE test_gc_read_1(a int primary key, b int, c int as (a+b) not null, d int as (a*b) stored); -CREATE TABLE test_gc_read_2(a int primary key, b int, c int as (a+b), d int as (a*b) stored not null); --- error 1048 -insert into test_gc_read_1(a, b) values (1, null); --- error 1048 -insert into test_gc_read_2(a, b) values (1, null); - -# TestSelectPartition -drop table if exists th, tr, tl; -create table th (a int, b int) partition by hash(a) partitions 3; -create table tr (a int, b int) - partition by range (a) ( - partition r0 values less than (4), - partition r1 values less than (7), - partition r3 values less than maxvalue); -create table tl (a int, b int, unique index idx(a)) partition by list (a) ( - partition p0 values in (3,5,6,9,17), - partition p1 values in (1,2,10,11,19,20), - partition p2 values in (4,12,13,14,18), - partition p3 values in (7,8,15,16,null)); -insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); -insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); -insert into tr values (-3,-3),(3,3),(4,4),(7,7),(8,8); -insert into tl values (3,3),(1,1),(4,4),(7,7),(8,8),(null,null); -select b from th partition (p0) order by a; -select b from tr partition (r0) order by a; -select b from tl partition (p0) order by a; -select b from th partition (p0,P0) order by a; -select b from tr partition (r0,R0,r0) order by a; -select b from tl partition (p0,P0,p0) order by a; -select b from th partition (P2,p0) order by a; -select b from tr partition (r1,R3) order by a; -select b from tl partition (p0,P3) order by a; --- error 1735 -select b from th partition (p0,p4); --- error 1735 -select b from tr partition (r1,r4); --- error 1735 -select b from tl partition (p0,p4); -begin; -insert into th values (10,10),(11,11); -select a, b from th where b>10; -commit; -select a, b from th where b>10; -drop table if exists tscalar; -create table tscalar (c1 int) partition by range (c1 % 30) ( - partition p0 values less than (0), - partition p1 values less than (10), - partition p2 values less than (20), - partition pm values less than (maxvalue)); -insert into tscalar values(0), (10), (40), (50), (55); -insert into tscalar values(-0), (-10), (-40), (-50), (-55); -select * from tscalar where c1 in (55, 55); -select * from tscalar where c1 in (40, 40); -select * from tscalar where c1 in (40); -select * from tscalar where c1 in (-40); -select * from tscalar where c1 in (-40, -40); -select * from tscalar where c1 in (-1); - -# TestPrepareLoadData --- error 1295 -prepare stmt from "load data local infile '/tmp/load_data_test.csv' into table test"; - -# TestPrepareImportInto --- error 1295 -prepare stmt from "import into test from 'xx' format 'delimited'"; - -# TestHandleTransfer -drop table if exists t; -create table t(a int, index idx(a)); -insert into t values(1), (2), (4); -begin; -update t set a = 3 where a = 4; -select * from t ignore index(idx); -insert into t values(4); -select * from t use index(idx); -select * from t use index(idx) order by a desc; -update t set a = 5 where a = 3; -select * from t use index(idx); -commit; -drop table if exists t; -create table t(a int, b int, index idx(a)); -insert into t values(3, 3), (1, 1), (2, 2); -select * from t use index(idx) order by a; - -# TestMaxInt64Handle -drop table if exists t; -create table t(id bigint, PRIMARY KEY (id)); -insert into t values(9223372036854775807); -select * from t where id = 9223372036854775807; -select * from t where id = 9223372036854775807; -select * from t; ---error 1062 -insert into t values(9223372036854775807); -delete from t where id = 9223372036854775807; -select * from t; - -# TestUnsignedPk -drop table if exists t; -create table t(id bigint unsigned primary key); -insert into t values(9223372036854775808), (9223372036854775809), (1), (2); -select * from t order by id; -select * from t where id not in (2); -drop table if exists t; -create table t(a bigint unsigned primary key, b int, index idx(b)); -insert into t values(9223372036854775808, 1), (1, 1); -select * from t use index(idx) where b = 1 and a < 2; -select * from t use index(idx) where b = 1 order by b, a; - -# TestSignedCommonHandle -set @@tidb_enable_clustered_index = 1; -drop table if exists t; -create table t(k1 int, k2 int, primary key(k1, k2)); -insert into t(k1, k2) value(-100, 1), (-50, 1), (0, 0), (1, 1), (3, 3); -select k1 from t order by k1; -select k1 from t order by k1 desc; -select k1 from t where k1 < -51; -select k1 from t where k1 < -1; -select k1 from t where k1 <= 0; -select k1 from t where k1 < 2; -select k1 from t where k1 < -1 and k1 > -90; -set @@tidb_enable_clustered_index = default; - -# TestContainDotColumn -drop table if exists t1, t2, t3; -create table t1(t1.a char); -create table t2(a char, t2.b int); --- error 1103 -create table t3(s.a char); - -# TestCheckTableClusterIndex -set @@tidb_enable_clustered_index = 1; -drop table if exists admin_test; -create table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1, c2), index (c1), unique key(c2)); -insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3); -admin check table admin_test; -set @@tidb_enable_clustered_index = default; - -# TestIncorrectLimitArg -drop table if exists t; -create table t(a bigint); -prepare stmt1 from 'select * from t limit ?'; -prepare stmt2 from 'select * from t limit ?, ?'; -set @a = -1; -set @b = 1; --- error 1210 -execute stmt1 using @a; --- error 1210 -execute stmt2 using @b, @a; --- error 1210 -execute stmt2 using @a, @b; --- error 1210 -execute stmt2 using @a, @a; - -# TestEmptyEnum -drop table if exists t; -create table t (e enum('Y', 'N')); -set sql_mode='STRICT_TRANS_TABLES'; ---error 1265 -insert into t values (0); ---error 1265 -insert into t values ('abc'); -set sql_mode=''; -insert into t values (0); -select * from t; -insert into t values ('abc'); -select * from t; -insert into t values (null); -select * from t; -drop table if exists t; -create table t (id int auto_increment primary key, c1 enum('a', '', 'c')); -insert into t(c1) values (0); -select id, c1+0, c1 from t; -alter table t change c1 c1 enum('a', '') not null; -select id, c1+0, c1 from t; -insert into t(c1) values (0); -select id, c1+0, c1 from t; -set sql_mode=default; - -# TestDIVZeroInPartitionExpr -drop table if exists t1; -create table t1(a int) partition by range (10 div a) (partition p0 values less than (10), partition p1 values less than maxvalue); -set @@sql_mode=''; -insert into t1 values (NULL), (0), (1); -set @@sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO'; --- error 1365 -insert into t1 values (NULL), (0), (1); -set @@sql_mode=default; - -# TestInsertIntoGivenPartitionSet -drop table if exists t1; -create table t1( - a int(11) DEFAULT NULL, - b varchar(10) DEFAULT NULL, - UNIQUE KEY idx_a (a)) PARTITION BY RANGE (a) - (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, - PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, - PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, - PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, - PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); -insert into t1 partition(p0) values(1, 'a'), (2, 'b'); -select * from t1 partition(p0) order by a; -insert into t1 partition(p0, p1) values(3, 'c'), (4, 'd'); -select * from t1 partition(p1); --- error 1062 -insert into t1 values(1, 'a'); --- error 1735 -insert into t1 partition(p0, p_non_exist) values(1, 'a'); --- error 1748 -insert into t1 partition(p0, p1) values(40, 'a'); -replace into t1 partition(p0) values(1, 'replace'); -replace into t1 partition(p0, p1) values(3, 'replace'), (4, 'replace'); -replace into t1 values(1, 'a'); -select * from t1 partition (p0) order by a; --- error 1735 -replace into t1 partition(p0, p_non_exist) values(1, 'a'); --- error 1748 -replace into t1 partition(p0, p1) values(40, 'a'); -truncate table t1; -drop table if exists t; -create table t(a int, b char(10)); --- error 1747 -insert into t partition(p0, p1) values(1, 'a'); -insert into t values(1, 'a'), (2, 'b'); -insert into t1 partition(p0) select * from t; -select * from t1 partition(p0) order by a; -truncate table t; -insert into t values(3, 'c'), (4, 'd'); -insert into t1 partition(p0, p1) select * from t; -select * from t1 partition(p1) order by a; -select * from t1 partition(p0) order by a; --- error 1062 -insert into t1 select 1, 'a'; --- error 1735 -insert into t1 partition(p0, p_non_exist) select 1, 'a'; --- error 1748 -insert into t1 partition(p0, p1) select 40, 'a'; -replace into t1 partition(p0) select 1, 'replace'; -truncate table t; -insert into t values(3, 'replace'), (4, 'replace'); -replace into t1 partition(p0, p1) select * from t; -replace into t1 select 1, 'a'; -select * from t1 partition (p0) order by a; --- error 1735 -replace into t1 partition(p0, p_non_exist) select 1, 'a'; --- error 1748 -replace into t1 partition(p0, p1) select 40, 'a'; - -# TestUpdateGivenPartitionSet -drop table if exists t1, t2, t3; -create table t1( - a int(11), - b varchar(10) DEFAULT NULL, - primary key idx_a (a)) PARTITION BY RANGE (a) - (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, - PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, - PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, - PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, - PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); -create table t2( - a int(11) DEFAULT NULL, - b varchar(10) DEFAULT NULL) PARTITION BY RANGE (a) - (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, - PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, - PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, - PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, - PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); -create table t3 (a int(11), b varchar(10) default null); -insert into t3 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); --- error 1747 -update t3 partition(p0) set a = 40 where a = 2; -insert into t1 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); --- error 1748 -update t1 partition(p0, p1) set a = 40; --- error 1748 -update t1 partition(p0) set a = 40 where a = 2; --- error 1735 -update t1 partition (p0, p_non_exist) set a = 40; --- error 1748 -update t1 partition (p0), t3 set t1.a = 40 where t3.a = 2; -update t1 partition(p0) set a = 3 where a = 2; -update t1 partition(p0, p3) set a = 33 where a = 1; -insert into t2 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); --- error 1748 -update t2 partition(p0, p1) set a = 40; --- error 1748 -update t2 partition(p0) set a = 40 where a = 2; -update t2 partition(p0) set a = 3 where a = 2; -update t2 partition(p0, p3) set a = 33 where a = 1; -drop table if exists t4; -create table t4(a int primary key, b int) partition by hash(a) partitions 2; -insert into t4(a, b) values(1, 1),(2, 2),(3, 3); --- error 1748 -update t4 partition(p0) set a = 5 where a = 2; - -# TestIssue19667 -drop table if exists t; -CREATE TABLE t (a DATETIME); -INSERT INTO t VALUES('1988-04-17 01:59:59'); -SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t; - -# TestZeroDateTimeCompatibility ---enable_warnings -select YEAR(0000-00-00), YEAR("0000-00-00"); -select MONTH(0000-00-00), MONTH("0000-00-00"); -select DAYOFMONTH(0000-00-00), DAYOFMONTH("0000-00-00"); -select QUARTER(0000-00-00), QUARTER("0000-00-00"); -select EXTRACT(DAY FROM 0000-00-00), EXTRACT(DAY FROM "0000-00-00"); -select EXTRACT(MONTH FROM 0000-00-00), EXTRACT(MONTH FROM "0000-00-00"); -select EXTRACT(YEAR FROM 0000-00-00), EXTRACT(YEAR FROM "0000-00-00"); -select EXTRACT(WEEK FROM 0000-00-00), EXTRACT(WEEK FROM "0000-00-00"); -select EXTRACT(QUARTER FROM 0000-00-00), EXTRACT(QUARTER FROM "0000-00-00"); -select DAYOFWEEK(0000-00-00), DAYOFWEEK("0000-00-00"); -select DAYOFYEAR(0000-00-00), DAYOFYEAR("0000-00-00"); ---disable_warnings -drop table if exists t; -create table t(v1 datetime, v2 datetime(3)); -insert ignore into t values(0,0); ---enable_warnings -select YEAR(v1), YEAR(v2) from t; -select MONTH(v1), MONTH(v2) from t; -select DAYOFMONTH(v1), DAYOFMONTH(v2) from t; -select QUARTER(v1), QUARTER(v2) from t; -select EXTRACT(DAY FROM v1), EXTRACT(DAY FROM v2) from t; -select EXTRACT(MONTH FROM v1), EXTRACT(MONTH FROM v2) from t; -select EXTRACT(YEAR FROM v1), EXTRACT(YEAR FROM v2) from t; -select EXTRACT(WEEK FROM v1), EXTRACT(WEEK FROM v2) from t; -select EXTRACT(QUARTER FROM v1), EXTRACT(QUARTER FROM v2) from t; -select DAYOFWEEK(v1), DAYOFWEEK(v2) from t; -select DAYOFYEAR(v1), DAYOFYEAR(v2) from t; ---disable_warnings - -# TestInvalidDateValueInCreateTable -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE'; --- error 1067 -create table t (a datetime default '2999-00-00 00:00:00'); -create table t (a datetime); --- error 1067 -alter table t modify column a datetime default '2999-00-00 00:00:00'; -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE'; --- error 1067 -create table t (a datetime default '0000-00-00 00:00:00'); -create table t (a datetime); --- error 1067 -alter table t modify column a datetime default '0000-00-00 00:00:00'; -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES'; -create table t (a datetime default '2999-00-00 00:00:00'); -drop table if exists t; -create table t (a datetime default '0000-00-00 00:00:00'); -drop table if exists t; -create table t (a datetime); -alter table t modify column a datetime default '2999-00-00 00:00:00'; -alter table t modify column a datetime default '0000-00-00 00:00:00'; -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES'; --- error 1067 -create table t (a datetime default '2999-02-30 00:00:00'); -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE'; --- error 1067 -create table t (a datetime default '2999-02-30 00:00:00'); -drop table if exists t; -set @@sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES'; -create table t (a datetime default '2999-02-30 00:00:00'); -drop table if exists t; -create table t (a datetime); -alter table t modify column a datetime default '2999-02-30 00:00:00'; -drop table if exists t; -set @@sql_mode=default; - -# TestEncodingSet -drop table if exists `enum-set`; -CREATE TABLE `enum-set` (`set` SET('x00','x01','x02','x03','x04','x05','x06','x07','x08','x09','x10','x11','x12','x13','x14','x15','x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31','x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47','x48','x49','x50','x51','x52','x53','x54','x55','x56','x57','x58','x59','x60','x61','x62','x63')NOT NULL PRIMARY KEY); -INSERT INTO `enum-set` VALUES ("x00,x59"); -select `set` from `enum-set` use index(PRIMARY); -admin check table `enum-set`; - -# TestYearTypeDeleteIndex -drop table if exists t; -create table t(a YEAR, PRIMARY KEY(a)); -insert into t set a = '2151'; -delete from t; -admin check table t; - -# TestRowID -drop table if exists t; -set @@tidb_enable_clustered_index = 'int_only'; -create table t(a varchar(10), b varchar(10), c varchar(1), index idx(a, b, c)); -insert into t values('a', 'b', 'c'); -insert into t values('a', 'b', 'c'); -select b, _tidb_rowid from t use index(idx) where a = 'a'; -begin; -select * from t for update; -select distinct b from t use index(idx) where a = 'a'; -commit; -drop table if exists t; -create table t(a varchar(5) primary key); -insert into t values('a'); -select *, _tidb_rowid from t use index(`primary`) where _tidb_rowid=1; -set @@tidb_enable_clustered_index = default; - -# TestSubqueryTableAlias -drop table if exists t; -set sql_mode = ''; --- error 1248 -select a, b from (select 1 a) ``, (select 2 b) ``; --- error 1066 -select a, b from (select 1 a) `x`, (select 2 b) `x`; --- error 1248 -select a, b from (select 1 a), (select 2 b); --- error 1248 -select a from (select 1 a) ``, (select 2 a) ``; --- error 1066 -select a from (select 1 a) `x`, (select 2 a) `x`; --- error 1066 -select x.a from (select 1 a) `x`, (select 2 a) `x`; --- error 1248 -select a from (select 1 a), (select 2 a); -set sql_mode = 'oracle'; -select a, b from (select 1 a) ``, (select 2 b) ``; -select a, b from (select 1 a) `x`, (select 2 b) `x`; -select a, b from (select 1 a), (select 2 b); --- error 1052 -select a from (select 1 a) ``, (select 2 a) ``; --- error 1052 -select a from (select 1 a) `x`, (select 2 a) `x`; --- error 1052 -select x.a from (select 1 a) `x`, (select 2 a) `x`; --- error 1052 -select a from (select 1 a), (select 2 a); -set sql_mode = default; - -# TestSelectHashPartitionTable -drop table if exists th; -create table th (a int, b int) partition by hash(a) partitions 3; -insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); -insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); -select b from th order by a; -select * from th where a=-2; -select * from th where a=5; -drop table if exists th; - -# TestSelectView -drop table if exists view_t; -create table view_t (a int,b int); -insert into view_t values(1,2); -create definer='root'@'localhost' view view1 as select * from view_t; -create definer='root'@'localhost' view view2(c,d) as select * from view_t; -create definer='root'@'localhost' view view3(c,d) as select a,b from view_t; -create definer='root'@'localhost' view view4 as select * from (select * from (select * from view_t) tb1) tb; -select * from view1; -select * from view2; -select * from view3; -select * from view4; -drop table view_t; -create table view_t(c int,d int); --- error 1356 -select * from view1; --- error 1356 -select * from view2; --- error 1356 -select * from view3; -drop table view_t; -create table view_t(a int,b int,c int); -insert into view_t values(1,2,3); -select * from view1; -select * from view2; -select * from view3; -select * from view4; -alter table view_t drop column a; -alter table view_t add column a int after b; -update view_t set a=1; -select * from view1; -select * from view2; -select * from view3; -select * from view4; -drop table view_t; -drop view view1,view2,view3,view4; -set @@tidb_enable_window_function = 1; -create table t(a int, b int); -insert into t values (1,1),(1,2),(2,1),(2,2); -create definer='root'@'localhost' view v as select a, first_value(a) over(rows between 1 preceding and 1 following), last_value(a) over(rows between 1 preceding and 1 following) from t; -select * from v; -drop view v; -set @@tidb_enable_window_function = default; - -# TestBinaryStrNumericOperator -drop table if exists t; -create table t(a varbinary(10)); -insert into t values ('123.12'); ---enable_warnings -select 1+a from t; -select a-1 from t; -select -10*a from t; -select a/-2 from t; ---disable_warnings - -# TestSetOperationOnDiffColType -drop table if exists t1, t2, t3; -create table t1(a int, b int); -create table t2(a int, b varchar(20)); -create table t3(a int, b decimal(30,10)); -insert into t1 values (1,1),(1,1),(2,2),(3,3),(null,null); -insert into t2 values (1,'1'),(2,'2'),(null,null),(null,'3'); -insert into t3 values (2,2.1),(3,3); -explain format = 'brief' select * from t3 union select * from t1; ---sorted_result -select * from t3 union select * from t1; -explain format = 'brief' select * from t2 union all select * from t1; ---sorted_result -select * from t2 union all select * from t1; -explain format = 'brief' select * from t1 except select * from t3; ---sorted_result -select * from t1 except select * from t3; -explain format = 'brief' select * from t1 intersect select * from t2; ---sorted_result -select * from t1 intersect select * from t2; -explain format = 'brief' select * from t1 union all select * from t2 union all select * from t3; ---sorted_result -select * from t1 union all select * from t2 union all select * from t3; -explain format = 'brief' select * from t1 union all select * from t2 except select * from t3; ---sorted_result -select * from t1 union all select * from t2 except select * from t3; -explain format = 'brief' select * from t1 intersect select * from t2 intersect select * from t1; ---sorted_result -select * from t1 intersect select * from t2 intersect select * from t1; -explain format = 'brief' select * from t1 union all select * from t2 intersect select * from t3; ---sorted_result -select * from t1 union all select * from t2 intersect select * from t3; -explain format = 'brief' select * from t1 except select * from t2 intersect select * from t3; ---sorted_result -select * from t1 except select * from t2 intersect select * from t3; - -# TestIndexScanWithYearCol -# issue-23038: wrong key range of index scan for year column -set tidb_cost_model_version=2; -drop table if exists t; -create table t (c1 year(4), c2 int, key(c1)); -insert into t values(2001, 1); -explain format = 'brief' select t1.c1, t2.c1 from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; ---sorted_result -select t1.c1, t2.c1 from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -explain format = 'brief' select * from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; ---sorted_result -select * from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -explain format = 'brief' select count(*) from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; ---sorted_result -select count(*) from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -explain format = 'brief' select t1.c1, t2.c1 from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; ---sorted_result -select t1.c1, t2.c1 from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -explain format = 'brief' select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; ---sorted_result -select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -explain format = 'brief' select count(*) from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; ---sorted_result -select count(*) from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL; -explain format = 'brief' select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 is not NULL; ---sorted_result -select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 is not NULL; - -# TestSetOperation -set tidb_cost_model_version=2; -drop table if exists t1, t2, t3; -create table t1(a int); -create table t2 like t1; -create table t3 like t1; -insert into t1 values (1),(1),(2),(3),(null); -insert into t2 values (1),(2),(null),(null); -insert into t3 values (2),(3); -explain format='brief' select * from t3 union select * from t1; ---sorted_result -select * from t3 union select * from t1; -explain format='brief' select * from t2 union all select * from t1; ---sorted_result -select * from t2 union all select * from t1; -explain format='brief' select * from t1 except select * from t3; ---sorted_result -select * from t1 except select * from t3; -explain format='brief' select * from t1 intersect select * from t2; ---sorted_result -select * from t1 intersect select * from t2; -explain format='brief' select * from t1 union all select * from t2 union all select * from t3; ---sorted_result -select * from t1 union all select * from t2 union all select * from t3; -explain format='brief' select * from t1 union all select * from t2 except select * from t3; ---sorted_result -select * from t1 union all select * from t2 except select * from t3; -explain format='brief' select * from t1 intersect select * from t2 intersect select * from t1; ---sorted_result -select * from t1 intersect select * from t2 intersect select * from t1; -explain format='brief' select * from t1 union all select * from t2 intersect select * from t3; ---sorted_result -select * from t1 union all select * from t2 intersect select * from t3; -explain format='brief' select * from t1 except select * from t2 intersect select * from t3; ---sorted_result -select * from t1 except select * from t2 intersect select * from t3; -explain format='brief' select * from t1 intersect (select * from t2 except (select * from t3)); ---sorted_result -select * from t1 intersect (select * from t2 except (select * from t3)); -explain format='brief' select * from t1 union all (select * from t2 except select * from t3); ---sorted_result -select * from t1 union all (select * from t2 except select * from t3); -explain format='brief' select * from t1 union (select * from t2 union all select * from t3); ---sorted_result -select * from t1 union (select * from t2 union all select * from t3); -explain format='brief' (select * from t1 intersect select * from t1) except (select * from t2 union select * from t3); ---sorted_result -(select * from t1 intersect select * from t1) except (select * from t2 union select * from t3); - -# https://github.com/pingcap/tidb/issues/40279 -drop table if exists issue40279; -CREATE TABLE `issue40279` (`a` char(155) NOT NULL DEFAULT 'on1unvbxp5sko6mbetn3ku26tuiyju7w3wc0olzto9ew7gsrx',`b` mediumint(9) NOT NULL DEFAULT '2525518',PRIMARY KEY (`b`,`a`) /*T![clustered_index] CLUSTERED */); -insert into `issue40279` values (); -( select `issue40279`.`b` as r0 , from_base64( `issue40279`.`a` ) as r1 from `issue40279` ) except ( select `issue40279`.`a` as r0 , elt(2, `issue40279`.`a` , `issue40279`.`a` ) as r1 from `issue40279`); -drop table if exists t2; -CREATE TABLE `t2` ( `a` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; -insert into t2 values(0xCED2); -(select elt(2,t2.a,t2.a) from t2) except (select 0xCED2 from t2); - -# TestCompareIssue38361 -drop table if exists t; -create table t(a datetime, b bigint, c bigint); -insert into t values(cast('2023-08-09 00:00:00' as datetime), 20230809, 20231310); -select a > 20230809 from t; -select a = 20230809 from t; -select a < 20230810 from t; -# 20231310 can't be converted to valid datetime, thus should be compared using real date type,and datetime will be -# converted to something like 'YYYYMMDDHHMMSS', bigger than 20231310 -select a < 20231310 from t; -select 20230809 < a from t; -select 20230809 = a from t; -select 20230810 > a from t; -select 20231310 > a from t; -# constant datetime cmp numeric constant should be compared as real data type -select cast('2023-08-09 00:00:00' as datetime) > 20230809 from t; -select cast('2023-08-09 00:00:00' as datetime) = 20230809 from t; -select cast('2023-08-09 00:00:00' as datetime) < 20230810 from t; -select cast('2023-08-09 00:00:00' as datetime) < 20231310 from t; -select 20230809 < cast('2023-08-09 00:00:00' as datetime) from t; -select 20230809 = cast('2023-08-09 00:00:00' as datetime) from t; -select 20230810 > cast('2023-08-09 00:00:00' as datetime) from t; -select 20231310 > cast('2023-08-09 00:00:00' as datetime) from t; -# datetime column cmp numeric column should be compared as real data type -select a > b from t; -select a = b from t; -select a < b + 1 from t; -select a < c from t; -select b < a from t; -select b = a from t; -select b > a from t; -select c > a from t; - -# TestLoadStats --- error 1064 -load stats; --- error 1064 -load stats ./xxx.json; - -# TestShow -drop database if exists test_show; -create database test_show; -use test_show; -show engines; -drop table if exists t; -create table t(a int primary key); -show index in t; -show index from t; ---replace_column 2 0 -show master status; -show create database test_show; -show privileges; ---replace_column 12 0 -show table status; - -drop database test_show; -use executor__executor; - -# TestSelectBackslashN -# Issue 3685. -select \N; -select "\N"; - -drop table if exists test; -create table test (`\N` int); -insert into test values (1); -select * from test; -select \N from test; -select (\N) from test; -select `\N` from test; -select (`\N`) from test; -select '\N' from test; -select ('\N') from test; - -# TestSelectNull -# Issue #4053. -select nUll; -select (null); -select null+NULL; - -# TestSelectStringLiteral Issue #3686. -select 'abc'; -select (('abc')); -select 'abc'+'def'; -## Below checks whether leading invalid chars are trimmed. -select '\n'; -## Lowercased letter is a valid char. -select '\t col'; -## Uppercased letter is a valid char. -select '\t Col'; -## Chinese char is a valid char. -select '\n\t 中文 col'; -## Punctuation is a valid char. -select ' \r\n .col'; -## Emoji is a valid char. -select ' 😆col'; -## Below checks whether trailing invalid chars are preserved. -select 'abc '; -select ' abc 123 '; -## Issue #4239. -select 'a' ' ' 'string'; -select 'a' " " "string"; -select 'string' 'string'; -select "ss" "a"; -select "ss" "a" "b"; -select "ss" "a" ' ' "b"; -select "ss" "a" ' ' "b" ' ' "d"; - -# TestUpdateClustered -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 int, k2 int, v int); -create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); -insert into a values (1, 1, 1), (2, 2, 2); -insert into b values (2, 2, 2, 2); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; -select * from b; -select * from a; -admin check table a; -admin check table b; -drop table if exists a, b; -create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); -create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); -insert into a values ('11', '11', '11'), ('22', '22', '22'); -insert into b values ('22', '22', '22', '22'); -update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); -select * from b; -select * from a; -admin check table a; -admin check table b; - -# TestClusterIndexOuterJoinElimination -set @@tidb_enable_clustered_index=On; -drop table if exists t; -create table t (a int, b int, c int, primary key(a,b)); -explain format = 'brief' select t1.a from t t1 left join t t2 on t1.a = t2.a and t1.b = t2.b; -set @@tidb_enable_clustered_index=default; - -# TestExecutorBit -drop table if exists t; -create table t (c1 bit(2)); -insert into t values (0), (1), (2), (3); --- error 1406 -insert into t values (4); --- error 1406 -insert into t values ('a'); -select hex(c1) from t where c1 = 2; -drop table if exists t; -create table t (c1 bit(31)); -insert into t values (0x7fffffff); --- error 1406 -insert into t values (0x80000000); --- error 1406 -insert into t values (0xffffffff); -insert into t values ('123'); -insert into t values ('1234'); --- error 1064 -insert into t values ('12345); -drop table if exists t; -create table t (c1 bit(62)); -insert into t values ('12345678'); -drop table if exists t; -create table t (c1 bit(61)); --- error 1406 -insert into t values ('12345678'); -drop table if exists t; -create table t (c1 bit(32)); -insert into t values (0x7fffffff); -insert into t values (0xffffffff); --- error 1406 -insert into t values (0x1ffffffff); -insert into t values ('1234'); --- error 1406 -insert into t values ('12345'); -drop table if exists t; -create table t (c1 bit(64)); -insert into t values (0xffffffffffffffff); -insert into t values ('12345678'); --- error 1366 -insert into t values ('123456789'); -drop table if exists t; -create table t (c1 bit(64)); -insert into t values (0xffffffffffffffff); -insert into t values ('12345678'); -select hex(c1) from t where c1; - -# TestTimestampTimeZone -drop table if exists t, t1; -create table t (ts timestamp); -set time_zone = '+00:00'; -insert into t values ('2017-04-27 22:40:42'); -set time_zone = '+10:00'; -select * from t; -set time_zone = '-6:00'; -select * from t; - -## For issue https://github.com/pingcap/tidb/issues/3467 -drop table if exists t1; -CREATE TABLE t1 ( - id bigint(20) NOT NULL AUTO_INCREMENT, - uid int(11) DEFAULT NULL, - datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - ip varchar(128) DEFAULT NULL, -PRIMARY KEY (id), - KEY i_datetime (datetime), - KEY i_userid (uid) -); -INSERT INTO t1 VALUES (123381351,1734,"2014-03-31 08:57:10","127.0.0.1"); -select datetime from t1; -select datetime from t1 where datetime='2014-03-31 08:57:10'; -select * from t1 where datetime='2014-03-31 08:57:10'; - -## For issue https://github.com/pingcap/tidb/issues/3485 -set time_zone = 'Asia/Shanghai'; -drop table if exists t1; -CREATE TABLE t1 ( - id bigint(20) NOT NULL AUTO_INCREMENT, - datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (id) -); -INSERT INTO t1 VALUES (123381351,"2014-03-31 08:57:10"); -select * from t1 where datetime="2014-03-31 08:57:10"; -alter table t1 add key i_datetime (datetime); -select * from t1 where datetime="2014-03-31 08:57:10"; -select * from t1; -select datetime from t1 where datetime='2014-03-31 08:57:10'; -set time_zone=default; - -# TestInsertValuesWithSubQuery -# this is from jira issue #5856 -drop table if exists t2; -create table t2(a int, b int, c int); --- error 1054 -insert into t2 values (11, 8, (select not b)); --- error 1064 -insert into t2 set a = 11, b = 8, c = (select b)); -insert into t2 values(1, 1, (select b from t2)); -select * from t2; -insert into t2 set a = 1, b = 1, c = (select b+1 from t2); -select * from t2; -delete from t2; -insert into t2 values(2, 4, a); -select * from t2; -insert into t2 set a = 3, b = 5, c = b; -select * from t2; - -## issue #30626 -drop table if exists t; -create table t(a int, b int); -## TODO: should insert success and get (81,1) from the table --- error 1105 -insert into t values ( 81, ( select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ) ); --- error 1105 -insert into t set a = 81, b = (select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ); -drop table if exists t2; - -# TestBitColumnIn -# fix issue https://github.com/pingcap/tidb/issues/32871 -drop table if exists t; -create table t (id bit(16), key id(id)); -insert into t values (65); -select * from t where id not in (-1,2); --- error 1582 -select * from t where id in (-1, -2); - -# TestProjectionBitType -drop table if exists t; -drop table if exists t1; -create table t(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) clustered); -create table t1(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) nonclustered); -insert into t(k1) select 1; -insert into t1(k1) select 1; -set @@tidb_enable_vectorized_expression = 0; -(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); -(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); -set @@tidb_enable_vectorized_expression = 1; -(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); -(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); - -set @@tidb_enable_vectorized_expression = default; - -# TestIssue24933 -drop table if exists t; -drop view if exists v; -create table t(a int); -insert into t values(1), (2), (3); -create definer='root'@'localhost' view v as select count(*) as c1 from t; -select * from v; -drop view v; -create definer='root'@'localhost' view v as select * from (select count(*) from t) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select avg(a) from t group by a) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select sum(a) from t group by a) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select group_concat(a) from t group by a) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select count(0) as c1 from t) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select count(*) as c1 from t) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select group_concat(a) as `concat(a)` from t group by a) s; -select * from v order by 1; -drop view v; -create definer='root'@'localhost' view v as select * from (select a from t group by a) s; -select * from v order by 1; --- error 1054 -SELECT `s`.`count(a)` FROM (SELECT COUNT(`a`) FROM `executor__executor`.`t`) AS `s`; -drop view v; -create definer='root'@'localhost' view v as select * from (select count(a) from t) s; -select * from v; -drop table if exists t; -create table t(c1 int); -insert into t values(111), (222), (333); -drop view if exists v; -create definer='root'@'localhost' view v as (select * from (select row_number() over (order by c1) from t) s); -select * from v; -drop view if exists v; -create definer='root'@'localhost' view v as (select * from (select c1, row_number() over (order by c1) from t) s); -select * from v; -drop view if exists v; -create definer='root'@'localhost' view v as (select * from (select c1 or 0 from t) s); -select * from v; -select `c1 or 0` from v; -drop view v; - -# TestCTEWithIndexLookupJoinDeadLock -drop table if exists t, t1, t2; -create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b)); -create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); -create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); - -## It's easy to reproduce this problem in 30 times execution of IndexLookUpJoin. ---disable_result_log -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; -with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; ---enable_result_log - -# TestAdminChecksumOfPartitionedTable -DROP TABLE IF EXISTS admin_checksum_partition_test; -CREATE TABLE admin_checksum_partition_test (a INT) PARTITION BY HASH(a) PARTITIONS 4; -INSERT INTO admin_checksum_partition_test VALUES (1), (2); -## The result is different with TiKV and unistore ---disable_result_log -ADMIN CHECKSUM TABLE admin_checksum_partition_test; ---enable_result_log - -# TestSQLMode -drop table if exists t; -create table t (a tinyint not null); -set sql_mode = 'STRICT_TRANS_TABLES'; --- error 1364 -insert t values (); --- error 1264 -insert t values ('1000'); -create table if not exists tdouble (a double(3,2)); --- error 1264 -insert tdouble values (10.23); -set sql_mode = ''; -insert t values (); -show warnings; --- error 1048 -insert t values (null); -insert ignore t values (null); -show warnings; -insert t select null; -show warnings; -insert t values (1000); -select * from t order by a; -insert tdouble values (10.23); -select * from tdouble; -set sql_mode = 'STRICT_TRANS_TABLES'; -set @@global.sql_mode = ''; - -connect (conn1, localhost, root,, executor__executor); -drop table if exists t2; -create table t2 (a varchar(3)); -insert t2 values ('abcd'); -select * from t2; -connection default; -disconnect conn1; - --- error 1406 -insert t2 values ('abcd'); -set sql_mode = default; -set @@global.sql_mode = default; - -# TestTableScan -use information_schema; -## There must be these tables: information_schema, mysql, performance_schema and test. -select count(*)>=4 from schemata; -create database mytest; -use information_schema; -select * from schemata where schema_name = 'mysql'; -select * from schemata where schema_name like 'my%'; -select 1 from tables limit 1; -use executor__executor; - -# TestAddDateBuiltinWithWarnings -set @@sql_mode='NO_ZERO_DATE'; -select date_add('2001-01-00', interval -2 hour); -show warnings; -set @@sql_mode=default; - -# TestStrToDateBuiltinWithWarnings -set @@sql_mode='NO_ZERO_DATE'; -drop table if exists t1; -SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d'); -show warnings; -SELECT CAST('4#,8?Q' AS DATE); -show warnings; -CREATE TABLE t1 (c1 INT, c2 TEXT); -INSERT INTO t1 VALUES (1833458842, '0.3503490908550797'); -SELECT CAST(t1.c2 AS DATE) FROM t1; -show warnings; -set @@sql_mode=default; - -# TestUnsignedDecimalOverflow -drop table if exists t; -create table t(a decimal(10,2) unsigned); --- error 1264 -insert into t values (-1); --- error 1264 -insert into t values ("-1.1e-1"); --- error 1264 -insert into t values (-1.1); -insert into t values (-0); -set sql_mode=''; -delete from t; -insert into t values (-1); -select a from t limit 1; -set sql_mode=default; - -# TestDoSubquery -drop table if exists t; -create table t(a int); -do 1 in (select * from t); -insert into t values(1); -do 1 in (select * from t); - -# TestCountDistinctJSON -drop table if exists t; -create table t(j JSON); -insert into t values('2010'); -insert into t values('2011'); -insert into t values('2012'); -insert into t values('2010.000'); -insert into t values(cast(18446744073709551615 as JSON)); -insert into t values(cast(18446744073709551616.000000 as JSON)); -select count(distinct j) from t; - -# TestHashJoinJSON -drop table if exists t; -create table t(id int(11), j JSON, d DOUBLE); -insert into t values(0, '2010', 2010); -insert into t values(1, '2011', 2011); -insert into t values(2, '2012', 2012); -insert into t values(3, cast(18446744073709551615 as JSON), 18446744073709551616.000000); -select /*+inl_hash_join(t2)*/ t1.id, t2.id from t t1 join t t2 on t1.j = t2.d; - -# TestPlanReplayerDumpTPCDS -drop table if exists catalog_sales, store_sales, date_dim; -create table catalog_sales -( - cs_sold_date_sk int , - cs_sold_time_sk int , - cs_ship_date_sk int , - cs_bill_customer_sk int , - cs_bill_cdemo_sk int , - cs_bill_hdemo_sk int , - cs_bill_addr_sk int , - cs_ship_customer_sk int , - cs_ship_cdemo_sk int , - cs_ship_hdemo_sk int , - cs_ship_addr_sk int , - cs_call_center_sk int , - cs_catalog_page_sk int , - cs_ship_mode_sk int , - cs_warehouse_sk int , - cs_item_sk int not null, - cs_promo_sk int , - cs_order_number int not null, - cs_quantity int , - cs_wholesale_cost decimal(7,2) , - cs_list_price decimal(7,2) , - cs_sales_price decimal(7,2) , - cs_ext_discount_amt decimal(7,2) , - cs_ext_sales_price decimal(7,2) , - cs_ext_wholesale_cost decimal(7,2) , - cs_ext_list_price decimal(7,2) , - cs_ext_tax decimal(7,2) , - cs_coupon_amt decimal(7,2) , - cs_ext_ship_cost decimal(7,2) , - cs_net_paid decimal(7,2) , - cs_net_paid_inc_tax decimal(7,2) , - cs_net_paid_inc_ship decimal(7,2) , - cs_net_paid_inc_ship_tax decimal(7,2) , - cs_net_profit decimal(7,2) , - primary key (cs_item_sk, cs_order_number) -); -create table store_sales -( - ss_sold_date_sk int , - ss_sold_time_sk int , - ss_item_sk int not null, - ss_customer_sk int , - ss_cdemo_sk int , - ss_hdemo_sk int , - ss_addr_sk int , - ss_store_sk int , - ss_promo_sk int , - ss_ticket_number int not null, - ss_quantity int , - ss_wholesale_cost decimal(7,2) , - ss_list_price decimal(7,2) , - ss_sales_price decimal(7,2) , - ss_ext_discount_amt decimal(7,2) , - ss_ext_sales_price decimal(7,2) , - ss_ext_wholesale_cost decimal(7,2) , - ss_ext_list_price decimal(7,2) , - ss_ext_tax decimal(7,2) , - ss_coupon_amt decimal(7,2) , - ss_net_paid decimal(7,2) , - ss_net_paid_inc_tax decimal(7,2) , - ss_net_profit decimal(7,2) , - primary key (ss_item_sk, ss_ticket_number) -); -create table date_dim -( - d_date_sk int not null, - d_date_id char(16) not null, - d_date date , - d_month_seq int , - d_week_seq int , - d_quarter_seq int , - d_year int , - d_dow int , - d_moy int , - d_dom int , - d_qoy int , - d_fy_year int , - d_fy_quarter_seq int , - d_fy_week_seq int , - d_day_name char(9) , - d_quarter_name char(6) , - d_holiday char(1) , - d_weekend char(1) , - d_following_holiday char(1) , - d_first_dom int , - d_last_dom int , - d_same_day_ly int , - d_same_day_lq int , - d_current_day char(1) , - d_current_week char(1) , - d_current_month char(1) , - d_current_quarter char(1) , - d_current_year char(1) , - primary key (d_date_sk) -); ---disable_result_log -plan replayer dump explain with ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci left join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -UNION - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci right join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100; ---enable_result_log - -# TestBDRRole -admin show bdr role; -admin set bdr role primary; -admin show bdr role; -admin set bdr role secondary; -admin show bdr role; -admin unset bdr role; -admin show bdr role; ---error 1064 -admin set bdr role test_err; -admin show bdr role; -admin unset bdr role; - -# TestCompileOutOfMemoryQuota -# Test for issue: https://github.com/pingcap/tidb/issues/38322 -set global tidb_mem_oom_action='CANCEL'; -drop table if exists t, t1; -create table t(a int, b int, index idx(a)); -create table t1(a int, c int, index idx(a)); -set tidb_mem_quota_query=10; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -select t.a, t1.a from t use index(idx), t1 use index(idx) where t.a = t1.a; -set global tidb_mem_oom_action=default; -set tidb_mem_quota_query=default; - -# TestOOMPanicAction -drop table if exists t, t1; -create table t (a int primary key, b double); -insert into t values (1,1); -SET GLOBAL tidb_mem_oom_action='CANCEL'; -set @@tidb_mem_quota_query=1; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -select sum(b) from t group by a; - -## Test insert from select oom panic. -drop table if exists t,t1; -create table t (a bigint); -create table t1 (a bigint); -set @@tidb_mem_quota_query=200; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -insert into t1 values (1),(2),(3),(4),(5); --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -replace into t1 values (1),(2),(3),(4),(5); -set @@tidb_mem_quota_query=10000; -insert into t1 values (1),(2),(3),(4),(5); -set @@tidb_mem_quota_query=10; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -insert into t select a from t1 order by a desc; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -replace into t select a from t1 order by a desc; -set @@tidb_mem_quota_query=10000; -insert into t values (1),(2),(3),(4),(5); -## Set the memory quota to 244 to make this SQL panic during the DeleteExec -## instead of the TableReaderExec. -set @@tidb_mem_quota_query=244; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -delete from t; -set @@tidb_mem_quota_query=10000; -delete from t1; -insert into t1 values(1); -insert into t values (1),(2),(3),(4),(5); -set @@tidb_mem_quota_query=244; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -delete t, t1 from t join t1 on t.a = t1.a; -set @@tidb_mem_quota_query=100000; -truncate table t; -insert into t values(1),(2),(3); -## set the memory to quota to make the SQL panic during UpdateExec instead -## of TableReader. -set @@tidb_mem_quota_query=244; --- replace_regex /conn=[-0-9]+/conn=/ --- error 8175 -update t set a = 4; - -SET GLOBAL tidb_mem_oom_action = DEFAULT; -set @@tidb_mem_quota_query=DEFAULT; - -# TestTrackAggMemoryUsage -drop table if exists t; -create table t(a int); -insert into t values(1); -set tidb_track_aggregate_memory_usage = off; - ---replace_column 5 6 ---replace_regex /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ -explain analyze select /*+ HASH_AGG() */ sum(a) from t; - ---replace_column 5 6 ---replace_regex /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ -explain analyze select /*+ STREAM_AGG() */ sum(a) from t; - -set tidb_track_aggregate_memory_usage = on; - ---replace_column 5 6 ---replace_regex /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ -explain analyze select /*+ HASH_AGG() */ sum(a) from t; - ---replace_column 5 6 ---replace_regex /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ -explain analyze select /*+ STREAM_AGG() */ sum(a) from t; - -set tidb_track_aggregate_memory_usage = default; - -# TestBind -drop table if exists testbind; -create table testbind(i int, s varchar(20)); -create index index_t on testbind(i,s); -create global binding for select * from testbind using select * from testbind use index for join(index_t); ---replace_column 5 6 -show global bindings where default_db='executor__executor'; -create session binding for select * from testbind using select * from testbind use index for join(index_t); ---replace_column 5 6 -show session bindings where default_db='executor__executor'; - -drop session binding for select * from testbind using select * from testbind use index for join(index_t); -drop global binding for select * from testbind using select * from testbind use index for join(index_t); - -# TestIndexMergeRuntimeStats -drop table if EXISTS t1; -create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); -insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); ---replace_regex /.*time:.*loops:.*cop_task:.*/.*time:.*loops:.*cop_task:.*/ /.*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.*/.*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.*/ /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ -explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; -set @@tidb_enable_collect_execution_info=0; -select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; -set @@tidb_enable_collect_execution_info=default; - -# TestIndexLookupRuntimeStats -drop table if exists t1; -create table t1 (a int, b int, index(a)); -insert into t1 values (1,2),(2,3),(3,4); ---replace_regex /.*time:.*loops:.*index_task:.*table_task: {total_time.*num.*concurrency.*}.*/.*time:.*loops:.*index_task:.*table_task: {total_time.*num.*concurrency.*}.*/ /.*time:.*loops:.*cop_task:.*/.*time:.*loops:.*cop_task:.*/ /[.0-9]+ KB/ KB/ /[0-9]+ Bytes/ Bytes/ -explain analyze select * from t1 use index(a) where a > 1; - -# TestHashAggRuntimeStats -drop table if exists t1; -create table t1 (a int, b int); -insert into t1 values (1,2),(2,3),(3,4); ---replace_regex /.*time:.*loops:.*partial_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*final_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*/.*time:.*loops:.*partial_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*final_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*/ /time:.*loops:.*cop_task.*/time.*loops.*cop_task.*/ /tikv_task:.*/tikv_task:.*/ /[.0-9]+ KB/ KB/ /[.0-9]+ Bytes/ Bytes/ -explain analyze SELECT /*+ HASH_AGG() */ count(*) FROM t1 WHERE a < 10; - -# TestSelectForUpdate -set global tidb_txn_mode=''; -drop table if exists t, t1; -create table t (c1 int, c2 int, c3 int); -insert t values (11, 2, 3); -insert t values (12, 2, 3); -insert t values (13, 2, 3); -create table t1 (c1 int); -insert t1 values (11); - -connect (conn1, localhost, root,, executor__executor); -begin; -select * from t where c1=11 for update; - -connect (conn2, localhost, root,, executor__executor); -begin; -update t set c2=211 where c1=11; -commit; - -connection conn1; ---replace_regex /txnStartTS.*reason/ reason/ ---error 9007 -commit; - -begin; -select * from t where exists(select null from t1 where t1.c1=t.c1) for update; - -connection conn2; -begin; -update t set c2=211 where c1=12; -commit; - -connection conn1; -commit; - -begin; -select * from t where c1=11 for update; - -connection conn2; -begin; -update t set c2=22 where c1=12; -commit; - -connection conn1; -commit; - -set @@autocommit=1; -select * from t where c1=11 for update; - -connection conn2; -begin; -update t set c2=211 where c1=11; -commit; - -connection conn1; -commit; - -begin; ---sorted_result -select * from (select * from t for update) t join t1 for update; - -connection conn2; -begin; -update t1 set c1 = 13; -commit; - -connection conn1; ---replace_regex /txnStartTS.*reason/ reason/ ---error 9007 -commit; - -disconnect conn1; -disconnect conn2; -set global tidb_txn_mode=pessimistic; - -# TestSelectForUpdateOf -drop table if exists t, t1; -create table t (i int); -create table t1 (i int); -insert t values (1); -insert t1 values (1); -begin pessimistic; -select * from t, t1 where t.i = t1.i for update of t; - -connect (conn1, localhost, root,, executor__executor); -begin pessimistic; -select * from t1 for update; ---error 3572 -select * from t for update nowait; - -connection default; -rollback; - -connection conn1; -select * from t for update nowait; -rollback; -disconnect conn1; - -# TestForSelectScopeInUnion -set session tidb_txn_mode=''; -# A union B for update, the "for update" option belongs to union statement, so -# it should works on both A and B. -drop table if exists t; -create table t(a int); -insert into t values (1); -begin; -select 1 as a union select a from t for update; - -connect (conn1, localhost, root,, executor__executor); -set session tidb_txn_mode=''; -update t set a = a + 1; - -connection default; -## As tk1 use select 'for update', it should detect conflict and fail. ---replace_regex /txnStartTS.*reason/ reason/ ---error 9007 -commit; - -begin; ---sorted_result -select 1 as a union select a from t limit 5 for update; -select 1 as a union select a from t order by a for update; - -connection conn1; -update t set a = a + 1; - -connection default; ---replace_regex /txnStartTS.*reason/ reason/ ---error 9007 -commit; - -disconnect conn1; -set session tidb_txn_mode=pessimistic; - -# TestAdminShowDDLJobsRowCount -# https://github.com/pingcap/tidb/issues/25968 -drop table if exists t; -create table t (id bigint key,b int); -split table t by (10),(20),(30); -insert into t values (0,0),(10,10),(20,20),(30,30); -alter table t add index idx1(b); ---replace_column 1 4 6 7 9 10 11 -admin show ddl jobs 1; - -insert into t values (1,0),(2,10),(3,20),(4,30); -alter table t add index idx2(b); ---replace_column 1 4 6 7 9 10 11 -admin show ddl jobs 1; - -# TestSummaryFailedUpdate -drop table if exists t; -create table t(a int, b int as(-a)); -insert into t(a) values(1), (3), (7); -SET GLOBAL tidb_mem_oom_action='CANCEL'; -set @@tidb_mem_quota_query=1; ---replace_regex /conn=[-0-9]+/conn=/ ---error 8175 -update t set t.a = t.a - 1 where t.a in (select a from t where a < 4); -set @@tidb_mem_quota_query=1000000000; -select stmt_type from information_schema.statements_summary where digest_text = 'update `t` set `t` . `a` = `t` . `a` - ? where `t` . `a` in ( select `a` from `t` where `a` < ? )'; - -set @@tidb_mem_quota_query=default; -set global tidb_mem_oom_action=default; - - -# TestTableLockPrivilege -drop table if exists t; -drop user if exists 'testuser'@'localhost'; -create table t(a int); -create user 'testuser'@'localhost'; - -connect (conn1, localhost, testuser,,); ---error 1044 -LOCK TABLE executor__executor.t WRITE; - -connection default; -GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; - -connection conn1; ---error 1142 -LOCK TABLE executor__executor.t WRITE; - -connection default; -REVOKE ALL ON executor__executor.* FROM 'testuser'@'localhost'; -GRANT SELECT ON executor__executor.* to 'testuser'@'localhost'; - -connection conn1; ---error 1044 -LOCK TABLE executor__executor.t WRITE; - -connection default; -GRANT LOCK TABLES ON executor__executor.* to 'testuser'@'localhost'; - -connection conn1; -LOCK TABLE executor__executor.t WRITE; - -connection default; -drop database if exists test2; -create database test2; -create table test2.t2(a int); - -connection conn1; ---error 1044 -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; - -connection default; -GRANT LOCK TABLES ON test2.* to 'testuser'@'localhost'; - -connection conn1; ---error 1142 -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; - -connection default; -GRANT SELECT ON test2.* to 'testuser'@'localhost'; - -connection conn1; -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; - -connection default; ---replace_regex /server: .*session: .*/server: session: / ---error 8020 -LOCK TABLE executor__executor.t WRITE, test2.t2 WRITE; - -connection conn1; -unlock tables; - -disconnect conn1; -unlock tables; -drop user 'testuser'@'localhost'; diff --git a/tests/integrationtest/t/executor/insert.test b/tests/integrationtest/t/executor/insert.test deleted file mode 100644 index 07cf8bcd82c8a..0000000000000 --- a/tests/integrationtest/t/executor/insert.test +++ /dev/null @@ -1,1646 +0,0 @@ -# TestClusterIndexInsertOnDuplicateKey -set tidb_enable_clustered_index = on; -drop table if exists t; -create table t(a char(20), b int, primary key(a)); -insert into t values('aa', 1), ('bb', 1); --- error 1062 -insert into t values('aa', 2); -drop table t; -create table t(a char(20), b varchar(30), c varchar(10), primary key(a, b, c)); -insert into t values ('a', 'b', 'c'), ('b', 'a', 'c'); --- error 1062 -insert into t values ('a', 'b', 'c'); -set tidb_enable_clustered_index = default; - -# TestPaddingCommonHandle -set tidb_enable_clustered_index = on; -drop table if exists t1; -create table t1(c1 decimal(6,4), primary key(c1)); -insert into t1 set c1 = 0.1; -insert into t1 set c1 = 0.1 on duplicate key update c1 = 1; -select * from t1; -set tidb_enable_clustered_index = default; - -# TestInsertReorgDelete -drop table if exists t1; -create table t1(c1 year); -insert into t1 set c1 = '2004'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 year); -insert into t1 set c1 = 2004; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 bit); -insert into t1 set c1 = 1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 smallint unsigned); -insert into t1 set c1 = 1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 int unsigned); -insert into t1 set c1 = 1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 smallint); -insert into t1 set c1 = -1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 int); -insert into t1 set c1 = -1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 decimal(6,4)); -insert into t1 set c1 = '1.1'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 decimal); -insert into t1 set c1 = 1.1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 numeric); -insert into t1 set c1 = -1; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 float); -insert into t1 set c1 = 1.2; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 double); -insert into t1 set c1 = 1.2; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 double); -insert into t1 set c1 = 1.3; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 real); -insert into t1 set c1 = 1.4; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 date); -insert into t1 set c1 = '2020-01-01'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 time); -insert into t1 set c1 = '20:00:00'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 datetime); -insert into t1 set c1 = '2020-01-01 22:22:22'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 timestamp); -insert into t1 set c1 = '2020-01-01 22:22:22'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 year); -insert into t1 set c1 = '2020'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 char(15)); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 varchar(15)); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 binary(3)); -insert into t1 set c1 = 'a'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 varbinary(3)); -insert into t1 set c1 = 'b'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 blob); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1(3)); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 text); -insert into t1 set c1 = 'test'; -alter table t1 add index idx(c1(3)); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 enum('a', 'b')); -insert into t1 set c1 = 'a'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; -drop table if exists t1; -create table t1(c1 set('a', 'b')); -insert into t1 set c1 = 'a,b'; -alter table t1 add index idx(c1); -delete from t1; -admin check table t1; - -# TestUpdateDuplicateKey -drop table if exists c; -create table c(i int,j int,k int,primary key(i,j,k)); -insert into c values(1,2,3); -insert into c values(1,2,4); --- error 1062 -update c set i=1,j=2,k=4 where i=1 and j=2 and k=3; - -# TestIssue37187 -drop table if exists t1, t2; -create table t1 (a int(11) ,b varchar(100) ,primary key (a)); -create table t2 (c int(11) ,d varchar(100) ,primary key (c)); -prepare in1 from 'insert into t1 (a,b) select c,null from t2 t on duplicate key update b=t.d'; -execute in1; - -# TestInsertWrongValueForField -drop table if exists t1; -create table t1(a bigint); --- error 1366 -insert into t1 values("asfasdfsajhlkhlksdaf"); -drop table if exists t1; -create table t1(a varchar(10)) charset ascii; --- error 1366 -insert into t1 values('我'); -drop table if exists t1; -create table t1(a char(10) charset utf8); -insert into t1 values('我'); -alter table t1 add column b char(10) charset ascii as ((a)); -select * from t1; -drop table if exists t; -create table t (a year); --- error 1264 -insert into t values(2156); -DROP TABLE IF EXISTS ts; -CREATE TABLE ts (id int DEFAULT NULL, time1 TIMESTAMP NULL DEFAULT NULL); -SET @@sql_mode=''; -INSERT INTO ts (id, time1) VALUES (1, TIMESTAMP '1018-12-23 00:00:00'); -SHOW WARNINGS; -SELECT * FROM ts ORDER BY id; -SET @@sql_mode='STRICT_TRANS_TABLES'; --- error 1292 -INSERT INTO ts (id, time1) VALUES (2, TIMESTAMP '1018-12-24 00:00:00'); -DROP TABLE ts; -CREATE TABLE t0(c0 SMALLINT AUTO_INCREMENT PRIMARY KEY); -INSERT IGNORE INTO t0(c0) VALUES (194626268); -INSERT IGNORE INTO t0(c0) VALUES ('*'); -SHOW WARNINGS; -SET @@sql_mode=default; - -# TestInsertValueForCastDecimalField -drop table if exists t1; -create table t1(a decimal(15,2)); -insert into t1 values (1111111111111.01); -select * from t1; -select cast(a as decimal) from t1; - -# TestInsertForMultiValuedIndex -drop table if exists t1; -create table t1(a json, b int, unique index idx((cast(a as signed array)))); -insert into t1 values ('[1,11]', 1); -insert into t1 values ('[2, 22]', 2); -select * from t1; --- error 1062 -insert into t1 values ('[2, 222]', 2); -replace into t1 values ('[1, 10]', 10); -select * from t1; -replace into t1 values ('[1, 2]', 1); -select * from t1; -replace into t1 values ('[1, 11]', 1); -insert into t1 values ('[2, 22]', 2); -select * from t1; -insert ignore into t1 values ('[1]', 2); -select * from t1; -insert ignore into t1 values ('[1, 2]', 2); -select * from t1; -insert into t1 values ('[2]', 2) on duplicate key update b = 10; -select * from t1; --- error 1062 -insert into t1 values ('[2, 1]', 2) on duplicate key update a = '[1,2]'; --- error 1062 -insert into t1 values ('[1,2]', 2) on duplicate key update a = '[1,2]'; --- error 1062 -insert into t1 values ('[11, 22]', 2) on duplicate key update a = '[1,2]'; - -# TestInsertDateTimeWithTimeZone -set time_zone="+09:00"; -drop table if exists t; -create table t (id int, c1 datetime not null default CURRENT_TIMESTAMP); -set TIMESTAMP = 1234; -insert t (id) values (1); -select * from t; -drop table if exists t; -create table t (dt datetime); -set @@time_zone='+08:00'; -delete from t; -insert into t values ('2020-10-22'); -select * from t; -delete from t; -insert into t values ('2020-10-22-16'); -select * from t; -delete from t; -insert into t values ('2020-10-22 16-31'); -select * from t; -delete from t; -insert into t values ('2020-10-22 16:31-15'); -select * from t; -delete from t; -insert into t values ('2020-10-22T16:31:15-10'); -select * from t; -delete from t; -insert into t values ('2020.10-22'); -select * from t; -delete from t; -insert into t values ('2020-10.22-16'); -select * from t; -delete from t; -insert into t values ('2020-10-22.16-31'); -select * from t; -delete from t; -insert into t values ('2020-10-22 16.31-15'); -select * from t; -delete from t; -insert into t values ('2020-10-22T16.31.15+14'); -select * from t; -delete from t; -insert into t values ('2020-10:22'); -select * from t; -delete from t; -insert into t values ('2020-10-22:16'); -select * from t; -delete from t; -insert into t values ('2020-10-22-16:31'); -select * from t; -delete from t; -insert into t values ('2020-10-22 16-31:15'); -select * from t; -delete from t; -insert into t values ('2020-10-22T16.31.15+09:30'); -select * from t; -delete from t; -insert into t values ('2020.10-22:16'); -select * from t; -delete from t; -insert into t values ('2020-10.22-16:31'); -select * from t; -delete from t; -insert into t values ('2020-10-22.16-31:15'); -select * from t; -delete from t; -insert into t values ('2020-10-22T16:31.15+09:30'); -select * from t; -drop table if exists t; -create table t (dt datetime, ts timestamp); -delete from t; -set @@time_zone='+08:00'; -insert into t values ('2020-10-22T16:53:40Z', '2020-10-22T16:53:40Z'); -set @@time_zone='+00:00'; -select * from t; -delete from t; -set @@time_zone='-08:00'; -insert into t values ('2020-10-22T16:53:40Z', '2020-10-22T16:53:40Z'); -set @@time_zone='+08:00'; -select * from t; -delete from t; -set @@time_zone='-03:00'; -insert into t values ('2020-10-22T16:53:40+03:00', '2020-10-22T16:53:40+03:00'); -set @@time_zone='+08:00'; -select * from t; -delete from t; -set @@time_zone='+08:00'; -insert into t values ('2020-10-22T16:53:40+08:00', '2020-10-22T16:53:40+08:00'); -set @@time_zone='+08:00'; -select * from t; -drop table if exists t; -create table t (ts timestamp); -insert into t values ('2020-10-22T12:00:00Z'), ('2020-10-22T13:00:00Z'), ('2020-10-22T14:00:00Z'); -select count(*) from t where ts > '2020-10-22T12:00:00Z'; -set @@time_zone='+08:00'; -drop table if exists t; -create table t (dt datetime(2), ts timestamp(2)); -insert into t values ('2020-10-27T14:39:10.10+00:00', '2020-10-27T14:39:10.10+00:00'); -select * from t; -drop table if exists t; -create table t (dt datetime(1), ts timestamp(1)); -insert into t values ('2020-10-27T14:39:10.3+0200', '2020-10-27T14:39:10.3+0200'); -select * from t; -drop table if exists t; -create table t (dt datetime(6), ts timestamp(6)); -insert into t values ('2020-10-27T14:39:10.3-02', '2020-10-27T14:39:10.3-02'); -select * from t; -drop table if exists t; -create table t (dt datetime(2), ts timestamp(2)); -insert into t values ('2020-10-27T14:39:10.10Z', '2020-10-27T14:39:10.10Z'); -select * from t; -set time_zone=default; -set timestamp=default; - -# TestInsertZeroYear -drop table if exists t1; -create table t1(a year(4)); -insert into t1 values(0000),(00),("0000"),("000"), ("00"), ("0"), (79), ("79"); -select * from t1; -drop table if exists t; -create table t(f_year year NOT NULL DEFAULT '0000')ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; -insert into t values(); -select * from t; -insert into t values('0000'); -select * from t; - -# TestAllowInvalidDates -drop table if exists t1, t2, t3, t4; -create table t1(d date); -create table t2(d datetime); -create table t3(d date); -create table t4(d datetime); -set sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES'; -insert into t1 values ('0000-00-00'); -insert into t2 values ('0000-00-00'); -insert into t1 values ('2019-00-00'); -insert into t2 values ('2019-00-00'); -insert into t1 values ('2019-01-00'); -insert into t2 values ('2019-01-00'); -insert into t1 values ('2019-00-01'); -insert into t2 values ('2019-00-01'); -insert into t1 values ('2019-02-31'); -insert into t2 values ('2019-02-31'); -select year(d), month(d), day(d) from t1; -select year(d), month(d), day(d) from t2; -insert t3 select d from t1; -select year(d), month(d), day(d) from t3; -insert t4 select d from t2; -select year(d), month(d), day(d) from t4; - -truncate t1;truncate t2;truncate t3;truncate t4; -set sql_mode='ALLOW_INVALID_DATES'; -insert into t1 values ('0000-00-00'); -insert into t2 values ('0000-00-00'); -insert into t1 values ('2019-00-00'); -insert into t2 values ('2019-00-00'); -insert into t1 values ('2019-01-00'); -insert into t2 values ('2019-01-00'); -insert into t1 values ('2019-00-01'); -insert into t2 values ('2019-00-01'); -insert into t1 values ('2019-02-31'); -insert into t2 values ('2019-02-31'); -select year(d), month(d), day(d) from t1; -select year(d), month(d), day(d) from t2; -insert t3 select d from t1; -select year(d), month(d), day(d) from t3; -insert t4 select d from t2; -select year(d), month(d), day(d) from t4; -set sql_mode=default; - -# TestPartitionInsertOnDuplicate -drop table if exists t1, t2, t3; -create table t1 (a int,b int,primary key(a,b)) partition by range(a) (partition p0 values less than (100),partition p1 values less than (1000)); -insert into t1 set a=1, b=1; -insert into t1 set a=1,b=1 on duplicate key update a=1,b=1; -select * from t1; -create table t2 (a int,b int,primary key(a,b)) partition by hash(a) partitions 4; -insert into t2 set a=1,b=1; -insert into t2 set a=1,b=1 on duplicate key update a=1,b=1; -select * from t2; -CREATE TABLE t3 (a int, b int, c int, d int, e int, - PRIMARY KEY (a,b), - UNIQUE KEY (b,c,d) -) PARTITION BY RANGE ( b ) ( - PARTITION p0 VALUES LESS THAN (4), - PARTITION p1 VALUES LESS THAN (7), - PARTITION p2 VALUES LESS THAN (11) -); -insert into t3 values (1,2,3,4,5); -insert into t3 values (1,2,3,4,5),(6,2,3,4,6) on duplicate key update e = e + values(e); -select * from t3; - -# TestBit -drop table if exists t1; -create table t1 (a bit(3)); --- error 1406 -insert into t1 values(-1); --- error 1406 -insert into t1 values(9); -create table t64 (a bit(64)); -insert into t64 values(-1); -insert into t64 values(18446744073709551615); --- error 1264 -insert into t64 values(18446744073709551616); - -# TestJiraIssue5366 -drop table if exists bug; -create table bug (a varchar(100)); -insert into bug select ifnull(JSON_UNQUOTE(JSON_EXTRACT('[{"amount":2000,"feeAmount":0,"merchantNo":"20190430140319679394","shareBizCode":"20160311162_SECOND"}]', '$[0].merchantNo')),'') merchant_no union SELECT '20180531557' merchant_no; ---sorted_result -select * from bug; - -# TestDMLCast -drop table if exists t; -create table t (a int, b double); -insert into t values (ifnull('',0)+0, 0); -insert into t values (0, ifnull('',0)+0); -select * from t; --- error 1366 -insert into t values ('', 0); --- error 1366 -insert into t values (0, ''); --- error 1292 -update t set a = ''; --- error 1292 -update t set b = ''; -update t set a = ifnull('',0)+0; -update t set b = ifnull('',0)+0; -delete from t where a = ''; -select * from t; - -# TestInsertFloatOverflow -drop table if exists t,t1; -create table t(col1 FLOAT, col2 FLOAT(10,2), col3 DOUBLE, col4 DOUBLE(10,2), col5 DECIMAL, col6 DECIMAL(10,2)); --- error 1264 -insert into t values (-3.402823466E+68, -34028234.6611, -1.7976931348623157E+308, -17976921.34, -9999999999, -99999999.99); --- error 1264 -insert into t values (-34028234.6611, -3.402823466E+68, -1.7976931348623157E+308, -17976921.34, -9999999999, -99999999.99); -create table t1(id1 float,id2 float); -insert ignore into t1 values(999999999999999999999999999999999999999,-999999999999999999999999999999999999999); -select @@warning_count; -select convert(id1,decimal(65)),convert(id2,decimal(65)) from t1; - -# TestTextTooLongError -# Fix https://github.com/pingcap/tidb/issues/32601 -set sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; -# For max_allowed_packet default value is big enough to ensure tinytext, text can test correctly -drop table if exists t1; -CREATE TABLE t1(c1 TINYTEXT CHARACTER SET utf8mb4); --- error 1406 -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 128)); -drop table if exists t1; -CREATE TABLE t1(c1 Text CHARACTER SET utf8mb4); --- error 1406 -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 32768)); -drop table if exists t1; -CREATE TABLE t1(c1 mediumtext); --- error 1406 -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 8777215)); -# For long text, max_allowed_packet default value can not allow 4GB package, skip the test case. -# Set non strict sql_mode, we are not supposed to raise an error but to truncate the value. -set sql_mode = 'ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; -drop table if exists t1; -CREATE TABLE t1(c1 TINYTEXT CHARACTER SET utf8mb4); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 128)); -select length(c1) from t1; -drop table if exists t1; -CREATE TABLE t1(c1 Text CHARACTER SET utf8mb4); -INSERT INTO t1 (c1) VALUES(REPEAT(X'C385', 32768)); -select length(c1) from t1; -# For mediumtext or bigger size, for tikv limit, we will get:ERROR 8025 (HY000): entry too large, the max entry size is 6291456, the size of data is 16777247, no need to test. -set sql_mode = default; - -# TestAutoRandomIDExplicit -set @@allow_auto_random_explicit_insert = true; -drop table if exists ar; -create table ar (id bigint key clustered auto_random, name char(10)); -insert into ar(id) values (1); -select id from ar; -select last_insert_id(); -delete from ar; -insert into ar(id) values (1), (2); -select id from ar; -select last_insert_id(); -delete from ar; -drop table ar; -set @@allow_auto_random_explicit_insert = default; - -# TestInsertErrorMsg -drop table if exists t, t1; -create table t (a int primary key, b datetime, d date); --- error 1292 -insert into t values (1, '2019-02-11 30:00:00', '2019-01-31'); -CREATE TABLE t1 (a BINARY(16) PRIMARY KEY); -INSERT INTO t1 VALUES (AES_ENCRYPT('a','a')); --- error 1062 -INSERT INTO t1 VALUES (AES_ENCRYPT('a','a')); -INSERT INTO t1 VALUES (AES_ENCRYPT('b','b')); --- error 1062 -INSERT INTO t1 VALUES (AES_ENCRYPT('b','b')); -drop table if exists t1; -create table t1 (a bit primary key) engine=innodb; -insert into t1 values (b'0'); --- error 1062 -insert into t1 values (b'0'); - -# TestIssue16366 -drop table if exists t; -create table t(c numeric primary key); -insert ignore into t values(null); --- error 1062 -insert into t values(0); - -# TestClusterPrimaryTablePlainInsert -set tidb_enable_clustered_index = on; -drop table if exists t1pk; -create table t1pk(id varchar(200) primary key, v int); -insert into t1pk(id, v) values('abc', 1); -select * from t1pk; -set @@tidb_constraint_check_in_place=true; --- error 1062 -insert into t1pk(id, v) values('abc', 2); -set @@tidb_constraint_check_in_place=false; --- error 1062 -insert into t1pk(id, v) values('abc', 3); -select v, id from t1pk; -select id from t1pk where id = 'abc'; -select v, id from t1pk where id = 'abc'; -drop table if exists t3pk; -create table t3pk(id1 varchar(200), id2 varchar(200), v int, id3 int, primary key(id1, id2, id3)); -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 100, 1); -select * from t3pk; -set @@tidb_constraint_check_in_place=true; --- error 1062 -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 100, 2); -set @@tidb_constraint_check_in_place=false; --- error 1062 -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 100, 3); -select v, id3, id2, id1 from t3pk; -select id3, id2, id1 from t3pk where id3 = 100 and id2 = 'xyz' and id1 = 'abc'; -select id3, id2, id1, v from t3pk where id3 = 100 and id2 = 'xyz' and id1 = 'abc'; -insert into t3pk(id1, id2, id3, v) values('abc', 'xyz', 101, 1); -insert into t3pk(id1, id2, id3, v) values('abc', 'zzz', 101, 1); -drop table if exists t1pku; -create table t1pku(id varchar(200) primary key, uk int, v int, unique key ukk(uk)); -insert into t1pku(id, uk, v) values('abc', 1, 2); -select * from t1pku where id = 'abc'; --- error 1062 -insert into t1pku(id, uk, v) values('aaa', 1, 3); -select * from t1pku; -select * from t3pk where (id1, id2, id3) in (('abc', 'xyz', 100), ('abc', 'xyz', 101), ('abc', 'zzz', 101)); -set @@tidb_constraint_check_in_place=default; -set tidb_enable_clustered_index = default; - -# TestClusterPrimaryTableInsertIgnore -set tidb_enable_clustered_index = on; -drop table if exists it1pk; -create table it1pk(id varchar(200) primary key, v int); -insert into it1pk(id, v) values('abc', 1); -insert ignore into it1pk(id, v) values('abc', 2); -select * from it1pk where id = 'abc'; -drop table if exists it2pk; -create table it2pk(id1 varchar(200), id2 varchar(200), v int, primary key(id1, id2)); -insert into it2pk(id1, id2, v) values('abc', 'cba', 1); -select * from it2pk where id1 = 'abc' and id2 = 'cba'; -insert ignore into it2pk(id1, id2, v) values('abc', 'cba', 2); -select * from it2pk where id1 = 'abc' and id2 = 'cba'; -drop table if exists it1pku; -create table it1pku(id varchar(200) primary key, uk int, v int, unique key ukk(uk)); -insert into it1pku(id, uk, v) values('abc', 1, 2); -select * from it1pku where id = 'abc'; -insert ignore into it1pku(id, uk, v) values('aaa', 1, 3), ('bbb', 2, 1); -select * from it1pku; -set tidb_enable_clustered_index = default; - -# TestClusterPrimaryTableInsertDuplicate -set tidb_enable_clustered_index = on; -drop table if exists dt1pi; -create table dt1pi(id varchar(200) primary key, v int); -insert into dt1pi(id, v) values('abb', 1),('acc', 2); -insert into dt1pi(id, v) values('abb', 2) on duplicate key update v = v + 1; -select * from dt1pi; -insert into dt1pi(id, v) values('abb', 2) on duplicate key update v = v + 1, id = 'xxx'; -select * from dt1pi; -drop table if exists dt1piu; -create table dt1piu(id varchar(200) primary key, uk int, v int, unique key uuk(uk)); -insert into dt1piu(id, uk, v) values('abb', 1, 10),('acc', 2, 20); -insert into dt1piu(id, uk, v) values('xyz', 1, 100) on duplicate key update v = v + 1; -select * from dt1piu; -insert into dt1piu(id, uk, v) values('abb', 1, 2) on duplicate key update v = v + 1, id = 'xxx'; -select * from dt1piu; -drop table if exists ts1pk; -create table ts1pk(id1 timestamp, id2 timestamp, v int, primary key(id1, id2)); -insert into ts1pk (id1, id2, v) values('2018-01-01 11:11:11', '2018-01-01 11:11:11', 1); -select id1, id2, v from ts1pk; -insert into ts1pk (id1, id2, v) values('2018-01-01 11:11:11', '2018-01-01 11:11:11', 2) on duplicate key update v = values(v); -select id1, id2, v from ts1pk; -insert into ts1pk (id1, id2, v) values('2018-01-01 11:11:11', '2018-01-01 11:11:11', 2) on duplicate key update v = values(v), id1 = '2018-01-01 11:11:12'; -select id1, id2, v from ts1pk; -set tidb_enable_clustered_index = default; - -# TestClusterPrimaryKeyForIndexScan -set tidb_enable_clustered_index = on; -drop table if exists pkt1; -CREATE TABLE pkt1 (a varchar(255), b int, index idx(b), primary key(a,b)); -insert into pkt1 values ('aaa',1); -select b from pkt1 where b = 1; -drop table if exists pkt2; -CREATE TABLE pkt2 (a varchar(255), b int, unique index idx(b), primary key(a,b)); -insert into pkt2 values ('aaa',1); -select b from pkt2 where b = 1; -drop table if exists issue_18232; -create table issue_18232 (a int, b int, c int, d int, primary key (a, b), index idx(c)); -select a from issue_18232 use index (idx); -select b from issue_18232 use index (idx); -select a,b from issue_18232 use index (idx); -select c from issue_18232 use index (idx); -select a,c from issue_18232 use index (idx); -select b,c from issue_18232 use index (idx); -select a,b,c from issue_18232 use index (idx); -select d from issue_18232 use index (idx); -select a,d from issue_18232 use index (idx); -select b,d from issue_18232 use index (idx); -select a,b,d from issue_18232 use index (idx); -select c,d from issue_18232 use index (idx); -select a,c,d from issue_18232 use index (idx); -select b,c,d from issue_18232 use index (idx); -select a,b,c,d from issue_18232 use index (idx); -set tidb_enable_clustered_index = default; - -# TestIssue20768 -drop table if exists t1, t2; -create table t1(a year, primary key(a)); -insert ignore into t1 values(null); -create table t2(a int, key(a)); -insert into t2 values(0); -select /*+ hash_join(t1) */ * from t1 join t2 on t1.a = t2.a; -select /*+ inl_join(t1) */ * from t1 join t2 on t1.a = t2.a; -select /*+ inl_join(t2) */ * from t1 join t2 on t1.a = t2.a; -select /*+ inl_hash_join(t1) */ * from t1 join t2 on t1.a = t2.a; -select /*+ inl_merge_join(t1) */ * from t1 join t2 on t1.a = t2.a; -select /*+ merge_join(t1) */ * from t1 join t2 on t1.a = t2.a; - -# TestIssue10402 -drop table if exists vctt; -create table vctt (v varchar(4), c char(4)); -insert into vctt values ('ab ', 'ab '); -select * from vctt; -delete from vctt; -insert into vctt values ('ab\n\n\n', 'ab\n\n\n'), ('ab\t\t\t', 'ab\t\t\t'), ('ab ', 'ab '), ('ab\r\r\r', 'ab\r\r\r'); -show warnings; -select * from vctt; -select length(v), length(c) from vctt; - -# TestDuplicatedEntryErr -# See https://github.com/pingcap/tidb/issues/24582 -drop table if exists t1; -create table t1(a int, b varchar(20), primary key(a,b(3)) clustered); -insert into t1 values(1,'aaaaa'); --- error 1062 -insert into t1 values(1,'aaaaa'); --- error 1062 -insert into t1 select 1, 'aaa'; -insert into t1 select 1, 'bb'; --- error 1062 -insert into t1 select 1, 'bb'; - -# TestBinaryLiteralInsertToEnum -drop table if exists bintest; -create table bintest (h enum(0x61, '1', 'b')) character set utf8mb4; -insert into bintest(h) values(0x61); -select * from bintest; - -# TestBinaryLiteralInsertToSet -drop table if exists bintest; -create table bintest (h set(0x61, '1', 'b')) character set utf8mb4; -insert into bintest(h) values(0x61); -select * from bintest; - -# TestGlobalTempTableAutoInc -drop table if exists temp_test; -create global temporary table temp_test(id int primary key auto_increment) on commit delete rows; - -## Data is cleared after transaction auto commits. -insert into temp_test(id) values(0); -select * from temp_test; - -## Data is not cleared inside a transaction. -begin; -insert into temp_test(id) values(0); -select * from temp_test; -commit; - -## AutoID allocator is cleared. -begin; -insert into temp_test(id) values(0); -select * from temp_test; -## Test whether auto-inc is incremental -insert into temp_test(id) values(0); -select id from temp_test order by id; -commit; - -## multi-value insert -begin; -insert into temp_test(id) values(0), (0); -select id from temp_test order by id; -insert into temp_test(id) values(0), (0); -select id from temp_test order by id; -commit; - -## rebase -begin; -insert into temp_test(id) values(10); -insert into temp_test(id) values(0); -select id from temp_test order by id; -insert into temp_test(id) values(20), (30); -insert into temp_test(id) values(0), (0); -select id from temp_test order by id; -commit; -drop table if exists temp_test; - -# TestGlobalTempTableRowID -drop table if exists temp_test; -create global temporary table temp_test(id int) on commit delete rows; - -## Data is cleared after transaction auto commits. -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test; - -## Data is not cleared inside a transaction. -begin; -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test; -commit; - -## AutoID allocator is cleared. -begin; -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test; -## Test whether row id is incremental -insert into temp_test(id) values(0); -select _tidb_rowid from temp_test order by _tidb_rowid; -commit; - -## multi-value insert -begin; -insert into temp_test(id) values(0), (0); -select _tidb_rowid from temp_test order by _tidb_rowid; -insert into temp_test(id) values(0), (0); -select _tidb_rowid from temp_test order by _tidb_rowid; -commit; -drop table if exists temp_test; - -# TestIssue26762 -drop table if exists t1; -create table t1(c1 date); --- error 1292 -insert into t1 values('2020-02-31'); -set @@sql_mode='ALLOW_INVALID_DATES'; -insert into t1 values('2020-02-31'); -select * from t1; -set @@sql_mode='STRICT_TRANS_TABLES'; --- error 1292 -insert into t1 values('2020-02-31'); -set sql_mode=default; - -# TestStringtoDecimal -drop table if exists t; -create table t (id decimal(10)); --- error 1366 -insert into t values('1sdf'); --- error 1366 -insert into t values('1edf'); --- error 1366 -insert into t values('12Ea'); --- error 1366 -insert into t values('1E'); --- error 1366 -insert into t values('1e'); --- error 1366 -insert into t values('1.2A'); --- error 1366 -insert into t values('1.2.3.4.5'); --- error 1366 -insert into t values('1.2.'); --- error 1366 -insert into t values('1,999.00'); -## TODO: MySQL8.0 reports Note 1265 Data truncated for column 'id' at row 1 -insert into t values('12e-3'); -show warnings; -select id from t; -drop table if exists t; - -# TestReplaceAllocatingAutoID -# https://github.com/pingcap/tidb/issues/29483 -SET sql_mode='NO_ENGINE_SUBSTITUTION'; -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (a tinyint not null auto_increment primary key, b char(20)); -INSERT INTO t1 VALUES (127,'maxvalue'); -## Note that this error is different from MySQL's duplicated primary key error --- error 1467 -REPLACE INTO t1 VALUES (0,'newmaxvalue'); -set sql_mode=default; - -# TestInsertIntoSelectError -DROP TABLE IF EXISTS t1; -CREATE TABLE t1(a INT) ENGINE = InnoDB; -INSERT IGNORE into t1(SELECT SLEEP(NULL)); -SHOW WARNINGS; -INSERT IGNORE into t1(SELECT SLEEP(-1)); -SHOW WARNINGS; -INSERT IGNORE into t1(SELECT SLEEP(1)); -SELECT * FROM t1; -DROP TABLE t1; - -# TestIssue32213 -drop table if exists t1; -create table t1(c1 float); -insert into t1 values(999.99); -select cast(t1.c1 as decimal(4, 1)) from t1; -select cast(t1.c1 as decimal(5, 1)) from t1; -drop table if exists t1; -create table t1(c1 decimal(6, 4)); -insert into t1 values(99.9999); -select cast(t1.c1 as decimal(5, 3)) from t1; -select cast(t1.c1 as decimal(6, 3)) from t1; - -# TestInsertBigScientificNotation -# https://github.com/pingcap/tidb/issues/47787 -drop table if exists t1; -create table t1(id int, a int); -set @@SQL_MODE='STRICT_TRANS_TABLES'; --- error 1264 -insert into t1 values(1, '1e100'); --- error 1264 -insert into t1 values(2, '-1e100'); -select id, a from t1; -set @@SQL_MODE=''; -insert into t1 values(1, '1e100'); -show warnings; -insert into t1 values(2, '-1e100'); -show warnings; -select id, a from t1 order by id asc; -set sql_mode=default; - -# TestUnsignedDecimalFloatInsertNegative -# https://github.com/pingcap/tidb/issues/47945 -drop table if exists tf; -create table tf(a float(1, 0) unsigned); --- error 1264 -insert into tf values('-100'); -set @@sql_mode=''; -insert into tf values('-100'); -select * from tf; -set @@sql_mode=default; - -# TestIssue17745 -drop table if exists tt1; -create table tt1 (c1 decimal(64)); --- error 1264 -insert into tt1 values(89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000); --- error 1264 -insert into tt1 values(89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000); -insert ignore into tt1 values(89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000); -show warnings; -select c1 from tt1; --- error 1264 -update tt1 set c1 = 89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000; -drop table if exists tt1; --- error 1367 -insert into tt1 values(4556414e723532); -select 888888888888888888888888888888888888888888888888888888888888888888888888888888888888; -show warnings; - -# TestIssue38950 -drop table if exists t; -create table t (id smallint auto_increment primary key); -alter table t add column c1 int default 1; ---enable_info -insert ignore into t(id) values (194626268); ---disable_info -select * from t; ---enable_info -insert ignore into t(id) values ('*') on duplicate key update c1 = 2; ---disable_info -select * from t; - -# TestInsertIgnoreOnDup -drop table if exists t; -create table t (i int not null primary key, j int unique key); ---enable_info -insert into t values (1, 1), (2, 2); -insert ignore into t values(1, 1) on duplicate key update i = 2; ---disable_info -select * from t; ---enable_info -insert ignore into t values(1, 1) on duplicate key update j = 2; ---disable_info -select * from t; - -drop table if exists t2; -create table t2(`col_25` set('Alice','Bob','Charlie','David') NOT NULL,`col_26` date NOT NULL DEFAULT '2016-04-15', PRIMARY KEY (`col_26`) clustered, UNIQUE KEY `idx_9` (`col_25`,`col_26`),UNIQUE KEY `idx_10` (`col_25`)); -insert into t2(col_25, col_26) values('Bob', '1989-03-23'),('Alice', '2023-11-24'), ('Charlie', '2023-12-05'); -insert ignore into t2 (col_25,col_26) values ( 'Bob','1977-11-23' ) on duplicate key update col_25 = 'Alice', col_26 = '2036-12-13'; -show warnings; -select * from t2; - -drop table if exists t4; -create table t4(id int primary key clustered, k int, v int, unique key uk1(k)); -insert into t4 values (1, 10, 100), (3, 30, 300); -insert ignore into t4 (id, k, v) values(1, 0, 0) on duplicate key update id = 2, k = 30; -show warnings; -select * from t4; - -drop table if exists t5; -create table t5(k1 varchar(100), k2 varchar(100), uk1 int, v int, primary key(k1, k2) clustered, unique key ukk1(uk1), unique key ukk2(v)); -insert into t5(k1, k2, uk1, v) values('1', '1', 1, '100'), ('1', '3', 2, '200'); -update ignore t5 set k2 = '2', uk1 = 2 where k1 = '1' and k2 = '1'; -show warnings; -select * from t5; - -drop table if exists t6; -create table t6 (a int, b int, c int, primary key(a, b) clustered, unique key idx_14(b), unique key idx_15(b), unique key idx_16(a, b)); -insert into t6 select 10, 10, 20; -insert ignore into t6 set a = 20, b = 10 on duplicate key update a = 100; -select * from t6; -insert ignore into t6 set a = 200, b= 10 on duplicate key update c = 1000; -select * from t6; - -# TestInsertAutoInc -drop table if exists insert_autoinc_test; -create table insert_autoinc_test (id int primary key auto_increment, c1 int); -insert into insert_autoinc_test(c1) values (1), (2); -begin; -select * from insert_autoinc_test; -commit; -begin; -insert into insert_autoinc_test(id, c1) values (5,5); -insert into insert_autoinc_test(c1) values (6); -commit; -begin; -select * from insert_autoinc_test; -commit; -begin; -insert into insert_autoinc_test(id, c1) values (3,3); -commit; -begin; -select * from insert_autoinc_test; -commit; -begin; -insert into insert_autoinc_test(c1) values (7); -commit; -begin; -select * from insert_autoinc_test; -commit; -drop table if exists insert_autoinc_test; - -## issue-962 -create table insert_autoinc_test (id int primary key auto_increment, c1 int); -insert into insert_autoinc_test(id, c1) values (0.3, 1); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (-0.3, 2); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (-3.3, 3); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (4.3, 4); -select * from insert_autoinc_test; -insert into insert_autoinc_test(c1) values (5); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (null, 6); -select * from insert_autoinc_test; -drop table if exists insert_autoinc_test; - -## SQL_MODE=NO_AUTO_VALUE_ON_ZERO -create table insert_autoinc_test (id int primary key auto_increment, c1 int); -insert into insert_autoinc_test(id, c1) values (5, 1); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (0, 2); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (0, 3); -select * from insert_autoinc_test; -set SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -insert into insert_autoinc_test(id, c1) values (0, 4); -select * from insert_autoinc_test; --- error 1062 -insert into insert_autoinc_test(id, c1) values (0, 5); -insert into insert_autoinc_test(c1) values (6); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (null, 7); -select * from insert_autoinc_test; -set SQL_MODE=''; -insert into insert_autoinc_test(id, c1) values (0, 8); -select * from insert_autoinc_test; -insert into insert_autoinc_test(id, c1) values (null, 9); -select * from insert_autoinc_test; -set sql_mode = default; - -# TestInsert -drop table if exists insert_test; -create table insert_test (id int PRIMARY KEY AUTO_INCREMENT, c1 int, c2 int, c3 int default 1); ---enable_info -insert insert_test (c1) values (1),(2),(NULL); ---disable_info -begin; --- error 1136 -insert insert_test (c1) values (); -rollback; -begin; --- error 1136 -insert insert_test (c1, c2) values (1,2),(1); -rollback; -begin; --- error 1054 -insert insert_test (xxx) values (3); -rollback; -begin; --- error 1146 -insert insert_test_xxx (c1) values (); -rollback; ---enable_info -insert insert_test set c1 = 3; ---disable_info -begin; --- error 1110 -insert insert_test set c1 = 4, c1 = 5; -rollback; -begin; --- error 1054 -insert insert_test set xxx = 6; -rollback; - -drop table if exists insert_test_1, insert_test_2; -create table insert_test_1 (id int, c1 int); ---enable_info -insert insert_test_1 select id, c1 from insert_test; ---disable_info -create table insert_test_2 (id int, c1 int); ---enable_info -insert insert_test_1 select id, c1 from insert_test union select id * 10, c1 * 10 from insert_test; ---disable_info -begin; --- error 1136 -insert insert_test_1 select c1 from insert_test; -rollback; -begin; --- error 1136 -insert insert_test_1 values(default, default, default, default, default); -rollback; -select * from insert_test where id = 1; ---enable_info -insert into insert_test (id, c3) values (1, 2) on duplicate key update id=values(id), c2=10; ---disable_info -select * from insert_test where id = 1; ---enable_info -insert into insert_test (id, c2) values (1, 1) on duplicate key update insert_test.c2=10; ---disable_info --- error 1054 -insert into insert_test (id, c2) values(1, 1) on duplicate key update t.c2 = 10; ---enable_info -INSERT INTO insert_test (id, c3) VALUES (1, 2) ON DUPLICATE KEY UPDATE c3=values(c3)+c3+3; ---disable_info -select * from insert_test where id = 1; ---enable_info -INSERT IGNORE INTO insert_test (id, c3) VALUES (1, 2) ON DUPLICATE KEY UPDATE c3=values(c3)+c3+3; ---disable_info -select * from insert_test where id = 1; - -drop table if exists insert_err; -create table insert_err (id int, c1 varchar(8)); --- error 1406 -insert insert_err values (1, 'abcdabcdabcd'); -insert insert_err values (1, '你好,世界'); -create table TEST1 (ID INT NOT NULL, VALUE INT DEFAULT NULL, PRIMARY KEY (ID)); ---enable_info -INSERT INTO TEST1(id,value) VALUE(3,3) on DUPLICATE KEY UPDATE VALUE=4; ---disable_info - -drop table if exists t; -create table t (id int); -insert into t values(1); -update t t1 set id = (select count(*) + 1 from t t2 where t1.id = t2.id); -select * from t; - -## issue 3235 -drop table if exists t; -create table t(c decimal(5, 5)); -insert into t value(0); --- error 1264 -insert into t value(1); - -drop table if exists t; -create table t(c binary(255)); -insert into t value(1); -select length(c) from t; - -drop table if exists t; -create table t(c varbinary(255)); -insert into t value(1); -select length(c) from t; - -## issue 3509 -drop table if exists t; -create table t(c int); -set @@time_zone = '+08:00'; -insert into t value(Unix_timestamp('2002-10-27 01:00')); -select * from t; -set @@time_zone = default; - -## issue 3832 -drop table if exists t1; -create table t1 (b char(0)); -insert into t1 values (""); - -## issue 3895 -DROP TABLE IF EXISTS t; -CREATE TABLE t(a DECIMAL(4,2)); -INSERT INTO t VALUES (1.000001); -SHOW WARNINGS; -INSERT INTO t VALUES (1.000000); -SHOW WARNINGS; - -## issue 4653 -DROP TABLE IF EXISTS t; -CREATE TABLE t(a datetime); --- error 1292 -INSERT INTO t VALUES('2017-00-00'); -set sql_mode = ''; -INSERT INTO t VALUES('2017-00-00'); -SELECT * FROM t; -set sql_mode = 'strict_all_tables'; -SELECT * FROM t; -set sql_mode = default; - -drop table if exists test; -CREATE TABLE test(id int(10) UNSIGNED NOT NULL AUTO_INCREMENT, p int(10) UNSIGNED NOT NULL, PRIMARY KEY(p), KEY(id)); -insert into test(p) value(1); -select * from test; -select * from test use index (id) where id = 1; -insert into test values(NULL, 2); -select * from test use index (id) where id = 2; -insert into test values(2, 3); -select * from test use index (id) where id = 2; - -## issue 6360 -drop table if exists t; -create table t(a bigint unsigned); -set @@sql_mode = 'strict_all_tables'; --- error 1264 -insert into t value (-1); -set @@sql_mode = ''; -insert into t value (-1); -show warnings; -insert into t select -1; -show warnings; -insert into t select cast(-1 as unsigned); -insert into t value (-1.111); -show warnings; -insert into t value ('-1.111'); -show warnings; -update t set a = -1 limit 1; -show warnings; -select * from t; -set @@sql_mode = default; - -# issue 6424 & issue 20207 -drop table if exists t; -create table t(a time(6)); -insert into t value('20070219173709.055870'), ('20070219173709.055'), ('20070219173709.055870123'); -select * from t; -truncate table t; -insert into t value(20070219173709.055870), (20070219173709.055), (20070219173709.055870123); -select * from t; --- error 1292 -insert into t value(-20070219173709.055870); - -drop table if exists t; -set @@sql_mode=''; -create table t(a float unsigned, b double unsigned); -insert into t value(-1.1, -1.1), (-2.1, -2.1), (0, 0), (1.1, 1.1); -show warnings; -select * from t; -set @@sql_mode=default; - -## issue 7061 -drop table if exists t; -create table t(a int default 1, b int default 2); -insert into t values(default, default); -select * from t; -truncate table t; -insert into t values(default(b), default(a)); -select * from t; -truncate table t; -insert into t (b) values(default); -select * from t; -truncate table t; -insert into t (b) values(default(a)); -select * from t; - -drop view if exists v; -create view v as select * from t; --- error 1105 -insert into v values(1,2); --- error 1105 -replace into v values(1,2); -drop view v; - -drop sequence if exists seq; -create sequence seq; --- error 1105 -insert into seq values(); --- error 1105 -replace into seq values(); -drop sequence seq; - -## issue 22851 -drop table if exists t; -create table t(name varchar(255), b int, c int, primary key(name(2))); -insert into t(name, b) values("cha", 3); --- error 1062 -insert into t(name, b) values("chb", 3); -insert into t(name, b) values("测试", 3); --- error 1062 -insert into t(name, b) values("测试", 3); - -# TestInsertOnDup -drop table if exists t; -create table t (i int unique key); ---enable_info -insert into t values (1),(2); ---disable_info -select * from t; ---enable_info -insert into t values (1), (2) on duplicate key update i = values(i); ---disable_info -select * from t; ---enable_info -insert into t values (2), (3) on duplicate key update i = 3; ---disable_info -select * from t; - -drop table if exists t; -create table t (i int primary key, j int unique key); ---enable_info -insert into t values (-1, 1); ---disable_info -select * from t; ---enable_info -insert into t values (1, 1) on duplicate key update j = values(j); ---disable_info -select * from t; - -drop table if exists test; -create table test (i int primary key, j int unique); -begin; -insert into test values (1,1); -insert into test values (2,1) on duplicate key update i = -i, j = -j; -commit; -select * from test; -delete from test; -insert into test values (1, 1); -begin; -delete from test where i = 1; -insert into test values (2, 1) on duplicate key update i = -i, j = -j; -commit; -select * from test; -delete from test; -insert into test values (1, 1); -begin; -update test set i = 2, j = 2 where i = 1; -insert into test values (1, 3) on duplicate key update i = -i, j = -j; -insert into test values (2, 4) on duplicate key update i = -i, j = -j; -commit; -select * from test order by i; -delete from test; -begin; -insert into test values (1, 3), (1, 3) on duplicate key update i = values(i), j = values(j); -commit; -select * from test order by i; -create table tmp (id int auto_increment, code int, primary key(id, code)); -create table m (id int primary key auto_increment, code int unique); -insert tmp (code) values (1); -insert tmp (code) values (1); -set tidb_init_chunk_size=1; -insert m (code) select code from tmp on duplicate key update code = values(code); -select * from m; - -## The following two cases are used for guaranteeing the last_insert_id -## to be set as the value of on-duplicate-update assigned. -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT AUTO_INCREMENT PRIMARY KEY, -f2 VARCHAR(5) NOT NULL UNIQUE); ---enable_info -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); ---disable_info -SELECT LAST_INSERT_ID(); ---enable_info -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); ---disable_info -SELECT LAST_INSERT_ID(); - -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT AUTO_INCREMENT UNIQUE, -f2 VARCHAR(5) NOT NULL UNIQUE); ---enable_info -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); ---disable_info -SELECT LAST_INSERT_ID(); ---enable_info -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1); ---disable_info -SELECT LAST_INSERT_ID(); ---enable_info -INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = 2; ---disable_info -SELECT LAST_INSERT_ID(); - -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT); ---enable_info -INSERT t1 VALUES (1) ON DUPLICATE KEY UPDATE f1 = 1; ---disable_info -SELECT * FROM t1; - -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT NOT NULL UNIQUE); ---enable_info -INSERT t1 VALUES (1, 1); -INSERT t1 VALUES (1, 1), (1, 1) ON DUPLICATE KEY UPDATE f1 = 2, f2 = 2; ---disable_info -SELECT * FROM t1 order by f1; --- error 1048 -INSERT t1 VALUES (1, 1) ON DUPLICATE KEY UPDATE f2 = null; ---enable_info -INSERT IGNORE t1 VALUES (1, 1) ON DUPLICATE KEY UPDATE f2 = null; ---disable_info -show warnings; -SELECT * FROM t1 order by f1; - -SET sql_mode=''; --- error 1048 -INSERT t1 VALUES (1, 1) ON DUPLICATE KEY UPDATE f2 = null; -SELECT * FROM t1 order by f1; -set sql_mode=default; - -set tidb_init_chunk_size=default; - - -# TestInsertOnDuplicateKey -drop table if exists t1, t2; -create table t1(a1 bigint primary key, b1 bigint); -create table t2(a2 bigint primary key, b2 bigint); ---enable_info -insert into t1 values(1, 100); -insert into t2 values(1, 200); -insert into t1 select a2, b2 from t2 on duplicate key update b1 = a2; ---disable_info -select * from t1; ---enable_info -insert into t1 select a2, b2 from t2 on duplicate key update b1 = b2; ---disable_info -select * from t1; ---enable_info -insert into t1 select a2, b2 from t2 on duplicate key update a1 = a2; ---disable_info -select * from t1; ---enable_info -insert into t1 select a2, b2 from t2 on duplicate key update b1 = 300; ---disable_info -select * from t1; ---enable_info -insert into t1 values(1, 1) on duplicate key update b1 = 400; ---disable_info -select * from t1; ---enable_info -insert into t1 select 1, 500 from t2 on duplicate key update b1 = 400; ---disable_info -select * from t1; - -drop table if exists t1, t2; -create table t1(a bigint primary key, b bigint); -create table t2(a bigint primary key, b bigint); --- error 1054 -insert into t1 select * from t2 on duplicate key update c = t2.b; - -drop table if exists t1, t2; -create table t1(a bigint primary key, b bigint); -create table t2(a bigint primary key, b bigint); --- error 1052 -insert into t1 select * from t2 on duplicate key update a = b; - -drop table if exists t1, t2; -create table t1(a bigint primary key, b bigint); -create table t2(a bigint primary key, b bigint); --- error 1054 -insert into t1 select * from t2 on duplicate key update c = b; - -drop table if exists t1, t2; -create table t1(a1 bigint primary key, b1 bigint); -create table t2(a2 bigint primary key, b2 bigint); --- error 1054 -insert into t1 select * from t2 on duplicate key update a1 = values(b2); - -drop table if exists t1, t2; -create table t1(a1 bigint primary key, b1 bigint); -create table t2(a2 bigint primary key, b2 bigint); ---enable_info -insert into t1 values(1, 100); -insert into t2 values(1, 200); -insert into t1 select * from t2 on duplicate key update b1 = values(b1) + b2; ---disable_info -select * from t1; ---enable_info -insert into t1 select * from t2 on duplicate key update b1 = values(b1) + b2; ---disable_info -select * from t1; - -drop table if exists t; -create table t(k1 bigint, k2 bigint, val bigint, primary key(k1, k2)); ---enable_info -insert into t (val, k1, k2) values (3, 1, 2); ---disable_info -select * from t; ---enable_info -insert into t (val, k1, k2) select c, a, b from (select 1 as a, 2 as b, 4 as c) tmp on duplicate key update val = tmp.c; ---disable_info -select * from t; - -drop table if exists t; -create table t(k1 double, k2 double, v double, primary key(k1, k2)); ---enable_info -insert into t (v, k1, k2) select c, a, b from (select "3" c, "1" a, "2" b) tmp on duplicate key update v=c; ---disable_info -select * from t; ---enable_info -insert into t (v, k1, k2) select c, a, b from (select "3" c, "1" a, "2" b) tmp on duplicate key update v=c; ---disable_info -select * from t; - -drop table if exists t1, t2; -create table t1(id int, a int, b int); ---enable_info -insert into t1 values (1, 1, 1); -insert into t1 values (2, 2, 1); -insert into t1 values (3, 3, 1); ---disable_info -create table t2(a int primary key, b int, unique(b)); ---enable_info -insert into t2 select a, b from t1 order by id on duplicate key update a=t1.a, b=t1.b; ---disable_info -select * from t2 order by a; - -drop table if exists t1, t2; -create table t1(id int, a int, b int); ---enable_info -insert into t1 values (1, 1, 1); -insert into t1 values (2, 1, 2); -insert into t1 values (3, 3, 1); ---disable_info -create table t2(a int primary key, b int, unique(b)); ---enable_info -insert into t2 select a, b from t1 order by id on duplicate key update a=t1.a, b=t1.b; ---disable_info -select * from t2 order by a; - -drop table if exists t1, t2; -create table t1(id int, a int, b int, c int); ---enable_info -insert into t1 values (1, 1, 1, 1); -insert into t1 values (2, 2, 1, 2); -insert into t1 values (3, 3, 2, 2); -insert into t1 values (4, 4, 2, 2); ---disable_info -create table t2(a int primary key, b int, c int, unique(b), unique(c)); ---enable_info -insert into t2 select a, b, c from t1 order by id on duplicate key update b=t2.b, c=t2.c; ---disable_info -select * from t2 order by a; - -drop table if exists t1; -create table t1(a int primary key, b int); ---enable_info -insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5); -insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18) on duplicate key update b=b+10; ---disable_info - -drop table if exists a, b; -create table a(x int primary key); -create table b(x int, y int); ---enable_info -insert into a values(1); -insert into b values(1, 2); -insert into a select x from b ON DUPLICATE KEY UPDATE a.x=b.y; ---disable_info -select * from a; - ---echo ## Test issue 28078. ---echo ## Use different types of columns so that there's likely to be error if the types mismatches. -drop table if exists a, b; -create table a(id int, a1 timestamp, a2 varchar(10), a3 float, unique(id)); -create table b(id int, b1 time, b2 varchar(10), b3 int); ---enable_info -insert into a values (1, '2022-01-04 07:02:04', 'a', 1.1), (2, '2022-01-04 07:02:05', 'b', 2.2); -insert into b values (2, '12:34:56', 'c', 10), (3, '01:23:45', 'd', 20); -insert into a (id) select id from b on duplicate key update a.a2 = b.b2, a.a3 = 3.3; ---disable_info -select * from a; ---enable_info -insert into a (id) select 4 from b where b3 = 20 on duplicate key update a.a3 = b.b3; ---disable_info -select * from a; ---enable_info -insert into a (a2, a3) select 'x', 1.2 from b on duplicate key update a.a2 = b.b3; ---disable_info -select * from a; - ---echo ## reproduce insert on duplicate key update bug under new row format. -drop table if exists t1; -create table t1(c1 decimal(6,4), primary key(c1)); -insert into t1 set c1 = 0.1; -insert into t1 set c1 = 0.1 on duplicate key update c1 = 1; -select * from t1 use index(primary); - -# TestNonStrictInsertOverflowValue -drop table if exists t; -create table t (d int); --- error 1690 -insert into t values (cast('18446744073709551616' as unsigned)); -set sql_mode=''; ---enable_warnings -insert into t values (cast('18446744073709551616' as unsigned)); ---disable_warnings -set sql_mode=DEFAULT; - -# TestInsertIgnoreOnDupWithFK -drop table if exists parent, child; -create table parent (id int primary key, ref int, key(ref)); -create table child (id int primary key, ref int, foreign key (ref) references parent(ref)); -insert into parent values (1, 1), (2, 2); -insert into child values (1, 1); - -insert into child values (1, 2) on duplicate key update ref = 2; --- error 1452 -insert into child values (1, 3) on duplicate key update ref = 3; ---enable_warnings -insert ignore into child values (1, 3) on duplicate key update ref = 3; ---disable_warnings - --- error 1451 -insert into parent values (2, 3) on duplicate key update ref = 3; ---enable_warnings -insert ignore into parent values (2, 3) on duplicate key update ref = 3; ---disable_warnings - -# TestIssue55457 -drop table if exists t1, t2; -create table t1 (id int primary key, col1 varchar(10) not null default ''); -create table t2 (id int primary key, col1 varchar(10)); -insert into t2 values (1, null); -insert ignore into t1 values(5, null); -set session sql_mode = ''; --- error 1048 -insert into t1 values(1, null); --- error 1048 -insert into t1 set id = 1, col1 = null; --- error 1048 -insert t1 VALUES (5, 5) ON DUPLICATE KEY UPDATE col1 = null; -insert t1 VALUES (5, 5), (6, null) ON DUPLICATE KEY UPDATE col1 = null; -select * from t1; -insert into t1 select * from t2; -show warnings; -insert into t1 values(2, null), (3, 3), (4, 4); -show warnings; -update t1 set col1 = null where id = 3; -show warnings; -insert ignore t1 VALUES (4, 4) ON DUPLICATE KEY UPDATE col1 = null; -select * from t1;