From 2e90bc5f72a697b0f44394b50549d40d86b2cc91 Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Thu, 7 Sep 2023 09:09:44 +0800 Subject: [PATCH] expression, cmd: move some issue tests to explaintest (#46680) ref pingcap/tidb#46679 --- cmd/explaintest/r/expression/issues.result | 2519 +++++++++++++++++ cmd/explaintest/t/expression/issues.test | 1693 +++++++++++ expression/builtin_time_test.go | 45 +- .../integration_serial_test.go | 510 ---- .../integration_test/integration_test.go | 2203 +------------- 5 files changed, 4252 insertions(+), 2718 deletions(-) create mode 100644 cmd/explaintest/r/expression/issues.result create mode 100644 cmd/explaintest/t/expression/issues.test diff --git a/cmd/explaintest/r/expression/issues.result b/cmd/explaintest/r/expression/issues.result new file mode 100644 index 0000000000..63861b9a2a --- /dev/null +++ b/cmd/explaintest/r/expression/issues.result @@ -0,0 +1,2519 @@ +drop table if exists t1, t2; +create table t1 (b enum('a', 'b')); +insert into t1 values ('a'); +create table t2 (b enum('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +b b +a a +drop table if exists t1, t2; +create table t1 (b set('a', 'b')); +insert into t1 values ('a'); +create table t2 (b set('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +b b +a a +drop table if exists t1, t2; +create table t1 (b enum('a', 'b')); +insert into t1 values ('a'); +create table t2 (b set('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +b b +a a +drop table if exists t1, t2; +create table t1 (b char(10)); +insert into t1 values ('a'); +create table t2 (b enum('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +b b +a a +drop table if exists t1, t2; +create table t1 (b char(10)); +insert into t1 values ('a'); +create table t2 (b set('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +b b +a a +drop table if exists t; +create table t(a decimal(16, 2)); +select sum(case when 1 then a end) from t group by a; +sum(case when 1 then a end) +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` decimal(16,2) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +create table t(a tinyint, b bit(63)); +insert ignore into t values(599999999, -1); +show warnings; +Level Code Message +select * from t; +a b +127 ˙˙˙˙˙˙˙ +drop table if exists t; +create table t(b bit(16)); +insert ignore into t values(0x3635313836),(0x333830); +show warnings; +Level Code Message +select * from t; +b +˙˙ +˙˙ +drop table if exists t; +create table t(a char(32) not null, b float default '0') engine=innodb default charset=utf8mb4; +insert into t value('0a6f9d012f98467f8e671e9870044528', 208.867); +select concat_ws( ',', b) from t where a = '0a6f9d012f98467f8e671e9870044528'; +concat_ws( ',', b) +208.867 +drop table if exists t; +CREATE TABLE t (b BIT(8)); +INSERT INTO t SET b = b'11111111'; +INSERT INTO t SET b = b'1010'; +INSERT INTO t SET b = b'0101'; +SELECT b+0, BIN(b), OCT(b), HEX(b) FROM t; +b+0 BIN(b) OCT(b) HEX(b) +255 11111111 377 FF +10 1010 12 A +5 101 5 5 +drop table if exists t; +create table t(a char(20)); +select convert(a using a) from t; +[parser:1115]Unknown character set: 'a' +drop table if exists t1; +create table t1(c1 varbinary(100)); +insert into t1 values('abc'); +select 1 from t1 where char_length(c1) = 10; +1 +drop table if exists t; +create table t (id int NOT NULL DEFAULT 8); +SET sql_mode = ''; +insert into t values (1), (NULL), (2); +show warnings; +Level Code Message +select * from t; +id +1 +0 +2 +set @@sql_mode=default; +drop table if exists t; +create table t(a json); +insert into t values ('"a"'), ('"B"'), ('"c"'), ('"D"'), ('{"a": 1}'), ('1'), ('{"b": 2}'), ('[1, 2]'), ('[3, 4]'); +select min(a) from t; +min(a) +1 +select max(a) from t; +max(a) +[3, 4] +select min(a collate utf8mb4_bin) from t; +min(a collate utf8mb4_bin) +"B" +select max(a collate utf8mb4_bin) from t; +max(a collate utf8mb4_bin) +{"b": 2} +select min(a collate utf8mb4_unicode_ci) from t; +min(a collate utf8mb4_unicode_ci) +"a" +select max(a collate utf8mb4_unicode_ci) from t; +max(a collate utf8mb4_unicode_ci) +1 +SET timestamp=UNIX_TIMESTAMP('2011-11-01 17:48:00'); +SELECT cast(cast('12:12:12' as time) as datetime(6)); +cast(cast('12:12:12' as time) as datetime(6)) +2011-11-01 12:12:12.000000 +drop table if exists t; +create table t (tm time(6)); +insert into t values('23:59:59'); +SELECT cast(tm as datetime(6)) from t; +cast(tm as datetime(6)) +2011-11-01 23:59:59.000000 +drop table if exists `PK_S_MULTI_43`; +CREATE TABLE `PK_S_MULTI_43`(`COL1` time(2) NOT NULL, `COL2` time(2) NOT NULL, `COL3` time(2) DEFAULT NULL, PRIMARY KEY(`COL1`,`COL2`)); +insert into PK_S_MULTI_43(col1, col2) values('-512:37:22.00', '-512:37:22.00'); +select extract(day_microsecond from '-512:37:22.00'); +extract(day_microsecond from '-512:37:22.00') +-5123722000000 +select extract(day_microsecond from col1) from PK_S_MULTI_43; +extract(day_microsecond from col1) +-5123722000000 +drop table if exists t; +create table t(c datetime(6)); +insert into t values('2001-01-01 02:03:04.050607'); +select extract(day_microsecond from cast('2001-01-01 02:03:04.050607' as datetime(6))) from t; +extract(day_microsecond from cast('2001-01-01 02:03:04.050607' as datetime(6))) +1020304050607 +select extract(day_microsecond from c) from t; +extract(day_microsecond from c) +1020304050607 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar char(44)); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +1973-11-30 08:38:10.123457 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar varchar(44)); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +1973-11-30 08:38:10.123457 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar blob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +1973-11-30 08:38:10.123457 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar tinyblob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +1973-11-30 08:38:10.123457 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar mediumblob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +1973-11-30 08:38:10.123457 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar longblob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +1973-11-30 08:38:10.123457 +truncate table ft; +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234000000000000000000100111111111'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +show warnings; +Level Code Message +truncate table ft; +insert into ft values(1234567890,123467890.1234,123467890.1234,'11111123467890.1234'); +SELECT FROM_UNIXTIME(tchar) from ft; +FROM_UNIXTIME(tchar) +NULL +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar char(44)); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +SELECT FROM_UNIXTIME(tchar) from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ; +FROM_UNIXTIME(tchar) +1973-11-30 08:38:10.123400 +SELECT FROM_UNIXTIME(cast(tchar as decimal(44,1))) from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ; +FROM_UNIXTIME(cast(tchar as decimal(44,1))) +1973-11-30 08:38:10.1 +SELECT FROM_UNIXTIME(tchar,'%Y%m%d') from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ; +FROM_UNIXTIME(tchar,'%Y%m%d') +19731130 +drop table if exists t; +create table t(dou double, varc varchar(100)); +insert into t values (1.23e23, '111111111111111111111111111111111111111111111111111111111111111111111111111'); +select from_unixtime(dou) from t; +from_unixtime(dou) +NULL +select from_unixtime(varc) from t; +from_unixtime(varc) +NULL +select from_unixtime(dou, '%Y-%m-%d') from t; +from_unixtime(dou, '%Y-%m-%d') +NULL +select from_unixtime(varc, '%Y-%m-%d') from t; +from_unixtime(varc, '%Y-%m-%d') +NULL +drop table if exists `sun`; +CREATE TABLE `sun` ( `dest` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into sun values('20231020'); +set @@sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +set @@tidb_enable_vectorized_expression = on; +select str_to_date(substr(dest,1,6),'%H%i%s') from sun; +str_to_date(substr(dest,1,6),'%H%i%s') +20:23:10 +set @@tidb_enable_vectorized_expression = off; +select str_to_date(substr(dest,1,6),'%H%i%s') from sun; +str_to_date(substr(dest,1,6),'%H%i%s') +20:23:10 +set @@sql_mode=default; +drop table if exists `6bf9e76d-ab44-4031-8a07-418b10741580`, `8919f3f4-25be-4a1a-904a-bb5e863d8fc8`; +CREATE TABLE `6bf9e76d-ab44-4031-8a07-418b10741580` ( +`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` set('7','va','ung60','ow','1g','gxwz5','uhnh','k','5la1','q8d9c','1f') NOT NULL DEFAULT '7,1g,uhnh,5la1,q8d9c', +`fbc3527f-9617-4b9d-a5dc-4be31c00d8a5` datetime DEFAULT '6449-09-28 14:39:04', +PRIMARY KEY (`e0b5f703-6cfe-49b4-bc21-16a6455e43a7`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin; +CREATE TABLE `8919f3f4-25be-4a1a-904a-bb5e863d8fc8` ( +`9804d5f2-cbc7-43b7-b241-ea2656dc941a` enum('s951','36d','ua65','49yru','6l2em','4ea','jf2d2','vprsc','3yl7n','hz','ov') DEFAULT '4ea', +`323cdbcb-0c14-4362-90ab-ea42caaed6a5` year(4) NOT NULL DEFAULT '1983', +`b9b70f39-1a02-4114-9d7d-fa6259c1b691` time DEFAULT '20:18:04', +PRIMARY KEY (`323cdbcb-0c14-4362-90ab-ea42caaed6a5`) /*T![clustered_index] CLUSTERED */, +KEY `a704d6bb-772b-44ea-8cb0-6f7491c1aaa6` (`323cdbcb-0c14-4362-90ab-ea42caaed6a5`,`9804d5f2-cbc7-43b7-b241-ea2656dc941a`) +) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin; +delete from `6bf9e76d-ab44-4031-8a07-418b10741580` where not( `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( select `9804d5f2-cbc7-43b7-b241-ea2656dc941a` from `8919f3f4-25be-4a1a-904a-bb5e863d8fc8` where `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( '1f' ) and `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( '1g' ,'va' ,'uhnh' ) ) ) and not( IsNull( `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` ) ); +drop table if exists test; +create table test (name1 blob,name2 blob); +insert into test values(aes_encrypt('a', 'x'), aes_encrypt('b', 'x')); +SELECT * FROM test WHERE CAST(AES_DECRYPT(name1, 'x') AS CHAR) = '00' AND CAST(AES_DECRYPT(name2, 'x') AS CHAR) = '1'; +name1 name2 +drop table if exists ordres; +CREATE TABLE orders (id bigint(20) unsigned NOT NULL ,account_id bigint(20) unsigned NOT NULL DEFAULT '0' ,loan bigint(20) unsigned NOT NULL DEFAULT '0' ,stage_num int(20) unsigned NOT NULL DEFAULT '0' ,apply_time bigint(20) unsigned NOT NULL DEFAULT '0' ,PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */,KEY idx_orders_account_id (account_id),KEY idx_orders_apply_time (apply_time)); +insert into orders values (20, 210802010000721168, 20000 , 2 , 1682484268727), (22, 210802010000721168, 35100 , 4 , 1650885615002); +select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1; +min max +20000 35100 +drop table if exists t_tiny, t_small, t_medium, t_int, t_big; +create table t_tiny (c0 TINYINT UNSIGNED); +INSERT IGNORE INTO t_tiny(c0) VALUES (1E9); +show warnings; +Level Code Message +select * from t_tiny; +c0 +255 +create table t_small (c0 SMALLINT UNSIGNED); +INSERT IGNORE INTO t_small(c0) VALUES (1E9); +show warnings; +Level Code Message +select * from t_small; +c0 +65535 +create table t_medium (c0 MEDIUMINT UNSIGNED); +INSERT IGNORE INTO t_medium(c0) VALUES (1E9); +show warnings; +Level Code Message +select * from t_medium; +c0 +16777215 +create table t_int (c0 INT UNSIGNED); +INSERT IGNORE INTO t_int(c0) VALUES (1E20); +show warnings; +Level Code Message +select * from t_int; +c0 +4294967295 +create table t_big (c0 BIGINT UNSIGNED); +INSERT IGNORE INTO t_big(c0) VALUES (1E20); +show warnings; +Level Code Message +select * from t_big; +c0 +18446744073709551615 +drop table if exists t; +CREATE TABLE t (a bigint unsigned,key (a)); +INSERT INTO t VALUES (0), (4), (5), (6), (7), (8), (9223372036854775810), (18446744073709551614), (18446744073709551615); +SELECT a FROM t WHERE a NOT IN (-1, -2, 18446744073709551615); +a +0 +4 +5 +6 +7 +8 +9223372036854775810 +18446744073709551614 +SELECT a FROM t WHERE a NOT IN (-1, -2, 4, 9223372036854775810); +a +0 +5 +6 +7 +8 +18446744073709551614 +18446744073709551615 +SELECT a FROM t WHERE a NOT IN (-1, -2, 0, 4, 18446744073709551614); +a +5 +6 +7 +8 +9223372036854775810 +18446744073709551615 +drop table if exists t1; +create table t1 (some_id smallint(5) unsigned,key (some_id) ); +insert into t1 values (1),(2); +select some_id from t1 where some_id not in(2,-1); +some_id +1 +select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m')); +monthname(str_to_date(null, '%m')) monthname(str_to_date(null, '%m')) monthname(str_to_date(1, '%m')) monthname(str_to_date(0, '%m')) +NULL NULL NULL NULL +select str_to_date(1, '%m'); +str_to_date(1, '%m') +NULL +select str_to_date(01, '%d'); +str_to_date(01, '%d') +NULL +select str_to_date(2019, '%Y'); +str_to_date(2019, '%Y') +NULL +select str_to_date('5,2019','%m,%Y'); +str_to_date('5,2019','%m,%Y') +NULL +select str_to_date('01,2019','%d,%Y'); +str_to_date('01,2019','%d,%Y') +NULL +select str_to_date('01,5','%d,%m'); +str_to_date('01,5','%d,%m') +NULL +set sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +select str_to_date(1, '%m'); +str_to_date(1, '%m') +0000-01-00 +select str_to_date(01, '%d'); +str_to_date(01, '%d') +0000-00-01 +select str_to_date(2019, '%Y'); +str_to_date(2019, '%Y') +2019-00-00 +select str_to_date('5,2019','%m,%Y'); +str_to_date('5,2019','%m,%Y') +2019-05-00 +select str_to_date('01,2019','%d,%Y'); +str_to_date('01,2019','%d,%Y') +2019-00-01 +select str_to_date('01,5','%d,%m'); +str_to_date('01,5','%d,%m') +0000-05-01 +set @@sql_mode=default; +drop table if exists t1, t2; +CREATE TABLE `t1` (`period_name` varchar(24) DEFAULT NULL ,`period_id` bigint(20) DEFAULT NULL ,`starttime` bigint(20) DEFAULT NULL); +CREATE TABLE `t2` (`bussid` bigint(20) DEFAULT NULL,`ct` bigint(20) DEFAULT NULL); +select +a.period_name, +b.date8 +from +(select * from t1) a +left join +(select bussid,date(from_unixtime(ct)) date8 from t2) b +on +a.period_id = b.bussid +where +datediff(b.date8, date(from_unixtime(a.starttime))) >= 0; +period_name date8 +SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND; +"1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND +8895-03-27 22:11:40 +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 37 SECOND; +"1900-01-01 00:00:00" + INTERVAL 1 << 37 SECOND +6255-04-08 15:04:32 +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 31 MINUTE; +"1900-01-01 00:00:00" + INTERVAL 1 << 31 MINUTE +5983-01-24 02:08:00 +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 38 SECOND; +"1900-01-01 00:00:00" + INTERVAL 1 << 38 SECOND +NULL +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 33 MINUTE; +"1900-01-01 00:00:00" + INTERVAL 1 << 33 MINUTE +NULL +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 30 HOUR; +"1900-01-01 00:00:00" + INTERVAL 1 << 30 HOUR +NULL +SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND; +"1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND +NULL +SELECT 19000101000000 + INTERVAL "100000000:214748364700" MINUTE_SECOND; +19000101000000 + INTERVAL "100000000:214748364700" MINUTE_SECOND +8895-03-27 22:11:40 +SELECT 19000101000000 + INTERVAL 1 << 37 SECOND; +19000101000000 + INTERVAL 1 << 37 SECOND +6255-04-08 15:04:32 +SELECT 19000101000000 + INTERVAL 1 << 31 MINUTE; +19000101000000 + INTERVAL 1 << 31 MINUTE +5983-01-24 02:08:00 +SELECT "8895-03-27 22:11:40" - INTERVAL "100000000:214748364700" MINUTE_SECOND; +"8895-03-27 22:11:40" - INTERVAL "100000000:214748364700" MINUTE_SECOND +1900-01-01 00:00:00 +SELECT "6255-04-08 15:04:32" - INTERVAL 1 << 37 SECOND; +"6255-04-08 15:04:32" - INTERVAL 1 << 37 SECOND +1900-01-01 00:00:00 +SELECT "5983-01-24 02:08:00" - INTERVAL 1 << 31 MINUTE; +"5983-01-24 02:08:00" - INTERVAL 1 << 31 MINUTE +1900-01-01 00:00:00 +SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 39 SECOND; +"9999-01-01 00:00:00" - INTERVAL 1 << 39 SECOND +NULL +SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 33 MINUTE; +"9999-01-01 00:00:00" - INTERVAL 1 << 33 MINUTE +NULL +SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 30 HOUR; +"9999-01-01 00:00:00" - INTERVAL 1 << 30 HOUR +NULL +SELECT "9999-01-01 00:00:00" - INTERVAL "10000000000:214748364700" MINUTE_SECOND; +"9999-01-01 00:00:00" - INTERVAL "10000000000:214748364700" MINUTE_SECOND +NULL +SELECT 88950327221140 - INTERVAL "100000000:214748364700" MINUTE_SECOND ; +88950327221140 - INTERVAL "100000000:214748364700" MINUTE_SECOND +1900-01-01 00:00:00 +SELECT 62550408150432 - INTERVAL 1 << 37 SECOND; +62550408150432 - INTERVAL 1 << 37 SECOND +1900-01-01 00:00:00 +SELECT 59830124020800 - INTERVAL 1 << 31 MINUTE; +59830124020800 - INTERVAL 1 << 31 MINUTE +1900-01-01 00:00:00 +SELECT 10000101000000 + INTERVAL "111111111111111111" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111" MICROSECOND +4520-12-21 05:31:51.111111 +SELECT 10000101000000 + INTERVAL "111111111111.111111" SECOND; +10000101000000 + INTERVAL "111111111111.111111" SECOND +4520-12-21 05:31:51.111111 +SELECT 10000101000000 + INTERVAL "111111111111.111111111" SECOND; +10000101000000 + INTERVAL "111111111111.111111111" SECOND +4520-12-21 05:31:51.111111 +SELECT 10000101000000 + INTERVAL "111111111111.111" SECOND; +10000101000000 + INTERVAL "111111111111.111" SECOND +4520-12-21 05:31:51.111000 +SELECT 10000101000000 + INTERVAL "111111111111." SECOND; +10000101000000 + INTERVAL "111111111111." SECOND +4520-12-21 05:31:51 +SELECT 10000101000000 + INTERVAL "111111111111111111.5" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111.5" MICROSECOND +4520-12-21 05:31:51.111112 +SELECT 10000101000000 + INTERVAL "111111111111111112.5" MICROSECOND; +10000101000000 + INTERVAL "111111111111111112.5" MICROSECOND +4520-12-21 05:31:51.111113 +SELECT 10000101000000 + INTERVAL "111111111111111111.500000" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111.500000" MICROSECOND +4520-12-21 05:31:51.111112 +SELECT 10000101000000 + INTERVAL "111111111111111111.50000000" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111.50000000" MICROSECOND +4520-12-21 05:31:51.111112 +SELECT 10000101000000 + INTERVAL "111111111111111111.6" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111.6" MICROSECOND +4520-12-21 05:31:51.111112 +SELECT 10000101000000 + INTERVAL "111111111111111111.499999" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111.499999" MICROSECOND +4520-12-21 05:31:51.111111 +SELECT 10000101000000 + INTERVAL "111111111111111111.499999999999" MICROSECOND; +10000101000000 + INTERVAL "111111111111111111.499999999999" MICROSECOND +4520-12-21 05:31:51.111111 +SELECT INTERVAL 1.123456789e3 SECOND + "1900-01-01 00:00:00"; +INTERVAL 1.123456789e3 SECOND + "1900-01-01 00:00:00" +1900-01-01 00:18:43.456789 +SELECT INTERVAL 1 Year + 19000101000000; +INTERVAL 1 Year + 19000101000000 +1901-01-01 00:00:00 +select interval 6 month + date("1900-01-01"); +interval 6 month + date("1900-01-01") +1900-07-01 +select interval "5:2" MINUTE_SECOND + "1900-01-01"; +interval "5:2" MINUTE_SECOND + "1900-01-01" +1900-01-01 00:05:02 +drop table if exists t; +create table t(a bigint unsigned primary key); +insert into t values(9223372036854775807), (18446744073709551615); +select * from t where a > 9223372036854775807-0.5 order by a; +a +9223372036854775807 +18446744073709551615 +drop table if exists t1, t2; +create table t1(id varchar(36) not null primary key, org_id varchar(36) not null, status tinyint default 1 not null, ns varchar(36) default '' not null); +create table t2(id varchar(36) not null primary key, order_id varchar(36) not null, begin_time timestamp(3) default CURRENT_TIMESTAMP(3) not null); +create index idx_oid on t2(order_id); +insert into t1 value (1,1,1,'a'); +insert into t1 value (2,1,2,'a'); +insert into t1 value (3,1,3,'a'); +insert into t2 value (1,2,date'2020-05-08'); +explain format = 'brief' SELECT /*+ INL_MERGE_JOIN(t1,t2) */ COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.order_id WHERE t1.ns = 'a' AND t1.org_id IN (1) AND t1.status IN (2,6,10) AND timestampdiff(month, t2.begin_time, date'2020-05-06') = 0; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(1)->Column#10 +└─IndexMergeJoin 0.03 root inner join, inner:Selection, outer key:expression__issues.t1.id, inner key:expression__issues.t2.order_id + ├─TableReader(Build) 0.02 root data:Selection + │ └─Selection 0.02 cop[tikv] eq(cast(expression__issues.t1.org_id, double BINARY), 1), eq(expression__issues.t1.ns, "a"), in(expression__issues.t1.status, 2, 6, 10) + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─Selection(Probe) 0.03 root eq(timestampdiff("MONTH", expression__issues.t2.begin_time, 2020-05-06), 0) + └─Projection 0.04 root expression__issues.t2.order_id, expression__issues.t2.begin_time + └─IndexLookUp 0.04 root + ├─IndexRangeScan(Build) 0.04 cop[tikv] table:t2, index:idx_oid(order_id) range: decided by [eq(expression__issues.t2.order_id, expression__issues.t1.id)], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 0.04 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ INL_MERGE_JOIN(t1,t2) */ COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.order_id WHERE t1.ns = 'a' AND t1.org_id IN (1) AND t1.status IN (2,6,10) AND timestampdiff(month, t2.begin_time, date'2020-05-06') = 0; +COUNT(*) +1 +drop table if exists t; +create table t(a int); +insert into t values(1); +select * from t where a < -184467440737095516167.1; +a +select * from t where a > -184467440737095516167.1; +a +1 +select * from t where a < 184467440737095516167.1; +a +1 +select * from t where a > 184467440737095516167.1; +a +drop table if exists t; +create table t(b bit(1)); +insert into t values(b'1'); +select count(*) from t where b = 1; +count(*) +1 +select count(*) from t where b = '1'; +count(*) +1 +select count(*) from t where b = b'1'; +count(*) +1 +drop table if exists t; +create table t(b bit(63)); +insert into t values(b'111111111111111111111111111111111111111111111111111111111111111'); +select count(*) from t where b = 9223372036854775807; +count(*) +1 +select count(*) from t where b = '9223372036854775807'; +count(*) +1 +select count(*) from t where b = b'111111111111111111111111111111111111111111111111111111111111111'; +count(*) +1 +drop table if exists t1; +CREATE TABLE t1 (v bigint(20) UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (1), (2); +SELECT SUM(IF(v > 1, v, -v)) FROM t1; +SUM(IF(v > 1, v, -v)) +1 +SELECT sum(IFNULL(cast(null+rand() as unsigned), -v)) FROM t1; +sum(IFNULL(cast(null+rand() as unsigned), -v)) +-3 +SELECT sum(COALESCE(cast(null+rand() as unsigned), -v)) FROM t1; +sum(COALESCE(cast(null+rand() as unsigned), -v)) +-3 +SELECT sum(COALESCE(cast(null+rand() as unsigned), v)) FROM t1; +sum(COALESCE(cast(null+rand() as unsigned), v)) +3 +drop table if exists t; +CREATE TABLE t (a decimal(6,3),b double(6,3),c float(6,3)); +INSERT INTO t VALUES (1.100,1.100,1.100); +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) FROM t; +DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) +2003-11-18 07:27:53 +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) FROM t; +DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) +2003-11-18 07:27:53 +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) FROM t; +DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) +2003-11-18 07:27:53 +drop table if exists t; +CREATE TABLE t (a decimal(11,7),b double(11,7),c float(11,7)); +INSERT INTO t VALUES (123.9999999,123.9999999,123.9999999),(-123.9999999,-123.9999999,-123.9999999); +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) FROM t; +DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) +2004-03-13 03:14:52 +2003-07-25 11:35:34 +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) FROM t; +DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) +2004-03-13 03:14:52 +2003-07-25 11:35:34 +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) FROM t; +DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) +2003-11-18 09:29:13 +2003-11-18 05:21:13 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_MICROSECOND) +2007-03-28 22:08:25.800000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND_MICROSECOND) +2007-03-28 22:08:25.800000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MICROSECOND) +2007-03-28 22:08:25.800000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MICROSECOND) +2007-03-28 22:08:25.800000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND) +2007-03-28 22:08:25.800000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_SECOND) +2007-03-28 22:06:26 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_SECOND) +2007-03-28 22:06:26 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_SECOND) +2007-03-28 22:06:26 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE) +2007-03-28 22:06:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MINUTE); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MINUTE) +2007-03-28 20:06:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MINUTE); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MINUTE) +2007-03-28 20:06:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_HOUR); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_HOUR) +2007-03-26 20:08:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 YEAR_MONTH); +DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 YEAR_MONTH) +2005-01-28 22:08:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_MICROSECOND) +2007-03-28 22:08:30.200000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND_MICROSECOND) +2007-03-28 22:08:30.200000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MICROSECOND) +2007-03-28 22:08:30.200000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MICROSECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MICROSECOND) +2007-03-28 22:08:30.200000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND) +2007-03-28 22:08:30.200000 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_SECOND) +2007-03-28 22:10:30 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_SECOND) +2007-03-28 22:10:30 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_SECOND); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_SECOND) +2007-03-28 22:10:30 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE) +2007-03-28 22:10:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MINUTE); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MINUTE) +2007-03-29 00:10:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MINUTE); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MINUTE) +2007-03-29 00:10:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR) +2007-03-31 00:08:28 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH); +DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH) +2009-05-28 22:08:28 +drop table if exists t; +create table t (d decimal(19, 0), i bigint(11)); +insert into t values (123456789012, 123456789012); +select * from t where d = i; +d i +123456789012 123456789012 +select '0-3261554956'+0.0; +'0-3261554956'+0.0 +0 +select cast('0-1234' as real); +cast('0-1234' as real) +0 +drop table if exists testValuesBinary; +create table testValuesBinary(id int primary key auto_increment, a bit(1)); +insert into testValuesBinary values(1,1); +insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a); +select a=0 from testValuesBinary; +a=0 +0 +insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a); +select a=0 from testValuesBinary; +a=0 +1 +drop table testValuesBinary; +DROP TABLE IF EXISTS t; +CREATE TABLE t (v VARCHAR(100)); +INSERT INTO t VALUES ('3289742893213123732904809'); +SELECT * FROM t WHERE v; +v +3289742893213123732904809 +drop table if exists tt; +create table tt(a varchar(10)); +insert into tt values(NULL); +analyze table tt; +select * from tt; +a +NULL +select collation(format_bytes(1024)) != 'binary'; +collation(format_bytes(1024)) != 'binary' +1 +select collation(format_nano_time(234)) != 'binary'; +collation(format_nano_time(234)) != 'binary' +1 +drop table if exists t; +create table t (a char(10) charset gbk collate gbk_chinese_ci, b time); +insert into t values ('08:00:00', '08:00:00'); +select t1.a, t2.b from t as t1 right join t as t2 on t1.a = t2.b; +a b +08:00:00 08:00:00 +drop table if exists table_30_utf8_4, t; +create table t(a int); +insert into t values(1); +create table table_30_utf8_4 ( `pk` int primary key, `col_int_key_unsigned` int unsigned , `col_int_key_signed` int, `col_float_key_signed` float , `col_float_key_unsigned` float unsigned) character set utf8 partition by hash(pk) partitions 4; +insert ignore into table_30_utf8_4 values (0,91, 10, 14,19.0495); +alter table table_30_utf8_4 add column a int as (col_int_key_signed * 2); +SELECT count(1) AS val FROM table_30_utf8_4 WHERE table_30_utf8_4.col_int_key_unsigned!=table_30_utf8_4.a OR (SELECT count(1) AS val FROM t WHERE table_30_utf8_4.col_float_key_signed!=table_30_utf8_4.col_float_key_unsigned )!=7984764426240273913; +val +1 +select a from table_30_utf8_4 order by a; +a +20 +drop table if exists t1; +CREATE TABLE t1 ( id INT NOT NULL PRIMARY KEY auto_increment, pad VARCHAR(10) NOT NULL, expr varchar(100) AS (NOT 1 BETWEEN -5 AND 5)); +INSERT INTO t1 (pad) VALUES ('a'), ('b'); +SELECT id, pad, expr, NOT 1 BETWEEN -5 AND 5 as expr_in_select FROM t1; +id pad expr expr_in_select +1 a 0 0 +2 b 0 0 +drop table if exists t0; +CREATE TABLE t0(c0 int); +INSERT INTO t0 VALUES (0); +SELECT t0.c0 FROM t0 WHERE CHAR(204355900); +c0 +0 +SELECT t0.c0 FROM t0 WHERE not CHAR(204355900); +c0 +SELECT t0.c0 FROM t0 WHERE '.0'; +c0 +SELECT t0.c0 FROM t0 WHERE not '.0'; +c0 +0 +select * from t0 where '.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +c0 +0 +select * from t0 where not '.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +c0 +select * from t0 where '.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +c0 +select * from t0 where not '.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +c0 +0 +drop table if exists testjson; +CREATE TABLE testjson (j json DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO testjson SET j='{"test":3}'; +INSERT INTO testjson SET j='{"test":0}'; +insert into testjson set j='{"test":"0"}'; +insert into testjson set j='{"test":0.0}'; +INSERT INTO testjson SET j='{"test":"aaabbb"}'; +INSERT INTO testjson SET j='{"test":3.1415}'; +INSERT INTO testjson SET j='{"test":[]}'; +INSERT INTO testjson SET j='{"test":[1,2]}'; +INSERT INTO testjson SET j='{"test":["b","c"]}'; +INSERT INTO testjson SET j='{"test":{"ke":"val"}}'; +insert into testjson set j='{"test":"2015-07-27 09:43:47"}'; +insert into testjson set j='{"test":"0000-00-00 00:00:00"}'; +insert into testjson set j='{"test":"0778"}'; +insert into testjson set j='{"test":"0000"}'; +insert into testjson set j='{"test":null}'; +insert into testjson set j=null; +insert into testjson set j='{"test":[null]}'; +insert into testjson set j='{"test":true}'; +insert into testjson set j='{"test":false}'; +insert into testjson set j='""'; +insert into testjson set j='null'; +insert into testjson set j='0'; +insert into testjson set j='"0"'; +SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test'); +j +{"test": 3} +{"test": "0"} +{"test": "aaabbb"} +{"test": 3.1415} +{"test": []} +{"test": [1, 2]} +{"test": ["b", "c"]} +{"test": {"ke": "val"}} +{"test": "2015-07-27 09:43:47"} +{"test": "0000-00-00 00:00:00"} +{"test": "0778"} +{"test": "0000"} +{"test": null} +{"test": [null]} +{"test": true} +{"test": false} +select * from testjson where j; +j +{"test": 3} +{"test": 0} +{"test": "0"} +{"test": 0} +{"test": "aaabbb"} +{"test": 3.1415} +{"test": []} +{"test": [1, 2]} +{"test": ["b", "c"]} +{"test": {"ke": "val"}} +{"test": "2015-07-27 09:43:47"} +{"test": "0000-00-00 00:00:00"} +{"test": "0778"} +{"test": "0000"} +{"test": null} +{"test": [null]} +{"test": true} +{"test": false} +"" +null +"0" +insert into mysql.expr_pushdown_blacklist values('json_extract','tikv',''); +admin reload expr_pushdown_blacklist; + +SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test'); +j +{"test": 3} +{"test": "0"} +{"test": "aaabbb"} +{"test": 3.1415} +{"test": []} +{"test": [1, 2]} +{"test": ["b", "c"]} +{"test": {"ke": "val"}} +{"test": "2015-07-27 09:43:47"} +{"test": "0000-00-00 00:00:00"} +{"test": "0778"} +{"test": "0000"} +{"test": null} +{"test": [null]} +{"test": true} +{"test": false} +select * from testjson where j; +j +{"test": 3} +{"test": 0} +{"test": "0"} +{"test": 0} +{"test": "aaabbb"} +{"test": 3.1415} +{"test": []} +{"test": [1, 2]} +{"test": ["b", "c"]} +{"test": {"ke": "val"}} +{"test": "2015-07-27 09:43:47"} +{"test": "0000-00-00 00:00:00"} +{"test": "0778"} +{"test": "0000"} +{"test": null} +{"test": [null]} +{"test": true} +{"test": false} +"" +null +"0" +drop table if exists t0; +CREATE TABLE t0(c0 int); +INSERT INTO t0 VALUES (1); +SELECT * FROM t0 WHERE 1 AND 0.4; +c0 +1 +drop table if exists t; +create table t(a int); +insert into t values(2); +select * from t where (not not a) = a; +a +select * from t where (not not not not a) = a; +a +drop table if exists t0; +CREATE TABLE t0(c0 INT); +INSERT INTO t0(c0) VALUES (0); +SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION SELECT * FROM t0; +c0 +0 +SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION all SELECT * FROM t0; +c0 +0 +0 +drop table if exists t0; +CREATE TABLE t0(c0 TEXT(10)); +INSERT INTO t0(c0) VALUES (1); +SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0; +c0 +1 +CREATE INDEX i0 ON t0(c0(10)); +SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0; +c0 +1 +drop table if exists t0; +CREATE TABLE t0(c0 INT, c1 INT AS (c0)); +CREATE INDEX i0 ON t0(c1); +SELECT t0.c0 FROM t0 UNION ALL SELECT 0 FROM t0; +c0 +drop table if exists t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +SELECT * FROM t1 NATURAL LEFT JOIN t0 WHERE NOT t1.c0; +c0 +drop table if exists t0,t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +INSERT INTO t0 VALUES (NULL), (1); +INSERT INTO t1 VALUES (0); +SELECT t0.c0 FROM t0 JOIN t1 ON (t0.c0 REGEXP 1) | t1.c0 WHERE BINARY STRCMP(t1.c0, t0.c0); +c0 +1 +drop table if exists t; +create table t (a int); +insert into t values (42); +select a from t where a/10000; +a +42 +select a from t where a/100000; +a +42 +select a from t where a/1000000; +a +42 +select a from t where a/10000000; +a +42 +drop table if exists t; +create table t(a datetime, b year); +insert into t values('2000-05-03 16:44:44', 2018); +insert into t values('2020-10-01 11:11:11', 2000); +insert into t values('2020-10-01 11:11:11', 2070); +insert into t values('2020-10-01 11:11:11', 1999); +select * from t where t.a < t.b; +a b +2000-05-03 16:44:44 2018 +2020-10-01 11:11:11 2070 +select * from t where t.a > t.b; +a b +2020-10-01 11:11:11 2000 +2020-10-01 11:11:11 1999 +drop table if exists tt; +create table tt(a date, b year); +insert into tt values('2019-11-11', 2000); +insert into tt values('2019-11-11', 2020); +insert into tt values('2019-11-11', 2022); +select * from tt where tt.a > tt.b; +a b +2019-11-11 2000 +select * from tt where tt.a < tt.b; +a b +2019-11-11 2020 +2019-11-11 2022 +drop table if exists ttt; +create table ttt(a timestamp, b year); +insert into ttt values('2019-11-11 11:11:11', 2019); +insert into ttt values('2019-11-11 11:11:11', 2000); +insert into ttt values('2019-11-11 11:11:11', 2022); +select * from ttt where ttt.a > ttt.b; +a b +2019-11-11 11:11:11 2019 +2019-11-11 11:11:11 2000 +select * from ttt where ttt.a < ttt.b; +a b +2019-11-11 11:11:11 2022 +drop table if exists t0, t1; +create table t0 (c0 int); +create table t1 (c0 int); +SELECT * FROM t1 LEFT JOIN t0 ON TRUE WHERE BINARY EXPORT_SET(0, 0, 0 COLLATE 'binary', t0.c0, 0 COLLATE 'binary'); +c0 c0 +drop table if exists t; +create table t(a int,b varchar(20),c datetime,d double,e int,f int as(a+b),key(a),key(b),key(c),key(d),key(e),key(f)); +insert into t(a,b,e) values(null,"5",null); +insert into t(a,b,e) values("5",null,null); +select /*+ use_index_merge(t)*/ * from t where t.e=5 or t.a=5; +a b c d e f +5 NULL NULL NULL NULL NULL +drop table if exists t1, t2; +create table t1(a char) collate utf8mb4_bin; +create table t2(a char) collate utf8mb4_bin; +insert into t1 values('a'); +insert into t2 values('a'); +select collation(t1.a) from t1 union select collation(t2.a) from t2; +collation(t1.a) +utf8mb4_bin +select collation(user()); +collation(user()) +utf8mb4_bin +select collation(compress('abc')); +collation(compress('abc')) +binary +set tidb_enable_prepared_plan_cache=1; +drop table if exists t; +set @@tidb_enable_vectorized_expression = false; +create table t(a datetime); +insert into t values(from_unixtime(1589873945)), (from_unixtime(1589873946)); +prepare stmt7 from 'SELECT unix_timestamp(a) FROM t WHERE a = from_unixtime(?);'; +set @val1 = 1589873945; +set @val2 = 1589873946; +execute stmt7 using @val1; +unix_timestamp(a) +1589873945 +execute stmt7 using @val2; +unix_timestamp(a) +1589873946 +drop table if exists t0; +create table t0(a char(10), b int as ((a))); +insert into t0(a) values("0.5"); +select * from t0; +a b +0.5 1 +drop table if exists t; +create table t(a int, b json, c int AS (JSON_EXTRACT(b, '$.population')), key(c)); +select /*+ TIDB_INLJ(t2) */ t1.a, t1.c, t2.a from t t1, t t2 where t1.c=t2.c; +a c a +drop table if exists t; +CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,type tinyint(4) NOT NULL,create_time int(11) NOT NULL,PRIMARY KEY (id)); +insert into t values (4, 2, 1598584933); +select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 1 group by t_day union all select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 2 group by t_day; +t_day cnt +2020-08-28 1 +drop table if exists t1; +create table t1 (col0 BLOB, col1 CHAR(74), col2 DATE UNIQUE); +insert into t1 values ('l', '7a34bc7d-6786-461b-92d3-fd0a6cd88f39', '1000-01-03'); +insert into t1 values ('l', NULL, '1000-01-04'); +insert into t1 values ('b', NULL, '1000-01-02'); +select INTERVAL( ( CONVERT( -11752 USING utf8 ) ), 6558853612195285496, `col1`) from t1; +INTERVAL( ( CONVERT( -11752 USING utf8 ) ), 6558853612195285496, `col1`) +0 +0 +0 +drop table if exists t, t1; +create table t(a int, b enum('A', 'B')); +create table t1(a1 int, b1 enum('B', 'A')); +insert into t values (1, 'A'); +insert into t1 values (1, 'A'); +select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1; +a b a1 b1 +1 A 1 A +drop table t, t1; +create table t(a int, b set('A', 'B')); +create table t1(a1 int, b1 set('B', 'A')); +insert into t values (1, 'A'); +insert into t1 values (1, 'A'); +select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1; +a b a1 b1 +1 A 1 A +drop table if exists t1; +create table t1 (c_int int, primary key (c_int)); +insert into t1 values (1), (2), (3); +drop table if exists t2; +create table t2 (c_int int, primary key (c_int)); +insert into t2 values (1); +select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1; +c1 c2 +1 1 +0 0 +0 0 +select (select count(c_int*c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1; +c1 c2 +1 1 +0 0 +0 0 +drop table if exists t0; +CREATE TABLE t0(c0 INTEGER AS (NULL) NOT NULL, c1 INT); +CREATE INDEX i0 ON t0(c0, c1); +INSERT IGNORE INTO t0(c1) VALUES (0); +SELECT * FROM t0; +c0 c1 +0 0 +begin; +INSERT IGNORE INTO t0(c1) VALUES (0); +SELECT * FROM t0; +c0 c1 +0 0 +0 0 +rollback; +drop table if exists t; +create table t (a int) partition by range(a) (PARTITION p0 VALUES LESS THAN (10)); +alter table t add partition (partition p1 values less than (a)); +Error 1054: Unknown column 'a' in 'expression' +select * from t; +a +drop table if exists t; +create table t (a int) partition by range(a) (PARTITION p0 VALUES LESS THAN (a)); +Error 1054: Unknown column 'a' in 'expression' +DROP TABLE IF EXISTS `table_float`; +DROP TABLE IF EXISTS `table_int_float_varchar`; +CREATE TABLE `table_float` (`id_1` int(16) NOT NULL AUTO_INCREMENT,`col_float_1` float DEFAULT NULL,PRIMARY KEY (`id_1`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=97635; +CREATE TABLE `table_int_float_varchar` (`id_6` int(16) NOT NULL AUTO_INCREMENT,`col_int_6` int(16) DEFAULT NULL,`col_float_6` float DEFAULT NULL,`col_varchar_6` varchar(511) DEFAULT NULL,PRIMARY KEY (`id_6`),KEY `vhyen` (`id_6`,`col_int_6`,`col_float_6`,`col_varchar_6`(1)),KEY `zzylq` (`id_6`,`col_int_6`,`col_float_6`,`col_varchar_6`(1))) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=90818; +INSERT INTO `table_float` VALUES (1,NULL),(2,0.1),(3,0),(4,-0.1),(5,-0.1),(6,NULL),(7,0.5),(8,0),(9,0),(10,NULL),(11,1),(12,1.5),(13,NULL),(14,NULL); +INSERT INTO `table_int_float_varchar` VALUES (1,0,0.1,'true'),(2,-1,1.5,'2020-02-02 02:02:00'),(3,NULL,1.5,NULL),(4,65535,0.1,'true'),(5,NULL,0.1,'1'),(6,-1,1.5,'2020-02-02 02:02:00'),(7,-1,NULL,''),(8,NULL,-0.1,NULL),(9,NULL,-0.1,'1'),(10,-1,NULL,''),(11,NULL,1.5,'false'),(12,-1,0,NULL),(13,0,-0.1,NULL),(14,-1,NULL,'-0'),(15,65535,-1,'1'),(16,NULL,0.5,NULL),(17,-1,NULL,NULL); +select count(*) from table_float +JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) +IS NULL WHERE col_int_6=0; +count(*) +14 +SELECT count(*) FROM (table_float JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) IS NULL); +count(*) +154 +SELECT * FROM (table_int_float_varchar AS tmp3) WHERE (col_varchar_6 AND NULL) IS NULL AND col_int_6=0; +id_6 col_int_6 col_float_6 col_varchar_6 +13 0 -0.1 NULL +drop table if exists papers; +create table papers(title text, content longtext); +insert into papers values('title', 'content'); +select to_base64(title), to_base64(content) from papers; +to_base64(title) to_base64(content) +dGl0bGU= Y29udGVudA== +set tidb_enable_vectorized_expression = 0; +select to_base64(title), to_base64(content) from papers; +to_base64(title) to_base64(content) +dGl0bGU= Y29udGVudA== +set tidb_enable_vectorized_expression = 1; +drop table if exists t, t1; +create table t(a enum('a', 'b'), b tinyint); +create table t1(c varchar(20)); +insert into t values('b', 0); +insert into t1 values('b'); +select * from t, t1 where t.a= t1.c; +a b c +b 0 b +select * from t, t1 where t.b= t1.c; +a b c +b 0 b +select * from t, t1 where t.a = t1.c and t.b= t1.c; +a b c +b 0 b +drop table if exists t; +create table t(a enum('a','b')); +insert into t values('b'); +select * from t where a > 1 and a = "b"; +a +b +drop table if exists lt; +create table lt (d decimal(10, 4)); +insert into lt values(0.2),(0.2); +select LEAD(d,1,1) OVER(), LAG(d,1,1) OVER() from lt; +LEAD(d,1,1) OVER() LAG(d,1,1) OVER() +0.2000 1.0000 +1.0000 0.2000 +drop table if exists t; +create table t(a int); +insert into t values (1); +insert into t select values(a) from t; +select * from t; +a +1 +NULL +DROP TABLE IF EXISTS tmp; +CREATE TABLE tmp (id int(11) NOT NULL,value int(1) NOT NULL,PRIMARY KEY (id)); +INSERT INTO tmp VALUES (1, 1),(2,2),(3,3),(4,4),(5,5); +SET @sum := 10; +SELECT @sum := IF(@sum=20,4,@sum + tmp.value) sum FROM tmp ORDER BY tmp.id; +sum +11 +13 +16 +20 +4 +drop table if exists t; +create table t(id int primary key, c int, d timestamp null default null); +insert into t values(1, 2, '2038-01-18 20:20:30'); +update t set d = adddate(d, interval 1 day) where id < 10; +Error 1292: Incorrect timestamp value: '2038-01-19 20:20:30' +drop view if exists t15847; +CREATE VIEW t15847(c0) AS SELECT NULL; +SELECT * FROM t15847 WHERE (NOT (IF(t15847.c0, NULL, NULL))); +c0 +drop view if exists t15847; +select json_array(true); +json_array(true) +[true] +select json_array(1=2); +json_array(1=2) +[false] +select json_array(1!=2); +json_array(1!=2) +[true] +select json_array(1<2); +json_array(1<2) +[true] +select json_array(1<=2); +json_array(1<=2) +[true] +select json_array(1>2); +json_array(1>2) +[false] +select json_array(1>=2); +json_array(1>=2) +[false] +select json_object(true, null <=> null); +json_object(true, null <=> null) +{"1": true} +select json_object(false, 1 and 2); +json_object(false, 1 and 2) +{"0": true} +select json_object(false, 1 and 0); +json_object(false, 1 and 0) +{"0": false} +select json_object(false, 1 or 0); +json_object(false, 1 or 0) +{"0": true} +select json_object(false, 1 xor 0); +json_object(false, 1 xor 0) +{"0": true} +select json_object(false, 1 xor 1); +json_object(false, 1 xor 1) +{"0": false} +select json_object(false, not 1); +json_object(false, not 1) +{"0": false} +select json_array(null and 1); +json_array(null and 1) +[null] +select json_array(null and 0); +json_array(null and 0) +[false] +select json_array(null or 1); +json_array(null or 1) +[true] +select json_array(null or 0); +json_array(null or 0) +[null] +select json_array(1.15 or 0); +json_array(1.15 or 0) +[true] +select json_array('abc' or 0); +json_array('abc' or 0) +[false] +select json_array('1abc' or 0); +json_array('1abc' or 0) +[true] +select json_array(null is true); +json_array(null is true) +[false] +select json_array(null is null); +json_array(null is null) +[true] +select json_array(1 in (1, 2)); +json_array(1 in (1, 2)) +[true] +select json_array(0 in (1, 2)); +json_array(0 in (1, 2)) +[false] +select json_array(0 not in (1, 2)); +json_array(0 not in (1, 2)) +[true] +select json_array(1 between 0 and 2); +json_array(1 between 0 and 2) +[true] +select json_array(1 not between 0 and 2); +json_array(1 not between 0 and 2) +[false] +select json_array('123' like '123'); +json_array('123' like '123') +[true] +select json_array('abcdef' rlike 'a.*c.*'); +json_array('abcdef' rlike 'a.*c.*') +[true] +select json_array(is_ipv4('127.0.0.1')); +json_array(is_ipv4('127.0.0.1')) +[true] +select json_array(is_ipv6('1a6b:8888:ff66:77ee:0000:1234:5678:bcde')); +json_array(is_ipv6('1a6b:8888:ff66:77ee:0000:1234:5678:bcde')) +[true] +drop table if exists t7; +create table t7 (col0 SMALLINT, col1 VARBINARY(1), col2 DATE, col3 BIGINT, col4 BINARY(166)); +insert into t7 values ('32767', '', '1000-01-03', '-0', '11101011'); +select col2 = 1 from t7; +col2 = 1 +0 +select col2 != 1 from t7; +col2 != 1 +1 +select CAST("9223372036854775808" as json); +CAST("9223372036854775808" as json) +9223372036854775808 +select json_type(CAST("9223372036854775808" as json)); +json_type(CAST("9223372036854775808" as json)) +UNSIGNED INTEGER +select CAST(9223372036854775808 as json); +CAST(9223372036854775808 as json) +9223372036854775808 +select json_type(CAST(9223372036854775808 as json)); +json_type(CAST(9223372036854775808 as json)) +UNSIGNED INTEGER +select CAST(-9223372036854775808 as json); +CAST(-9223372036854775808 as json) +-9223372036854775808 +select json_type(CAST(-9223372036854775808 as json)); +json_type(CAST(-9223372036854775808 as json)) +INTEGER +drop table if exists tx2; +create table tx2 (col json); +insert into tx2 values (json_array("3")),(json_array("3")),(json_array("3")),(json_array("3")); +insert into tx2 values (json_array(3.0)); +insert into tx2 values (json_array(3)); +insert into tx2 values (json_array(3.0)); +insert into tx2 values (json_array(-3)); +insert into tx2 values (json_array(-3.0)); +insert into tx2 values (json_array(922337203685477580)); +insert into tx2 values (json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)); +select col, count(1) c from tx2 group by col order by c desc; +col c +[922337203685477581] 5 +["3"] 4 +[3] 3 +[-3] 2 +[922337203685477580] 1 +drop table if exists t12205; +create table t12205( +`col_varchar_64` varchar(64) DEFAULT NULL, +`col_varchar_64_key` varchar(64) DEFAULT NULL +); +insert into t12205 values('-1038024704','-527892480'); +select SEC_TO_TIME( ( `col_varchar_64` & `col_varchar_64_key` ) ),`col_varchar_64` & `col_varchar_64_key` from t12205; +SEC_TO_TIME( ( `col_varchar_64` & `col_varchar_64_key` ) ) `col_varchar_64` & `col_varchar_64_key` +838:59:59 18446744072635875328 +show warnings; +Level Code Message +drop table if exists t; +create table t(1e int); +insert into t values (1); +select t.1e from expression__issues.t; +1e +1 +drop table if exists t; +create table t(99e int, r10 int); +insert into t values (1, 10), (2, 2); +select 99e+r10 from t; +99e+r10 +11 +4 +select .78$123; +$123 +0.78 +select .78$421+1; +[parser:1064]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 15 near "+1;" +select t. `r10` > 3 from t; +t. `r10` > 3 +1 +0 +select * from t where t. `r10` > 3; +99e r10 +1 10 +drop table if exists t1; +create table t1 (f1 decimal(5,5)); +insert into t1 values (-0.12345); +select concat(f1) from t1; +concat(f1) +-0.12345 +drop table if exists t12206; +create table t12206( +`col_tinyint_unsigned` tinyint(3) unsigned DEFAULT NULL, +`col_double_unsigned` double unsigned DEFAULT NULL, +`col_year_key` year(4) DEFAULT NULL +); +insert into t12206 values(73,0,0000); +SELECT TIME_FORMAT( `col_tinyint_unsigned`, ( IFNULL( `col_double_unsigned`, `col_year_key` ) ) ) AS field1 FROM `t12206`; +field1 +NULL +show warnings; +Level Code Message +drop table if exists t12209; +create table t12209(a bigint(20)); +insert into t12209 values(1); +select `a` DIV ( ROUND( ( SCHEMA() ), '1978-05-18 03:35:52.043591' ) ) from `t12209`; +`a` DIV ( ROUND( ( SCHEMA() ), '1978-05-18 03:35:52.043591' ) ) +NULL +drop table if exists ta, tb; +CREATE TABLE `ta` ( `k` varchar(32) NOT NULL DEFAULT ' ', `c0` varchar(32) NOT NULL DEFAULT ' ', `c` varchar(18) NOT NULL DEFAULT ' ', `e0` varchar(1) NOT NULL DEFAULT ' ', PRIMARY KEY (`k`,`c0`,`c`), KEY `idx` (`c`,`e0`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE `tb` ( `k` varchar(32) NOT NULL DEFAULT ' ', `e` int(11) NOT NULL DEFAULT '0', `i` int(11) NOT NULL DEFAULT '0', `s` varchar(1) NOT NULL DEFAULT ' ', `c` varchar(50) NOT NULL DEFAULT ' ', PRIMARY KEY (`k`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +prepare stmt from "select a.* from ta a left join tb b on a.k = b.k where (a.k <> '000000' and ((b.s = ? and i = ? ) or (b.s = ? and e = ?) or (b.s not in(?, ?))) and b.c like '%1%') or (a.c <> '000000' and a.k = '000000')"; +set @a=3; +set @b=20200414; +set @c='a'; +set @d=20200414; +set @e=3; +set @f='a'; +execute stmt using @a,@b,@c,@d,@e,@f; +k c0 c e0 +drop table if exists t; +create table t( +a enum('a','','c'), +b enum('0','1','2'), +c set('a','','c'), +d set('0','1','2') +); +insert into t values(1,1,1,1),(2,2,2,2),(3,3,3,3); +set @@sql_mode = ''; +insert into t values('','','',''); +select * from t; +a b c d +a 0 a 0 + 1 1 +c 2 a, 0,1 + +select a from t where a; +a +a + +c + +select b from t where b; +b +0 +1 +2 +select c from t where c; +c +a + +a, + +select d from t where d; +d +0 +1 +0,1 +set @@sql_mode=default; +drop table if exists t; +create table t(a year); +insert into t values(2002); +select * from t where a=2; +a +2002 +select * from t where a='2'; +a +2002 +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) ); +create table t2 like t1 ; +insert into t1 values (1, 'crazy lumiere'), (10, 'goofy mestorf'); +insert into t2 select * from t1 ; +select (select t2.c_str from t2 where t2.c_str = t1.c_str and t2.c_int = 10 order by t2.c_str limit 1) x from t1; +x +NULL +goofy mestorf +drop table if exists t1; +create table t1(c1 int); +insert into t1 values(-2147483648), (-2147483648), (null); +select count(*) from t1 where c1 > (select sum(c1) from t1); +count(*) +2 +drop table if exists t; +create table t(a int primary key, b set('Alice','Bob') DEFAULT NULL); +insert into t value(1,'Bob'); +select max(b) + 0 from t group by a; +max(b) + 0 +2 +drop table if exists t; +create table t(a int, b set('Alice','Bob') DEFAULT NULL); +insert into t value(1,'Bob'); +select max(b) + 0 from t group by a; +max(b) + 0 +2 +drop table if exists test_decimal,test_t; +create table test_decimal(col_decimal decimal(10,0)); +insert into test_decimal values(null),(8); +create table test_t(a int(11), b decimal(32,0)); +insert into test_t values(1,4),(2,4),(5,4),(7,4),(9,4); +SELECT ( test_decimal . `col_decimal` , test_decimal . `col_decimal` ) IN ( select * from test_t ) as field1 FROM test_decimal; +field1 +NULL +0 +drop table if exists foo, bar; +create table foo(a decimal(65,0)); +create table bar(a decimal(65,0), b decimal(65,0)); +insert into bar values(0,0),(1,1),(2,2); +insert into foo select if(b>0, if(a/b>1, 1, 2), null) from bar; +drop table if exists t1_1, t2_1; +CREATE TABLE `t1_1` (`col1` double DEFAULT NULL, `col2` double DEFAULT NULL); +CREATE TABLE `t2_1` (`col1` varchar(20) DEFAULT NULL, `col2` double DEFAULT NULL); +insert into t1_1 values(12.991, null), (12.991, null); +insert into t2_1(col2) values(87), (-9.183), (-9.183); +set @@tidb_enable_vectorized_expression = false; +select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3; +col1 col1 col2 +set @@tidb_enable_vectorized_expression = true; +select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3; +col1 col1 col2 +drop table if exists tbl_6, tbl_17; +create table tbl_6 (col_31 year, index(col_31)); +create table tbl_17 (col_102 int, col_105 int); +replace into tbl_17 (col_102, col_105) values (9999, 0); +select tbl_6.col_31 from tbl_6 where col_31 in (select col_102 from tbl_17 where tbl_17.col_102 = 9999 and tbl_17.col_105 = 0); +col_31 +drop table if exists tbl_0,tbl_9; +CREATE TABLE `tbl_9` ( +`col_54` mediumint NOT NULL DEFAULT '2412996', +`col_55` int NOT NULL, +`col_56` bigint unsigned NOT NULL, +`col_57` varchar(108) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, +PRIMARY KEY (`col_57`(3),`col_55`,`col_56`,`col_54`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE `tbl_0` ( +`col_76` bigint(20) unsigned DEFAULT NULL, +`col_1` time NOT NULL DEFAULT '13:11:28', +`col_2` datetime DEFAULT '1990-07-29 00:00:00', +`col_3` date NOT NULL DEFAULT '1976-09-16', +`col_4` date DEFAULT NULL, +`col_143` varbinary(208) DEFAULT 'lXRTXUkTeWaJ', +KEY `idx_0` (`col_2`,`col_1`,`col_76`,`col_4`,`col_3`), +PRIMARY KEY (`col_1`,`col_3`) /*T![clustered_index] NONCLUSTERED */, +KEY `idx_2` (`col_1`,`col_4`,`col_76`,`col_3`), +KEY `idx_3` (`col_4`,`col_76`,`col_3`,`col_2`,`col_1`), +UNIQUE KEY `idx_4` (`col_76`,`col_3`,`col_1`,`col_4`), +KEY `idx_5` (`col_3`,`col_4`,`col_76`,`col_2`), +KEY `idx_6` (`col_2`), +KEY `idx_7` (`col_76`,`col_3`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into tbl_9 values (-5765442,-597990898,384599625723370089,"ZdfkUJiHcOfi"); +(select col_76,col_1,col_143,col_2 from tbl_0) union (select col_54,col_57,col_55,col_56 from tbl_9); +col_76 col_1 col_143 col_2 +-5765442 ZdfkUJiHcOfi -597990898 384599625723370089 +drop table if exists t1; +create table t1 (c_int int not null); +insert into t1 values (1), (2), (3),(1),(2),(3); +drop table if exists t2; +create table t2 (c_int int not null); +insert into t2 values (1), (2), (3),(1),(2),(3); +select (select count(distinct c_int) from t2 where c_int >= t1.c_int) c1, (select count(distinct c_int) from t2 where c_int >= t1.c_int) c2 from t1 group by c_int; +c1 c2 +3 3 +2 2 +1 1 +drop table if exists t; +CREATE TABLE `t` ( +`COL1` tinyint(45) NOT NULL, +`COL2` tinyint(45) NOT NULL, +PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into t values(122,100),(124,-22),(124,34),(127,103); +SELECT col2 FROM t AS T1 WHERE ( SELECT count(DISTINCT COL1, COL2) FROM t AS T2 WHERE T2.COL1 > T1.COL1 ) > 2 ; +col2 +100 +select extract(hour_second from "-838:59:59.00"); +extract(hour_second from "-838:59:59.00") +-8385959 +drop table if exists t; +create table t(c1 varchar(100)); +insert into t values('-838:59:59.00'), ('700:59:59.00'); +select extract(hour_second from c1) from t order by c1; +extract(hour_second from c1) +-8385959 +7005959 +select a + 1 as f from (select cast(0xfffffffffffffff0 as unsigned) as a union select cast(1 as unsigned)) t having f != 2; +f +18446744073709551601 +drop table if exists PK_TCOLLATION3966STROBJSTROBJ; +CREATE TABLE `PK_TCOLLATION3966STROBJSTROBJ` ( +`COL1` enum('ll','aa','bb','cc','dd','ee') COLLATE utf8_general_ci NOT NULL, +`COL2` varchar(20) COLLATE utf8_general_ci DEFAULT NULL, +PRIMARY KEY (`COL1`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +insert into PK_TCOLLATION3966STROBJSTROBJ values("ee", "tttt"); +SELECT col1, COL2 FROM PK_TCOLLATION3966STROBJSTROBJ WHERE COL1 IN ('notexist','6') and col2 not in ("abcd"); +col1 COL2 +drop table if exists perf_offline_day; +CREATE TABLE perf_offline_day ( +uuid varchar(50), +ts timestamp NOT NULL, +user_id varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, +platform varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, +host_id bigint(20) DEFAULT NULL, +PRIMARY KEY (uuid,ts) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci +PARTITION BY RANGE ( UNIX_TIMESTAMP(ts) ) ( +PARTITION p20210906 VALUES LESS THAN (1630944000), +PARTITION p20210907 VALUES LESS THAN (1631030400), +PARTITION p20210908 VALUES LESS THAN (1631116800), +PARTITION p20210909 VALUES LESS THAN (1631203200) +); +set @@tidb_partition_prune_mode = 'static'; +INSERT INTO `perf_offline_day` VALUES ('dd082c8a-3bab-4431-943a-348fe0592abd','2021-09-08 13:00:07','Xg9C8zq81jGNbugM', 'pc', 12345); +SELECT cast(floor(hour(ts) / 4) as char) as win_start FROM perf_offline_day partition (p20210907, p20210908) GROUP BY win_start; +win_start +3 +drop table if exists t; +create table t(a time(4)); +insert into t values("-838:59:59.000000"); +insert into t values("838:59:59.000000"); +set tidb_enable_vectorized_expression = on; +select hour(a) from t; +hour(a) +838 +838 +set tidb_enable_vectorized_expression = off; +select hour(a) from t; +hour(a) +838 +838 +set tidb_enable_vectorized_expression = default; +drop table if exists t; +create table t(a enum("a", "b"), b enum("a", "b"), c bool); +insert into t values("a", "a", 1); +select * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c; +a b c a b c +a a 1 a a 1 +drop table if exists t; +create table t(a enum("a", "b"), b enum("a", "b"), c bool, d int, index idx(d)); +insert into t values("a", "a", 1, 1); +select /*+ inl_hash_join(t1) */ * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c and t1.d=t2.d; +a b c d a b c d +a a 1 1 a a 1 1 +drop table if exists t1; +create table t1(c1 datetime); +insert into t1 values('2021-12-12 10:10:10.000'); +set tidb_enable_vectorized_expression = on; +select greatest(c1, '99999999999999') from t1; +greatest(c1, '99999999999999') +99999999999999 +select least(c1, '99999999999999') from t1; +least(c1, '99999999999999') +2021-12-12 10:10:10 +set tidb_enable_vectorized_expression = off; +select greatest(c1, '99999999999999') from t1; +greatest(c1, '99999999999999') +99999999999999 +select least(c1, '99999999999999') from t1; +least(c1, '99999999999999') +2021-12-12 10:10:10 +set tidb_enable_vectorized_expression = default; +drop table if exists t; +create table t(a time(4)); +insert into t values("-700:10:10.123456111"); +insert into t values("700:10:10.123456111"); +set tidb_enable_vectorized_expression = on; +select microsecond(a) from t; +microsecond(a) +123500 +123500 +set tidb_enable_vectorized_expression = off; +select microsecond(a) from t; +microsecond(a) +123500 +123500 +set tidb_enable_vectorized_expression = default; +set tidb_enable_vectorized_expression = on; +select char(123, NULL, 123); +char(123, NULL, 123) +{{ +select char(NULL, 123, 123); +char(NULL, 123, 123) +{{ +set tidb_enable_vectorized_expression = off; +select char(123, NULL, 123); +char(123, NULL, 123) +{{ +select char(NULL, 123, 123); +char(NULL, 123, 123) +{{ +set tidb_enable_vectorized_expression = default; +drop table if exists t1; +create table t1(c1 bigint unsigned, c2 bigint unsigned); +insert into t1 values(9223372036854775808, 9223372036854775809); +select greatest(c1, c2) from t1; +greatest(c1, c2) +9223372036854775809 +drop table if exists t; +create table t(a int); +insert into t values(1),(1),(2),(2); +set tidb_window_concurrency = 1; +select (FIRST_VALUE(1) over (partition by v.a)) as c3 from (select a from t where t.a = (select a from t t2 where t.a = t2.a)) as v; +Error 1242: Subquery returns more than 1 row +drop table if exists t1,t2; +CREATE TABLE `t1` ( +`c1` enum('Alice','Bob','Charlie','David') NOT NULL, +`c2` blob NOT NULL, +PRIMARY KEY (`c2`(5)), +UNIQUE KEY `idx_89` (`c1`) +); +CREATE TABLE `t2` ( +`c1` enum('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'Alice', +`c2` set('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'David', +`c3` enum('Alice','Bob','Charlie','David') NOT NULL, +PRIMARY KEY (`c3`,`c2`) +); +insert into t1 values('Charlie',''); +insert into t2 values('Charlie','Charlie','Alice'); +select * from t2 where c3 in (select c2 from t1); +c1 c2 c3 +select * from t2 where c2 in (select c2 from t1); +c1 c2 c3 +drop table if exists t1; +CREATE TABLE t1 (a text)character set utf8 ; +INSERT INTO t1 VALUES (REPEAT(0125,200000000)); +Error 1301: Result of repeat() was larger than max_allowed_packet (67108864) - truncated +select * from t1; +a +insert into t1 (a) values ('a'),('b'); +insert into t1 select REPEAT(a,200000000) from t1; +Error 1301: Result of repeat() was larger than max_allowed_packet (67108864) - truncated +select a from t1 order by a; +a +a +b +insert into t1 values (cast("a" as binary(4294967295))); +Error 1301: Result of cast_as_binary() was larger than max_allowed_packet (67108864) - truncated +select a from t1 order by a; +a +a +b +INSERT IGNORE INTO t1 VALUES (REPEAT(0125,200000000)); +show warnings; +Level Code Message +select a from t1 order by a; +a +NULL +a +b +drop table if exists t; +create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +insert into t values('Ęž'), ('İ'); +set @@tidb_enable_vectorized_expression = false; +select binary upper(a), lower(a) from t order by upper(a); +binary upper(a) lower(a) +İ i +ęž° Ęž +select distinct upper(a), lower(a) from t order by upper(a); +upper(a) lower(a) +İ i +ęž° Ęž +set @@tidb_enable_vectorized_expression = true; +select binary upper(a), lower(a) from t order by upper(a); +binary upper(a) lower(a) +İ i +ęž° Ęž +select distinct upper(a), lower(a) from t order by upper(a); +upper(a) lower(a) +İ i +ęž° Ęž +set @@tidb_enable_vectorized_expression = default; +drop table if exists t; +create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +insert into t values(''), (''); +set @@tidb_enable_vectorized_expression = true; +select compress(a) from t; +compress(a) + + +set @@tidb_enable_vectorized_expression = false; +select compress(a) from t; +compress(a) + + +set @@tidb_enable_vectorized_expression = default; +drop table if exists t; +create table t(a varchar(32)); +insert into t values(date_add(cast('00:00:00' as time), interval 1.1 second)); +select * from t; +a +00:00:01.1 +select cast(date_add(cast('00:00:00' as time), interval 1.1 second) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 second) as char) +00:00:01.1 +select cast(date_add(cast('00:00:00' as time), interval 1.1 microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 microsecond) as char) +00:00:00.000001 +select cast(date_add(cast('00:00:00' as time), interval 1000000 microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1000000 microsecond) as char) +00:00:01.000000 +select cast(date_add(cast('00:00:00' as time), interval 1.1111119 second) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1111119 second) as char) +00:00:01.111111 +select cast(date_add(cast('00:00:00' as time), interval 1.0 second) as char); +cast(date_add(cast('00:00:00' as time), interval 1.0 second) as char) +00:00:01.0 +select cast(date_add(cast('00:00:00' as time), interval 1.1 second_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 second_microsecond) as char) +00:00:01.100000 +select cast(date_add(cast('00:00:00' as time), interval 1111111 second_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1111111 second_microsecond) as char) +00:00:01.111111 +select cast(date_add(cast('00:00:00' as time), interval 1.1 minute_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 minute_microsecond) as char) +00:00:01.100000 +select cast(date_add(cast('00:00:00' as time), interval 1111111 minute_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1111111 minute_microsecond) as char) +00:00:01.111111 +select cast(date_add(cast('00:00:00' as time), interval 1.1 minute_second) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 minute_second) as char) +00:01:01 +select cast(date_add(cast('00:00:00' as time), interval 1111111 minute_second) as char); +cast(date_add(cast('00:00:00' as time), interval 1111111 minute_second) as char) +308:38:31 +select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 hour_microsecond) as char) +00:00:01.100000 +select cast(date_add(cast('00:00:00' as time), interval 1111111 hour_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1111111 hour_microsecond) as char) +00:00:01.111111 +select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_second) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 hour_second) as char) +00:01:01 +select cast(date_add(cast('00:00:00' as time), interval 1111111 hour_second) as char); +cast(date_add(cast('00:00:00' as time), interval 1111111 hour_second) as char) +308:38:31 +select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_minute) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 hour_minute) as char) +01:01:00 +select cast(date_add(cast('00:00:00' as time), interval 1.1 day_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1.1 day_microsecond) as char) +00:00:01.100000 +select cast(date_add(cast('00:00:00' as time), interval 1111111 day_microsecond) as char); +cast(date_add(cast('00:00:00' as time), interval 1111111 day_microsecond) as char) +00:00:01.111111 +drop table if exists t; +create table t(i int, c varchar(32)); +insert into t values(1, date_add(cast('2001-01-01 00:00:00' as datetime), interval 1 second)); +insert into t values(2, date_add(cast('2001-01-01 00:00:00' as datetime(6)), interval 1 second)); +insert into t values(3, date_add(cast('2001-01-01 00:00:00' as datetime), interval 1.1 second)); +insert into t values(4, date_add(cast('2001-01-01 00:00:00' as datetime(6)), interval 1.1 second)); +insert into t values(5, date_add(cast('00:00:00' as time), interval 1.1 second)); +select c from t order by i; +c +2001-01-01 00:00:01 +2001-01-01 00:00:01.000000 +2001-01-01 00:00:01.1 +2001-01-01 00:00:01.100000 +00:00:01.1 +set time_zone = '+00:00'; +drop table if exists t; +create table t(ts timestamp(6) not null default current_timestamp(6) on update current_timestamp(6)); +insert into t values('1970-01-01 01:00:01.000000'); +insert into t values('1970-01-01 01:00:01.000001'); +insert into t values('1971-01-01 01:00:00.000000'); +insert into t values('1971-01-01 01:00:00.000001'); +insert into t values('2001-01-01 00:00:00.000000'); +insert into t values('2001-01-01 00:00:00.000001'); +insert into t values('2001-01-01 01:00:00.000000'); +insert into t values('2001-01-01 01:00:00.000001'); +select date_add(ts, interval 1 minute) from t order by ts; +date_add(ts, interval 1 minute) +1970-01-01 01:01:01.000000 +1970-01-01 01:01:01.000001 +1971-01-01 01:01:00.000000 +1971-01-01 01:01:00.000001 +2001-01-01 00:01:00.000000 +2001-01-01 00:01:00.000001 +2001-01-01 01:01:00.000000 +2001-01-01 01:01:00.000001 +select date_sub(ts, interval 1 minute) from t order by ts; +date_sub(ts, interval 1 minute) +1970-01-01 00:59:01.000000 +1970-01-01 00:59:01.000001 +1971-01-01 00:59:00.000000 +1971-01-01 00:59:00.000001 +2000-12-31 23:59:00.000000 +2000-12-31 23:59:00.000001 +2001-01-01 00:59:00.000000 +2001-01-01 00:59:00.000001 +set time_zone = default; +set time_zone = '+00:00'; +drop table if exists t; +create table t (tm_fsp0 time(0), tm_fsp1 time(1), tm_fsp3 time(3),tm_fsp6 time(6), d date, dt_fsp0 datetime(0), dt_fsp1 datetime(1), dt_fsp3 datetime(3), dt_fsp6 datetime(6)); +insert into t values(null, '12:12:01.1', '12:12:02.123', '12:12:03.123456', '20221212', null, '2020/12/11 12:12:11.1', '2020/12/12 12:12:12.123', '2020/12/13 12:12:13.123456'); +insert into t values('12:12:00', null, '12:12:02.123', '12:12:03.123456', '20221212', '2020/12/10 12:12:10', null, '2020/12/12 12:12:12.123', '2020/12/13 12:12:13.123456'); +insert into t values('12:12:00', '12:12:01.1', null, '12:12:03.123456', '20221212', '2020/12/10 12:12:10', '2020/12/11 12:12:11.1', null, '2020/12/13 12:12:13.123456'); +insert into t values('12:12:00', '12:12:01.1', '12:12:02.123', null, '20221212', '2020/12/10 12:12:10', '2020/12/11 12:12:11.1', '2020/12/12 12:12:12.123', null); +select coalesce(null, tm_fsp0, tm_fsp1, tm_fsp3, tm_fsp6) from t; +coalesce(null, tm_fsp0, tm_fsp1, tm_fsp3, tm_fsp6) +12:12:01.100000 +12:12:00.000000 +12:12:00.000000 +12:12:00.000000 +select coalesce(tm_fsp1, tm_fsp0, tm_fsp3) from t; +coalesce(tm_fsp1, tm_fsp0, tm_fsp3) +12:12:01.100 +12:12:00.000 +12:12:01.100 +12:12:01.100 +select coalesce(tm_fsp3, tm_fsp0) from t; +coalesce(tm_fsp3, tm_fsp0) +12:12:02.123 +12:12:02.123 +12:12:00.000 +12:12:02.123 +select coalesce(tm_fsp6) from t; +coalesce(tm_fsp6) +12:12:03.123456 +12:12:03.123456 +12:12:03.123456 +NULL +select coalesce(null, dt_fsp0, dt_fsp1, dt_fsp3, dt_fsp6) from t; +coalesce(null, dt_fsp0, dt_fsp1, dt_fsp3, dt_fsp6) +2020-12-11 12:12:11.100000 +2020-12-10 12:12:10.000000 +2020-12-10 12:12:10.000000 +2020-12-10 12:12:10.000000 +select coalesce(dt_fsp0, dt_fsp1, dt_fsp3) from t; +coalesce(dt_fsp0, dt_fsp1, dt_fsp3) +2020-12-11 12:12:11.100 +2020-12-10 12:12:10.000 +2020-12-10 12:12:10.000 +2020-12-10 12:12:10.000 +select coalesce(dt_fsp3, dt_fsp0) from t; +coalesce(dt_fsp3, dt_fsp0) +2020-12-12 12:12:12.123 +2020-12-12 12:12:12.123 +2020-12-10 12:12:10.000 +2020-12-12 12:12:12.123 +select coalesce(dt_fsp6) from t; +coalesce(dt_fsp6) +2020-12-13 12:12:13.123456 +2020-12-13 12:12:13.123456 +2020-12-13 12:12:13.123456 +NULL +select coalesce(null, d) from t; +coalesce(null, d) +2022-12-12 +2022-12-12 +2022-12-12 +2022-12-12 +set time_zone = default; +drop table if exists t; +create table t (c int primary key, c2 enum('a', 'b')); +set session sql_mode = ''; +insert into t values(4, 'a'); +insert into t values(4, 0) on duplicate key update c=values(c), c2=values(c2); +show warnings; +Level Code Message +insert into t values(4, 'a') on duplicate key update c=values(c), c2=values(c2); +show warnings; +Level Code Message +set @@sql_mode=default; +drop table if exists t0, t1; +CREATE TABLE t0(c0 BOOL, c1 INT); +CREATE TABLE t1 LIKE t0; +CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT IS_IPV4(t0.c1) FROM t0, t1; +INSERT INTO t0(c0, c1) VALUES (true, 0); +INSERT INTO t1(c0, c1) VALUES (true, 2); +SELECT v0.c0 FROM v0 WHERE (v0.c0)NOT LIKE(BINARY v0.c0); +c0 +SELECT v0.c0 FROM v0 WHERE (v0.c0)NOT LIKE(BINARY v0.c0) or v0.c0 > 0; +c0 +select greatest(time '21:00', year(date'20220101'), 23); +greatest(time '21:00', year(date'20220101'), 23) +23 +select greatest(time '21:00', date'891001', 120000); +greatest(time '21:00', date'891001', 120000) +21:00:00 +select greatest(time '20:00', date'101001', 120101); +greatest(time '20:00', date'101001', 120101) +20:00:00 +select greatest(date'101001', '19990329', 120101); +greatest(date'101001', '19990329', 120101) +2012-01-01 +select greatest(time '20:00', date'691231'); +greatest(time '20:00', date'691231') +2069-12-31 00:00:00 +select greatest(date '120301', date'691231'); +greatest(date '120301', date'691231') +2069-12-31 +select greatest(time '203001', time '2230'); +greatest(time '203001', time '2230') +20:30:01 +select greatest(timestamp '2021-01-31 00:00:01', timestamp '2021-12-31 12:00:00'); +greatest(timestamp '2021-01-31 00:00:01', timestamp '2021-12-31 12:00:00') +2021-12-31 12:00:00 +select greatest(time '00:00:01', timestamp '2069-12-31 12:00:00'); +greatest(time '00:00:01', timestamp '2069-12-31 12:00:00') +2069-12-31 12:00:00 +select greatest(date '21000101', timestamp '2069-12-31 12:00:00'); +greatest(date '21000101', timestamp '2069-12-31 12:00:00') +2100-01-01 00:00:00 +select greatest(cast('1' as JSON), cast('2' as JSON)); +greatest(cast('1' as JSON), cast('2' as JSON)) +2 +select greatest(time '20:00:00', 120000); +greatest(time '20:00:00', 120000) +20:00:00 +select greatest(date '2005-05-05', 20010101, 20040404, 20030303); +greatest(date '2005-05-05', 20010101, 20040404, 20030303) +2005-05-05 +select greatest(date '1995-05-05', 19910101, 20050505, 19930303); +greatest(date '1995-05-05', 19910101, 20050505, 19930303) +2005-05-05 +drop table if exists t1,t2; +CREATE TABLE `t1` (a datetime, b date, c time); +insert into t1 values(timestamp'2021-01-31 00:00:01', '2069-12-31', '20:00:01'); +set tidb_enable_vectorized_expression = on; +select greatest(c, year(date'20220101'), 23) from t1; +greatest(c, year(date'20220101'), 23) +23 +select greatest(c, date'891001', 120000) from t1; +greatest(c, date'891001', 120000) +20:00:01 +select greatest(c, date'101001', 120101) from t1; +greatest(c, date'101001', 120101) +20:00:01 +select greatest(b, '19990329', 120101) from t1; +greatest(b, '19990329', 120101) +2069-12-31 +select greatest(time '20:00', b) from t1; +greatest(time '20:00', b) +2069-12-31 00:00:00 +select greatest(date '120301', b) from t1; +greatest(date '120301', b) +2069-12-31 +select greatest(c, time '2230') from t1; +greatest(c, time '2230') +20:00:01 +select greatest(a, timestamp '2021-12-31 12:00:00') from t1; +greatest(a, timestamp '2021-12-31 12:00:00') +2021-12-31 12:00:00 +select greatest(c, timestamp '2069-12-31 12:00:00') from t1; +greatest(c, timestamp '2069-12-31 12:00:00') +2069-12-31 12:00:00 +select greatest(date '21000101', a) from t1; +greatest(date '21000101', a) +2100-01-01 00:00:00 +select greatest(cast(a as JSON), cast('3' as JSON)) from t1; +greatest(cast(a as JSON), cast('3' as JSON)) +3 +set tidb_enable_vectorized_expression = default; +set tidb_enable_prepared_plan_cache=ON; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment, a timestamp NOT NULL); +INSERT INTO t1 VALUES (null, '2020-05-30 20:30:00'); +PREPARE mystmt FROM 'SELECT * FROM t1 WHERE UNIX_TIMESTAMP(a) >= ?'; +SET @a=1590868800; +EXECUTE mystmt USING @a; +id a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +SET @a=1590868801; +EXECUTE mystmt USING @a; +id a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +prepare stmt from 'select unix_timestamp(?)'; +set @a = '2020-05-30 20:30:00'; +execute stmt using @a; +unix_timestamp(?) +1590841800 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set @a = '2020-06-12 13:47:58'; +execute stmt using @a; +unix_timestamp(?) +1591940878 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +drop table if exists t; +set sql_mode=default; +create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b '); +drop table if exists test; +create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C'); +drop table if exists t; +create table t(a char(4) collate utf8_general_ci primary key /*T![clustered_index] clustered */); +insert into t values('`?'); +explain format='brief' select * from t where a like '`%'; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] like(expression__issues.t.a, "`%", 92) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +select * from t where a like '`%'; +a +`? +drop table if exists t; +create table t(a char(4) collate binary primary key /*T![clustered_index] clustered */); +insert into t values('`?'); +explain format='brief' select * from t where a like '`%'; +id estRows task access object operator info +TableReader 250.00 root data:TableRangeScan +└─TableRangeScan 250.00 cop[tikv] table:t range:[0x60,0x61), keep order:false, stats:pseudo +select * from t where a like '`%'; +a +`? +drop table if exists t; +CREATE TABLE `t` ( `a` enum('a','b') DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +insert into t values('a'); +select * from t where a = 'A'; +a +a +drop table if exists tx; +CREATE TABLE `tx` ( `a` int(11) NOT NULL,`b` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL); +insert into tx values (1, 'a'), (2, 'Ă€'), (3, 'á'), (4, 'Ă '), (5, 'b'), (6, 'c'), (7, ' '); +select count(distinct(b)) from tx; +count(distinct(b)) +4 +drop table if exists tx; +CREATE TABLE `tx` ( `a` int(11) NOT NULL,`b` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, `c` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL); +insert into tx values (1, 'a', 'a'), (2, 'A ', 'a '), (3, 'A', 'A'), (4, 'a ', 'A '); +select count(distinct b) from tx; +count(distinct b) +1 +select count(distinct c) from tx; +count(distinct c) +2 +select count(distinct b, c) from tx where a < 3; +count(distinct b, c) +1 +select approx_count_distinct(b) from tx; +approx_count_distinct(b) +1 +select approx_count_distinct(c) from tx; +approx_count_distinct(c) +2 +select approx_count_distinct(b, c) from tx where a < 3; +approx_count_distinct(b, c) +1 +drop table if exists t; +create table t(a enum('a', 'a ')) charset utf8 collate utf8_bin; +Error 1291: Column 'a' has duplicated value 'a' in ENUM +create table t(a enum('a', 'Ă')) charset utf8 collate utf8_general_ci; +Error 1291: Column 'a' has duplicated value 'Ă' in ENUM +create table t(a enum('a', 'a ')) charset utf8mb4 collate utf8mb4_bin; +Error 1291: Column 'a' has duplicated value 'a' in ENUM +create table t(a enum('a', 'A')) charset utf8 collate utf8_bin; +drop table if exists t3; +create table t3(a enum('a', 'A')) charset utf8mb4 collate utf8mb4_bin; +drop table if exists t; +create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci); +insert into t (a, b) values ('a', 'A'); +select * from t t1, t t2 where t1.a = t2.b collate utf8mb4_general_ci; +a b a b +a A a A +select * from t t1 left join t t2 on t1.a = t2.b collate utf8mb4_general_ci; +a b a b +a A a A +drop table if exists t; +create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci); +insert into t (a, b) values ('a', 'A'); +select * from t where field('A', a collate utf8mb4_general_ci, b) > 1; +a b +select * from t where field('A', a, b collate utf8mb4_general_ci) > 1; +a b +select * from t where field('A' collate utf8mb4_general_ci, a, b) > 1; +a b +select * from t where field('A', a, b) > 1; +a b +a A +set names utf8mb4 collate utf8mb4_general_ci; +select collation(concat(1 collate `binary`)); +collation(concat(1 collate `binary`)) +binary +select coercibility(concat(1 collate `binary`)); +coercibility(concat(1 collate `binary`)) +0 +select collation(concat(NULL,NULL)); +collation(concat(NULL,NULL)) +binary +select coercibility(concat(NULL,NULL)); +coercibility(concat(NULL,NULL)) +6 +select collation(concat(1,1)); +collation(concat(1,1)) +utf8mb4_general_ci +select coercibility(concat(1,1)); +coercibility(concat(1,1)) +4 +select collation(1); +collation(1) +binary +select coercibility(1); +coercibility(1) +5 +select coercibility(1=1); +coercibility(1=1) +5 +drop table if exists t; +create table t(a datetime); +insert into t values ('2020-02-02'); +select collation(concat(unix_timestamp(a))) from t; +collation(concat(unix_timestamp(a))) +utf8mb4_general_ci +select coercibility(concat(unix_timestamp(a))) from t; +coercibility(concat(unix_timestamp(a))) +4 +set names default; +drop table if exists t; +create table t(a char, b char) collate utf8mb4_general_ci; +insert into t values('a', 'b'); +insert into t values('a', 'B'); +select * from t where if(a='x', a, b) = 'b'; +a b +a b +a B +select collation(if(a='x', a, b)) from t; +collation(if(a='x', a, b)) +utf8mb4_general_ci +utf8mb4_general_ci +select coercibility(if(a='x', a, b)) from t; +coercibility(if(a='x', a, b)) +2 +2 +select collation(lag(b, 1, 'B') over w) from t window w as (order by b); +collation(lag(b, 1, 'B') over w) +utf8mb4_general_ci +utf8mb4_general_ci +select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b); +coercibility(lag(b, 1, 'B') over w) +2 +2 +SELECT 'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0; +'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0 +0 +show warnings; +Level Code Message +SELECT 'aa' BETWEEN 'bb' AND 0; +'aa' BETWEEN 'bb' AND 0 +1 +show warnings; +Level Code Message +select 1 between 0 and b'110'; +1 between 0 and b'110' +1 +show warnings; +Level Code Message +select 'b' between 'a' and b'110'; +'b' between 'a' and b'110' +0 +show warnings; +Level Code Message +drop table if exists t; +create table t(a set('a', 'b', 'c')); +alter table t change a a set('a', 'b', 'c', 'c'); +Error 1291: Column 'a' has duplicated value 'c' in SET +drop table if exists t; +create table t(a enum('a', 'b', 'c')); +alter table t change a a enum('a', 'b', 'c', 'c'); +Error 1291: Column 'a' has duplicated value 'c' in ENUM +drop table if exists t; +create table t(a set('a', 'b', 'c')); +alter table t change a a set('a', 'b', 'c', 'd'); +insert into t values('d'); +alter table t change a a set('a', 'b', 'c', 'e', 'f'); +Error 1265: Data truncated for column 'a', value is 'd' +set @@character_set_client=utf8mb4; +set @@collation_connection=utf8_bin; +CREATE VIEW tview_1 AS SELECT 'a' AS `id`; +set @@character_set_client=default; +set @@collation_connection=default; +drop table if exists t; +create table t(a enum('a ', 'b\t', ' c '), b set('a ', 'b\t', ' c ')); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` enum('a','b ',' c') DEFAULT NULL, + `b` set('a','b ',' c') DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t change a aa enum('a ', 'b\t', ' c '); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `aa` enum('a','b ',' c') DEFAULT NULL, + `b` set('a','b ',' c') DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +select '䇇Հ' collate utf8mb4_bin like '___Ő€'; +'䇇Հ' collate utf8mb4_bin like '___Ő€' +0 +drop table if exists t; +create table t(raw JSON); +insert into t(raw) values('["a","ab"]'), ('["a"]'), (null); +SELECT JSON_SEARCH(raw,'one','c') FROM t; +JSON_SEARCH(raw,'one','c') +NULL +NULL +NULL +drop table if exists t; +CREATE TABLE `t` ( `a` char(10) COLLATE utf8mb4_unicode_ci NOT NULL, `b` char(20) COLLATE utf8mb4_general_ci NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`,`b`,`c`), KEY `idx` (`a`)); +insert into t values ('#', 'C', 10), ('$', 'c', 20), ('$', 'c', 30), ('a', 'a', 10), ('A', 'A', 30); +analyze table t; +select * from t where a='#'; +a b c +# C 10 +CREATE TABLE `tbl_5` ( `col_25` time NOT NULL DEFAULT '05:35:58', `col_26` blob NOT NULL, `col_27` double NOT NULL, `col_28` char(83) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `col_29` timestamp NOT NULL, `col_30` varchar(36) COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'ywzIn', `col_31` binary(85) DEFAULT 'OIstcXsGmAyc', `col_32` datetime NOT NULL DEFAULT '2024-08-02 00:00:00', PRIMARY KEY (`col_26`(3),`col_27`) /*T![clustered_index] CLUSTERED */, UNIQUE KEY `idx_10` (`col_26`(5))); +insert ignore into tbl_5 set col_28 = 'ZmZIdSnq' , col_25 = '18:50:52.00' on duplicate key update col_26 = 'y'; +drop table if exists t1; +create table t1(a varchar(36) NOT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_general_ci; +set names utf8; +select t2.b from (select t1.a as b from t1 union all select t1.a as b from t1) t2 where case when (t2.b is not null) then t2.b else '' end > '1234567'; +b +set names default; +select case 1 when 1 then 'a' collate utf8mb4_unicode_ci else 'b' collate utf8mb4_general_ci end; +Error 1267: Illegal mix of collations (utf8mb4_unicode_ci,EXPLICIT) and (utf8mb4_general_ci,EXPLICIT) for operation 'case' +select case when 1 then 'a' collate utf8mb4_unicode_ci when 2 then 'b' collate utf8mb4_general_ci end; +Error 1267: Illegal mix of collations (utf8mb4_unicode_ci,EXPLICIT) and (utf8mb4_general_ci,EXPLICIT) for operation 'case' +select case 1 when 1 then 'a' collate utf8mb4_unicode_ci when 2 then 'b' collate utf8mb4_general_ci else 'b' collate utf8mb4_bin end; +Error 1270: Illegal mix of collations (utf8mb4_unicode_ci,EXPLICIT), (utf8mb4_general_ci,EXPLICIT), (utf8mb4_bin,EXPLICIT) for operation 'case' +drop table if exists t0,t1; +create table t0(col1 varchar(255)); +create table t1(col1 int(11)); +insert into t0 values("\\9jM\\M"); +insert into t1 values(0); +insert into t1 values(null); +insert into t1 values(null); +select t0.col1, t1.col1 from t0 left join t1 on t0.col1 not like t0.col1; +col1 col1 +\9jM\M NULL +\9jM\M NULL +\9jM\M 0 +select 'a' like '\\a'; +'a' like '\\a' +1 +select 'a' like '+a' escape '+'; +'a' like '+a' escape '+' +1 +drop table if exists table_int; +CREATE TABLE table_int ( +id_0 int(16) NOT NULL AUTO_INCREMENT, +col_int_0 int(16) DEFAULT NULL, +PRIMARY KEY (id_0), +KEY fvclc (id_0,col_int_0)); +INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0); +drop table if exists table_varchar; +CREATE TABLE table_varchar ( +id_2 int(16) NOT NULL AUTO_INCREMENT, +col_varchar_2 varchar(511) DEFAULT NULL, +PRIMARY KEY (id_2)); +INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,''); +drop table if exists table_int_float_varchar; +CREATE TABLE table_int_float_varchar ( +id_6 int(16) NOT NULL AUTO_INCREMENT, +col_int_6 int(16) NOT NULL, +col_float_6 float DEFAULT NULL, +col_varchar_6 varchar(511) DEFAULT NULL, +PRIMARY KEY (id_6,col_int_6) +) +PARTITION BY RANGE ( col_int_6 ) ( +PARTITION p0 VALUES LESS THAN (1), +PARTITION p2 VALUES LESS THAN (1000), +PARTITION p3 VALUES LESS THAN (10000), +PARTITION p5 VALUES LESS THAN (1000000), +PARTITION p7 VALUES LESS THAN (100000000), +PARTITION p9 VALUES LESS THAN (10000000000), +PARTITION p10 VALUES LESS THAN (100000000000), +PARTITION pn VALUES LESS THAN (MAXVALUE)); +INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1'); +drop table if exists table_float; +CREATE TABLE table_float ( +id_1 int(16) NOT NULL AUTO_INCREMENT, +col_float_1 float DEFAULT NULL, +PRIMARY KEY (id_1), +KEY zbjus (id_1,col_float_1)); +INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1); +drop view if exists view_4; +CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS +SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ +tmp1.id_6 AS col_1, +tmp1.col_int_6 AS col_2, +tmp1.col_float_6 AS col_3, +tmp1.col_varchar_6 AS col_4, +tmp2.id_2 AS col_5, +tmp2.col_varchar_2 AS col_6, +tmp3.id_0 AS col_7, +tmp3.col_int_0 AS col_8, +tmp4.id_1 AS col_9, +tmp4.col_float_1 AS col_10 +FROM (( +expression__issues.table_int_float_varchar AS tmp1 LEFT JOIN +expression__issues.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL +) JOIN +expression__issues.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) +JOIN +expression__issues.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5; +drop view if exists view_10; +CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS +SELECT table_int.id_0 AS col_1, +table_int.col_int_0 AS col_2 +FROM expression__issues.table_int +WHERE +((-1e+00=1) OR (0e+00>=table_int.col_int_0)) +ORDER BY col_1,col_2 +LIMIT 5,9; +SELECT col_1 FROM expression__issues.view_10; +col_1 +16 +18 +19 +SELECT col_1 FROM expression__issues.view_4; +col_1 +8 +8 +8 +8 +8 +SELECT view_10.col_1 FROM view_4 JOIN view_10; +col_1 +16 +16 +16 +16 +16 +18 +18 +18 +18 +18 +19 +19 +19 +19 +19 +drop table if exists t; +create table t(a int, b tinyint as(a+1), c int as(b+1)); +set sql_mode=''; +insert into t(a) values(2000); +create index idx on t(c); +select c from t; +c +128 +admin check table t; + +set @@sql_mode=default; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( `pk` int not null primary key auto_increment, `col_smallint_key_signed` smallint , key (`col_smallint_key_signed`)); +INSERT INTO `t1` VALUES (1,0),(2,NULL),(3,NULL),(4,0),(5,0),(6,NULL),(7,NULL),(8,0),(9,0),(10,0); +SELECT * FROM t1 WHERE ( LOG( `col_smallint_key_signed`, -8297584758403770424 ) ) DIV 1; +pk col_smallint_key_signed +drop table if exists t, t1, t2; +CREATE TABLE t ( +id int(11) NOT NULL AUTO_INCREMENT, +a char(10) DEFAULT NULL, +PRIMARY KEY (id) +); +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +a char(10) DEFAULT NULL, +b char(10) DEFAULT NULL, +c char(10) DEFAULT NULL, +PRIMARY KEY (id) +); +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +a char(10) DEFAULT NULL, +b char(10) DEFAULT NULL, +PRIMARY KEY (id), +UNIQUE KEY b (b) +); +insert into t1(a,b,c) values('hs4_0004', "04", "101"), ('a01', "01", "101"),('a011', "02", "101"); +insert into t2(a,b) values("02","03"); +insert into t(a) values('101'),('101'); +select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ; +invode +a011 +a011 +drop table if exists t, t1; +CREATE TABLE `t` (`a` bit(10) DEFAULT NULL,`b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +INSERT INTO `t` VALUES (_binary '\0',1),(_binary '\0',2),(_binary '\0',5),(_binary '\0',4),(_binary '\0',2),(_binary '\0 ',4); +CREATE TABLE `t1` (`a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +INSERT INTO `t1` VALUES (1,1),(1,5),(2,3),(2,4),(3,3); +select * from t where t.b > (select min(t1.b) from t1 where t1.a > t.a); +a b + 2 + 5 + 4 + 2 +drop table if exists t1; +create table t1(a date); +insert into t1 values (20100202); +select a in ('2020-02-02', 20100202) from t1; +a in ('2020-02-02', 20100202) +1 +drop table if exists t; +create table t(b enum('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') DEFAULT NULL, c decimal(40,20)); +insert into t values('z', 19.18040000000000000000); +insert into t values('z', 26.18040000000000000000); +insert into t values('z', 25.18040000000000000000); +select * from t where t.b > t.c; +b c +z 19.18040000000000000000 +z 25.18040000000000000000 +select * from t where t.b < t.c; +b c +z 26.18040000000000000000 +drop table if exists t1; +CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (0); +SELECT c1>=CAST('-787360724' AS TIME) FROM t1; +c1>=CAST('-787360724' AS TIME) +1 diff --git a/cmd/explaintest/t/expression/issues.test b/cmd/explaintest/t/expression/issues.test new file mode 100644 index 0000000000..c51e99fb1a --- /dev/null +++ b/cmd/explaintest/t/expression/issues.test @@ -0,0 +1,1693 @@ +# TestIssue19654 +drop table if exists t1, t2; +create table t1 (b enum('a', 'b')); +insert into t1 values ('a'); +create table t2 (b enum('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +drop table if exists t1, t2; +create table t1 (b set('a', 'b')); +insert into t1 values ('a'); +create table t2 (b set('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +drop table if exists t1, t2; +create table t1 (b enum('a', 'b')); +insert into t1 values ('a'); +create table t2 (b set('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +drop table if exists t1, t2; +create table t1 (b char(10)); +insert into t1 values ('a'); +create table t2 (b enum('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; +drop table if exists t1, t2; +create table t1 (b char(10)); +insert into t1 values ('a'); +create table t2 (b set('b','a') not null, unique(b)); +insert into t2 values ('a'); +select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b; + +# TestIssue19387 +drop table if exists t; +create table t(a decimal(16, 2)); +select sum(case when 1 then a end) from t group by a; +show create table t; + +# TestIssue20118 +drop table if exists t; +create table t(a tinyint, b bit(63)); +insert ignore into t values(599999999, -1); +show warnings; +select * from t; + +# TestIssue24900 +drop table if exists t; +create table t(b bit(16)); +insert ignore into t values(0x3635313836),(0x333830); +show warnings; +select * from t; + +# TestIssue9123 +drop table if exists t; +create table t(a char(32) not null, b float default '0') engine=innodb default charset=utf8mb4; +insert into t value('0a6f9d012f98467f8e671e9870044528', 208.867); +select concat_ws( ',', b) from t where a = '0a6f9d012f98467f8e671e9870044528'; + +# TestIssue4356 +drop table if exists t; +CREATE TABLE t (b BIT(8)); +INSERT INTO t SET b = b'11111111'; +INSERT INTO t SET b = b'1010'; +INSERT INTO t SET b = b'0101'; +SELECT b+0, BIN(b), OCT(b), HEX(b) FROM t; + +# TestIssue4436 +drop table if exists t; +create table t(a char(20)); +-- error 1115 +select convert(a using a) from t; + +# TestIssue31603 +drop table if exists t1; +create table t1(c1 varbinary(100)); +insert into t1 values('abc'); +select 1 from t1 where char_length(c1) = 10; + +# TestIssue11648 +drop table if exists t; +create table t (id int NOT NULL DEFAULT 8); +SET sql_mode = ''; +insert into t values (1), (NULL), (2); +show warnings; +select * from t; +set @@sql_mode=default; + +# TestIssue31640 +drop table if exists t; +create table t(a json); +insert into t values ('"a"'), ('"B"'), ('"c"'), ('"D"'), ('{"a": 1}'), ('1'), ('{"b": 2}'), ('[1, 2]'), ('[3, 4]'); +select min(a) from t; +select max(a) from t; +select min(a collate utf8mb4_bin) from t; +select max(a collate utf8mb4_bin) from t; +select min(a collate utf8mb4_unicode_ci) from t; +select max(a collate utf8mb4_unicode_ci) from t; + +# TestIssue36279 +SET timestamp=UNIX_TIMESTAMP('2011-11-01 17:48:00'); +SELECT cast(cast('12:12:12' as time) as datetime(6)); +drop table if exists t; +create table t (tm time(6)); +insert into t values('23:59:59'); +SELECT cast(tm as datetime(6)) from t; + +# TestIssue34998 +drop table if exists `PK_S_MULTI_43`; +CREATE TABLE `PK_S_MULTI_43`(`COL1` time(2) NOT NULL, `COL2` time(2) NOT NULL, `COL3` time(2) DEFAULT NULL, PRIMARY KEY(`COL1`,`COL2`)); +insert into PK_S_MULTI_43(col1, col2) values('-512:37:22.00', '-512:37:22.00'); +select extract(day_microsecond from '-512:37:22.00'); +select extract(day_microsecond from col1) from PK_S_MULTI_43; + +# TestIssue36358 +drop table if exists t; +create table t(c datetime(6)); +insert into t values('2001-01-01 02:03:04.050607'); +select extract(day_microsecond from cast('2001-01-01 02:03:04.050607' as datetime(6))) from t; +select extract(day_microsecond from c) from t; + +# TestIssue35184 +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar char(44)); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar varchar(44)); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar blob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar tinyblob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar mediumblob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar longblob); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789'); +SELECT FROM_UNIXTIME(tchar) from ft; +truncate table ft; +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234000000000000000000100111111111'); +SELECT FROM_UNIXTIME(tchar) from ft; +show warnings; +truncate table ft; +insert into ft values(1234567890,123467890.1234,123467890.1234,'11111123467890.1234'); +SELECT FROM_UNIXTIME(tchar) from ft; +drop table if exists ft; +create table ft (tint int, tdou double, tdec decimal(22,9),tchar char(44)); +insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234'); +SELECT FROM_UNIXTIME(tchar) from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ; +SELECT FROM_UNIXTIME(cast(tchar as decimal(44,1))) from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ; +SELECT FROM_UNIXTIME(tchar,'%Y%m%d') from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ; + +# TestFix38127 +drop table if exists t; +create table t(dou double, varc varchar(100)); +insert into t values (1.23e23, '111111111111111111111111111111111111111111111111111111111111111111111111111'); +select from_unixtime(dou) from t; +select from_unixtime(varc) from t; +select from_unixtime(dou, '%Y-%m-%d') from t; +select from_unixtime(varc, '%Y-%m-%d') from t; + +# TestIssue39146 +drop table if exists `sun`; +CREATE TABLE `sun` ( `dest` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into sun values('20231020'); +set @@sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +set @@tidb_enable_vectorized_expression = on; +select str_to_date(substr(dest,1,6),'%H%i%s') from sun; +set @@tidb_enable_vectorized_expression = off; +select str_to_date(substr(dest,1,6),'%H%i%s') from sun; +set @@sql_mode=default; + +# TestIssue40536 +drop table if exists `6bf9e76d-ab44-4031-8a07-418b10741580`, `8919f3f4-25be-4a1a-904a-bb5e863d8fc8`; +CREATE TABLE `6bf9e76d-ab44-4031-8a07-418b10741580` ( + `e0b5f703-6cfe-49b4-bc21-16a6455e43a7` set('7','va','ung60','ow','1g','gxwz5','uhnh','k','5la1','q8d9c','1f') NOT NULL DEFAULT '7,1g,uhnh,5la1,q8d9c', + `fbc3527f-9617-4b9d-a5dc-4be31c00d8a5` datetime DEFAULT '6449-09-28 14:39:04', + PRIMARY KEY (`e0b5f703-6cfe-49b4-bc21-16a6455e43a7`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin; +CREATE TABLE `8919f3f4-25be-4a1a-904a-bb5e863d8fc8` ( + `9804d5f2-cbc7-43b7-b241-ea2656dc941a` enum('s951','36d','ua65','49yru','6l2em','4ea','jf2d2','vprsc','3yl7n','hz','ov') DEFAULT '4ea', + `323cdbcb-0c14-4362-90ab-ea42caaed6a5` year(4) NOT NULL DEFAULT '1983', + `b9b70f39-1a02-4114-9d7d-fa6259c1b691` time DEFAULT '20:18:04', + PRIMARY KEY (`323cdbcb-0c14-4362-90ab-ea42caaed6a5`) /*T![clustered_index] CLUSTERED */, + KEY `a704d6bb-772b-44ea-8cb0-6f7491c1aaa6` (`323cdbcb-0c14-4362-90ab-ea42caaed6a5`,`9804d5f2-cbc7-43b7-b241-ea2656dc941a`) +) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin; +delete from `6bf9e76d-ab44-4031-8a07-418b10741580` where not( `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( select `9804d5f2-cbc7-43b7-b241-ea2656dc941a` from `8919f3f4-25be-4a1a-904a-bb5e863d8fc8` where `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( '1f' ) and `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( '1g' ,'va' ,'uhnh' ) ) ) and not( IsNull( `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` ) ); + +# TestAesDecryptionVecEvalWithZeroChunk, Issue43063 +drop table if exists test; +create table test (name1 blob,name2 blob); +insert into test values(aes_encrypt('a', 'x'), aes_encrypt('b', 'x')); +SELECT * FROM test WHERE CAST(AES_DECRYPT(name1, 'x') AS CHAR) = '00' AND CAST(AES_DECRYPT(name2, 'x') AS CHAR) = '1'; + + +# TestIfFunctionWithNull, Issue43805 +drop table if exists ordres; +CREATE TABLE orders (id bigint(20) unsigned NOT NULL ,account_id bigint(20) unsigned NOT NULL DEFAULT '0' ,loan bigint(20) unsigned NOT NULL DEFAULT '0' ,stage_num int(20) unsigned NOT NULL DEFAULT '0' ,apply_time bigint(20) unsigned NOT NULL DEFAULT '0' ,PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */,KEY idx_orders_account_id (account_id),KEY idx_orders_apply_time (apply_time)); +insert into orders values (20, 210802010000721168, 20000 , 2 , 1682484268727), (22, 210802010000721168, 35100 , 4 , 1650885615002); +select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1; + +# TestIssue41733 +drop table if exists t_tiny, t_small, t_medium, t_int, t_big; +create table t_tiny (c0 TINYINT UNSIGNED); +INSERT IGNORE INTO t_tiny(c0) VALUES (1E9); +show warnings; +select * from t_tiny; +create table t_small (c0 SMALLINT UNSIGNED); +INSERT IGNORE INTO t_small(c0) VALUES (1E9); +show warnings; +select * from t_small; +create table t_medium (c0 MEDIUMINT UNSIGNED); +INSERT IGNORE INTO t_medium(c0) VALUES (1E9); +show warnings; +select * from t_medium; +create table t_int (c0 INT UNSIGNED); +INSERT IGNORE INTO t_int(c0) VALUES (1E20); +show warnings; +select * from t_int; +create table t_big (c0 BIGINT UNSIGNED); +INSERT IGNORE INTO t_big(c0) VALUES (1E20); +show warnings; +select * from t_big; + +# TestInPredicate4UnsignedInt, TestIssue6661 +drop table if exists t; +CREATE TABLE t (a bigint unsigned,key (a)); +INSERT INTO t VALUES (0), (4), (5), (6), (7), (8), (9223372036854775810), (18446744073709551614), (18446744073709551615); +SELECT a FROM t WHERE a NOT IN (-1, -2, 18446744073709551615); +SELECT a FROM t WHERE a NOT IN (-1, -2, 4, 9223372036854775810); +SELECT a FROM t WHERE a NOT IN (-1, -2, 0, 4, 18446744073709551614); + +# TestIssue4473 +drop table if exists t1; +create table t1 (some_id smallint(5) unsigned,key (some_id) ); +insert into t1 values (1),(2); +select some_id from t1 where some_id not in(2,-1); + +# TestIssue9732 +select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m')); +select str_to_date(1, '%m'); +select str_to_date(01, '%d'); +select str_to_date(2019, '%Y'); +select str_to_date('5,2019','%m,%Y'); +select str_to_date('01,2019','%d,%Y'); +select str_to_date('01,5','%d,%m'); +set sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +select str_to_date(1, '%m'); +select str_to_date(01, '%d'); +select str_to_date(2019, '%Y'); +select str_to_date('5,2019','%m,%Y'); +select str_to_date('01,2019','%d,%Y'); +select str_to_date('01,5','%d,%m'); +set @@sql_mode=default; + +# TestIssue10156 +drop table if exists t1, t2; +CREATE TABLE `t1` (`period_name` varchar(24) DEFAULT NULL ,`period_id` bigint(20) DEFAULT NULL ,`starttime` bigint(20) DEFAULT NULL); +CREATE TABLE `t2` (`bussid` bigint(20) DEFAULT NULL,`ct` bigint(20) DEFAULT NULL); +select + a.period_name, + b.date8 +from + (select * from t1) a +left join + (select bussid,date(from_unixtime(ct)) date8 from t2) b +on + a.period_id = b.bussid +where + datediff(b.date8, date(from_unixtime(a.starttime))) >= 0; + +# TestIssue9727 +SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND; +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 37 SECOND; +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 31 MINUTE; +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 38 SECOND; +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 33 MINUTE; +SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 30 HOUR; +SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND; +SELECT 19000101000000 + INTERVAL "100000000:214748364700" MINUTE_SECOND; +SELECT 19000101000000 + INTERVAL 1 << 37 SECOND; +SELECT 19000101000000 + INTERVAL 1 << 31 MINUTE; +SELECT "8895-03-27 22:11:40" - INTERVAL "100000000:214748364700" MINUTE_SECOND; +SELECT "6255-04-08 15:04:32" - INTERVAL 1 << 37 SECOND; +SELECT "5983-01-24 02:08:00" - INTERVAL 1 << 31 MINUTE; +SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 39 SECOND; +SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 33 MINUTE; +SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 30 HOUR; +SELECT "9999-01-01 00:00:00" - INTERVAL "10000000000:214748364700" MINUTE_SECOND; +SELECT 88950327221140 - INTERVAL "100000000:214748364700" MINUTE_SECOND ; +SELECT 62550408150432 - INTERVAL 1 << 37 SECOND; +SELECT 59830124020800 - INTERVAL 1 << 31 MINUTE; +SELECT 10000101000000 + INTERVAL "111111111111111111" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111.111111" SECOND; +SELECT 10000101000000 + INTERVAL "111111111111.111111111" SECOND; +SELECT 10000101000000 + INTERVAL "111111111111.111" SECOND; +SELECT 10000101000000 + INTERVAL "111111111111." SECOND; +SELECT 10000101000000 + INTERVAL "111111111111111111.5" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111111112.5" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111111111.500000" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111111111.50000000" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111111111.6" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111111111.499999" MICROSECOND; +SELECT 10000101000000 + INTERVAL "111111111111111111.499999999999" MICROSECOND; + +# TestIssue30253 +SELECT INTERVAL 1.123456789e3 SECOND + "1900-01-01 00:00:00"; +SELECT INTERVAL 1 Year + 19000101000000; +select interval 6 month + date("1900-01-01"); +select interval "5:2" MINUTE_SECOND + "1900-01-01"; + +# TestIssue10181 +drop table if exists t; +create table t(a bigint unsigned primary key); +insert into t values(9223372036854775807), (18446744073709551615); +select * from t where a > 9223372036854775807-0.5 order by a; + +# TestIssue16973 +drop table if exists t1, t2; +create table t1(id varchar(36) not null primary key, org_id varchar(36) not null, status tinyint default 1 not null, ns varchar(36) default '' not null); +create table t2(id varchar(36) not null primary key, order_id varchar(36) not null, begin_time timestamp(3) default CURRENT_TIMESTAMP(3) not null); +create index idx_oid on t2(order_id); +insert into t1 value (1,1,1,'a'); +insert into t1 value (2,1,2,'a'); +insert into t1 value (3,1,3,'a'); +insert into t2 value (1,2,date'2020-05-08'); +explain format = 'brief' SELECT /*+ INL_MERGE_JOIN(t1,t2) */ COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.order_id WHERE t1.ns = 'a' AND t1.org_id IN (1) AND t1.status IN (2,6,10) AND timestampdiff(month, t2.begin_time, date'2020-05-06') = 0; +SELECT /*+ INL_MERGE_JOIN(t1,t2) */ COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.order_id WHERE t1.ns = 'a' AND t1.org_id IN (1) AND t1.status IN (2,6,10) AND timestampdiff(month, t2.begin_time, date'2020-05-06') = 0; + +# TestIssue10675 +drop table if exists t; +create table t(a int); +insert into t values(1); +select * from t where a < -184467440737095516167.1; +select * from t where a > -184467440737095516167.1; +select * from t where a < 184467440737095516167.1; +select * from t where a > 184467440737095516167.1; + +# TestIssue11647 +drop table if exists t; +create table t(b bit(1)); +insert into t values(b'1'); +select count(*) from t where b = 1; +select count(*) from t where b = '1'; +select count(*) from t where b = b'1'; +drop table if exists t; +create table t(b bit(63)); +# Not 64, because the behavior of mysql is amazing. I have no idea to fix it. +insert into t values(b'111111111111111111111111111111111111111111111111111111111111111'); +select count(*) from t where b = 9223372036854775807; +select count(*) from t where b = '9223372036854775807'; +select count(*) from t where b = b'111111111111111111111111111111111111111111111111111111111111111'; + +# TestIssue11594 +drop table if exists t1; +CREATE TABLE t1 (v bigint(20) UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (1), (2); +SELECT SUM(IF(v > 1, v, -v)) FROM t1; +SELECT sum(IFNULL(cast(null+rand() as unsigned), -v)) FROM t1; +SELECT sum(COALESCE(cast(null+rand() as unsigned), -v)) FROM t1; +SELECT sum(COALESCE(cast(null+rand() as unsigned), v)) FROM t1; + +# TestIssue11309 +drop table if exists t; +CREATE TABLE t (a decimal(6,3),b double(6,3),c float(6,3)); +INSERT INTO t VALUES (1.100,1.100,1.100); +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) FROM t; +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) FROM t; +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) FROM t; +drop table if exists t; +CREATE TABLE t (a decimal(11,7),b double(11,7),c float(11,7)); +INSERT INTO t VALUES (123.9999999,123.9999999,123.9999999),(-123.9999999,-123.9999999,-123.9999999); +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) FROM t; +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) FROM t; +SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) FROM t; + +# TestIssue11319 +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MINUTE); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MINUTE); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_HOUR); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 YEAR_MONTH); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MICROSECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_SECOND); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MINUTE); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MINUTE); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR); +SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH); + +# TestIssue12301 +drop table if exists t; +create table t (d decimal(19, 0), i bigint(11)); +insert into t values (123456789012, 123456789012); +select * from t where d = i; + +# TestIssue15315 +select '0-3261554956'+0.0; +select cast('0-1234' as real); + +# TestValuesForBinaryLiteral, TestIssue15310 +drop table if exists testValuesBinary; +create table testValuesBinary(id int primary key auto_increment, a bit(1)); +insert into testValuesBinary values(1,1); +insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a); +select a=0 from testValuesBinary; +insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a); +select a=0 from testValuesBinary; +drop table testValuesBinary; + +# TestIssue14159 +DROP TABLE IF EXISTS t; +CREATE TABLE t (v VARCHAR(100)); +INSERT INTO t VALUES ('3289742893213123732904809'); +SELECT * FROM t WHERE v; + +# TestIssue14146 +drop table if exists tt; +create table tt(a varchar(10)); +insert into tt values(NULL); +analyze table tt; +select * from tt; + +# TestIssue15346 +select collation(format_bytes(1024)) != 'binary'; +select collation(format_nano_time(234)) != 'binary'; + +# TestJoinOnDifferentCollations, TestIssue34500 +drop table if exists t; +create table t (a char(10) charset gbk collate gbk_chinese_ci, b time); +insert into t values ('08:00:00', '08:00:00'); +select t1.a, t2.b from t as t1 right join t as t2 on t1.a = t2.b; + +# TestIssue20071 +drop table if exists table_30_utf8_4, t; +create table t(a int); +insert into t values(1); +create table table_30_utf8_4 ( `pk` int primary key, `col_int_key_unsigned` int unsigned , `col_int_key_signed` int, `col_float_key_signed` float , `col_float_key_unsigned` float unsigned) character set utf8 partition by hash(pk) partitions 4; +insert ignore into table_30_utf8_4 values (0,91, 10, 14,19.0495); +alter table table_30_utf8_4 add column a int as (col_int_key_signed * 2); +SELECT count(1) AS val FROM table_30_utf8_4 WHERE table_30_utf8_4.col_int_key_unsigned!=table_30_utf8_4.a OR (SELECT count(1) AS val FROM t WHERE table_30_utf8_4.col_float_key_signed!=table_30_utf8_4.col_float_key_unsigned )!=7984764426240273913; +select a from table_30_utf8_4 order by a; + +# TestIssue17791 +drop table if exists t1; +CREATE TABLE t1 ( id INT NOT NULL PRIMARY KEY auto_increment, pad VARCHAR(10) NOT NULL, expr varchar(100) AS (NOT 1 BETWEEN -5 AND 5)); +INSERT INTO t1 (pad) VALUES ('a'), ('b'); +SELECT id, pad, expr, NOT 1 BETWEEN -5 AND 5 as expr_in_select FROM t1; + +# TestIssue15986 +drop table if exists t0; +CREATE TABLE t0(c0 int); +INSERT INTO t0 VALUES (0); +SELECT t0.c0 FROM t0 WHERE CHAR(204355900); +SELECT t0.c0 FROM t0 WHERE not CHAR(204355900); +SELECT t0.c0 FROM t0 WHERE '.0'; +SELECT t0.c0 FROM t0 WHERE not '.0'; +select * from t0 where '.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +select * from t0 where not '.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +select * from t0 where '.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; +select * from t0 where not '.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'; + +# TestIssue1223 +drop table if exists testjson; +CREATE TABLE testjson (j json DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO testjson SET j='{"test":3}'; +INSERT INTO testjson SET j='{"test":0}'; +insert into testjson set j='{"test":"0"}'; +insert into testjson set j='{"test":0.0}'; +INSERT INTO testjson SET j='{"test":"aaabbb"}'; +INSERT INTO testjson SET j='{"test":3.1415}'; +INSERT INTO testjson SET j='{"test":[]}'; +INSERT INTO testjson SET j='{"test":[1,2]}'; +INSERT INTO testjson SET j='{"test":["b","c"]}'; +INSERT INTO testjson SET j='{"test":{"ke":"val"}}'; +insert into testjson set j='{"test":"2015-07-27 09:43:47"}'; +insert into testjson set j='{"test":"0000-00-00 00:00:00"}'; +insert into testjson set j='{"test":"0778"}'; +insert into testjson set j='{"test":"0000"}'; +insert into testjson set j='{"test":null}'; +insert into testjson set j=null; +insert into testjson set j='{"test":[null]}'; +insert into testjson set j='{"test":true}'; +insert into testjson set j='{"test":false}'; +insert into testjson set j='""'; +insert into testjson set j='null'; +insert into testjson set j='0'; +insert into testjson set j='"0"'; +SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test'); +select * from testjson where j; +insert into mysql.expr_pushdown_blacklist values('json_extract','tikv',''); +admin reload expr_pushdown_blacklist; +SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test'); +select * from testjson where j; + +# TestIssue15743 +drop table if exists t0; +CREATE TABLE t0(c0 int); +INSERT INTO t0 VALUES (1); +SELECT * FROM t0 WHERE 1 AND 0.4; + +# TestIssue15725 +drop table if exists t; +create table t(a int); +insert into t values(2); +select * from t where (not not a) = a; +select * from t where (not not not not a) = a; + +# TestIssue15790 +drop table if exists t0; +CREATE TABLE t0(c0 INT); +INSERT INTO t0(c0) VALUES (0); +SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION SELECT * FROM t0; +SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION all SELECT * FROM t0; + +# TestIssue15990 +drop table if exists t0; +CREATE TABLE t0(c0 TEXT(10)); +INSERT INTO t0(c0) VALUES (1); +SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0; +CREATE INDEX i0 ON t0(c0(10)); +SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0; + +# TestIssue15992 +drop table if exists t0; +CREATE TABLE t0(c0 INT, c1 INT AS (c0)); +CREATE INDEX i0 ON t0(c1); +SELECT t0.c0 FROM t0 UNION ALL SELECT 0 FROM t0; + +# TestIssue16419 +drop table if exists t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +SELECT * FROM t1 NATURAL LEFT JOIN t0 WHERE NOT t1.c0; + +# TestIssue16029 +drop table if exists t0,t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +INSERT INTO t0 VALUES (NULL), (1); +INSERT INTO t1 VALUES (0); +SELECT t0.c0 FROM t0 JOIN t1 ON (t0.c0 REGEXP 1) | t1.c0 WHERE BINARY STRCMP(t1.c0, t0.c0); + +# TestIssue16426 +drop table if exists t; +create table t (a int); +insert into t values (42); +select a from t where a/10000; +select a from t where a/100000; +select a from t where a/1000000; +select a from t where a/10000000; + +# TestIssue20121 +drop table if exists t; +create table t(a datetime, b year); +insert into t values('2000-05-03 16:44:44', 2018); +insert into t values('2020-10-01 11:11:11', 2000); +insert into t values('2020-10-01 11:11:11', 2070); +insert into t values('2020-10-01 11:11:11', 1999); +select * from t where t.a < t.b; +select * from t where t.a > t.b; +drop table if exists tt; +create table tt(a date, b year); +insert into tt values('2019-11-11', 2000); +insert into tt values('2019-11-11', 2020); +insert into tt values('2019-11-11', 2022); +select * from tt where tt.a > tt.b; +select * from tt where tt.a < tt.b; +drop table if exists ttt; +create table ttt(a timestamp, b year); +insert into ttt values('2019-11-11 11:11:11', 2019); +insert into ttt values('2019-11-11 11:11:11', 2000); +insert into ttt values('2019-11-11 11:11:11', 2022); +select * from ttt where ttt.a > ttt.b; +select * from ttt where ttt.a < ttt.b; + +# TestIssue16779 +drop table if exists t0, t1; +create table t0 (c0 int); +create table t1 (c0 int); +SELECT * FROM t1 LEFT JOIN t0 ON TRUE WHERE BINARY EXPORT_SET(0, 0, 0 COLLATE 'binary', t0.c0, 0 COLLATE 'binary'); + +# TestIssue17045 +drop table if exists t; +create table t(a int,b varchar(20),c datetime,d double,e int,f int as(a+b),key(a),key(b),key(c),key(d),key(e),key(f)); +insert into t(a,b,e) values(null,"5",null); +insert into t(a,b,e) values("5",null,null); +select /*+ use_index_merge(t)*/ * from t where t.e=5 or t.a=5; + +# TestIssue17098 +drop table if exists t1, t2; +create table t1(a char) collate utf8mb4_bin; +create table t2(a char) collate utf8mb4_bin; +insert into t1 values('a'); +insert into t2 values('a'); +select collation(t1.a) from t1 union select collation(t2.a) from t2; + +# TestIssue17115 +select collation(user()); +select collation(compress('abc')); + +# TestIssue17287 +set tidb_enable_prepared_plan_cache=1; +drop table if exists t; +set @@tidb_enable_vectorized_expression = false; +create table t(a datetime); +insert into t values(from_unixtime(1589873945)), (from_unixtime(1589873946)); +prepare stmt7 from 'SELECT unix_timestamp(a) FROM t WHERE a = from_unixtime(?);'; +set @val1 = 1589873945; +set @val2 = 1589873946; +execute stmt7 using @val1; +execute stmt7 using @val2; + +# TestIssue17898 +drop table if exists t0; +create table t0(a char(10), b int as ((a))); +insert into t0(a) values("0.5"); +select * from t0; + +# TestIssue18515 +drop table if exists t; +create table t(a int, b json, c int AS (JSON_EXTRACT(b, '$.population')), key(c)); +select /*+ TIDB_INLJ(t2) */ t1.a, t1.c, t2.a from t t1, t t2 where t1.c=t2.c; + +# TestIssue20223 +drop table if exists t; +CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,type tinyint(4) NOT NULL,create_time int(11) NOT NULL,PRIMARY KEY (id)); +insert into t values (4, 2, 1598584933); +select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 1 group by t_day union all select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 2 group by t_day; + +# TestIssue18525 +drop table if exists t1; +create table t1 (col0 BLOB, col1 CHAR(74), col2 DATE UNIQUE); +insert into t1 values ('l', '7a34bc7d-6786-461b-92d3-fd0a6cd88f39', '1000-01-03'); +insert into t1 values ('l', NULL, '1000-01-04'); +insert into t1 values ('b', NULL, '1000-01-02'); +select INTERVAL( ( CONVERT( -11752 USING utf8 ) ), 6558853612195285496, `col1`) from t1; + +# TestIssue18850 +drop table if exists t, t1; +create table t(a int, b enum('A', 'B')); +create table t1(a1 int, b1 enum('B', 'A')); +insert into t values (1, 'A'); +insert into t1 values (1, 'A'); +select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1; +drop table t, t1; +create table t(a int, b set('A', 'B')); +create table t1(a1 int, b1 set('B', 'A')); +insert into t values (1, 'A'); +insert into t1 values (1, 'A'); +select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1; + +# TestIssue19504 +drop table if exists t1; +create table t1 (c_int int, primary key (c_int)); +insert into t1 values (1), (2), (3); +drop table if exists t2; +create table t2 (c_int int, primary key (c_int)); +insert into t2 values (1); +select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1; +select (select count(c_int*c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1; + +# TestIssue17767 +drop table if exists t0; +CREATE TABLE t0(c0 INTEGER AS (NULL) NOT NULL, c1 INT); +CREATE INDEX i0 ON t0(c0, c1); +INSERT IGNORE INTO t0(c1) VALUES (0); +SELECT * FROM t0; +begin; +INSERT IGNORE INTO t0(c1) VALUES (0); +SELECT * FROM t0; +rollback; + +# TestIssue19596 +drop table if exists t; +create table t (a int) partition by range(a) (PARTITION p0 VALUES LESS THAN (10)); +-- error 1054 +alter table t add partition (partition p1 values less than (a)); +select * from t; +drop table if exists t; +-- error 1054 +create table t (a int) partition by range(a) (PARTITION p0 VALUES LESS THAN (a)); + +# TestIssue17476 +DROP TABLE IF EXISTS `table_float`; +DROP TABLE IF EXISTS `table_int_float_varchar`; +CREATE TABLE `table_float` (`id_1` int(16) NOT NULL AUTO_INCREMENT,`col_float_1` float DEFAULT NULL,PRIMARY KEY (`id_1`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=97635; +CREATE TABLE `table_int_float_varchar` (`id_6` int(16) NOT NULL AUTO_INCREMENT,`col_int_6` int(16) DEFAULT NULL,`col_float_6` float DEFAULT NULL,`col_varchar_6` varchar(511) DEFAULT NULL,PRIMARY KEY (`id_6`),KEY `vhyen` (`id_6`,`col_int_6`,`col_float_6`,`col_varchar_6`(1)),KEY `zzylq` (`id_6`,`col_int_6`,`col_float_6`,`col_varchar_6`(1))) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=90818; +INSERT INTO `table_float` VALUES (1,NULL),(2,0.1),(3,0),(4,-0.1),(5,-0.1),(6,NULL),(7,0.5),(8,0),(9,0),(10,NULL),(11,1),(12,1.5),(13,NULL),(14,NULL); +INSERT INTO `table_int_float_varchar` VALUES (1,0,0.1,'true'),(2,-1,1.5,'2020-02-02 02:02:00'),(3,NULL,1.5,NULL),(4,65535,0.1,'true'),(5,NULL,0.1,'1'),(6,-1,1.5,'2020-02-02 02:02:00'),(7,-1,NULL,''),(8,NULL,-0.1,NULL),(9,NULL,-0.1,'1'),(10,-1,NULL,''),(11,NULL,1.5,'false'),(12,-1,0,NULL),(13,0,-0.1,NULL),(14,-1,NULL,'-0'),(15,65535,-1,'1'),(16,NULL,0.5,NULL),(17,-1,NULL,NULL); +select count(*) from table_float + JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) + IS NULL WHERE col_int_6=0; +SELECT count(*) FROM (table_float JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) IS NULL); +SELECT * FROM (table_int_float_varchar AS tmp3) WHERE (col_varchar_6 AND NULL) IS NULL AND col_int_6=0; + +# TestIssue14349 +drop table if exists papers; +create table papers(title text, content longtext); +insert into papers values('title', 'content'); +select to_base64(title), to_base64(content) from papers; +set tidb_enable_vectorized_expression = 0; +select to_base64(title), to_base64(content) from papers; +set tidb_enable_vectorized_expression = 1; + +# TestIssue20180 +drop table if exists t, t1; +create table t(a enum('a', 'b'), b tinyint); +create table t1(c varchar(20)); +insert into t values('b', 0); +insert into t1 values('b'); +select * from t, t1 where t.a= t1.c; +select * from t, t1 where t.b= t1.c; +select * from t, t1 where t.a = t1.c and t.b= t1.c; +drop table if exists t; +create table t(a enum('a','b')); +insert into t values('b'); +select * from t where a > 1 and a = "b"; + +# TestIssue11755 +drop table if exists lt; +create table lt (d decimal(10, 4)); +insert into lt values(0.2),(0.2); +select LEAD(d,1,1) OVER(), LAG(d,1,1) OVER() from lt; + +# TestIssue20369 +drop table if exists t; +create table t(a int); +insert into t values (1); +insert into t select values(a) from t; +select * from t; + +# TestIssue20730 +DROP TABLE IF EXISTS tmp; +CREATE TABLE tmp (id int(11) NOT NULL,value int(1) NOT NULL,PRIMARY KEY (id)); +INSERT INTO tmp VALUES (1, 1),(2,2),(3,3),(4,4),(5,5); +SET @sum := 10; +SELECT @sum := IF(@sum=20,4,@sum + tmp.value) sum FROM tmp ORDER BY tmp.id; + +# TestIssue20860 +drop table if exists t; +create table t(id int primary key, c int, d timestamp null default null); +insert into t values(1, 2, '2038-01-18 20:20:30'); +-- error 1292 +update t set d = adddate(d, interval 1 day) where id < 10; + +# TestIssue15847 +drop view if exists t15847; +CREATE VIEW t15847(c0) AS SELECT NULL; +SELECT * FROM t15847 WHERE (NOT (IF(t15847.c0, NULL, NULL))); +drop view if exists t15847; + +# TestIssue10462 +select json_array(true); +select json_array(1=2); +select json_array(1!=2); +select json_array(1<2); +select json_array(1<=2); +select json_array(1>2); +select json_array(1>=2); +select json_object(true, null <=> null); +select json_object(false, 1 and 2); +select json_object(false, 1 and 0); +select json_object(false, 1 or 0); +select json_object(false, 1 xor 0); +select json_object(false, 1 xor 1); +select json_object(false, not 1); +select json_array(null and 1); +select json_array(null and 0); +select json_array(null or 1); +select json_array(null or 0); +select json_array(1.15 or 0); +select json_array('abc' or 0); +select json_array('1abc' or 0); +select json_array(null is true); +select json_array(null is null); +select json_array(1 in (1, 2)); +select json_array(0 in (1, 2)); +select json_array(0 not in (1, 2)); +select json_array(1 between 0 and 2); +select json_array(1 not between 0 and 2); +select json_array('123' like '123'); +select json_array('abcdef' rlike 'a.*c.*'); +select json_array(is_ipv4('127.0.0.1')); +select json_array(is_ipv6('1a6b:8888:ff66:77ee:0000:1234:5678:bcde')); + +# TestIssue17868 +drop table if exists t7; +create table t7 (col0 SMALLINT, col1 VARBINARY(1), col2 DATE, col3 BIGINT, col4 BINARY(166)); +insert into t7 values ('32767', '', '1000-01-03', '-0', '11101011'); +select col2 = 1 from t7; +select col2 != 1 from t7; + +# TestIssue21619 +select CAST("9223372036854775808" as json); +select json_type(CAST("9223372036854775808" as json)); +select CAST(9223372036854775808 as json); +select json_type(CAST(9223372036854775808 as json)); +select CAST(-9223372036854775808 as json); +select json_type(CAST(-9223372036854775808 as json)); + +# TestIssue10467 +drop table if exists tx2; +create table tx2 (col json); +insert into tx2 values (json_array("3")),(json_array("3")),(json_array("3")),(json_array("3")); +insert into tx2 values (json_array(3.0)); +insert into tx2 values (json_array(3)); +insert into tx2 values (json_array(3.0)); +insert into tx2 values (json_array(-3)); +insert into tx2 values (json_array(-3.0)); +insert into tx2 values (json_array(922337203685477580)); +insert into tx2 values (json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)); +# TODO: in MySQL these values will hash the same because the first is stored as JSON type DECIMAL. +# Currently TiDB does not support JSON type DECIMAL. +# See: https://github.com/pingcap/tidb/issues/9988 +# insert into tx2 values (json_array(9223372036854775808.0)); +# insert into tx2 values (json_array(9223372036854775808)); +# +# ordering by a JSON col is not supported in MySQL, and the order is a bit questionable in TiDB. +# sort by count for test result stability. +select col, count(1) c from tx2 group by col order by c desc; + + +# TestIssue12205 +drop table if exists t12205; +create table t12205( + `col_varchar_64` varchar(64) DEFAULT NULL, + `col_varchar_64_key` varchar(64) DEFAULT NULL +); +insert into t12205 values('-1038024704','-527892480'); +select SEC_TO_TIME( ( `col_varchar_64` & `col_varchar_64_key` ) ),`col_varchar_64` & `col_varchar_64_key` from t12205; ; +show warnings; + +# TestIssue21677 +drop table if exists t; +create table t(1e int); +insert into t values (1); +select t.1e from expression__issues.t; +drop table if exists t; +create table t(99e int, r10 int); +insert into t values (1, 10), (2, 2); +select 99e+r10 from t; +select .78$123; +-- error 1064 +select .78$421+1; +select t. `r10` > 3 from t; +select * from t where t. `r10` > 3; + +# TestIssue29417 +drop table if exists t1; +create table t1 (f1 decimal(5,5)); +insert into t1 values (-0.12345); +select concat(f1) from t1; + +# TestIssue12206 +drop table if exists t12206; +create table t12206( + `col_tinyint_unsigned` tinyint(3) unsigned DEFAULT NULL, + `col_double_unsigned` double unsigned DEFAULT NULL, + `col_year_key` year(4) DEFAULT NULL +); +insert into t12206 values(73,0,0000); +SELECT TIME_FORMAT( `col_tinyint_unsigned`, ( IFNULL( `col_double_unsigned`, `col_year_key` ) ) ) AS field1 FROM `t12206`; +show warnings; + +# TestIssue12209 +drop table if exists t12209; +create table t12209(a bigint(20)); +insert into t12209 values(1); +select `a` DIV ( ROUND( ( SCHEMA() ), '1978-05-18 03:35:52.043591' ) ) from `t12209`; + +# TestIssue22098 +drop table if exists ta, tb; +CREATE TABLE `ta` ( `k` varchar(32) NOT NULL DEFAULT ' ', `c0` varchar(32) NOT NULL DEFAULT ' ', `c` varchar(18) NOT NULL DEFAULT ' ', `e0` varchar(1) NOT NULL DEFAULT ' ', PRIMARY KEY (`k`,`c0`,`c`), KEY `idx` (`c`,`e0`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE `tb` ( `k` varchar(32) NOT NULL DEFAULT ' ', `e` int(11) NOT NULL DEFAULT '0', `i` int(11) NOT NULL DEFAULT '0', `s` varchar(1) NOT NULL DEFAULT ' ', `c` varchar(50) NOT NULL DEFAULT ' ', PRIMARY KEY (`k`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +prepare stmt from "select a.* from ta a left join tb b on a.k = b.k where (a.k <> '000000' and ((b.s = ? and i = ? ) or (b.s = ? and e = ?) or (b.s not in(?, ?))) and b.c like '%1%') or (a.c <> '000000' and a.k = '000000')"; +set @a=3;set @b=20200414;set @c='a';set @d=20200414;set @e=3;set @f='a'; +execute stmt using @a,@b,@c,@d,@e,@f; + +# TestIssue22717 +drop table if exists t; +create table t( + a enum('a','','c'), + b enum('0','1','2'), + c set('a','','c'), + d set('0','1','2') +); +insert into t values(1,1,1,1),(2,2,2,2),(3,3,3,3); +set @@sql_mode = ''; +insert into t values('','','',''); +select * from t; +select a from t where a; +select b from t where b; +select c from t where c; +select d from t where d; +set @@sql_mode=default; + +# TestIssue23262 +drop table if exists t; +create table t(a year); +insert into t values(2002); +select * from t where a=2; +select * from t where a='2'; + +# TestClusteredIndexCorCol, TestIssue23076 +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) ); +create table t2 like t1 ; +insert into t1 values (1, 'crazy lumiere'), (10, 'goofy mestorf'); +insert into t2 select * from t1 ; +select (select t2.c_str from t2 where t2.c_str = t1.c_str and t2.c_int = 10 order by t2.c_str limit 1) x from t1; + +# TestIssue23623 +drop table if exists t1; +create table t1(c1 int); +insert into t1 values(-2147483648), (-2147483648), (null); +select count(*) from t1 where c1 > (select sum(c1) from t1); + +# TestIssue23925 +drop table if exists t; +create table t(a int primary key, b set('Alice','Bob') DEFAULT NULL); +insert into t value(1,'Bob'); +select max(b) + 0 from t group by a; +drop table if exists t; +create table t(a int, b set('Alice','Bob') DEFAULT NULL); +insert into t value(1,'Bob'); +select max(b) + 0 from t group by a; + +# TestIssue23889 +drop table if exists test_decimal,test_t; +create table test_decimal(col_decimal decimal(10,0)); +insert into test_decimal values(null),(8); +create table test_t(a int(11), b decimal(32,0)); +insert into test_t values(1,4),(2,4),(5,4),(7,4),(9,4); +SELECT ( test_decimal . `col_decimal` , test_decimal . `col_decimal` ) IN ( select * from test_t ) as field1 FROM test_decimal; + +# TestIssue37414 +drop table if exists foo, bar; +create table foo(a decimal(65,0)); +create table bar(a decimal(65,0), b decimal(65,0)); +insert into bar values(0,0),(1,1),(2,2); +insert into foo select if(b>0, if(a/b>1, 1, 2), null) from bar; + +# TestIssue25591 +drop table if exists t1_1, t2_1; +CREATE TABLE `t1_1` (`col1` double DEFAULT NULL, `col2` double DEFAULT NULL); +CREATE TABLE `t2_1` (`col1` varchar(20) DEFAULT NULL, `col2` double DEFAULT NULL); +insert into t1_1 values(12.991, null), (12.991, null); +insert into t2_1(col2) values(87), (-9.183), (-9.183); +set @@tidb_enable_vectorized_expression = false; +select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3; +set @@tidb_enable_vectorized_expression = true; +select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3; + +# TestIssue25526 +drop table if exists tbl_6, tbl_17; +create table tbl_6 (col_31 year, index(col_31)); +create table tbl_17 (col_102 int, col_105 int); +replace into tbl_17 (col_102, col_105) values (9999, 0); +select tbl_6.col_31 from tbl_6 where col_31 in (select col_102 from tbl_17 where tbl_17.col_102 = 9999 and tbl_17.col_105 = 0); + +# TestIssue24953 +drop table if exists tbl_0,tbl_9; +CREATE TABLE `tbl_9` ( + `col_54` mediumint NOT NULL DEFAULT '2412996', + `col_55` int NOT NULL, + `col_56` bigint unsigned NOT NULL, + `col_57` varchar(108) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + PRIMARY KEY (`col_57`(3),`col_55`,`col_56`,`col_54`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE `tbl_0` ( + `col_76` bigint(20) unsigned DEFAULT NULL, + `col_1` time NOT NULL DEFAULT '13:11:28', + `col_2` datetime DEFAULT '1990-07-29 00:00:00', + `col_3` date NOT NULL DEFAULT '1976-09-16', + `col_4` date DEFAULT NULL, + `col_143` varbinary(208) DEFAULT 'lXRTXUkTeWaJ', + KEY `idx_0` (`col_2`,`col_1`,`col_76`,`col_4`,`col_3`), + PRIMARY KEY (`col_1`,`col_3`) /*T![clustered_index] NONCLUSTERED */, + KEY `idx_2` (`col_1`,`col_4`,`col_76`,`col_3`), + KEY `idx_3` (`col_4`,`col_76`,`col_3`,`col_2`,`col_1`), + UNIQUE KEY `idx_4` (`col_76`,`col_3`,`col_1`,`col_4`), + KEY `idx_5` (`col_3`,`col_4`,`col_76`,`col_2`), + KEY `idx_6` (`col_2`), + KEY `idx_7` (`col_76`,`col_3`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into tbl_9 values (-5765442,-597990898,384599625723370089,"ZdfkUJiHcOfi"); +(select col_76,col_1,col_143,col_2 from tbl_0) union (select col_54,col_57,col_55,col_56 from tbl_9); + +# TestIssue26958 +drop table if exists t1; +create table t1 (c_int int not null); +insert into t1 values (1), (2), (3),(1),(2),(3); +drop table if exists t2; +create table t2 (c_int int not null); +insert into t2 values (1), (2), (3),(1),(2),(3); +select (select count(distinct c_int) from t2 where c_int >= t1.c_int) c1, (select count(distinct c_int) from t2 where c_int >= t1.c_int) c2 from t1 group by c_int; + +# TestIssue27233 +drop table if exists t; +CREATE TABLE `t` ( + `COL1` tinyint(45) NOT NULL, + `COL2` tinyint(45) NOT NULL, + PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into t values(122,100),(124,-22),(124,34),(127,103); +SELECT col2 FROM t AS T1 WHERE ( SELECT count(DISTINCT COL1, COL2) FROM t AS T2 WHERE T2.COL1 > T1.COL1 ) > 2 ; + +# TestIssue27236 +select extract(hour_second from "-838:59:59.00"); +drop table if exists t; +create table t(c1 varchar(100)); +insert into t values('-838:59:59.00'), ('700:59:59.00'); +select extract(hour_second from c1) from t order by c1; + +# TestIssue26977 +select a + 1 as f from (select cast(0xfffffffffffffff0 as unsigned) as a union select cast(1 as unsigned)) t having f != 2; + +# TestIssue27610 +drop table if exists PK_TCOLLATION3966STROBJSTROBJ; +CREATE TABLE `PK_TCOLLATION3966STROBJSTROBJ` ( + `COL1` enum('ll','aa','bb','cc','dd','ee') COLLATE utf8_general_ci NOT NULL, + `COL2` varchar(20) COLLATE utf8_general_ci DEFAULT NULL, + PRIMARY KEY (`COL1`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +insert into PK_TCOLLATION3966STROBJSTROBJ values("ee", "tttt"); +SELECT col1, COL2 FROM PK_TCOLLATION3966STROBJSTROBJ WHERE COL1 IN ('notexist','6') and col2 not in ("abcd"); + +# TestIssue28804 +drop table if exists perf_offline_day; +CREATE TABLE perf_offline_day ( +uuid varchar(50), +ts timestamp NOT NULL, +user_id varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, +platform varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, +host_id bigint(20) DEFAULT NULL, +PRIMARY KEY (uuid,ts) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci +PARTITION BY RANGE ( UNIX_TIMESTAMP(ts) ) ( +PARTITION p20210906 VALUES LESS THAN (1630944000), +PARTITION p20210907 VALUES LESS THAN (1631030400), +PARTITION p20210908 VALUES LESS THAN (1631116800), +PARTITION p20210909 VALUES LESS THAN (1631203200) +); +set @@tidb_partition_prune_mode = 'static'; +INSERT INTO `perf_offline_day` VALUES ('dd082c8a-3bab-4431-943a-348fe0592abd','2021-09-08 13:00:07','Xg9C8zq81jGNbugM', 'pc', 12345); +SELECT cast(floor(hour(ts) / 4) as char) as win_start FROM perf_offline_day partition (p20210907, p20210908) GROUP BY win_start; + +# TestIssue28643 +drop table if exists t; +create table t(a time(4)); +insert into t values("-838:59:59.000000"); +insert into t values("838:59:59.000000"); +set tidb_enable_vectorized_expression = on; +select hour(a) from t; +set tidb_enable_vectorized_expression = off; +select hour(a) from t; +set tidb_enable_vectorized_expression = default; + +# TestIssue27831 +drop table if exists t; +create table t(a enum("a", "b"), b enum("a", "b"), c bool); +insert into t values("a", "a", 1); +select * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c; +drop table if exists t; +create table t(a enum("a", "b"), b enum("a", "b"), c bool, d int, index idx(d)); +insert into t values("a", "a", 1, 1); +select /*+ inl_hash_join(t1) */ * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c and t1.d=t2.d; + +# TestIssue29434 +drop table if exists t1; +create table t1(c1 datetime); +insert into t1 values('2021-12-12 10:10:10.000'); +set tidb_enable_vectorized_expression = on; +select greatest(c1, '99999999999999') from t1; +select least(c1, '99999999999999') from t1; +set tidb_enable_vectorized_expression = off; +select greatest(c1, '99999999999999') from t1; +select least(c1, '99999999999999') from t1; +set tidb_enable_vectorized_expression = default; + +# TestIssue29244 +drop table if exists t; +create table t(a time(4)); +insert into t values("-700:10:10.123456111"); +insert into t values("700:10:10.123456111"); +set tidb_enable_vectorized_expression = on; +select microsecond(a) from t; +set tidb_enable_vectorized_expression = off; +select microsecond(a) from t; +set tidb_enable_vectorized_expression = default; + +# TestIssue29755 +set tidb_enable_vectorized_expression = on; +select char(123, NULL, 123); +select char(NULL, 123, 123); +set tidb_enable_vectorized_expression = off; +select char(123, NULL, 123); +select char(NULL, 123, 123); +set tidb_enable_vectorized_expression = default; + +# TestIssue30101 +drop table if exists t1; +create table t1(c1 bigint unsigned, c2 bigint unsigned); +insert into t1 values(9223372036854775808, 9223372036854775809); +select greatest(c1, c2) from t1; + +# TestIssue30326 +drop table if exists t; +create table t(a int); +insert into t values(1),(1),(2),(2); +set tidb_window_concurrency = 1; +-- error 1242 +select (FIRST_VALUE(1) over (partition by v.a)) as c3 from (select a from t where t.a = (select a from t t2 where t.a = t2.a)) as v; + +# TestIssue30174 +drop table if exists t1,t2; +CREATE TABLE `t1` ( + `c1` enum('Alice','Bob','Charlie','David') NOT NULL, + `c2` blob NOT NULL, + PRIMARY KEY (`c2`(5)), + UNIQUE KEY `idx_89` (`c1`) +); +CREATE TABLE `t2` ( + `c1` enum('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'Alice', + `c2` set('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'David', + `c3` enum('Alice','Bob','Charlie','David') NOT NULL, + PRIMARY KEY (`c3`,`c2`) +); +insert into t1 values('Charlie',''); +insert into t2 values('Charlie','Charlie','Alice'); +select * from t2 where c3 in (select c2 from t1); +select * from t2 where c2 in (select c2 from t1); + +# TestIssue29708 +drop table if exists t1; +CREATE TABLE t1 (a text)character set utf8 ; +-- error 1301 +INSERT INTO t1 VALUES (REPEAT(0125,200000000)); +select * from t1; +insert into t1 (a) values ('a'),('b'); +-- error 1301 +insert into t1 select REPEAT(a,200000000) from t1; +select a from t1 order by a; +-- error 1301 +insert into t1 values (cast("a" as binary(4294967295))); +select a from t1 order by a; +INSERT IGNORE INTO t1 VALUES (REPEAT(0125,200000000)); +show warnings; +select a from t1 order by a; + +# TestIssue32488 +drop table if exists t; +create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +insert into t values('Ęž'), ('İ'); +set @@tidb_enable_vectorized_expression = false; +select binary upper(a), lower(a) from t order by upper(a); +select distinct upper(a), lower(a) from t order by upper(a); +set @@tidb_enable_vectorized_expression = true; +select binary upper(a), lower(a) from t order by upper(a); +select distinct upper(a), lower(a) from t order by upper(a); +set @@tidb_enable_vectorized_expression = default; + +# TestIssue33397 +drop table if exists t; +create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +insert into t values(''), (''); +set @@tidb_enable_vectorized_expression = true; +select compress(a) from t; +set @@tidb_enable_vectorized_expression = false; +select compress(a) from t; +set @@tidb_enable_vectorized_expression = default; + +# TestIssue34659 +drop table if exists t; +create table t(a varchar(32)); +insert into t values(date_add(cast('00:00:00' as time), interval 1.1 second)); +select * from t; +select cast(date_add(cast('00:00:00' as time), interval 1.1 second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1000000 microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1111119 second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.0 second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 second_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1111111 second_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 minute_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1111111 minute_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 minute_second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1111111 minute_second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1111111 hour_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1111111 hour_second) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_minute) as char); +select cast(date_add(cast('00:00:00' as time), interval 1.1 day_microsecond) as char); +select cast(date_add(cast('00:00:00' as time), interval 1111111 day_microsecond) as char); + +# TestIssue31799 +drop table if exists t; +create table t(i int, c varchar(32)); +insert into t values(1, date_add(cast('2001-01-01 00:00:00' as datetime), interval 1 second)); +insert into t values(2, date_add(cast('2001-01-01 00:00:00' as datetime(6)), interval 1 second)); +insert into t values(3, date_add(cast('2001-01-01 00:00:00' as datetime), interval 1.1 second)); +insert into t values(4, date_add(cast('2001-01-01 00:00:00' as datetime(6)), interval 1.1 second)); +insert into t values(5, date_add(cast('00:00:00' as time), interval 1.1 second)); +select c from t order by i; + +# TestIssue31867 +set time_zone = '+00:00'; +drop table if exists t; +create table t(ts timestamp(6) not null default current_timestamp(6) on update current_timestamp(6)); +insert into t values('1970-01-01 01:00:01.000000'); +insert into t values('1970-01-01 01:00:01.000001'); +insert into t values('1971-01-01 01:00:00.000000'); +insert into t values('1971-01-01 01:00:00.000001'); +insert into t values('2001-01-01 00:00:00.000000'); +insert into t values('2001-01-01 00:00:00.000001'); +insert into t values('2001-01-01 01:00:00.000000'); +insert into t values('2001-01-01 01:00:00.000001'); +select date_add(ts, interval 1 minute) from t order by ts; +select date_sub(ts, interval 1 minute) from t order by ts; +set time_zone = default; + +# TestIssue31600 +set time_zone = '+00:00'; +drop table if exists t; +create table t (tm_fsp0 time(0), tm_fsp1 time(1), tm_fsp3 time(3),tm_fsp6 time(6), d date, dt_fsp0 datetime(0), dt_fsp1 datetime(1), dt_fsp3 datetime(3), dt_fsp6 datetime(6)); +insert into t values(null, '12:12:01.1', '12:12:02.123', '12:12:03.123456', '20221212', null, '2020/12/11 12:12:11.1', '2020/12/12 12:12:12.123', '2020/12/13 12:12:13.123456'); +insert into t values('12:12:00', null, '12:12:02.123', '12:12:03.123456', '20221212', '2020/12/10 12:12:10', null, '2020/12/12 12:12:12.123', '2020/12/13 12:12:13.123456'); +insert into t values('12:12:00', '12:12:01.1', null, '12:12:03.123456', '20221212', '2020/12/10 12:12:10', '2020/12/11 12:12:11.1', null, '2020/12/13 12:12:13.123456'); +insert into t values('12:12:00', '12:12:01.1', '12:12:02.123', null, '20221212', '2020/12/10 12:12:10', '2020/12/11 12:12:11.1', '2020/12/12 12:12:12.123', null); +select coalesce(null, tm_fsp0, tm_fsp1, tm_fsp3, tm_fsp6) from t; +select coalesce(tm_fsp1, tm_fsp0, tm_fsp3) from t; +select coalesce(tm_fsp3, tm_fsp0) from t; +select coalesce(tm_fsp6) from t; +select coalesce(null, dt_fsp0, dt_fsp1, dt_fsp3, dt_fsp6) from t; +select coalesce(dt_fsp0, dt_fsp1, dt_fsp3) from t; +select coalesce(dt_fsp3, dt_fsp0) from t; +select coalesce(dt_fsp6) from t; +select coalesce(null, d) from t; +set time_zone = default; + +# TestIssue31569 +drop table if exists t; +create table t (c int primary key, c2 enum('a', 'b')); +set session sql_mode = ''; +insert into t values(4, 'a'); +insert into t values(4, 0) on duplicate key update c=values(c), c2=values(c2); +show warnings; +insert into t values(4, 'a') on duplicate key update c=values(c), c2=values(c2); +show warnings; +set @@sql_mode=default; + +# TestIssue38736 +drop table if exists t0, t1; +CREATE TABLE t0(c0 BOOL, c1 INT); +CREATE TABLE t1 LIKE t0; +CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT IS_IPV4(t0.c1) FROM t0, t1; +INSERT INTO t0(c0, c1) VALUES (true, 0); +INSERT INTO t1(c0, c1) VALUES (true, 2); +SELECT v0.c0 FROM v0 WHERE (v0.c0)NOT LIKE(BINARY v0.c0); +SELECT v0.c0 FROM v0 WHERE (v0.c0)NOT LIKE(BINARY v0.c0) or v0.c0 > 0; + +# TestIssue30264 +# compare Time/Int/Int as string type, return string type +select greatest(time '21:00', year(date'20220101'), 23); +# compare Time/Date/Int as string type, return string type +select greatest(time '21:00', date'891001', 120000); +# compare Time/Date/Int as string type, return string type +select greatest(time '20:00', date'101001', 120101); +# compare Date/String/Int as Date type, return string type +select greatest(date'101001', '19990329', 120101); +# compare Time/Date as DateTime type, return DateTime type +select greatest(time '20:00', date'691231'); +# compare Date/Date as DateTime type, return DateTime type +select greatest(date '120301', date'691231'); +# compare Time/Time as Time type, return Time type +select greatest(time '203001', time '2230'); +# compare DateTime/DateTime as DateTime type, return DateTime type +select greatest(timestamp '2021-01-31 00:00:01', timestamp '2021-12-31 12:00:00'); +# compare Time/DateTime as DateTime type, return DateTime type +select greatest(time '00:00:01', timestamp '2069-12-31 12:00:00'); +# compare Date/DateTime as DateTime type, return DateTime type +select greatest(date '21000101', timestamp '2069-12-31 12:00:00'); +# compare JSON/JSON, return JSON type +select greatest(cast('1' as JSON), cast('2' as JSON)); +# Original 30264 Issue +select greatest(time '20:00:00', 120000); +select greatest(date '2005-05-05', 20010101, 20040404, 20030303); +select greatest(date '1995-05-05', 19910101, 20050505, 19930303); +drop table if exists t1,t2; +CREATE TABLE `t1` (a datetime, b date, c time); +insert into t1 values(timestamp'2021-01-31 00:00:01', '2069-12-31', '20:00:01'); +set tidb_enable_vectorized_expression = on; +# compare Time/Int/Int as string type, return string type +select greatest(c, year(date'20220101'), 23) from t1; +# compare Time/Date/Int as string type, return string type +select greatest(c, date'891001', 120000) from t1; +# compare Time/Date/Int as string type, return string type +select greatest(c, date'101001', 120101) from t1; +# compare Date/String/Int as Date type, return string type +select greatest(b, '19990329', 120101) from t1; +# compare Time/Date as DateTime type, return DateTime type +select greatest(time '20:00', b) from t1; +# compare Date/Date as Date type, return Date type +select greatest(date '120301', b) from t1; +# compare Time/Time as Time type, return Time type +select greatest(c, time '2230') from t1; +# compare DateTime/DateTime as DateTime type, return DateTime type +select greatest(a, timestamp '2021-12-31 12:00:00') from t1; +# compare Time/DateTime as DateTime type, return DateTime type +select greatest(c, timestamp '2069-12-31 12:00:00') from t1; +# compare Date/DateTime as DateTime type, return DateTime type +select greatest(date '21000101', a) from t1; +# compare JSON/JSON, return JSON type +select greatest(cast(a as JSON), cast('3' as JSON)) from t1; +set tidb_enable_vectorized_expression = default; + +# TestIssue17727 +set tidb_enable_prepared_plan_cache=ON; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment, a timestamp NOT NULL); +INSERT INTO t1 VALUES (null, '2020-05-30 20:30:00'); +PREPARE mystmt FROM 'SELECT * FROM t1 WHERE UNIX_TIMESTAMP(a) >= ?'; +SET @a=1590868800; +EXECUTE mystmt USING @a; +select @@last_plan_from_cache; +SET @a=1590868801; +EXECUTE mystmt USING @a; +select @@last_plan_from_cache; +prepare stmt from 'select unix_timestamp(?)'; +set @a = '2020-05-30 20:30:00'; +execute stmt using @a; +select @@last_plan_from_cache; +set @a = '2020-06-12 13:47:58'; +execute stmt using @a; +select @@last_plan_from_cache; + +# TestIssue17891 +drop table if exists t; +set sql_mode=default; +create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b '); +drop table if exists test; +create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C'); + +# TestIssue31174 +drop table if exists t; +create table t(a char(4) collate utf8_general_ci primary key /*T![clustered_index] clustered */); +insert into t values('`?'); +explain format='brief' select * from t where a like '`%'; +select * from t where a like '`%'; +drop table if exists t; +create table t(a char(4) collate binary primary key /*T![clustered_index] clustered */); +insert into t values('`?'); +explain format='brief' select * from t where a like '`%'; +select * from t where a like '`%'; + +# TestIssue20268 +drop table if exists t; +CREATE TABLE `t` ( `a` enum('a','b') DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +insert into t values('a'); +select * from t where a = 'A'; + +# TestIssue16668 +drop table if exists tx; +CREATE TABLE `tx` ( `a` int(11) NOT NULL,`b` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL); +insert into tx values (1, 'a'), (2, 'Ă€'), (3, 'á'), (4, 'Ă '), (5, 'b'), (6, 'c'), (7, ' '); +select count(distinct(b)) from tx; + +# TestIssue27091 +drop table if exists tx; +CREATE TABLE `tx` ( `a` int(11) NOT NULL,`b` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, `c` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL); +insert into tx values (1, 'a', 'a'), (2, 'A ', 'a '), (3, 'A', 'A'), (4, 'a ', 'A '); +select count(distinct b) from tx; +select count(distinct c) from tx; +select count(distinct b, c) from tx where a < 3; +select approx_count_distinct(b) from tx; +select approx_count_distinct(c) from tx; +select approx_count_distinct(b, c) from tx where a < 3; + +# TestIssue17176 +drop table if exists t; +-- error 1291 +create table t(a enum('a', 'a ')) charset utf8 collate utf8_bin; +-- error 1291 +create table t(a enum('a', 'Ă')) charset utf8 collate utf8_general_ci; +-- error 1291 +create table t(a enum('a', 'a ')) charset utf8mb4 collate utf8mb4_bin; +create table t(a enum('a', 'A')) charset utf8 collate utf8_bin; +drop table if exists t3; +create table t3(a enum('a', 'A')) charset utf8mb4 collate utf8mb4_bin; + +# TestIssue18638 +drop table if exists t; +create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci); +insert into t (a, b) values ('a', 'A'); +select * from t t1, t t2 where t1.a = t2.b collate utf8mb4_general_ci; +select * from t t1 left join t t2 on t1.a = t2.b collate utf8mb4_general_ci; + +# TestIssue18662 +drop table if exists t; +create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci); +insert into t (a, b) values ('a', 'A'); +select * from t where field('A', a collate utf8mb4_general_ci, b) > 1; +select * from t where field('A', a, b collate utf8mb4_general_ci) > 1; +select * from t where field('A' collate utf8mb4_general_ci, a, b) > 1; +select * from t where field('A', a, b) > 1; + +# TestIssue19116 +set names utf8mb4 collate utf8mb4_general_ci; +select collation(concat(1 collate `binary`)); +select coercibility(concat(1 collate `binary`)); +select collation(concat(NULL,NULL)); +select coercibility(concat(NULL,NULL)); +select collation(concat(1,1)); +select coercibility(concat(1,1)); +select collation(1); +select coercibility(1); +select coercibility(1=1); +drop table if exists t; +create table t(a datetime); +insert into t values ('2020-02-02'); +select collation(concat(unix_timestamp(a))) from t; +select coercibility(concat(unix_timestamp(a))) from t; +set names default; + +# TestIssue17063 +drop table if exists t; +create table t(a char, b char) collate utf8mb4_general_ci; +insert into t values('a', 'b'); +insert into t values('a', 'B'); +select * from t where if(a='x', a, b) = 'b'; +select collation(if(a='x', a, b)) from t; +select coercibility(if(a='x', a, b)) from t; +select collation(lag(b, 1, 'B') over w) from t window w as (order by b); +select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b); + +# TestIssue11177 +SELECT 'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0; +show warnings; +SELECT 'aa' BETWEEN 'bb' AND 0; +show warnings; +select 1 between 0 and b'110'; +show warnings; +select 'b' between 'a' and b'110'; +show warnings; + +# TestIssue19804 +drop table if exists t; +create table t(a set('a', 'b', 'c')); +-- error 1291 +alter table t change a a set('a', 'b', 'c', 'c'); +drop table if exists t; +create table t(a enum('a', 'b', 'c')); +-- error 1291 +alter table t change a a enum('a', 'b', 'c', 'c'); +drop table if exists t; +create table t(a set('a', 'b', 'c')); +alter table t change a a set('a', 'b', 'c', 'd'); +insert into t values('d'); +-- error 1265 +alter table t change a a set('a', 'b', 'c', 'e', 'f'); + +# TestIssue20209 +set @@character_set_client=utf8mb4; +set @@collation_connection=utf8_bin; +CREATE VIEW tview_1 AS SELECT 'a' AS `id`; +set @@character_set_client=default; +set @@collation_connection=default; + +# TestIssue18949 +drop table if exists t; +create table t(a enum('a ', 'b\t', ' c '), b set('a ', 'b\t', ' c ')); +show create table t; +alter table t change a aa enum('a ', 'b\t', ' c '); +show create table t; + +# TestIssue20608 +select '䇇Հ' collate utf8mb4_bin like '___Ő€'; + +# TestIssue20161 +drop table if exists t; +create table t(raw JSON); +insert into t(raw) values('["a","ab"]'), ('["a"]'), (null); +SELECT JSON_SEARCH(raw,'one','c') FROM t; + +# TestIssue20876 +drop table if exists t; +CREATE TABLE `t` ( `a` char(10) COLLATE utf8mb4_unicode_ci NOT NULL, `b` char(20) COLLATE utf8mb4_general_ci NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`,`b`,`c`), KEY `idx` (`a`)); +insert into t values ('#', 'C', 10), ('$', 'c', 20), ('$', 'c', 30), ('a', 'a', 10), ('A', 'A', 30); +analyze table t; +select * from t where a='#'; + +# TestIssue23805 +CREATE TABLE `tbl_5` ( `col_25` time NOT NULL DEFAULT '05:35:58', `col_26` blob NOT NULL, `col_27` double NOT NULL, `col_28` char(83) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `col_29` timestamp NOT NULL, `col_30` varchar(36) COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'ywzIn', `col_31` binary(85) DEFAULT 'OIstcXsGmAyc', `col_32` datetime NOT NULL DEFAULT '2024-08-02 00:00:00', PRIMARY KEY (`col_26`(3),`col_27`) /*T![clustered_index] CLUSTERED */, UNIQUE KEY `idx_10` (`col_26`(5))); +insert ignore into tbl_5 set col_28 = 'ZmZIdSnq' , col_25 = '18:50:52.00' on duplicate key update col_26 = 'y'; + +# TestIssue26662 +drop table if exists t1; +create table t1(a varchar(36) NOT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_general_ci; +set names utf8; +select t2.b from (select t1.a as b from t1 union all select t1.a as b from t1) t2 where case when (t2.b is not null) then t2.b else '' end > '1234567'; +set names default; + +# TestIssue30245 +-- error 1267 +select case 1 when 1 then 'a' collate utf8mb4_unicode_ci else 'b' collate utf8mb4_general_ci end; +-- error 1267 +select case when 1 then 'a' collate utf8mb4_unicode_ci when 2 then 'b' collate utf8mb4_general_ci end; +-- error 1270 +select case 1 when 1 then 'a' collate utf8mb4_unicode_ci when 2 then 'b' collate utf8mb4_general_ci else 'b' collate utf8mb4_bin end; + +# TestIssue24502 +drop table if exists t0,t1; +create table t0(col1 varchar(255)); +create table t1(col1 int(11)); +insert into t0 values("\\9jM\\M"); +insert into t1 values(0); +insert into t1 values(null); +insert into t1 values(null); +select t0.col1, t1.col1 from t0 left join t1 on t0.col1 not like t0.col1; +select 'a' like '\\a'; +select 'a' like '+a' escape '+'; + +# TestIssue17233 +drop table if exists table_int; +CREATE TABLE table_int ( + id_0 int(16) NOT NULL AUTO_INCREMENT, + col_int_0 int(16) DEFAULT NULL, + PRIMARY KEY (id_0), + KEY fvclc (id_0,col_int_0)); +INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0); +drop table if exists table_varchar; +CREATE TABLE table_varchar ( + id_2 int(16) NOT NULL AUTO_INCREMENT, + col_varchar_2 varchar(511) DEFAULT NULL, + PRIMARY KEY (id_2)); +INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,''); +drop table if exists table_int_float_varchar; +CREATE TABLE table_int_float_varchar ( + id_6 int(16) NOT NULL AUTO_INCREMENT, + col_int_6 int(16) NOT NULL, + col_float_6 float DEFAULT NULL, + col_varchar_6 varchar(511) DEFAULT NULL, + PRIMARY KEY (id_6,col_int_6) + ) + PARTITION BY RANGE ( col_int_6 ) ( + PARTITION p0 VALUES LESS THAN (1), + PARTITION p2 VALUES LESS THAN (1000), + PARTITION p3 VALUES LESS THAN (10000), + PARTITION p5 VALUES LESS THAN (1000000), + PARTITION p7 VALUES LESS THAN (100000000), + PARTITION p9 VALUES LESS THAN (10000000000), + PARTITION p10 VALUES LESS THAN (100000000000), + PARTITION pn VALUES LESS THAN (MAXVALUE)); +INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1'); +drop table if exists table_float; +CREATE TABLE table_float ( + id_1 int(16) NOT NULL AUTO_INCREMENT, + col_float_1 float DEFAULT NULL, + PRIMARY KEY (id_1), + KEY zbjus (id_1,col_float_1)); +INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1); +drop view if exists view_4; +CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS + SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ + tmp1.id_6 AS col_1, + tmp1.col_int_6 AS col_2, + tmp1.col_float_6 AS col_3, + tmp1.col_varchar_6 AS col_4, + tmp2.id_2 AS col_5, + tmp2.col_varchar_2 AS col_6, + tmp3.id_0 AS col_7, + tmp3.col_int_0 AS col_8, + tmp4.id_1 AS col_9, + tmp4.col_float_1 AS col_10 + FROM (( + expression__issues.table_int_float_varchar AS tmp1 LEFT JOIN + expression__issues.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL + ) JOIN + expression__issues.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) + JOIN + expression__issues.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5; +drop view if exists view_10; +CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS + SELECT table_int.id_0 AS col_1, + table_int.col_int_0 AS col_2 + FROM expression__issues.table_int + WHERE + ((-1e+00=1) OR (0e+00>=table_int.col_int_0)) + ORDER BY col_1,col_2 + LIMIT 5,9; +SELECT col_1 FROM expression__issues.view_10; +SELECT col_1 FROM expression__issues.view_4; +SELECT view_10.col_1 FROM view_4 JOIN view_10; + +# TestIssue17989 +drop table if exists t; +create table t(a int, b tinyint as(a+1), c int as(b+1)); +set sql_mode=''; +insert into t(a) values(2000); +create index idx on t(c); +select c from t; +admin check table t; +set @@sql_mode=default; + +# TestIssue18652 +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( `pk` int not null primary key auto_increment, `col_smallint_key_signed` smallint , key (`col_smallint_key_signed`)); +INSERT INTO `t1` VALUES (1,0),(2,NULL),(3,NULL),(4,0),(5,0),(6,NULL),(7,NULL),(8,0),(9,0),(10,0); +SELECT * FROM t1 WHERE ( LOG( `col_smallint_key_signed`, -8297584758403770424 ) ) DIV 1; + +# TestIssue19045 +drop table if exists t, t1, t2; +CREATE TABLE t ( + id int(11) NOT NULL AUTO_INCREMENT, + a char(10) DEFAULT NULL, + PRIMARY KEY (id) +); +CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + a char(10) DEFAULT NULL, + b char(10) DEFAULT NULL, + c char(10) DEFAULT NULL, + PRIMARY KEY (id) +); +CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + a char(10) DEFAULT NULL, + b char(10) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY b (b) +); +insert into t1(a,b,c) values('hs4_0004', "04", "101"), ('a01', "01", "101"),('a011', "02", "101"); +insert into t2(a,b) values("02","03"); +insert into t(a) values('101'),('101'); +select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ; + +# TestIssue19315 +drop table if exists t, t1; +CREATE TABLE `t` (`a` bit(10) DEFAULT NULL,`b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +INSERT INTO `t` VALUES (_binary '\0',1),(_binary '\0',2),(_binary '\0',5),(_binary '\0',4),(_binary '\0',2),(_binary '\0 ',4); +CREATE TABLE `t1` (`a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +INSERT INTO `t1` VALUES (1,1),(1,5),(2,3),(2,4),(3,3); +select * from t where t.b > (select min(t1.b) from t1 where t1.a > t.a); + +# TestIssue21290 +drop table if exists t1; +create table t1(a date); +insert into t1 values (20100202); +select a in ('2020-02-02', 20100202) from t1; + +# TestIssue20128 +drop table if exists t; +create table t(b enum('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') DEFAULT NULL, c decimal(40,20)); +insert into t values('z', 19.18040000000000000000); +insert into t values('z', 26.18040000000000000000); +insert into t values('z', 25.18040000000000000000); +select * from t where t.b > t.c; +select * from t where t.b < t.c; + +# TestIssue45410 +drop table if exists t1; +CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (0); +SELECT c1>=CAST('-787360724' AS TIME) FROM t1; diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 49f111e368..44121d7295 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1900,7 +1900,7 @@ func TestDateArithFuncs(t *testing.T) { tests := []struct { inputDate string fc functionClass - inputDecimal float64 + inputDecimal interface{} expect string }{ {date[0], fcAdd, 1, date[1]}, @@ -1909,6 +1909,7 @@ func TestDateArithFuncs(t *testing.T) { {date[1], fcAdd, -1.4, date[0]}, {"1998-10-00", fcAdd, 1, ""}, {"2004-00-01", fcAdd, 1, ""}, + {"20111111", fcAdd, "-123", "2011-07-11"}, {date[1], fcSub, 1, date[0]}, {date[0], fcSub, -1, date[1]}, @@ -1916,6 +1917,7 @@ func TestDateArithFuncs(t *testing.T) { {date[0], fcSub, -1.4, date[1]}, {"1998-10-00", fcSub, 31, ""}, {"2004-00-01", fcSub, 31, ""}, + {"20111111", fcSub, "-123", "2012-03-13"}, } for _, test := range tests { args := types.MakeDatums(test.inputDate, test.inputDecimal, "DAY") @@ -2025,32 +2027,29 @@ func TestDateArithFuncs(t *testing.T) { require.Equal(t, test.expected, v.GetString()) } - testOverflowYears := []struct { + testOverflow := []struct { input string - year int + v int + unit string }{ - {"2008-11-23", -1465647104}, - {"2008-11-23", 1465647104}, + {"2008-11-23", -1465647104, "YEAR"}, + {"2008-11-23", 1465647104, "YEAR"}, + {"2000-04-13 07:17:02", -1465647104, "YEAR"}, + {"2000-04-13 07:17:02", 1465647104, "YEAR"}, + {"2008-11-23 22:47:31", 266076160, "QUARTER"}, + {"2008-11-23 22:47:31", -266076160, "QUARTER"}, } - for _, test := range testOverflowYears { - args = types.MakeDatums(test.input, test.year, "YEAR") - f, err = fcAdd.getFunction(ctx, datumsToConstants(args)) - require.NoError(t, err) - require.NotNil(t, f) - v, err = evalBuiltinFunc(f, chunk.Row{}) - require.NoError(t, err) - require.True(t, v.IsNull()) - } - - for _, test := range testOverflowYears { - args = types.MakeDatums(test.input, test.year, "YEAR") - f, err = fcSub.getFunction(ctx, datumsToConstants(args)) - require.NoError(t, err) - require.NotNil(t, f) - v, err = evalBuiltinFunc(f, chunk.Row{}) - require.NoError(t, err) - require.True(t, v.IsNull()) + for _, test := range testOverflow { + for _, fc := range []functionClass{fcAdd, fcSub} { + args = types.MakeDatums(test.input, test.v, test.unit) + f, err = fc.getFunction(ctx, datumsToConstants(args)) + require.NoError(t, err) + require.NotNil(t, f) + v, err = evalBuiltinFunc(f, chunk.Row{}) + require.NoError(t, err) + require.True(t, v.IsNull()) + } } testDurations := []struct { diff --git a/expression/integration_serial_test/integration_serial_test.go b/expression/integration_serial_test/integration_serial_test.go index 70c2978011..0a34edb228 100644 --- a/expression/integration_serial_test/integration_serial_test.go +++ b/expression/integration_serial_test/integration_serial_test.go @@ -38,76 +38,6 @@ import ( "github.com/tikv/client-go/v2/oracle" ) -func TestIssue17727(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - - tk.MustExec("use test;") - tk.MustExec("DROP TABLE IF EXISTS t1;") - tk.MustExec("CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment, a timestamp NOT NULL);") - tk.MustExec("INSERT INTO t1 VALUES (null, '2020-05-30 20:30:00');") - tk.MustExec("PREPARE mystmt FROM 'SELECT * FROM t1 WHERE UNIX_TIMESTAMP(a) >= ?';") - tk.MustExec("SET @a=1590868800;") - tk.MustQuery("EXECUTE mystmt USING @a;").Check(testkit.Rows()) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) - - tk.MustExec("SET @a=1590868801;") - tk.MustQuery("EXECUTE mystmt USING @a;").Check(testkit.Rows()) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) - - tk.MustExec("prepare stmt from 'select unix_timestamp(?)';") - tk.MustExec("set @a = '2020-05-30 20:30:00';") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1590841800")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) - - tk.MustExec("set @a = '2020-06-12 13:47:58';") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1591940878")) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) -} - -func TestIssue17891(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');") - tk.MustExec("drop table t") - tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');") -} - -func TestIssue31174(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(4) collate utf8_general_ci primary key /*T![clustered_index] clustered */);") - tk.MustExec("insert into t values('`?');") - // The 'like' condition can not be used to construct the range. - tk.HasPlan("select * from t where a like '`%';", "TableFullScan") - tk.MustQuery("select * from t where a like '`%';").Check(testkit.Rows("`?")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(4) collate binary primary key /*T![clustered_index] clustered */);") - tk.MustExec("insert into t values('`?');") - tk.HasPlan("select * from t where a like '`%';", "TableRangeScan") - tk.MustQuery("select * from t where a like '`%';").Check(testkit.Rows("`?\x00\x00")) -} - -func TestIssue20268(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("CREATE TABLE `t` ( `a` enum('a','b') DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;") - tk.MustExec("insert into t values('a');") - tk.MustExec("select * from t where a = 'A';") -} - func TestCollationBasic(t *testing.T) { store := testkit.CreateMockStore(t) @@ -663,33 +593,6 @@ func TestCollateIndexLookup(t *testing.T) { tk.MustQuery("select id from t_bin where v < 'b' and v > ' '").Sort().Check(testkit.Rows("1")) } -func TestIssue16668(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists tx") - tk.MustExec("CREATE TABLE `tx` ( `a` int(11) NOT NULL,`b` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL)") - tk.MustExec("insert into tx values (1, 'a'), (2, 'Ă€'), (3, 'á'), (4, 'Ă '), (5, 'b'), (6, 'c'), (7, ' ')") - tk.MustQuery("select count(distinct(b)) from tx").Check(testkit.Rows("4")) -} - -func TestIssue27091(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists tx") - tk.MustExec("CREATE TABLE `tx` ( `a` int(11) NOT NULL,`b` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, `c` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL)") - tk.MustExec("insert into tx values (1, 'a', 'a'), (2, 'A ', 'a '), (3, 'A', 'A'), (4, 'a ', 'A ')") - tk.MustQuery("select count(distinct b) from tx").Check(testkit.Rows("1")) - tk.MustQuery("select count(distinct c) from tx").Check(testkit.Rows("2")) - tk.MustQuery("select count(distinct b, c) from tx where a < 3").Check(testkit.Rows("1")) - tk.MustQuery("select approx_count_distinct(b) from tx").Check(testkit.Rows("1")) - tk.MustQuery("select approx_count_distinct(c) from tx").Check(testkit.Rows("2")) - tk.MustQuery("select approx_count_distinct(b, c) from tx where a < 3").Check(testkit.Rows("1")) -} - func TestCollateStringFunction(t *testing.T) { store := testkit.CreateMockStore(t) @@ -931,32 +834,6 @@ func TestNewCollationBinaryFlag(t *testing.T) { require.Contains(t, sct, "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") } -func TestIssue17176(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustGetErrMsg("create table t(a enum('a', 'a ')) charset utf8 collate utf8_bin;", "[types:1291]Column 'a' has duplicated value 'a' in ENUM") - tk.MustGetErrMsg("create table t(a enum('a', 'Ă')) charset utf8 collate utf8_general_ci;", "[types:1291]Column 'a' has duplicated value 'Ă' in ENUM") - tk.MustGetErrMsg("create table t(a enum('a', 'a ')) charset utf8mb4 collate utf8mb4_bin;", "[types:1291]Column 'a' has duplicated value 'a' in ENUM") - tk.MustExec("create table t(a enum('a', 'A')) charset utf8 collate utf8_bin;") - tk.MustExec("drop table t;") - tk.MustExec("create table t3(a enum('a', 'A')) charset utf8mb4 collate utf8mb4_bin;") -} - -func TestIssue18638(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci);") - tk.MustExec("insert into t (a, b) values ('a', 'A');") - tk.MustQuery("select * from t t1, t t2 where t1.a = t2.b collate utf8mb4_general_ci;").Check(testkit.Rows("a A a A")) - tk.MustQuery("select * from t t1 left join t t2 on t1.a = t2.b collate utf8mb4_general_ci;").Check(testkit.Rows("a A a A")) -} - func TestCollationText(t *testing.T) { store := testkit.CreateMockStore(t) @@ -970,115 +847,6 @@ func TestCollationText(t *testing.T) { tk.MustExec("admin check table t;") } -func TestIssue18662(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci);") - tk.MustExec("insert into t (a, b) values ('a', 'A');") - tk.MustQuery("select * from t where field('A', a collate utf8mb4_general_ci, b) > 1;").Check(testkit.Rows()) - tk.MustQuery("select * from t where field('A', a, b collate utf8mb4_general_ci) > 1;").Check(testkit.Rows()) - tk.MustQuery("select * from t where field('A' collate utf8mb4_general_ci, a, b) > 1;").Check(testkit.Rows()) - tk.MustQuery("select * from t where field('A', a, b) > 1;").Check(testkit.Rows("a A")) -} - -func TestIssue19116(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;") - tk.MustQuery("select collation(concat(1 collate `binary`));").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(concat(1 collate `binary`));").Check(testkit.Rows("0")) - tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(concat(NULL,NULL));").Check(testkit.Rows("6")) - tk.MustQuery("select collation(concat(1,1));").Check(testkit.Rows("utf8mb4_general_ci")) - tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4")) - tk.MustQuery("select collation(1);").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) - tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a datetime)") - tk.MustExec("insert into t values ('2020-02-02')") - tk.MustQuery("select collation(concat(unix_timestamp(a))) from t;").Check(testkit.Rows("utf8mb4_general_ci")) - tk.MustQuery("select coercibility(concat(unix_timestamp(a))) from t;").Check(testkit.Rows("4")) -} - -func TestIssue17063(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists t;`) - tk.MustExec("create table t(a char, b char) collate utf8mb4_general_ci;") - tk.MustExec(`insert into t values('a', 'b');`) - tk.MustExec(`insert into t values('a', 'B');`) - tk.MustQuery(`select * from t where if(a='x', a, b) = 'b';`).Check(testkit.Rows("a b", "a B")) - tk.MustQuery(`select collation(if(a='x', a, b)) from t;`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci")) - tk.MustQuery(`select coercibility(if(a='x', a, b)) from t;`).Check(testkit.Rows("2", "2")) - tk.MustQuery(`select collation(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci")) - tk.MustQuery(`select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("2", "2")) -} - -func TestIssue11177(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery("SELECT 'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0;").Check(testkit.Rows("0")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect DOUBLE value: 'lvuleck'", "Warning 1292 Truncated incorrect DOUBLE value: '2008-09-16 22:23:50'")) - tk.MustQuery("SELECT 'aa' BETWEEN 'bb' AND 0;").Check(testkit.Rows("1")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect DOUBLE value: 'aa'", "Warning 1292 Truncated incorrect DOUBLE value: 'bb'")) - tk.MustQuery("select 1 between 0 and b'110';").Check(testkit.Rows("1")) - tk.MustQuery("show warnings;").Check(testkit.Rows()) - tk.MustQuery("select 'b' between 'a' and b'110';").Check(testkit.Rows("0")) - tk.MustQuery("show warnings;").Check(testkit.Rows()) -} - -func TestIssue19804(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a set('a', 'b', 'c'));`) - tk.MustGetErrMsg("alter table t change a a set('a', 'b', 'c', 'c');", "[types:1291]Column 'a' has duplicated value 'c' in SET") - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a enum('a', 'b', 'c'));`) - tk.MustGetErrMsg("alter table t change a a enum('a', 'b', 'c', 'c');", "[types:1291]Column 'a' has duplicated value 'c' in ENUM") - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a set('a', 'b', 'c'));`) - tk.MustExec(`alter table t change a a set('a', 'b', 'c', 'd');`) - tk.MustExec(`insert into t values('d');`) - tk.MustGetErrMsg(`alter table t change a a set('a', 'b', 'c', 'e', 'f');`, "[types:1265]Data truncated for column 'a', value is 'd'") -} - -func TestIssue20209(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`set @@character_set_client=utf8mb4;`) - tk.MustExec(`set @@collation_connection=utf8_bin;`) - tk.MustExec("CREATE VIEW tview_1 AS SELECT 'a' AS `id`;") -} - -func TestIssue18949(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a enum('a ', 'b\t', ' c '), b set('a ', 'b\t', ' c '));`) - result := tk.MustQuery("show create table t").Rows()[0][1] - require.Regexp(t, `(?s).*enum\('a','b ',' c'\).*set\('a','b ',' c'\).*`, result) - tk.MustExec(`alter table t change a aa enum('a ', 'b\t', ' c ');`) - result = tk.MustQuery("show create table t").Rows()[0][1] - require.Regexp(t, `(?s).*enum\('a','b ',' c'\).*set\('a','b ',' c'\).*`, result) -} - func TestClusteredIndexAndNewCollationIndexEncodeDecodeV5(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1178,25 +946,6 @@ func TestClusteredIndexAndNewCollation(t *testing.T) { tk.MustQuery("select * from t").Check(testkit.Rows("&")) } -func TestIssue20608(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery("select '䇇Հ' collate utf8mb4_bin like '___Ő€';").Check(testkit.Rows("0")) -} - -func TestIssue20161(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(raw JSON);`) - tk.MustExec(`insert into t(raw) values('["a","ab"]'), ('["a"]'), (null);`) - tk.MustQuery(`SELECT JSON_SEARCH(raw,'one','c') FROM t;`). - Check(testkit.Rows("", "", "")) -} - func TestCollationIndexJoin(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1257,25 +1006,6 @@ func TestCollationMergeJoin(t *testing.T) { testkit.Rows("\x41 2.00000 a", "\x61 23.00000 A", "\x61 12523.00000 A")) } -func TestIssue20876(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("drop table if exists t;") - tk.MustExec("CREATE TABLE `t` (" + - " `a` char(10) COLLATE utf8mb4_unicode_ci NOT NULL," + - " `b` char(20) COLLATE utf8mb4_general_ci NOT NULL," + - " `c` int(11) NOT NULL," + - " PRIMARY KEY (`a`,`b`,`c`)," + - " KEY `idx` (`a`)" + - ")") - tk.MustExec("insert into t values ('#', 'C', 10), ('$', 'c', 20), ('$', 'c', 30), ('a', 'a', 10), ('A', 'A', 30)") - tk.MustExec("analyze table t") - tk.MustQuery("select * from t where a='#';").Check(testkit.Rows("# C 10")) -} - func TestLikeWithCollation(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1302,46 +1032,6 @@ func TestCollationPrefixClusteredIndex(t *testing.T) { tk.MustExec("admin check table t;") } -func TestIssue23805(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `tbl_5` (" + - " `col_25` time NOT NULL DEFAULT '05:35:58'," + - " `col_26` blob NOT NULL," + - " `col_27` double NOT NULL," + - " `col_28` char(83) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL," + - " `col_29` timestamp NOT NULL," + - " `col_30` varchar(36) COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'ywzIn'," + - " `col_31` binary(85) DEFAULT 'OIstcXsGmAyc'," + - " `col_32` datetime NOT NULL DEFAULT '2024-08-02 00:00:00'," + - " PRIMARY KEY (`col_26`(3),`col_27`) /*T![clustered_index] CLUSTERED */," + - " UNIQUE KEY `idx_10` (`col_26`(5)));") - tk.MustExec("insert ignore into tbl_5 set col_28 = 'ZmZIdSnq' , col_25 = '18:50:52.00' on duplicate key update col_26 = 'y';\n") -} - -func TestIssue26662(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(a varchar(36) NOT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_general_ci;") - tk.MustExec("set names utf8;") - tk.MustQuery("select t2.b from (select t1.a as b from t1 union all select t1.a as b from t1) t2 where case when (t2.b is not null) then t2.b else '' end > '1234567';"). - Check(testkit.Rows()) -} - -func TestIssue30245(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustGetErrCode("select case 1 when 1 then 'a' collate utf8mb4_unicode_ci else 'b' collate utf8mb4_general_ci end", mysql.ErrCantAggregate2collations) - tk.MustGetErrCode("select case when 1 then 'a' collate utf8mb4_unicode_ci when 2 then 'b' collate utf8mb4_general_ci end", mysql.ErrCantAggregate2collations) - tk.MustGetErrCode("select case 1 when 1 then 'a' collate utf8mb4_unicode_ci when 2 then 'b' collate utf8mb4_general_ci else 'b' collate utf8mb4_bin end", mysql.ErrCantAggregate3collations) -} - func TestCollationForBinaryLiteral(t *testing.T) { store := testkit.CreateMockStore(t) @@ -3938,123 +3628,6 @@ func TestCacheConstEval(t *testing.T) { tk.MustExec("admin reload expr_pushdown_blacklist") } -func TestIssue24502(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t0,t1;") - tk.MustExec("create table t0(col1 varchar(255));") - tk.MustExec("create table t1(col1 int(11));") - tk.MustExec(`insert into t0 values("\\9jM\\M");`) - tk.MustExec(`insert into t1 values(0);`) - tk.MustExec(`insert into t1 values(null);`) - tk.MustExec(`insert into t1 values(null);`) - - tk.MustQuery(`select t0.col1, t1.col1 from t0 left join t1 on t0.col1 not like t0.col1;`). - Check(testkit.Rows(`\9jM\M `, `\9jM\M `, `\9jM\M 0`)) - - tk.MustQuery(`select 'a' like '\\a'`).Check(testkit.Rows("1")) - tk.MustQuery(`select 'a' like '+a' escape '+'`).Check(testkit.Rows("1")) -} - -func TestIssue17233(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists table_int") - tk.MustExec(`CREATE TABLE table_int ( - id_0 int(16) NOT NULL AUTO_INCREMENT, - col_int_0 int(16) DEFAULT NULL, - PRIMARY KEY (id_0), - KEY fvclc (id_0,col_int_0));`) - tk.MustExec("INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0)") - - tk.MustExec("drop table if exists table_varchar") - tk.MustExec(`CREATE TABLE table_varchar ( - id_2 int(16) NOT NULL AUTO_INCREMENT, - col_varchar_2 varchar(511) DEFAULT NULL, - PRIMARY KEY (id_2));`) - tk.MustExec(`INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,'');`) - - tk.MustExec("drop table if exists table_float_varchar") - tk.MustExec(`CREATE TABLE table_int_float_varchar ( - id_6 int(16) NOT NULL AUTO_INCREMENT, - col_int_6 int(16) NOT NULL, - col_float_6 float DEFAULT NULL, - col_varchar_6 varchar(511) DEFAULT NULL, - PRIMARY KEY (id_6,col_int_6) - ) - PARTITION BY RANGE ( col_int_6 ) ( - PARTITION p0 VALUES LESS THAN (1), - PARTITION p2 VALUES LESS THAN (1000), - PARTITION p3 VALUES LESS THAN (10000), - PARTITION p5 VALUES LESS THAN (1000000), - PARTITION p7 VALUES LESS THAN (100000000), - PARTITION p9 VALUES LESS THAN (10000000000), - PARTITION p10 VALUES LESS THAN (100000000000), - PARTITION pn VALUES LESS THAN (MAXVALUE));`) - tk.MustExec(`INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1');`) - - tk.MustExec("drop table if exists table_float") - tk.MustExec(`CREATE TABLE table_float ( - id_1 int(16) NOT NULL AUTO_INCREMENT, - col_float_1 float DEFAULT NULL, - PRIMARY KEY (id_1), - KEY zbjus (id_1,col_float_1));`) - tk.MustExec(`INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1);`) - - tk.MustExec("drop view if exists view_4") - tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS - SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ - tmp1.id_6 AS col_1, - tmp1.col_int_6 AS col_2, - tmp1.col_float_6 AS col_3, - tmp1.col_varchar_6 AS col_4, - tmp2.id_2 AS col_5, - tmp2.col_varchar_2 AS col_6, - tmp3.id_0 AS col_7, - tmp3.col_int_0 AS col_8, - tmp4.id_1 AS col_9, - tmp4.col_float_1 AS col_10 - FROM (( - test.table_int_float_varchar AS tmp1 LEFT JOIN - test.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL - ) JOIN - test.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) - JOIN - test.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5;`) - - tk.MustExec("drop view if exists view_10") - tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS - SELECT table_int.id_0 AS col_1, - table_int.col_int_0 AS col_2 - FROM test.table_int - WHERE - ((-1e+00=1) OR (0e+00>=table_int.col_int_0)) - ORDER BY col_1,col_2 - LIMIT 5,9;`) - - tk.MustQuery("SELECT col_1 FROM test.view_10").Sort().Check(testkit.Rows("16", "18", "19")) - tk.MustQuery("SELECT col_1 FROM test.view_4").Sort().Check(testkit.Rows("8", "8", "8", "8", "8")) - tk.MustQuery("SELECT view_10.col_1 FROM view_4 JOIN view_10").Check(testkit.Rows("16", "16", "16", "16", "16", "18", "18", "18", "18", "18", "19", "19", "19", "19", "19")) -} - -func TestIssue17989(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b tinyint as(a+1), c int as(b+1));") - tk.MustExec("set sql_mode='';") - tk.MustExec("insert into t(a) values(2000);") - tk.MustExec("create index idx on t(c);") - tk.MustQuery("select c from t;").Check(testkit.Rows("128")) - tk.MustExec("admin check table t") -} - func TestNullValueRange(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4076,48 +3649,6 @@ func TestNullValueRange(t *testing.T) { tk.MustQuery("select c from t1 where a=1 and b is not null and c>2 order by c").Check(testkit.Rows("33", "44")) } -func TestIssue18652(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS t1") - tk.MustExec("CREATE TABLE t1 ( `pk` int not null primary key auto_increment, `col_smallint_key_signed` smallint , key (`col_smallint_key_signed`))") - tk.MustExec("INSERT INTO `t1` VALUES (1,0),(2,NULL),(3,NULL),(4,0),(5,0),(6,NULL),(7,NULL),(8,0),(9,0),(10,0)") - tk.MustQuery("SELECT * FROM t1 WHERE ( LOG( `col_smallint_key_signed`, -8297584758403770424 ) ) DIV 1").Check(testkit.Rows()) -} - -func TestIssue19045(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1, t2") - tk.MustExec(`CREATE TABLE t ( - id int(11) NOT NULL AUTO_INCREMENT, - a char(10) DEFAULT NULL, - PRIMARY KEY (id) -);`) - tk.MustExec(`CREATE TABLE t1 ( - id int(11) NOT NULL AUTO_INCREMENT, - a char(10) DEFAULT NULL, - b char(10) DEFAULT NULL, - c char(10) DEFAULT NULL, - PRIMARY KEY (id) -);`) - tk.MustExec(`CREATE TABLE t2 ( - id int(11) NOT NULL AUTO_INCREMENT, - a char(10) DEFAULT NULL, - b char(10) DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY b (b) -);`) - tk.MustExec(`insert into t1(a,b,c) values('hs4_0004', "04", "101"), ('a01', "01", "101"),('a011', "02", "101");`) - tk.MustExec(`insert into t2(a,b) values("02","03");`) - tk.MustExec(`insert into t(a) values('101'),('101');`) - tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011")) -} - // issues 14448, 19383, 17734 func TestNoopFunctions(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4184,21 +3715,6 @@ func TestNoopFunctions(t *testing.T) { } } -func TestIssue19315(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("CREATE TABLE `t` (`a` bit(10) DEFAULT NULL,`b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - tk.MustExec("INSERT INTO `t` VALUES (_binary '\\0',1),(_binary '\\0',2),(_binary '\\0',5),(_binary '\\0',4),(_binary '\\0',2),(_binary '\\0 ',4)") - tk.MustExec("CREATE TABLE `t1` (`a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - tk.MustExec("INSERT INTO `t1` VALUES (1,1),(1,5),(2,3),(2,4),(3,3)") - err := tk.QueryToErr("select * from t where t.b > (select min(t1.b) from t1 where t1.a > t.a)") - require.NoError(t, err) -} - func TestIssue18674(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4230,32 +3746,6 @@ func TestJsonObjectCompare(t *testing.T) { tk.MustQuery("select json_object('k', a) = json_object('k', b) from tx").Check(testkit.Rows("1")) } -func TestIssue21290(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(a date);") - tk.MustExec("insert into t1 values (20100202);") - tk.MustQuery("select a in ('2020-02-02', 20100202) from t1;").Check(testkit.Rows("1")) -} - -// for issue 20128 -func TestIssue20128(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(b enum('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') DEFAULT NULL, c decimal(40,20));") - tk.MustExec("insert into t values('z', 19.18040000000000000000);") - tk.MustExec("insert into t values('z', 26.18040000000000000000);") - tk.MustExec("insert into t values('z', 25.18040000000000000000);") - tk.MustQuery("select * from t where t.b > t.c;").Check(testkit.Rows("z 19.18040000000000000000", "z 25.18040000000000000000")) - tk.MustQuery("select * from t where t.b < t.c;").Check(testkit.Rows("z 26.18040000000000000000")) -} - func TestCrossDCQuery(t *testing.T) { store := testkit.CreateMockStore(t) diff --git a/expression/integration_test/integration_test.go b/expression/integration_test/integration_test.go index 044743153b..bc0efb2c65 100644 --- a/expression/integration_test/integration_test.go +++ b/expression/integration_test/integration_test.go @@ -53,68 +53,6 @@ import ( "github.com/stretchr/testify/require" ) -func Test19654(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - - // enum vs enum - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (b enum('a', 'b'));") - tk.MustExec("insert into t1 values ('a');") - tk.MustExec("create table t2 (b enum('b','a') not null, unique(b));") - tk.MustExec("insert into t2 values ('a');") - tk.MustQuery("select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b;").Check(testkit.Rows("a a")) - - // set vs set - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (b set('a', 'b'));") - tk.MustExec("insert into t1 values ('a');") - tk.MustExec("create table t2 (b set('b','a') not null, unique(b));") - tk.MustExec("insert into t2 values ('a');") - tk.MustQuery("select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b;").Check(testkit.Rows("a a")) - - // enum vs set - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (b enum('a', 'b'));") - tk.MustExec("insert into t1 values ('a');") - tk.MustExec("create table t2 (b set('b','a') not null, unique(b));") - tk.MustExec("insert into t2 values ('a');") - tk.MustQuery("select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b;").Check(testkit.Rows("a a")) - - // char vs enum - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (b char(10));") - tk.MustExec("insert into t1 values ('a');") - tk.MustExec("create table t2 (b enum('b','a') not null, unique(b));") - tk.MustExec("insert into t2 values ('a');") - tk.MustQuery("select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b;").Check(testkit.Rows("a a")) - - // char vs set - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (b char(10));") - tk.MustExec("insert into t1 values ('a');") - tk.MustExec("create table t2 (b set('b','a') not null, unique(b));") - tk.MustExec("insert into t2 values ('a');") - tk.MustQuery("select /*+ inl_join(t2)*/ * from t1, t2 where t1.b=t2.b;").Check(testkit.Rows("a a")) -} - -func Test19387(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a decimal(16, 2));") - tk.MustExec("select sum(case when 1 then a end) from t group by a;") - res := tk.MustQuery("show create table t") - require.Len(t, res.Rows(), 1) - str := res.Rows()[0][1].(string) - require.Contains(t, str, "decimal(16,2)") -} - func TestFuncREPEAT(t *testing.T) { store := testkit.CreateMockStore(t) @@ -497,24 +435,6 @@ func TestConvertToBit(t *testing.T) { tk.MustExec(`insert t1 value ('09-01-01')`) tk.MustExec(`insert t select a from t1`) tk.MustQuery("select a+0 from t").Check(testkit.Rows("20090101000000")) - - // For issue 20118 - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a tinyint, b bit(63));") - tk.MustExec("insert ignore into t values(599999999, -1);") - tk.MustQuery("show warnings;").Check(testkit.Rows( - "Warning 1264 Out of range value for column 'a' at row 1", - "Warning 1406 Data too long for column 'b' at row 1")) - tk.MustQuery("select * from t;").Check(testkit.Rows("127 \u007f\xff\xff\xff\xff\xff\xff\xff")) - - // For issue 24900 - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(b bit(16));") - tk.MustExec("insert ignore into t values(0x3635313836),(0x333830);") - tk.MustQuery("show warnings;").Check(testkit.Rows( - "Warning 1406 Data too long for column 'b' at row 1", - "Warning 1406 Data too long for column 'b' at row 2")) - tk.MustQuery("select * from t;").Check(testkit.Rows("\xff\xff", "\xff\xff")) } func TestStringBuiltin(t *testing.T) { @@ -546,12 +466,6 @@ func TestStringBuiltin(t *testing.T) { result.Check(testkit.Rows("")) result = tk.MustQuery("select concat(null, a, b) from t") result.Check(testkit.Rows("")) - tk.MustExec("drop table if exists t") - // Fix issue 9123 - tk.MustExec("create table t(a char(32) not null, b float default '0') engine=innodb default charset=utf8mb4") - tk.MustExec("insert into t value('0a6f9d012f98467f8e671e9870044528', 208.867)") - result = tk.MustQuery("select concat_ws( ',', b) from t where a = '0a6f9d012f98467f8e671e9870044528';") - result.Check(testkit.Rows("208.867")) // for concat_ws tk.MustExec("drop table if exists t") @@ -856,15 +770,6 @@ func TestStringBuiltin(t *testing.T) { result = tk.MustQuery(`select oct(-1.9), oct(1.9), oct(-1), oct(1), oct(-9999999999999999999999999), oct(9999999999999999999999999);`) result.Check(testkit.Rows("1777777777777777777777 1 1777777777777777777777 1 1777777777777777777777 1777777777777777777777")) - // #issue 4356 - tk.MustExec("drop table if exists t") - tk.MustExec("CREATE TABLE t (b BIT(8));") - tk.MustExec(`INSERT INTO t SET b = b'11111111';`) - tk.MustExec(`INSERT INTO t SET b = b'1010';`) - tk.MustExec(`INSERT INTO t SET b = b'0101';`) - result = tk.MustQuery(`SELECT b+0, BIN(b), OCT(b), HEX(b) FROM t;`) - result.Check(testkit.Rows("255 11111111 377 FF", "10 1010 12 A", "5 101 5 5")) - // for find_in_set result = tk.MustQuery(`select find_in_set("", ""), find_in_set("", ","), find_in_set("中文", "字符串,中文"), find_in_set("b,", "a,b,c,d");`) result.Check(testkit.Rows("0 1 2 0")) @@ -894,11 +799,6 @@ func TestStringBuiltin(t *testing.T) { // charset 866 does not have a default collation configured currently, so this will return error. err = tk.ExecToErr(`select convert("123" using "866");`) require.Error(t, err, "[parser:1115]Unknown character set: '866'") - // Test case in issue #4436. - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a char(20));") - err = tk.ExecToErr("select convert(a using a) from t;") - require.Error(t, err, "[parser:1115]Unknown character set: 'a'") // for insert result = tk.MustQuery(`select insert("中文", 1, 1, cast("aaa" as binary)), insert("ba", -1, 1, "aaa"), insert("ba", 1, 100, "aaa"), insert("ba", 100, 1, "aaa");`) @@ -949,12 +849,6 @@ func TestStringBuiltin(t *testing.T) { result = tk.MustQuery("select a,b,concat_ws(',',a,b) from t") result.Check(testkit.Rows("114.57011441 38.04620115 114.57011441,38.04620115", "-38.04620119 38.04620115 -38.04620119,38.04620115")) - - // For issue 31603, only affects unistore. - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 varbinary(100));") - tk.MustExec("insert into t1 values('abc');") - tk.MustQuery("select 1 from t1 where char_length(c1) = 10;").Check(testkit.Rows()) } func TestInvalidStrings(t *testing.T) { @@ -1253,25 +1147,6 @@ func TestDatetimeOverflow(t *testing.T) { rows = append(rows, "") } tk.MustQuery("select * from t1").Check(testkit.Rows(rows...)) - - // Fix ISSUE 11256 - tk.MustQuery(`select DATE_ADD('2000-04-13 07:17:02',INTERVAL -1465647104 YEAR);`).Check(testkit.Rows("")) - tk.MustQuery(`select DATE_ADD('2008-11-23 22:47:31',INTERVAL 266076160 QUARTER);`).Check(testkit.Rows("")) - tk.MustQuery(`select DATE_SUB('2000-04-13 07:17:02',INTERVAL 1465647104 YEAR);`).Check(testkit.Rows("")) - tk.MustQuery(`select DATE_SUB('2008-11-23 22:47:31',INTERVAL -266076160 QUARTER);`).Check(testkit.Rows("")) -} - -func TestIssue11648(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (id int NOT NULL DEFAULT 8);") - tk.MustExec("SET sql_mode = '';") - tk.MustExec("insert into t values (1), (NULL), (2);") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1048 Column 'id' cannot be null")) - tk.MustQuery("select * from t").Check(testkit.Rows("1", "0", "2")) } func TestExprDateTimeOnDST(t *testing.T) { @@ -2513,14 +2388,6 @@ func TestTimeLiteral(t *testing.T) { "Warning|1292|Incorrect datetime value: '2008-01-34'")) } -func TestIssue13822(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery("select ADDDATE(20111111, interval '-123' DAY);").Check(testkit.Rows("2011-07-11")) - tk.MustQuery("select SUBDATE(20111111, interval '-123' DAY);").Check(testkit.Rows("2012-03-13")) -} - func TestTimestampLiteral(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2785,7 +2652,6 @@ func TestColumnInfoModified(t *testing.T) { } func TestIssues(t *testing.T) { - t.Skip("it has been broken. Please fix it as soon as possible.") // for issue #4954 store := testkit.CreateMockStore(t) @@ -2845,30 +2711,6 @@ func TestIssues(t *testing.T) { tk.MustQuery("select b'10000000' / 10").Check(testkit.Rows("12.8000")) } -func TestInPredicate4UnsignedInt(t *testing.T) { - // for issue #6661 - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("CREATE TABLE t (a bigint unsigned,key (a));") - tk.MustExec("INSERT INTO t VALUES (0), (4), (5), (6), (7), (8), (9223372036854775810), (18446744073709551614), (18446744073709551615);") - r := tk.MustQuery(`SELECT a FROM t WHERE a NOT IN (-1, -2, 18446744073709551615);`) - r.Check(testkit.Rows("0", "4", "5", "6", "7", "8", "9223372036854775810", "18446744073709551614")) - r = tk.MustQuery(`SELECT a FROM t WHERE a NOT IN (-1, -2, 4, 9223372036854775810);`) - r.Check(testkit.Rows("0", "5", "6", "7", "8", "18446744073709551614", "18446744073709551615")) - r = tk.MustQuery(`SELECT a FROM t WHERE a NOT IN (-1, -2, 0, 4, 18446744073709551614);`) - r.Check(testkit.Rows("5", "6", "7", "8", "9223372036854775810", "18446744073709551615")) - - // for issue #4473 - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (some_id smallint(5) unsigned,key (some_id) )") - tk.MustExec("insert into t1 values (1),(2)") - r = tk.MustQuery(`select some_id from t1 where some_id not in(2,-1);`) - r.Check(testkit.Rows("1")) -} - func TestFilterExtractFromDNF(t *testing.T) { store := testkit.CreateMockStore(t) @@ -3467,38 +3309,6 @@ func TestDecimalConvertToTime(t *testing.T) { tk.MustQuery("select * from t").Check(testkit.Rows("2001-01-01 10:00:00.123456 2011-07-07 10:11:12")) } -func TestIssue9732(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustQuery(`select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), -monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));`).Check(testkit.Rows(" ")) - - nullCases := []struct { - sql string - ret string - }{ - {"select str_to_date(1, '%m')", "0000-01-00"}, - {"select str_to_date(01, '%d')", "0000-00-01"}, - {"select str_to_date(2019, '%Y')", "2019-00-00"}, - {"select str_to_date('5,2019','%m,%Y')", "2019-05-00"}, - {"select str_to_date('01,2019','%d,%Y')", "2019-00-01"}, - {"select str_to_date('01,5','%d,%m')", "0000-05-01"}, - } - - for _, nullCase := range nullCases { - tk.MustQuery(nullCase.sql).Check(testkit.Rows("")) - } - - // remove NO_ZERO_DATE mode - tk.MustExec("set sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'") - - for _, nullCase := range nullCases { - tk.MustQuery(nullCase.sql).Check(testkit.Rows(nullCase.ret)) - } -} - func TestDaynameArithmetic(t *testing.T) { store := testkit.CreateMockStore(t) @@ -3548,79 +3358,6 @@ func TestDaynameArithmetic(t *testing.T) { } } -func TestIssue10156(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `t1` (`period_name` varchar(24) DEFAULT NULL ,`period_id` bigint(20) DEFAULT NULL ,`starttime` bigint(20) DEFAULT NULL)") - tk.MustExec("CREATE TABLE `t2` (`bussid` bigint(20) DEFAULT NULL,`ct` bigint(20) DEFAULT NULL)") - q := ` -select - a.period_name, - b.date8 -from - (select * from t1) a -left join - (select bussid,date(from_unixtime(ct)) date8 from t2) b -on - a.period_id = b.bussid -where - datediff(b.date8, date(from_unixtime(a.starttime))) >= 0` - tk.MustQuery(q) -} - -func TestIssue9727(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - cases := []struct { - sql string - result string - }{ - {`SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND;`, "8895-03-27 22:11:40"}, - {`SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 37 SECOND;`, "6255-04-08 15:04:32"}, - {`SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 31 MINUTE;`, "5983-01-24 02:08:00"}, - {`SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 38 SECOND;`, ""}, - {`SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 33 MINUTE;`, ""}, - {`SELECT "1900-01-01 00:00:00" + INTERVAL 1 << 30 HOUR;`, ""}, - {`SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND;`, ""}, - {`SELECT 19000101000000 + INTERVAL "100000000:214748364700" MINUTE_SECOND;`, "8895-03-27 22:11:40"}, - {`SELECT 19000101000000 + INTERVAL 1 << 37 SECOND;`, "6255-04-08 15:04:32"}, - {`SELECT 19000101000000 + INTERVAL 1 << 31 MINUTE;`, "5983-01-24 02:08:00"}, - - {`SELECT "8895-03-27 22:11:40" - INTERVAL "100000000:214748364700" MINUTE_SECOND;`, "1900-01-01 00:00:00"}, - {`SELECT "6255-04-08 15:04:32" - INTERVAL 1 << 37 SECOND;`, "1900-01-01 00:00:00"}, - {`SELECT "5983-01-24 02:08:00" - INTERVAL 1 << 31 MINUTE;`, "1900-01-01 00:00:00"}, - {`SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 39 SECOND;`, ""}, - {`SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 33 MINUTE;`, ""}, - {`SELECT "9999-01-01 00:00:00" - INTERVAL 1 << 30 HOUR;`, ""}, - {`SELECT "9999-01-01 00:00:00" - INTERVAL "10000000000:214748364700" MINUTE_SECOND;`, ""}, - {`SELECT 88950327221140 - INTERVAL "100000000:214748364700" MINUTE_SECOND ;`, "1900-01-01 00:00:00"}, - {`SELECT 62550408150432 - INTERVAL 1 << 37 SECOND;`, "1900-01-01 00:00:00"}, - {`SELECT 59830124020800 - INTERVAL 1 << 31 MINUTE;`, "1900-01-01 00:00:00"}, - - {`SELECT 10000101000000 + INTERVAL "111111111111111111" MICROSECOND;`, `4520-12-21 05:31:51.111111`}, - {`SELECT 10000101000000 + INTERVAL "111111111111.111111" SECOND;`, `4520-12-21 05:31:51.111111`}, - {`SELECT 10000101000000 + INTERVAL "111111111111.111111111" SECOND;`, `4520-12-21 05:31:51.111111`}, - {`SELECT 10000101000000 + INTERVAL "111111111111.111" SECOND;`, `4520-12-21 05:31:51.111000`}, - {`SELECT 10000101000000 + INTERVAL "111111111111." SECOND;`, `4520-12-21 05:31:51`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111111.5" MICROSECOND;`, `4520-12-21 05:31:51.111112`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111112.5" MICROSECOND;`, `4520-12-21 05:31:51.111113`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111111.500000" MICROSECOND;`, `4520-12-21 05:31:51.111112`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111111.50000000" MICROSECOND;`, `4520-12-21 05:31:51.111112`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111111.6" MICROSECOND;`, `4520-12-21 05:31:51.111112`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111111.499999" MICROSECOND;`, `4520-12-21 05:31:51.111111`}, - {`SELECT 10000101000000 + INTERVAL "111111111111111111.499999999999" MICROSECOND;`, `4520-12-21 05:31:51.111111`}, - } - - for _, c := range cases { - tk.MustQuery(c.sql).Check(testkit.Rows(c.result)) - } -} - func TestTimestampDatumEncode(t *testing.T) { store := testkit.CreateMockStore(t) @@ -3661,36 +3398,6 @@ func TestDateTimeAddReal(t *testing.T) { } } -func TestIssue30253(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - cases := []struct { - sql string - result string - }{ - {`SELECT INTERVAL 1.123456789e3 SECOND + "1900-01-01 00:00:00"`, "1900-01-01 00:18:43.456789"}, - {`SELECT INTERVAL 1 Year + 19000101000000`, "1901-01-01 00:00:00"}, - {`select interval 6 month + date("1900-01-01")`, "1900-07-01"}, - {`select interval "5:2" MINUTE_SECOND + "1900-01-01"`, "1900-01-01 00:05:02"}, - } - - for _, c := range cases { - tk.MustQuery(c.sql).Check(testkit.Rows(c.result)) - } -} -func TestIssue10181(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a bigint unsigned primary key);`) - tk.MustExec(`insert into t values(9223372036854775807), (18446744073709551615)`) - tk.MustQuery(`select * from t where a > 9223372036854775807-0.5 order by a`).Check(testkit.Rows(`9223372036854775807`, `18446744073709551615`)) -} - func TestExprPushdown(t *testing.T) { store := testkit.CreateMockStore(t) @@ -3735,33 +3442,6 @@ func TestExprPushdown(t *testing.T) { tk.MustQuery("select count(id) from t use index(key2) where from_base64(to_base64(substr(col2, 1, 1))) = '5' and from_base64(to_base64(substr(col1, 1, 1))) = '4'").Check(testkit.Rows("1")) } -func TestIssue16973(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly - tk.MustExec("create table t1(id varchar(36) not null primary key, org_id varchar(36) not null, " + - "status tinyint default 1 not null, ns varchar(36) default '' not null);") - tk.MustExec("create table t2(id varchar(36) not null primary key, order_id varchar(36) not null, " + - "begin_time timestamp(3) default CURRENT_TIMESTAMP(3) not null);") - tk.MustExec("create index idx_oid on t2(order_id);") - tk.MustExec("insert into t1 value (1,1,1,'a');") - tk.MustExec("insert into t1 value (2,1,2,'a');") - tk.MustExec("insert into t1 value (3,1,3,'a');") - tk.MustExec("insert into t2 value (1,2,date'2020-05-08');") - - rows := tk.MustQuery("explain format = 'brief' SELECT /*+ INL_MERGE_JOIN(t1,t2) */ COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.order_id WHERE t1.ns = 'a' AND t1.org_id IN (1) " + - "AND t1.status IN (2,6,10) AND timestampdiff(month, t2.begin_time, date'2020-05-06') = 0;").Rows() - require.Regexp(t, ".*IndexMergeJoin.*", fmt.Sprintf("%v", rows[1][0])) - require.Equal(t, "table:t1", fmt.Sprintf("%v", rows[4][3])) - require.Regexp(t, ".*Selection.*", fmt.Sprintf("%v", rows[5][0])) - require.Equal(t, "table:t2", fmt.Sprintf("%v", rows[9][3])) - tk.MustQuery("SELECT /*+ INL_MERGE_JOIN(t1,t2) */ COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.order_id WHERE t1.ns = 'a' AND t1.org_id IN (1) " + - "AND t1.status IN (2,6,10) AND timestampdiff(month, t2.begin_time, date'2020-05-06') = 0;").Check(testkit.Rows("1")) -} - func TestShardIndexOnTiFlash(t *testing.T) { store := testkit.CreateMockStore(t) @@ -3861,38 +3541,6 @@ func TestIssue10804(t *testing.T) { tk.MustQuery(`SELECT @@GLOBAL.information_schema_stats_expiry`).Check(testkit.Rows(`0`)) } -func TestIssue10675(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a int);`) - tk.MustExec(`insert into t values(1);`) - tk.MustQuery(`select * from t where a < -184467440737095516167.1;`).Check(testkit.Rows()) - tk.MustQuery(`select * from t where a > -184467440737095516167.1;`).Check( - testkit.Rows("1")) - tk.MustQuery(`select * from t where a < 184467440737095516167.1;`).Check( - testkit.Rows("1")) - tk.MustQuery(`select * from t where a > 184467440737095516167.1;`).Check(testkit.Rows()) - - // issue 11647 - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(b bit(1));`) - tk.MustExec(`insert into t values(b'1');`) - tk.MustQuery(`select count(*) from t where b = 1;`).Check(testkit.Rows("1")) - tk.MustQuery(`select count(*) from t where b = '1';`).Check(testkit.Rows("1")) - tk.MustQuery(`select count(*) from t where b = b'1';`).Check(testkit.Rows("1")) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(b bit(63));`) - // Not 64, because the behavior of mysql is amazing. I have no idea to fix it. - tk.MustExec(`insert into t values(b'111111111111111111111111111111111111111111111111111111111111111');`) - tk.MustQuery(`select count(*) from t where b = 9223372036854775807;`).Check(testkit.Rows("1")) - tk.MustQuery(`select count(*) from t where b = '9223372036854775807';`).Check(testkit.Rows("1")) - tk.MustQuery(`select count(*) from t where b = b'111111111111111111111111111111111111111111111111111111111111111';`).Check(testkit.Rows("1")) -} - func TestDatetimeMicrosecond(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4062,88 +3710,6 @@ func TestFuncCaseWithLeftJoin(t *testing.T) { tk.MustQuery("select t1.id from kankan1 t1 left join kankan2 t2 on t1.id = t2.id where (case when t1.name='b' then 'case2' when t1.name='a' then 'case1' else NULL end) = 'case1' order by t1.id").Check(testkit.Rows("1", "2")) } -func TestIssue11594(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t1;`) - tk.MustExec("CREATE TABLE t1 (v bigint(20) UNSIGNED NOT NULL);") - tk.MustExec("INSERT INTO t1 VALUES (1), (2);") - tk.MustQuery("SELECT SUM(IF(v > 1, v, -v)) FROM t1;").Check(testkit.Rows("1")) - tk.MustQuery("SELECT sum(IFNULL(cast(null+rand() as unsigned), -v)) FROM t1;").Check(testkit.Rows("-3")) - tk.MustQuery("SELECT sum(COALESCE(cast(null+rand() as unsigned), -v)) FROM t1;").Check(testkit.Rows("-3")) - tk.MustQuery("SELECT sum(COALESCE(cast(null+rand() as unsigned), v)) FROM t1;").Check(testkit.Rows("3")) -} - -func TestIssue11309And11319(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`CREATE TABLE t (a decimal(6,3),b double(6,3),c float(6,3));`) - tk.MustExec(`INSERT INTO t VALUES (1.100,1.100,1.100);`) - tk.MustQuery(`SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) FROM t`).Check(testkit.Rows(`2003-11-18 07:27:53`)) - tk.MustQuery(`SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) FROM t`).Check(testkit.Rows(`2003-11-18 07:27:53`)) - tk.MustQuery(`SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) FROM t`).Check(testkit.Rows(`2003-11-18 07:27:53`)) - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`CREATE TABLE t (a decimal(11,7),b double(11,7),c float(11,7));`) - tk.MustExec(`INSERT INTO t VALUES (123.9999999,123.9999999,123.9999999),(-123.9999999,-123.9999999,-123.9999999);`) - tk.MustQuery(`SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL a MINUTE_SECOND) FROM t`).Check(testkit.Rows(`2004-03-13 03:14:52`, `2003-07-25 11:35:34`)) - tk.MustQuery(`SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL b MINUTE_SECOND) FROM t`).Check(testkit.Rows(`2004-03-13 03:14:52`, `2003-07-25 11:35:34`)) - tk.MustQuery(`SELECT DATE_ADD('2003-11-18 07:25:13',INTERVAL c MINUTE_SECOND) FROM t`).Check(testkit.Rows(`2003-11-18 09:29:13`, `2003-11-18 05:21:13`)) - tk.MustExec(`drop table if exists t;`) - - // for https://github.com/pingcap/tidb/issues/11319 - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:25.800000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:25.800000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:25.800000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:25.800000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 SECOND)`).Check(testkit.Rows("2007-03-28 22:08:25.800000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_SECOND)`).Check(testkit.Rows("2007-03-28 22:06:26")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_SECOND)`).Check(testkit.Rows("2007-03-28 22:06:26")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE_SECOND)`).Check(testkit.Rows("2007-03-28 22:06:26")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 MINUTE)`).Check(testkit.Rows("2007-03-28 22:06:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_MINUTE)`).Check(testkit.Rows("2007-03-28 20:06:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 HOUR_MINUTE)`).Check(testkit.Rows("2007-03-28 20:06:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 DAY_HOUR)`).Check(testkit.Rows("2007-03-26 20:08:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL -2.2 YEAR_MONTH)`).Check(testkit.Rows("2005-01-28 22:08:28")) - - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:30.200000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:30.200000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:30.200000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MICROSECOND)`).Check(testkit.Rows("2007-03-28 22:08:30.200000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 SECOND)`).Check(testkit.Rows("2007-03-28 22:08:30.200000")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_SECOND)`).Check(testkit.Rows("2007-03-28 22:10:30")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_SECOND)`).Check(testkit.Rows("2007-03-28 22:10:30")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE_SECOND)`).Check(testkit.Rows("2007-03-28 22:10:30")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 MINUTE)`).Check(testkit.Rows("2007-03-28 22:10:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_MINUTE)`).Check(testkit.Rows("2007-03-29 00:10:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 HOUR_MINUTE)`).Check(testkit.Rows("2007-03-29 00:10:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR)`).Check(testkit.Rows("2007-03-31 00:08:28")) - tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH)`).Check(testkit.Rows("2009-05-28 22:08:28")) -} - -func TestIssue12301(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (d decimal(19, 0), i bigint(11))") - tk.MustExec("insert into t values (123456789012, 123456789012)") - tk.MustQuery("select * from t where d = i").Check(testkit.Rows("123456789012 123456789012")) -} - -func TestIssue15315(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustQuery("select '0-3261554956'+0.0").Check(testkit.Rows("0")) - tk.MustQuery("select cast('0-1234' as real)").Check(testkit.Rows("0")) -} - func TestNotExistFunc(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4256,54 +3822,6 @@ func TestCastStrToInt(t *testing.T) { } } -func TestValuesForBinaryLiteral(t *testing.T) { - // See issue #15310 - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("create table testValuesBinary(id int primary key auto_increment, a bit(1));") - tk.MustExec("insert into testValuesBinary values(1,1);") - err := tk.ExecToErr("insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a);") - require.NoError(t, err) - tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("0")) - err = tk.ExecToErr("insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a);") - require.NoError(t, err) - tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("1")) - tk.MustExec("drop table testValuesBinary;") -} - -func TestIssue14159(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (v VARCHAR(100))") - tk.MustExec("INSERT INTO t VALUES ('3289742893213123732904809')") - tk.MustQuery("SELECT * FROM t WHERE v").Check(testkit.Rows("3289742893213123732904809")) -} - -func TestIssue14146(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table tt(a varchar(10))") - tk.MustExec("insert into tt values(NULL)") - tk.MustExec("analyze table tt;") - tk.MustQuery("select * from tt").Check(testkit.Rows("")) -} - -func TestIssue15346(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustQuery("select collation(format_bytes(1024)) != 'binary';").Check(testkit.Rows("1")) - tk.MustQuery("select collation(format_nano_time(234)) != 'binary';").Check(testkit.Rows("1")) -} - func TestOrderByFuncPlanCache(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4407,17 +3925,6 @@ func TestCollationAndCharset(t *testing.T) { tk.MustQuery("select replace('abc' collate utf8mb4_bin, 'b' collate utf8mb4_general_ci, 'd' collate utf8mb4_unicode_ci);").Check(testkit.Rows("adc")) } -// https://github.com/pingcap/tidb/issues/34500. -func TestJoinOnDifferentCollations(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("create table t (a char(10) charset gbk collate gbk_chinese_ci, b time);") - tk.MustExec("insert into t values ('08:00:00', '08:00:00');") - tk.MustQuery("select t1.a, t2.b from t as t1 right join t as t2 on t1.a = t2.b;"). - Check(testkit.Rows("08:00:00 08:00:00")) -} - func TestCoercibility(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4458,22 +3965,6 @@ func TestCoercibility(t *testing.T) { tk.MustQuery("SELECT COERCIBILITY(@straaa);").Check(testkit.Rows("2")) } -func TestIssue20071(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists table_30_utf8_4") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(1)") - tk.MustExec("create table table_30_utf8_4 ( `pk` int primary key, `col_int_key_unsigned` int unsigned , `col_int_key_signed` int, `col_float_key_signed` float , `col_float_key_unsigned` float unsigned) character set utf8 partition by hash(pk) partitions 4;") - tk.MustExec("insert ignore into table_30_utf8_4 values (0,91, 10, 14,19.0495)") - tk.MustExec("alter table table_30_utf8_4 add column a int as (col_int_key_signed * 2)") - tk.MustExec("SELECT count(1) AS val FROM table_30_utf8_4 WHERE table_30_utf8_4.col_int_key_unsigned!=table_30_utf8_4.a OR (SELECT count(1) AS val FROM t WHERE table_30_utf8_4.col_float_key_signed!=table_30_utf8_4.col_float_key_unsigned )!=7984764426240273913;") - tk.MustExec("select a from table_30_utf8_4 order by a") -} - func TestVirtualGeneratedColumnAndLimit(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4486,56 +3977,6 @@ func TestVirtualGeneratedColumnAndLimit(t *testing.T) { tk.MustQuery("select /*+ LIMIT_TO_COP() */ b from t order by b limit 1;").Check(testkit.Rows("2")) } -func TestIssue17791(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test;") - tk.MustExec("drop table if exists t;") - tk.MustExec("SET sql_mode=DEFAULT;") - tk.MustExec("CREATE TABLE t1 (" + - " id INT NOT NULL PRIMARY KEY auto_increment," + - " pad VARCHAR(10) NOT NULL," + - " expr varchar(100) AS (NOT 1 BETWEEN -5 AND 5)" + - ");") - tk.MustExec("INSERT INTO t1 (pad) VALUES ('a'), ('b');") - tk.MustQuery("SELECT id, pad, expr, NOT 1 BETWEEN -5 AND 5 as expr_in_select FROM t1;").Check(testkit.Rows("1 a 0 0", "2 b 0 0")) -} - -func TestIssue15986(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 int)") - tk.MustExec("INSERT INTO t0 VALUES (0)") - tk.MustQuery("SELECT t0.c0 FROM t0 WHERE CHAR(204355900);").Check(testkit.Rows("0")) - tk.MustQuery("SELECT t0.c0 FROM t0 WHERE not CHAR(204355900);").Check(testkit.Rows()) - tk.MustQuery("SELECT t0.c0 FROM t0 WHERE '.0';").Check(testkit.Rows()) - tk.MustQuery("SELECT t0.c0 FROM t0 WHERE not '.0';").Check(testkit.Rows("0")) - // If the number does not exceed the range of float64 and its value is not 0, it will be converted to true. - tk.MustQuery("select * from t0 where '.000000000000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000009';").Check(testkit.Rows("0")) - tk.MustQuery("select * from t0 where not '.000000000000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000009';").Check(testkit.Rows()) - - // If the number is truncated beyond the range of float64, it will be converted to true when the truncated result is 0. - tk.MustQuery("select * from t0 where '.0000000000000000000000000000000000000000000000000000000" + - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000009';").Check(testkit.Rows()) - tk.MustQuery("select * from t0 where not '.0000000000000000000000000000000000000000000000000000000" + - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000009';").Check(testkit.Rows("0")) -} - func TestNegativeZeroForHashJoin(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4551,122 +3992,6 @@ func TestNegativeZeroForHashJoin(t *testing.T) { tk.MustExec("drop table t1;") } -func TestIssue1223(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists testjson") - tk.MustExec("CREATE TABLE testjson (j json DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;") - tk.MustExec(`INSERT INTO testjson SET j='{"test":3}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":0}';`) - tk.MustExec(`insert into testjson set j='{"test":"0"}';`) - tk.MustExec(`insert into testjson set j='{"test":0.0}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":"aaabbb"}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":3.1415}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":[]}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":[1,2]}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":["b","c"]}';`) - tk.MustExec(`INSERT INTO testjson SET j='{"test":{"ke":"val"}}';`) - tk.MustExec(`insert into testjson set j='{"test":"2015-07-27 09:43:47"}';`) - tk.MustExec(`insert into testjson set j='{"test":"0000-00-00 00:00:00"}';`) - tk.MustExec(`insert into testjson set j='{"test":"0778"}';`) - tk.MustExec(`insert into testjson set j='{"test":"0000"}';`) - tk.MustExec(`insert into testjson set j='{"test":null}';`) - tk.MustExec(`insert into testjson set j=null;`) - tk.MustExec(`insert into testjson set j='{"test":[null]}';`) - tk.MustExec(`insert into testjson set j='{"test":true}';`) - tk.MustExec(`insert into testjson set j='{"test":false}';`) - tk.MustExec(`insert into testjson set j='""';`) - tk.MustExec(`insert into testjson set j='null';`) - tk.MustExec(`insert into testjson set j='0';`) - tk.MustExec(`insert into testjson set j='"0"';`) - tk.MustQuery("SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test');").Check(testkit.Rows(`{"test": 3}`, - `{"test": "0"}`, `{"test": "aaabbb"}`, `{"test": 3.1415}`, `{"test": []}`, `{"test": [1, 2]}`, - `{"test": ["b", "c"]}`, `{"test": {"ke": "val"}}`, `{"test": "2015-07-27 09:43:47"}`, - `{"test": "0000-00-00 00:00:00"}`, `{"test": "0778"}`, `{"test": "0000"}`, `{"test": null}`, - `{"test": [null]}`, `{"test": true}`, `{"test": false}`)) - tk.MustQuery("select * from testjson where j;").Check(testkit.Rows(`{"test": 3}`, `{"test": 0}`, - `{"test": "0"}`, `{"test": 0}`, `{"test": "aaabbb"}`, `{"test": 3.1415}`, `{"test": []}`, `{"test": [1, 2]}`, - `{"test": ["b", "c"]}`, `{"test": {"ke": "val"}}`, `{"test": "2015-07-27 09:43:47"}`, - `{"test": "0000-00-00 00:00:00"}`, `{"test": "0778"}`, `{"test": "0000"}`, `{"test": null}`, - `{"test": [null]}`, `{"test": true}`, `{"test": false}`, `""`, "null", `"0"`)) - tk.MustExec("insert into mysql.expr_pushdown_blacklist values('json_extract','tikv','');") - tk.MustExec("admin reload expr_pushdown_blacklist;") - tk.MustQuery("SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test');").Check(testkit.Rows("{\"test\": 3}", - "{\"test\": \"0\"}", "{\"test\": \"aaabbb\"}", "{\"test\": 3.1415}", "{\"test\": []}", "{\"test\": [1, 2]}", - "{\"test\": [\"b\", \"c\"]}", "{\"test\": {\"ke\": \"val\"}}", "{\"test\": \"2015-07-27 09:43:47\"}", - "{\"test\": \"0000-00-00 00:00:00\"}", "{\"test\": \"0778\"}", "{\"test\": \"0000\"}", "{\"test\": null}", - "{\"test\": [null]}", "{\"test\": true}", "{\"test\": false}")) - tk.MustQuery("select * from testjson where j;").Check(testkit.Rows(`{"test": 3}`, `{"test": 0}`, - `{"test": "0"}`, `{"test": 0}`, `{"test": "aaabbb"}`, `{"test": 3.1415}`, `{"test": []}`, `{"test": [1, 2]}`, - `{"test": ["b", "c"]}`, `{"test": {"ke": "val"}}`, `{"test": "2015-07-27 09:43:47"}`, - `{"test": "0000-00-00 00:00:00"}`, `{"test": "0778"}`, `{"test": "0000"}`, `{"test": null}`, - `{"test": [null]}`, `{"test": true}`, `{"test": false}`, `""`, "null", `"0"`)) -} - -func TestIssue15743(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 int)") - tk.MustExec("INSERT INTO t0 VALUES (1)") - tk.MustQuery("SELECT * FROM t0 WHERE 1 AND 0.4").Check(testkit.Rows("1")) -} - -func TestIssue15725(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(2)") - tk.MustQuery("select * from t where (not not a) = a").Check(testkit.Rows()) - tk.MustQuery("select * from t where (not not not not a) = a").Check(testkit.Rows()) -} - -func TestIssue15790(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 INT);") - tk.MustExec("INSERT INTO t0(c0) VALUES (0);") - tk.MustQuery("SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION SELECT * FROM t0;").Check(testkit.Rows("0")) - tk.MustQuery("SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION all SELECT * FROM t0;").Check(testkit.Rows("0", "0")) - tk.MustExec("drop table t0;") -} - -func TestIssue15990(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t0;") - tk.MustExec("CREATE TABLE t0(c0 TEXT(10));") - tk.MustExec("INSERT INTO t0(c0) VALUES (1);") - tk.MustQuery("SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0;").Check(testkit.Rows("1")) - tk.MustExec("CREATE INDEX i0 ON t0(c0(10));") - tk.MustQuery("SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0;").Check(testkit.Rows("1")) - tk.MustExec("drop table t0;") -} - -func TestIssue15992(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 INT, c1 INT AS (c0));") - tk.MustExec("CREATE INDEX i0 ON t0(c1);") - tk.MustQuery("SELECT t0.c0 FROM t0 UNION ALL SELECT 0 FROM t0;").Check(testkit.Rows()) - tk.MustExec("drop table t0;") -} - func TestCTEWithDML(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4695,48 +4020,6 @@ func TestCTEWithDML(t *testing.T) { tk.MustQuery("select * from t1").Check(testkit.Rows("1 1", "2 2", "3 3", "4 4", "5 5")) } -func TestIssue16419(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t0") - tk.MustExec("drop table if exists t1") - tk.MustExec("CREATE TABLE t0(c0 INT);") - tk.MustExec("CREATE TABLE t1(c0 INT);") - tk.MustQuery("SELECT * FROM t1 NATURAL LEFT JOIN t0 WHERE NOT t1.c0;").Check(testkit.Rows()) - tk.MustExec("drop table t0, t1;") -} - -func TestIssue16029(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t0,t1;") - tk.MustExec("CREATE TABLE t0(c0 INT);") - tk.MustExec("CREATE TABLE t1(c0 INT);") - tk.MustExec("INSERT INTO t0 VALUES (NULL), (1);") - tk.MustExec("INSERT INTO t1 VALUES (0);") - tk.MustQuery("SELECT t0.c0 FROM t0 JOIN t1 ON (t0.c0 REGEXP 1) | t1.c0 WHERE BINARY STRCMP(t1.c0, t0.c0);").Check(testkit.Rows("1")) - tk.MustExec("drop table t0;") - tk.MustExec("drop table t1;") -} - -func TestIssue16426(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int)") - tk.MustExec("insert into t values (42)") - tk.MustQuery("select a from t where a/10000").Check(testkit.Rows("42")) - tk.MustQuery("select a from t where a/100000").Check(testkit.Rows("42")) - tk.MustQuery("select a from t where a/1000000").Check(testkit.Rows("42")) - tk.MustQuery("select a from t where a/10000000").Check(testkit.Rows("42")) -} - func TestIssue16505(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4751,55 +4034,6 @@ func TestIssue16505(t *testing.T) { tk.MustExec("drop table t;") } -func TestIssue20121(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // testcase for Datetime vs Year - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a datetime, b year)") - tk.MustExec("insert into t values('2000-05-03 16:44:44', 2018)") - tk.MustExec("insert into t values('2020-10-01 11:11:11', 2000)") - tk.MustExec("insert into t values('2020-10-01 11:11:11', 2070)") - tk.MustExec("insert into t values('2020-10-01 11:11:11', 1999)") - - tk.MustQuery("select * from t where t.a < t.b").Check(testkit.Rows("2000-05-03 16:44:44 2018", "2020-10-01 11:11:11 2070")) - tk.MustQuery("select * from t where t.a > t.b").Check(testkit.Rows("2020-10-01 11:11:11 2000", "2020-10-01 11:11:11 1999")) - - // testcase for Date vs Year - tk.MustExec("drop table if exists tt") - tk.MustExec("create table tt(a date, b year)") - tk.MustExec("insert into tt values('2019-11-11', 2000)") - tk.MustExec("insert into tt values('2019-11-11', 2020)") - tk.MustExec("insert into tt values('2019-11-11', 2022)") - - tk.MustQuery("select * from tt where tt.a > tt.b").Check(testkit.Rows("2019-11-11 2000")) - tk.MustQuery("select * from tt where tt.a < tt.b").Check(testkit.Rows("2019-11-11 2020", "2019-11-11 2022")) - - // testcase for Timestamp vs Year - tk.MustExec("drop table if exists ttt") - tk.MustExec("create table ttt(a timestamp, b year)") - tk.MustExec("insert into ttt values('2019-11-11 11:11:11', 2019)") - tk.MustExec("insert into ttt values('2019-11-11 11:11:11', 2000)") - tk.MustExec("insert into ttt values('2019-11-11 11:11:11', 2022)") - - tk.MustQuery("select * from ttt where ttt.a > ttt.b").Check(testkit.Rows("2019-11-11 11:11:11 2019", "2019-11-11 11:11:11 2000")) - tk.MustQuery("select * from ttt where ttt.a < ttt.b").Check(testkit.Rows("2019-11-11 11:11:11 2022")) -} - -func TestIssue16779(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t0 (c0 int)") - tk.MustExec("create table t1 (c0 int)") - tk.MustQuery("SELECT * FROM t1 LEFT JOIN t0 ON TRUE WHERE BINARY EXPORT_SET(0, 0, 0 COLLATE 'binary', t0.c0, 0 COLLATE 'binary')") -} - func TestIssue16697(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4822,39 +4056,6 @@ func TestIssue16697(t *testing.T) { } } -func TestIssue17045(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int,b varchar(20),c datetime,d double,e int,f int as(a+b),key(a),key(b),key(c),key(d),key(e),key(f));") - tk.MustExec("insert into t(a,b,e) values(null,\"5\",null);") - tk.MustExec("insert into t(a,b,e) values(\"5\",null,null);") - tk.MustQuery("select /*+ use_index_merge(t)*/ * from t where t.e=5 or t.a=5;").Check(testkit.Rows("5 ")) -} - -func TestIssue17098(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a char) collate utf8mb4_bin;") - tk.MustExec("create table t2(a char) collate utf8mb4_bin;;") - tk.MustExec("insert into t1 values('a');") - tk.MustExec("insert into t2 values('a');") - tk.MustQuery("select collation(t1.a) from t1 union select collation(t2.a) from t2;").Check(testkit.Rows("utf8mb4_bin")) -} - -func TestIssue17115(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery("select collation(user());").Check(testkit.Rows("utf8mb4_bin")) - tk.MustQuery("select collation(compress('abc'));").Check(testkit.Rows("binary")) -} - func TestIndexedVirtualGeneratedColumnTruncate(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4888,351 +4089,6 @@ func TestIndexedVirtualGeneratedColumnTruncate(t *testing.T) { tk.MustExec("admin check table t") } -func TestIssue17287(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`set tidb_enable_prepared_plan_cache=1`) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t;") - tk.MustExec("set @@tidb_enable_vectorized_expression = false;") - tk.MustExec("create table t(a datetime);") - tk.MustExec("insert into t values(from_unixtime(1589873945)), (from_unixtime(1589873946));") - tk.MustExec("prepare stmt7 from 'SELECT unix_timestamp(a) FROM t WHERE a = from_unixtime(?);';") - tk.MustExec("set @val1 = 1589873945;") - tk.MustExec("set @val2 = 1589873946;") - tk.MustQuery("execute stmt7 using @val1;").Check(testkit.Rows("1589873945")) - tk.MustQuery("execute stmt7 using @val2;").Check(testkit.Rows("1589873946")) -} - -func TestIssue17898(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t0") - tk.MustExec("create table t0(a char(10), b int as ((a)));") - tk.MustExec("insert into t0(a) values(\"0.5\");") - tk.MustQuery("select * from t0;").Check(testkit.Rows("0.5 1")) -} - -func TestIssue18515(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b json, c int AS (JSON_EXTRACT(b, '$.population')), key(c));") - tk.MustExec("select /*+ TIDB_INLJ(t2) */ t1.a, t1.c, t2.a from t t1, t t2 where t1.c=t2.c;") -} - -func TestIssue20223(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("CREATE TABLE t (" + - "id int(10) unsigned NOT NULL AUTO_INCREMENT," + - "type tinyint(4) NOT NULL," + - "create_time int(11) NOT NULL," + - "PRIMARY KEY (id)" + - ")") - tk.MustExec("insert into t values (4, 2, 1598584933)") - tk.MustQuery("select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 1 " + - "group by t_day union all " + - "select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 2 " + - "group by t_day").Check(testkit.Rows("2020-08-28 1")) -} - -func TestIssue18525(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (col0 BLOB, col1 CHAR(74), col2 DATE UNIQUE)") - tk.MustExec("insert into t1 values ('l', '7a34bc7d-6786-461b-92d3-fd0a6cd88f39', '1000-01-03')") - tk.MustExec("insert into t1 values ('l', NULL, '1000-01-04')") - tk.MustExec("insert into t1 values ('b', NULL, '1000-01-02')") - tk.MustQuery("select INTERVAL( ( CONVERT( -11752 USING utf8 ) ), 6558853612195285496, `col1`) from t1").Check(testkit.Rows("0", "0", "0")) -} - -func TestIssue18850(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b enum('A', 'B'));") - tk.MustExec("create table t1(a1 int, b1 enum('B', 'A'));") - tk.MustExec("insert into t values (1, 'A');") - tk.MustExec("insert into t1 values (1, 'A');") - tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) - - tk.MustExec("drop table t, t1") - tk.MustExec("create table t(a int, b set('A', 'B'));") - tk.MustExec("create table t1(a1 int, b1 set('B', 'A'));") - tk.MustExec("insert into t values (1, 'A');") - tk.MustExec("insert into t1 values (1, 'A');") - tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) -} - -func TestIssue19504(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1 (c_int int, primary key (c_int));") - tk.MustExec("insert into t1 values (1), (2), (3);") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t2 (c_int int, primary key (c_int));") - tk.MustExec("insert into t2 values (1);") - tk.MustQuery("select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;"). - Check(testkit.Rows("1 1", "0 0", "0 0")) - tk.MustQuery("select (select count(c_int*c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;"). - Check(testkit.Rows("1 1", "0 0", "0 0")) -} - -func TestIssue17767(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0;") - tk.MustExec("CREATE TABLE t0(c0 INTEGER AS (NULL) NOT NULL, c1 INT);") - tk.MustExec("CREATE INDEX i0 ON t0(c0, c1);") - tk.MustExec("INSERT IGNORE INTO t0(c1) VALUES (0);") - tk.MustQuery("SELECT * FROM t0").Check(testkit.Rows("0 0")) - - tk.MustExec("begin") - tk.MustExec("INSERT IGNORE INTO t0(c1) VALUES (0);") - tk.MustQuery("SELECT * FROM t0").Check(testkit.Rows("0 0", "0 0")) - tk.MustExec("rollback") -} - -func TestIssue19596(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (a int) partition by range(a) (PARTITION p0 VALUES LESS THAN (10));") - tk.MustGetErrMsg("alter table t add partition (partition p1 values less than (a));", "[planner:1054]Unknown column 'a' in 'expression'") - tk.MustQuery("select * from t;") - tk.MustExec("drop table if exists t;") - tk.MustGetErrMsg("create table t (a int) partition by range(a) (PARTITION p0 VALUES LESS THAN (a));", "[planner:1054]Unknown column 'a' in 'expression'") -} - -func TestIssue17476(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS `table_float`;") - tk.MustExec("DROP TABLE IF EXISTS `table_int_float_varchar`;") - tk.MustExec("CREATE TABLE `table_float` (`id_1` int(16) NOT NULL AUTO_INCREMENT,`col_float_1` float DEFAULT NULL,PRIMARY KEY (`id_1`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=97635;") - tk.MustExec("CREATE TABLE `table_int_float_varchar` " + - "(`id_6` int(16) NOT NULL AUTO_INCREMENT," + - "`col_int_6` int(16) DEFAULT NULL,`col_float_6` float DEFAULT NULL," + - "`col_varchar_6` varchar(511) DEFAULT NULL,PRIMARY KEY (`id_6`)," + - "KEY `vhyen` (`id_6`,`col_int_6`,`col_float_6`,`col_varchar_6`(1))," + - "KEY `zzylq` (`id_6`,`col_int_6`,`col_float_6`,`col_varchar_6`(1))) " + - "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=90818;") - - tk.MustExec("INSERT INTO `table_float` VALUES (1,NULL),(2,0.1),(3,0),(4,-0.1),(5,-0.1),(6,NULL),(7,0.5),(8,0),(9,0),(10,NULL),(11,1),(12,1.5),(13,NULL),(14,NULL);") - tk.MustExec("INSERT INTO `table_int_float_varchar` VALUES (1,0,0.1,'true'),(2,-1,1.5,'2020-02-02 02:02:00'),(3,NULL,1.5,NULL),(4,65535,0.1,'true'),(5,NULL,0.1,'1'),(6,-1,1.5,'2020-02-02 02:02:00'),(7,-1,NULL,''),(8,NULL,-0.1,NULL),(9,NULL,-0.1,'1'),(10,-1,NULL,''),(11,NULL,1.5,'false'),(12,-1,0,NULL),(13,0,-0.1,NULL),(14,-1,NULL,'-0'),(15,65535,-1,'1'),(16,NULL,0.5,NULL),(17,-1,NULL,NULL);") - tk.MustQuery(`select count(*) from table_float - JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) - IS NULL WHERE col_int_6=0;`).Check(testkit.Rows("14")) - tk.MustQuery(`SELECT count(*) FROM (table_float JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) IS NULL);`).Check(testkit.Rows("154")) - tk.MustQuery(`SELECT * FROM (table_int_float_varchar AS tmp3) WHERE (col_varchar_6 AND NULL) IS NULL AND col_int_6=0;`).Check(testkit.Rows("13 0 -0.1 ")) -} - -func TestIssue14349(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists papers;") - tk.MustExec("create table papers(title text, content longtext)") - tk.MustExec("insert into papers values('title', 'content')") - tk.MustQuery(`select to_base64(title), to_base64(content) from papers;`).Check(testkit.Rows("dGl0bGU= Y29udGVudA==")) - tk.MustExec("set tidb_enable_vectorized_expression = 0;") - tk.MustQuery(`select to_base64(title), to_base64(content) from papers;`).Check(testkit.Rows("dGl0bGU= Y29udGVudA==")) - tk.MustExec("set tidb_enable_vectorized_expression = 1;") -} - -func TestIssue20180(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(a enum('a', 'b'), b tinyint);") - tk.MustExec("create table t1(c varchar(20));") - tk.MustExec("insert into t values('b', 0);") - tk.MustExec("insert into t1 values('b');") - tk.MustQuery("select * from t, t1 where t.a= t1.c;").Check(testkit.Rows("b 0 b")) - tk.MustQuery("select * from t, t1 where t.b= t1.c;").Check(testkit.Rows("b 0 b")) - tk.MustQuery("select * from t, t1 where t.a = t1.c and t.b= t1.c;").Check(testkit.Rows("b 0 b")) - - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a enum('a','b'));") - tk.MustExec("insert into t values('b');") - tk.MustQuery("select * from t where a > 1 and a = \"b\";").Check(testkit.Rows("b")) -} - -func TestIssue11755(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists lt;") - tk.MustExec("create table lt (d decimal(10, 4));") - tk.MustExec("insert into lt values(0.2),(0.2);") - tk.MustQuery("select LEAD(d,1,1) OVER(), LAG(d,1,1) OVER() from lt;").Check(testkit.Rows("0.2000 1.0000", "1.0000 0.2000")) -} - -func TestIssue20369(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int);") - tk.MustExec("insert into t values (1);") - tk.MustExec("insert into t select values(a) from t;") - tk.MustQuery("select * from t").Check(testkit.Rows("1", "")) -} - -func TestIssue20730(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS tmp;") - tk.MustExec("CREATE TABLE tmp (id int(11) NOT NULL,value int(1) NOT NULL,PRIMARY KEY (id))") - tk.MustExec("INSERT INTO tmp VALUES (1, 1),(2,2),(3,3),(4,4),(5,5)") - tk.MustExec("SET @sum := 10") - tk.MustQuery("SELECT @sum := IF(@sum=20,4,@sum + tmp.value) sum FROM tmp ORDER BY tmp.id").Check(testkit.Rows("11", "13", "16", "20", "4")) -} - -func TestIssue20860(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(id int primary key, c int, d timestamp null default null)") - tk.MustExec("insert into t values(1, 2, '2038-01-18 20:20:30')") - require.Error(t, tk.ExecToErr("update t set d = adddate(d, interval 1 day) where id < 10")) -} - -func TestIssue15847(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop view if exists t15847") - tk.MustExec("CREATE VIEW t15847(c0) AS SELECT NULL;") - tk.MustQuery("SELECT * FROM t15847 WHERE (NOT (IF(t15847.c0, NULL, NULL)));").Check(testkit.Rows()) - tk.MustExec("drop view if exists t15847") -} - -func TestIssue10462(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustQuery("select json_array(true)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1=2)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array(1!=2)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1<2)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1<=2)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1>2)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array(1>=2)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_object(true, null <=> null)").Check(testkit.Rows("{\"1\": true}")) - tk.MustQuery("select json_object(false, 1 and 2)").Check(testkit.Rows("{\"0\": true}")) - tk.MustQuery("select json_object(false, 1 and 0)").Check(testkit.Rows("{\"0\": false}")) - tk.MustQuery("select json_object(false, 1 or 0)").Check(testkit.Rows("{\"0\": true}")) - tk.MustQuery("select json_object(false, 1 xor 0)").Check(testkit.Rows("{\"0\": true}")) - tk.MustQuery("select json_object(false, 1 xor 1)").Check(testkit.Rows("{\"0\": false}")) - tk.MustQuery("select json_object(false, not 1)").Check(testkit.Rows("{\"0\": false}")) - tk.MustQuery("select json_array(null and 1)").Check(testkit.Rows("[null]")) - tk.MustQuery("select json_array(null and 0)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array(null or 1)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(null or 0)").Check(testkit.Rows("[null]")) - tk.MustQuery("select json_array(1.15 or 0)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array('abc' or 0)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array('1abc' or 0)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(null is true)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array(null is null)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1 in (1, 2))").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(0 in (1, 2))").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array(0 not in (1, 2))").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1 between 0 and 2)").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(1 not between 0 and 2)").Check(testkit.Rows("[false]")) - tk.MustQuery("select json_array('123' like '123')").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array('abcdef' rlike 'a.*c.*')").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(is_ipv4('127.0.0.1'))").Check(testkit.Rows("[true]")) - tk.MustQuery("select json_array(is_ipv6('1a6b:8888:ff66:77ee:0000:1234:5678:bcde'))").Check(testkit.Rows("[true]")) -} - -func TestIssue17868(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t7") - tk.MustExec("create table t7 (col0 SMALLINT, col1 VARBINARY(1), col2 DATE, col3 BIGINT, col4 BINARY(166))") - tk.MustExec("insert into t7 values ('32767', '', '1000-01-03', '-0', '11101011')") - tk.MustQuery("select col2 = 1 from t7").Check(testkit.Rows("0")) - tk.MustQuery("select col2 != 1 from t7").Check(testkit.Rows("1")) -} - -func TestIssue21619(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery(`select CAST("9223372036854775808" as json)`).Check(testkit.Rows("9223372036854775808")) - tk.MustQuery(`select json_type(CAST("9223372036854775808" as json))`).Check(testkit.Rows("UNSIGNED INTEGER")) - tk.MustQuery(`select CAST(9223372036854775808 as json)`).Check(testkit.Rows("9223372036854775808")) - tk.MustQuery(`select json_type(CAST(9223372036854775808 as json))`).Check(testkit.Rows("UNSIGNED INTEGER")) - tk.MustQuery(`select CAST(-9223372036854775808 as json)`).Check(testkit.Rows("-9223372036854775808")) - tk.MustQuery(`select json_type(CAST(-9223372036854775808 as json))`).Check(testkit.Rows("INTEGER")) -} - -func TestIssue10467(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists tx2;") - tk.MustExec("create table tx2 (col json);") - tk.MustExec(`insert into tx2 values (json_array("3")),(json_array("3")),(json_array("3")),(json_array("3"));`) - tk.MustExec(`insert into tx2 values (json_array(3.0));`) - tk.MustExec(`insert into tx2 values (json_array(3));`) - tk.MustExec(`insert into tx2 values (json_array(3.0));`) - tk.MustExec(`insert into tx2 values (json_array(-3));`) - tk.MustExec(`insert into tx2 values (json_array(-3.0));`) - tk.MustExec(`insert into tx2 values (json_array(922337203685477580));`) - tk.MustExec(`insert into tx2 values (json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581)),(json_array(922337203685477581));`) - - // TODO: in MySQL these values will hash the same because the first is stored as JSON type DECIMAL. - // Currently TiDB does not support JSON type DECIMAL. - // See: https://github.com/pingcap/tidb/issues/9988 - // insert into tx2 values (json_array(9223372036854775808.0)); - // insert into tx2 values (json_array(9223372036854775808)); - - // ordering by a JSON col is not supported in MySQL, and the order is a bit questionable in TiDB. - // sort by count for test result stability. - tk.MustQuery("select col, count(1) c from tx2 group by col order by c desc;").Check(testkit.Rows("[922337203685477581] 5", `["3"] 4`, "[3] 3", "[-3] 2", "[922337203685477580] 1")) -} - func TestIssue19892(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5482,6 +4338,24 @@ func TestIssue19892(t *testing.T) { tk.MustGetErrMsg("insert into table_20220419(lastLoginDate) select lastLoginDate from table_20220419;", "[types:1292]Incorrect datetime value: '0000-00-00 00:00:00'") } +func TestIssue11333(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("drop table if exists t1;") + tk.MustExec("create table t(col1 decimal);") + tk.MustExec(" insert into t values(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);") + tk.MustQuery(`select * from t;`).Check(testkit.Rows("0")) + tk.MustExec("create table t1(col1 decimal(65,30));") + tk.MustExec(" insert into t1 values(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);") + tk.MustQuery(`select * from t1;`).Check(testkit.Rows("0.000000000000000000000000000000")) + tk.MustQuery(`select 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000000")) + tk.MustQuery(`select 0.0000000000000000000000000000000000000000000000000000000000000000000000012;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) + tk.MustQuery(`select 0.000000000000000000000000000000000000000000000000000000000000000000000001;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) +} + // The actual results do not agree with the test results, It should be modified after the test suite is updated func TestIssue17726(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5507,72 +4381,6 @@ func TestDatetimeUserVariable(t *testing.T) { require.NotEqual(t, "", tk.MustQuery("select @p").Rows()[0][0]) } -func TestIssue12205(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t12205;") - tk.MustExec("create table t12205(\n `col_varchar_64` varchar(64) DEFAULT NULL,\n `col_varchar_64_key` varchar(64) DEFAULT NULL\n);") - tk.MustExec("insert into t12205 values('-1038024704','-527892480');") - tk.MustQuery("select SEC_TO_TIME( ( `col_varchar_64` & `col_varchar_64_key` ) ),`col_varchar_64` & `col_varchar_64_key` from t12205; ").Check( - testkit.Rows("838:59:59 18446744072635875328")) - tk.MustQuery("show warnings;").Check( - testkit.Rows("Warning 1292 Truncated incorrect time value: '18446744072635875000'")) -} - -func TestIssue21677(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(1e int);") - tk.MustExec("insert into t values (1);") - tk.MustQuery("select t.1e from test.t;").Check(testkit.Rows("1")) - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(99e int, r10 int);") - tk.MustExec("insert into t values (1, 10), (2, 2);") - tk.MustQuery("select 99e+r10 from t;").Check(testkit.Rows("11", "4")) - tk.MustQuery("select .78$123;").Check(testkit.Rows("0.78")) - tk.MustGetErrCode("select .78$421+1;", mysql.ErrParse) - tk.MustQuery("select t. `r10` > 3 from t;").Check(testkit.Rows("1", "0")) - tk.MustQuery("select * from t where t. `r10` > 3;").Check(testkit.Rows("1 10")) -} - -func TestIssue11333(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(col1 decimal);") - tk.MustExec(" insert into t values(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);") - tk.MustQuery(`select * from t;`).Check(testkit.Rows("0")) - tk.MustExec("create table t1(col1 decimal(65,30));") - tk.MustExec(" insert into t1 values(0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);") - tk.MustQuery(`select * from t1;`).Check(testkit.Rows("0.000000000000000000000000000000")) - tk.MustQuery(`select 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000000")) - tk.MustQuery(`select 0.0000000000000000000000000000000000000000000000000000000000000000000000012;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) - tk.MustQuery(`select 0.000000000000000000000000000000000000000000000000000000000000000000000001;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) -} - -func TestIssue12206(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t12206;") - tk.MustExec("create table t12206(\n `col_tinyint_unsigned` tinyint(3) unsigned DEFAULT NULL,\n `col_double_unsigned` double unsigned DEFAULT NULL,\n `col_year_key` year(4) DEFAULT NULL\n);") - tk.MustExec("insert into t12206 values(73,0,0000);") - tk.MustQuery("SELECT TIME_FORMAT( `col_tinyint_unsigned`, ( IFNULL( `col_double_unsigned`, `col_year_key` ) ) ) AS field1 FROM `t12206`;").Check( - testkit.Rows("")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '73'")) -} - func TestCastCoer(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5583,95 +4391,6 @@ func TestCastCoer(t *testing.T) { tk.MustQuery("select coercibility(convert('abc', char(10)));").Check(testkit.Rows("2")) } -func TestIssue12209(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t12209;") - tk.MustExec("create table t12209(a bigint(20));") - tk.MustExec("insert into t12209 values(1);") - tk.MustQuery("select `a` DIV ( ROUND( ( SCHEMA() ), '1978-05-18 03:35:52.043591' ) ) from `t12209`;").Check( - testkit.Rows("")) -} - -func TestIssue22098(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `ta` (" + - " `k` varchar(32) NOT NULL DEFAULT ' '," + - " `c0` varchar(32) NOT NULL DEFAULT ' '," + - " `c` varchar(18) NOT NULL DEFAULT ' '," + - " `e0` varchar(1) NOT NULL DEFAULT ' '," + - " PRIMARY KEY (`k`,`c0`,`c`)," + - " KEY `idx` (`c`,`e0`)" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - tk.MustExec("CREATE TABLE `tb` (" + - " `k` varchar(32) NOT NULL DEFAULT ' '," + - " `e` int(11) NOT NULL DEFAULT '0'," + - " `i` int(11) NOT NULL DEFAULT '0'," + - " `s` varchar(1) NOT NULL DEFAULT ' '," + - " `c` varchar(50) NOT NULL DEFAULT ' '," + - " PRIMARY KEY (`k`)" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - tk.MustExec("prepare stmt from \"select a.* from ta a left join tb b on a.k = b.k where (a.k <> '000000' and ((b.s = ? and i = ? ) or (b.s = ? and e = ?) or (b.s not in(?, ?))) and b.c like '%1%') or (a.c <> '000000' and a.k = '000000')\"") - tk.MustExec("set @a=3;set @b=20200414;set @c='a';set @d=20200414;set @e=3;set @f='a';") - tk.MustQuery("execute stmt using @a,@b,@c,@d,@e,@f").Check(testkit.Rows()) -} - -func Test22717(t *testing.T) { - // For issue 22717 - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec(`create table t( - a enum('a','','c'), - b enum('0','1','2'), - c set('a','','c'), - d set('0','1','2') - )`) - tk.MustExec("insert into t values(1,1,1,1),(2,2,2,2),(3,3,3,3)") - tk.MustExec("set @@sql_mode = ''") - tk.MustExec("insert into t values('','','','')") - tk.MustQuery("select * from t").Check(testkit.Rows("a 0 a 0", " 1 1", "c 2 a, 0,1", " ")) - tk.MustQuery("select a from t where a").Check(testkit.Rows("a", "", "c", "")) - tk.MustQuery("select b from t where b").Check(testkit.Rows("0", "1", "2")) - tk.MustQuery("select c from t where c").Check(testkit.Rows("a", "", "a,", "")) - tk.MustQuery("select d from t where d").Check(testkit.Rows("0", "1", "0,1")) -} - -func Test23262(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a year)") - tk.MustExec("insert into t values(2002)") - tk.MustQuery("select * from t where a=2").Check(testkit.Rows("2002")) - tk.MustQuery("select * from t where a='2'").Check(testkit.Rows("2002")) -} - -func TestClusteredIndexCorCol(t *testing.T) { - // For issue 23076 - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) );") - tk.MustExec("create table t2 like t1 ;") - tk.MustExec("insert into t1 values (1, 'crazy lumiere'), (10, 'goofy mestorf');") - tk.MustExec("insert into t2 select * from t1 ;") - tk.MustQuery("select (select t2.c_str from t2 where t2.c_str = t1.c_str and t2.c_int = 10 order by t2.c_str limit 1) x from t1;").Check(testkit.Rows("", "goofy mestorf")) -} - func TestEnumPushDown(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5790,17 +4509,6 @@ func TestJiraSetInnoDBDefaultRowFormat(t *testing.T) { tk.MustQuery("SHOW VARIABLES LIKE 'innodb_large_prefix'").Check(testkit.Rows("innodb_large_prefix ON")) } -func TestIssue23623(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 int);") - tk.MustExec("insert into t1 values(-2147483648), (-2147483648), (null);") - tk.MustQuery("select count(*) from t1 where c1 > (select sum(c1) from t1);").Check(testkit.Rows("2")) -} - func TestApproximatePercentile(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5911,23 +4619,6 @@ func TestSecurityEnhancedMode(t *testing.T) { tk.MustGetErrMsg("SELECT 1 INTO OUTFILE '/tmp/aaaa'", "[planner:8132]Feature 'SELECT INTO' is not supported when security enhanced mode is enabled") } -func TestIssue23925(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test;") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int primary key, b set('Alice','Bob') DEFAULT NULL);") - tk.MustExec("insert into t value(1,'Bob');") - tk.MustQuery("select max(b) + 0 from t group by a;").Check(testkit.Rows("2")) - - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int, b set('Alice','Bob') DEFAULT NULL);") - tk.MustExec("insert into t value(1,'Bob');") - tk.MustQuery("select max(b) + 0 from t group by a;").Check(testkit.Rows("2")) -} - func TestCTEInvalidUsage(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5971,21 +4662,6 @@ func TestCTEInvalidUsage(t *testing.T) { tk.MustGetErrCode("with recursive cte(n) as (select 1 union select 1 except select * from cte) select * from cte;", errno.ErrNotSupportedYet) } -func TestIssue23889(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists test_decimal,test_t;") - tk.MustExec("create table test_decimal(col_decimal decimal(10,0));") - tk.MustExec("insert into test_decimal values(null),(8);") - tk.MustExec("create table test_t(a int(11), b decimal(32,0));") - tk.MustExec("insert into test_t values(1,4),(2,4),(5,4),(7,4),(9,4);") - - tk.MustQuery("SELECT ( test_decimal . `col_decimal` , test_decimal . `col_decimal` ) IN ( select * from test_t ) as field1 FROM test_decimal;").Check( - testkit.Rows("", "0")) -} - func TestRefineArgNullValues(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6138,19 +4814,6 @@ func TestRedundantColumnResolve(t *testing.T) { tk.MustQuery("select t1.a, t2.a from t1 natural join t2").Check(testkit.Rows("1 1")) } -func TestIssue37414(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists foo") - tk.MustExec("drop table if exists bar") - tk.MustExec("create table foo(a decimal(65,0));") - tk.MustExec("create table bar(a decimal(65,0), b decimal(65,0));") - tk.MustExec("insert into bar values(0,0),(1,1),(2,2);") - tk.MustExec("insert into foo select if(b>0, if(a/b>1, 1, 2), null) from bar;") -} - func TestControlFunctionWithEnumOrSet(t *testing.T) { // issue 23114 store := testkit.CreateMockStore(t) @@ -6481,54 +5144,6 @@ func TestCharsetErr(t *testing.T) { require.Error(t, err, "[table:1366]Incorrect string value '\\xEF\\xBF\\xBD' for column 'c1'") } -func TestIssue25591(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1_1, t2_1;") - tk.MustExec("CREATE TABLE `t1_1` (`col1` double DEFAULT NULL, `col2` double DEFAULT NULL);") - tk.MustExec("CREATE TABLE `t2_1` (`col1` varchar(20) DEFAULT NULL, `col2` double DEFAULT NULL);") - tk.MustExec("insert into t1_1 values(12.991, null), (12.991, null);") - tk.MustExec("insert into t2_1(col2) values(87), (-9.183), (-9.183);") - - tk.MustExec("set @@tidb_enable_vectorized_expression = false;") - rows := tk.MustQuery("select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;") - rows.Check(testkit.Rows()) - - tk.MustExec("set @@tidb_enable_vectorized_expression = true;") - rows = tk.MustQuery("select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;") - rows.Check(testkit.Rows()) -} - -func TestIssue25526(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test;") - tk.MustExec("drop table if exists tbl_6, tbl_17;") - tk.MustExec("create table tbl_6 (col_31 year, index(col_31));") - tk.MustExec("create table tbl_17 (col_102 int, col_105 int);") - tk.MustExec("replace into tbl_17 (col_102, col_105) values (9999, 0);") - - rows := tk.MustQuery("select tbl_6.col_31 from tbl_6 where col_31 in (select col_102 from tbl_17 where tbl_17.col_102 = 9999 and tbl_17.col_105 = 0);") - rows.Check(testkit.Rows()) -} - -func TestIssue24953(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists tbl_0,tbl_9;") - tk.MustExec("CREATE TABLE `tbl_9` (\n `col_54` mediumint NOT NULL DEFAULT '2412996',\n `col_55` int NOT NULL,\n `col_56` bigint unsigned NOT NULL,\n `col_57` varchar(108) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,\n PRIMARY KEY (`col_57`(3),`col_55`,`col_56`,`col_54`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("CREATE TABLE `tbl_0` (\n `col_76` bigint(20) unsigned DEFAULT NULL,\n `col_1` time NOT NULL DEFAULT '13:11:28',\n `col_2` datetime DEFAULT '1990-07-29 00:00:00',\n `col_3` date NOT NULL DEFAULT '1976-09-16',\n `col_4` date DEFAULT NULL,\n `col_143` varbinary(208) DEFAULT 'lXRTXUkTeWaJ',\n KEY `idx_0` (`col_2`,`col_1`,`col_76`,`col_4`,`col_3`),\n PRIMARY KEY (`col_1`,`col_3`) /*T![clustered_index] NONCLUSTERED */,\n KEY `idx_2` (`col_1`,`col_4`,`col_76`,`col_3`),\n KEY `idx_3` (`col_4`,`col_76`,`col_3`,`col_2`,`col_1`),\n UNIQUE KEY `idx_4` (`col_76`,`col_3`,`col_1`,`col_4`),\n KEY `idx_5` (`col_3`,`col_4`,`col_76`,`col_2`),\n KEY `idx_6` (`col_2`),\n KEY `idx_7` (`col_76`,`col_3`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("insert into tbl_9 values (-5765442,-597990898,384599625723370089,\"ZdfkUJiHcOfi\");") - tk.MustQuery("(select col_76,col_1,col_143,col_2 from tbl_0) union (select col_54,col_57,col_55,col_56 from tbl_9);").Check(testkit.Rows("-5765442 ZdfkUJiHcOfi -597990898 384599625723370089")) -} - // issue https://github.com/pingcap/tidb/issues/28544 func TestPrimaryKeyRequiredSysvar(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6654,21 +5269,6 @@ func TestTranslate(t *testing.T) { tk.MustQuery("select translate(i, '0123456', 'abcdefg') from t").Check(testkit.Rows("a", "b", "c", "d", "e", "f", "g")) } -func TestIssue26958(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1 (c_int int not null);") - tk.MustExec("insert into t1 values (1), (2), (3),(1),(2),(3);") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t2 (c_int int not null);") - tk.MustExec("insert into t2 values (1), (2), (3),(1),(2),(3);") - tk.MustQuery("select \n(select count(distinct c_int) from t2 where c_int >= t1.c_int) c1, \n(select count(distinct c_int) from t2 where c_int >= t1.c_int) c2\nfrom t1 group by c_int;\n"). - Check(testkit.Rows("3 3", "2 2", "1 1")) -} - func TestConstPropNullFunctions(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6689,53 +5289,6 @@ func TestConstPropNullFunctions(t *testing.T) { tk.MustQuery("select * from t2 where t2.i2=((select count(1) from t1 where t1.i1=t2.i2))").Check(testkit.Rows("1 0.1")) } -func TestIssue27233(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t;") - tk.MustExec("CREATE TABLE `t` (\n `COL1` tinyint(45) NOT NULL,\n `COL2` tinyint(45) NOT NULL,\n PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("insert into t values(122,100),(124,-22),(124,34),(127,103);") - tk.MustQuery("SELECT col2 FROM t AS T1 WHERE ( SELECT count(DISTINCT COL1, COL2) FROM t AS T2 WHERE T2.COL1 > T1.COL1 ) > 2 ;"). - Check(testkit.Rows("100")) -} - -func TestIssue27236(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - row := tk.MustQuery(`select extract(hour_second from "-838:59:59.00");`) - row.Check(testkit.Rows("-8385959")) - - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(c1 varchar(100));`) - tk.MustExec(`insert into t values('-838:59:59.00'), ('700:59:59.00');`) - row = tk.MustQuery(`select extract(hour_second from c1) from t order by c1;`) - row.Check(testkit.Rows("-8385959", "7005959")) -} - -func TestIssue26977(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - result := tk.MustQuery("select a + 1 as f from (select cast(0xfffffffffffffff0 as unsigned) as a union select cast(1 as unsigned)) t having f != 2;") - result.Check(testkit.Rows("18446744073709551601")) -} - -func TestIssue27610(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists PK_TCOLLATION3966STROBJSTROBJ;`) - tk.MustExec("CREATE TABLE `PK_TCOLLATION3966STROBJSTROBJ` (\n `COL1` enum('ll','aa','bb','cc','dd','ee') COLLATE utf8_general_ci NOT NULL,\n `COL2` varchar(20) COLLATE utf8_general_ci DEFAULT NULL,\n PRIMARY KEY (`COL1`) /*T![clustered_index] CLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;") - tk.MustExec(`insert into PK_TCOLLATION3966STROBJSTROBJ values("ee", "tttt");`) - tk.MustQuery("SELECT col1, COL2 FROM PK_TCOLLATION3966STROBJSTROBJ WHERE COL1 IN ('notexist','6') and col2 not in (\"abcd\");"). - Check(testkit.Rows()) -} - func TestLastInsertId(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6817,82 +5370,6 @@ func TestIdentity(t *testing.T) { tk.MustQuery("SELECT @@identity, LAST_INSERT_ID()").Check(testkit.Rows("3 3")) } -func TestIssue28804(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists perf_offline_day;") - tk.MustExec(`CREATE TABLE perf_offline_day ( -uuid varchar(50), -ts timestamp NOT NULL, -user_id varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, -platform varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, -host_id bigint(20) DEFAULT NULL, -PRIMARY KEY (uuid,ts) /*T![clustered_index] NONCLUSTERED */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci -PARTITION BY RANGE ( UNIX_TIMESTAMP(ts) ) ( -PARTITION p20210906 VALUES LESS THAN (1630944000), -PARTITION p20210907 VALUES LESS THAN (1631030400), -PARTITION p20210908 VALUES LESS THAN (1631116800), -PARTITION p20210909 VALUES LESS THAN (1631203200) -);`) - tk.MustExec("set @@tidb_partition_prune_mode = 'static'") - tk.MustExec("INSERT INTO `perf_offline_day` VALUES ('dd082c8a-3bab-4431-943a-348fe0592abd','2021-09-08 13:00:07','Xg9C8zq81jGNbugM', 'pc', 12345);") - tk.MustQuery("SELECT cast(floor(hour(ts) / 4) as char) as win_start FROM perf_offline_day partition (p20210907, p20210908) GROUP BY win_start;").Check(testkit.Rows("3")) -} - -func TestIssue28643(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a time(4));") - tk.MustExec("insert into t values(\"-838:59:59.000000\");") - tk.MustExec("insert into t values(\"838:59:59.000000\");") - tk.MustExec("set tidb_enable_vectorized_expression = on;") - tk.MustQuery("select hour(a) from t;").Check(testkit.Rows("838", "838")) - tk.MustExec("set tidb_enable_vectorized_expression = off;") - tk.MustQuery("select hour(a) from t;").Check(testkit.Rows("838", "838")) -} - -func TestIssue27831(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a enum(\"a\", \"b\"), b enum(\"a\", \"b\"), c bool)") - tk.MustExec("insert into t values(\"a\", \"a\", 1);") - tk.MustQuery("select * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c;").Check(testkit.Rows("a a 1 a a 1")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a enum(\"a\", \"b\"), b enum(\"a\", \"b\"), c bool, d int, index idx(d))") - tk.MustExec("insert into t values(\"a\", \"a\", 1, 1);") - tk.MustQuery("select /*+ inl_hash_join(t1) */ * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c and t1.d=t2.d;").Check(testkit.Rows("a a 1 1 a a 1 1")) -} - -func TestIssue29434(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 datetime);") - tk.MustExec("insert into t1 values('2021-12-12 10:10:10.000');") - tk.MustExec("set tidb_enable_vectorized_expression = on;") - tk.MustQuery("select greatest(c1, '99999999999999') from t1;").Check(testkit.Rows("99999999999999")) - tk.MustExec("set tidb_enable_vectorized_expression = off;") - tk.MustQuery("select greatest(c1, '99999999999999') from t1;").Check(testkit.Rows("99999999999999")) - - tk.MustExec("set tidb_enable_vectorized_expression = on;") - tk.MustQuery("select least(c1, '99999999999999') from t1;").Check(testkit.Rows("2021-12-12 10:10:10")) - tk.MustExec("set tidb_enable_vectorized_expression = off;") - tk.MustQuery("select least(c1, '99999999999999') from t1;").Check(testkit.Rows("2021-12-12 10:10:10")) -} - func TestIssue29417(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6904,21 +5381,6 @@ func TestIssue29417(t *testing.T) { tk.MustQuery("select concat(f1) from t1;").Check(testkit.Rows("-0.12345")) } -func TestIssue29244(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a time(4));") - tk.MustExec("insert into t values(\"-700:10:10.123456111\");") - tk.MustExec("insert into t values(\"700:10:10.123456111\");") - tk.MustExec("set tidb_enable_vectorized_expression = on;") - tk.MustQuery("select microsecond(a) from t;").Check(testkit.Rows("123500", "123500")) - tk.MustExec("set tidb_enable_vectorized_expression = off;") - tk.MustQuery("select microsecond(a) from t;").Check(testkit.Rows("123500", "123500")) -} - func TestIssue29513(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6934,31 +5396,6 @@ func TestIssue29513(t *testing.T) { tk.MustQuery("select '123' union select cast(a as char(2)) from t;").Sort().Check(testkit.Rows("123", "45")) } -func TestIssue29755(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("set tidb_enable_vectorized_expression = on;") - tk.MustQuery("select char(123, NULL, 123)").Check(testkit.Rows("{{")) - tk.MustQuery("select char(NULL, 123, 123)").Check(testkit.Rows("{{")) - tk.MustExec("set tidb_enable_vectorized_expression = off;") - tk.MustQuery("select char(123, NULL, 123)").Check(testkit.Rows("{{")) - tk.MustQuery("select char(NULL, 123, 123)").Check(testkit.Rows("{{")) -} - -func TestIssue30101(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 bigint unsigned, c2 bigint unsigned);") - tk.MustExec("insert into t1 values(9223372036854775808, 9223372036854775809);") - tk.MustQuery("select greatest(c1, c2) from t1;").Sort().Check(testkit.Rows("9223372036854775809")) -} - func TestIssue28739(t *testing.T) { store := testkit.CreateMockStore(t) @@ -6980,368 +5417,6 @@ func TestIssue28739(t *testing.T) { " ")) } -func TestIssue30326(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int);") - tk.MustExec("insert into t values(1),(1),(2),(2);") - tk.MustExec("set tidb_window_concurrency = 1;") - err := tk.QueryToErr("select (FIRST_VALUE(1) over (partition by v.a)) as c3 from (select a from t where t.a = (select a from t t2 where t.a = t2.a)) as v;") - require.Error(t, err, "[executor:1242]Subquery returns more than 1 row") -} - -func TestIssue30174(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1,t2;") - tk.MustExec("CREATE TABLE `t1` (\n `c1` enum('Alice','Bob','Charlie','David') NOT NULL,\n `c2` blob NOT NULL,\n PRIMARY KEY (`c2`(5)),\n UNIQUE KEY `idx_89` (`c1`)\n);") - tk.MustExec("CREATE TABLE `t2` (\n `c1` enum('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'Alice',\n `c2` set('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'David',\n `c3` enum('Alice','Bob','Charlie','David') NOT NULL,\n PRIMARY KEY (`c3`,`c2`)\n);") - tk.MustExec("insert into t1 values('Charlie','');") - tk.MustExec("insert into t2 values('Charlie','Charlie','Alice');") - tk.MustQuery("select * from t2 where c3 in (select c2 from t1);").Check(testkit.Rows()) - tk.MustQuery("select * from t2 where c2 in (select c2 from t1);").Check(testkit.Rows()) -} - -func TestIssue30264(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // compare Time/Int/Int as string type, return string type - tk.MustQuery("select greatest(time '21:00', year(date'20220101'), 23);").Check(testkit.Rows("23")) - // compare Time/Date/Int as string type, return string type - tk.MustQuery("select greatest(time '21:00', date'891001', 120000);").Check(testkit.Rows("21:00:00")) - // compare Time/Date/Int as string type, return string type - tk.MustQuery("select greatest(time '20:00', date'101001', 120101);").Check(testkit.Rows("20:00:00")) - // compare Date/String/Int as Date type, return string type - tk.MustQuery("select greatest(date'101001', '19990329', 120101);").Check(testkit.Rows("2012-01-01")) - // compare Time/Date as DateTime type, return DateTime type - tk.MustQuery("select greatest(time '20:00', date'691231');").Check(testkit.Rows("2069-12-31 00:00:00")) - // compare Date/Date as Date type, return Date type - tk.MustQuery("select greatest(date '120301', date'691231');").Check(testkit.Rows("2069-12-31")) - // compare Time/Time as Time type, return Time type - tk.MustQuery("select greatest(time '203001', time '2230');").Check(testkit.Rows("20:30:01")) - // compare DateTime/DateTime as DateTime type, return DateTime type - tk.MustQuery("select greatest(timestamp '2021-01-31 00:00:01', timestamp '2021-12-31 12:00:00');").Check(testkit.Rows("2021-12-31 12:00:00")) - // compare Time/DateTime as DateTime type, return DateTime type - tk.MustQuery("select greatest(time '00:00:01', timestamp '2069-12-31 12:00:00');").Check(testkit.Rows("2069-12-31 12:00:00")) - // compare Date/DateTime as DateTime type, return DateTime type - tk.MustQuery("select greatest(date '21000101', timestamp '2069-12-31 12:00:00');").Check(testkit.Rows("2100-01-01 00:00:00")) - // compare JSON/JSON, return JSON type - tk.MustQuery("select greatest(cast('1' as JSON), cast('2' as JSON));").Check(testkit.Rows("2")) - //Original 30264 Issue: - tk.MustQuery("select greatest(time '20:00:00', 120000);").Check(testkit.Rows("20:00:00")) - tk.MustQuery("select greatest(date '2005-05-05', 20010101, 20040404, 20030303);").Check(testkit.Rows("2005-05-05")) - tk.MustQuery("select greatest(date '1995-05-05', 19910101, 20050505, 19930303);").Check(testkit.Rows("2005-05-05")) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t1,t2;") - tk.MustExec("CREATE TABLE `t1` (a datetime, b date, c time)") - tk.MustExec("insert into t1 values(timestamp'2021-01-31 00:00:01', '2069-12-31', '20:00:01');") - tk.MustExec("set tidb_enable_vectorized_expression = on;") - // compare Time/Int/Int as string type, return string type - tk.MustQuery("select greatest(c, year(date'20220101'), 23) from t1;").Check(testkit.Rows("23")) - // compare Time/Date/Int as string type, return string type - tk.MustQuery("select greatest(c, date'891001', 120000) from t1;").Check(testkit.Rows("20:00:01")) - // compare Time/Date/Int as string type, return string type - tk.MustQuery("select greatest(c, date'101001', 120101) from t1;").Check(testkit.Rows("20:00:01")) - // compare Date/String/Int as Date type, return string type - tk.MustQuery("select greatest(b, '19990329', 120101) from t1;").Check(testkit.Rows("2069-12-31")) - // compare Time/Date as DateTime type, return DateTime type - tk.MustQuery("select greatest(time '20:00', b) from t1;").Check(testkit.Rows("2069-12-31 00:00:00")) - // compare Date/Date as Date type, return Date type - tk.MustQuery("select greatest(date '120301', b) from t1;").Check(testkit.Rows("2069-12-31")) - // compare Time/Time as Time type, return Time type - tk.MustQuery("select greatest(c, time '2230') from t1;").Check(testkit.Rows("20:00:01")) - // compare DateTime/DateTime as DateTime type, return DateTime type - tk.MustQuery("select greatest(a, timestamp '2021-12-31 12:00:00') from t1;").Check(testkit.Rows("2021-12-31 12:00:00")) - // compare Time/DateTime as DateTime type, return DateTime type - tk.MustQuery("select greatest(c, timestamp '2069-12-31 12:00:00') from t1;").Check(testkit.Rows("2069-12-31 12:00:00")) - // compare Date/DateTime as DateTime type, return DateTime type - tk.MustQuery("select greatest(date '21000101', a) from t1;").Check(testkit.Rows("2100-01-01 00:00:00")) - // compare JSON/JSON, return JSON type - tk.MustQuery("select greatest(cast(a as JSON), cast('3' as JSON)) from t1;").Check(testkit.Rows("3")) -} - -func TestIssue29708(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("CREATE TABLE t1 (a text)character set utf8 ;") - tk.MustExecToErr("INSERT INTO t1 VALUES (REPEAT(0125,200000000));") - tk.MustQuery("select * from t1").Check(nil) - - // test vectorized build-in function - tk.MustExec("insert into t1 (a) values ('a'),('b');") - tk.MustExecToErr("insert into t1 select REPEAT(a,200000000) from t1;") - tk.MustQuery("select a from t1 order by a;").Check([][]interface{}{ - {"a"}, - {"b"}, - }) - - // test cast - tk.MustExecToErr(`insert into t1 values (cast("a" as binary(4294967295)));`) - tk.MustQuery("select a from t1 order by a;").Check([][]interface{}{ - {"a"}, - {"b"}, - }) - - tk.MustExec("INSERT IGNORE INTO t1 VALUES (REPEAT(0125,200000000));") - tk.MustQuery("show warnings;").CheckContain("Result of repeat() was larger than max_allowed_packet (67108864) - truncated") - tk.MustQuery("select a from t1 order by a;").Check([][]interface{}{ - {nil}, - {"a"}, - {"b"}, - }) -} - -func TestIssue32488(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;") - tk.MustExec("insert into t values('Ęž'), ('İ');") - tk.MustExec("set @@tidb_enable_vectorized_expression = false;") - tk.MustQuery("select binary upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"ęž° Ęž"}}) - tk.MustQuery("select distinct upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"ęž° Ęž"}}) - tk.MustExec("set @@tidb_enable_vectorized_expression = true;") - tk.MustQuery("select binary upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"ęž° Ęž"}}) - tk.MustQuery("select distinct upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"ęž° Ęž"}}) -} - -func TestIssue33397(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;") - tk.MustExec("insert into t values(''), ('');") - tk.MustExec("set @@tidb_enable_vectorized_expression = true;") - result := tk.MustQuery("select compress(a) from t").Rows() - require.Equal(t, [][]interface{}{{""}, {""}}, result) -} - -func TestIssue34659(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a varchar(32))") - tk.MustExec("insert into t values(date_add(cast('00:00:00' as time), interval 1.1 second))") - result := tk.MustQuery("select * from t").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.1"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 second) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.1"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:00.000001"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1000000 microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.000000"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1111119 second) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.111111"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.0 second) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.0"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 second_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.100000"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1111111 second_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.111111"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 minute_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.100000"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1111111 minute_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.111111"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 minute_second) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:01:01"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1111111 minute_second) as char)").Rows() - require.Equal(t, [][]interface{}{{"308:38:31"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.100000"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1111111 hour_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.111111"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_second) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:01:01"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1111111 hour_second) as char)").Rows() - require.Equal(t, [][]interface{}{{"308:38:31"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 hour_minute) as char)").Rows() - require.Equal(t, [][]interface{}{{"01:01:00"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1.1 day_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.100000"}}, result) - - result = tk.MustQuery("select cast(date_add(cast('00:00:00' as time), interval 1111111 day_microsecond) as char)").Rows() - require.Equal(t, [][]interface{}{{"00:00:01.111111"}}, result) -} - -func TestIssue31799(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(i int, c varchar(32))") - tk.MustExec("insert into t values(1, date_add(cast('2001-01-01 00:00:00' as datetime), interval 1 second))") - tk.MustExec("insert into t values(2, date_add(cast('2001-01-01 00:00:00' as datetime(6)), interval 1 second))") - tk.MustExec("insert into t values(3, date_add(cast('2001-01-01 00:00:00' as datetime), interval 1.1 second))") - tk.MustExec("insert into t values(4, date_add(cast('2001-01-01 00:00:00' as datetime(6)), interval 1.1 second))") - tk.MustExec("insert into t values(5, date_add(cast('00:00:00' as time), interval 1.1 second))") - tk.MustQuery("select c from t order by i").Check([][]interface{}{{"2001-01-01 00:00:01"}, {"2001-01-01 00:00:01.000000"}, {"2001-01-01 00:00:01.1"}, {"2001-01-01 00:00:01.100000"}, {"00:00:01.1"}}) - tk.MustExec("drop table t") -} - -func TestIssue31867(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set time_zone = '+00:00'") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(ts timestamp(6) not null default current_timestamp(6) on update current_timestamp(6))") - tk.MustExec("insert into t values('1970-01-01 01:00:01.000000')") - tk.MustExec("insert into t values('1970-01-01 01:00:01.000001')") - tk.MustExec("insert into t values('1971-01-01 01:00:00.000000')") - tk.MustExec("insert into t values('1971-01-01 01:00:00.000001')") - tk.MustExec("insert into t values('2001-01-01 00:00:00.000000')") - tk.MustExec("insert into t values('2001-01-01 00:00:00.000001')") - tk.MustExec("insert into t values('2001-01-01 01:00:00.000000')") - tk.MustExec("insert into t values('2001-01-01 01:00:00.000001')") - tk.MustQuery("select date_add(ts, interval 1 minute) from t order by ts").Check([][]interface{}{ - {"1970-01-01 01:01:01.000000"}, - {"1970-01-01 01:01:01.000001"}, - {"1971-01-01 01:01:00.000000"}, - {"1971-01-01 01:01:00.000001"}, - {"2001-01-01 00:01:00.000000"}, - {"2001-01-01 00:01:00.000001"}, - {"2001-01-01 01:01:00.000000"}, - {"2001-01-01 01:01:00.000001"}, - }) - tk.MustQuery("select date_sub(ts, interval 1 minute) from t order by ts").Check([][]interface{}{ - {"1970-01-01 00:59:01.000000"}, - {"1970-01-01 00:59:01.000001"}, - {"1971-01-01 00:59:00.000000"}, - {"1971-01-01 00:59:00.000001"}, - {"2000-12-31 23:59:00.000000"}, - {"2000-12-31 23:59:00.000001"}, - {"2001-01-01 00:59:00.000000"}, - {"2001-01-01 00:59:00.000001"}, - }) - tk.MustExec("drop table t") -} - -func TestIssue31600(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set time_zone = '+00:00'") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (tm_fsp0 time(0), tm_fsp1 time(1), tm_fsp3 time(3),tm_fsp6 time(6), d date, dt_fsp0 datetime(0), dt_fsp1 datetime(1), dt_fsp3 datetime(3), dt_fsp6 datetime(6))") - tk.MustExec("insert into t values(null, '12:12:01.1', '12:12:02.123', '12:12:03.123456', '20221212', null, '2020/12/11 12:12:11.1', '2020/12/12 12:12:12.123', '2020/12/13 12:12:13.123456')") - tk.MustExec("insert into t values('12:12:00', null, '12:12:02.123', '12:12:03.123456', '20221212', '2020/12/10 12:12:10', null, '2020/12/12 12:12:12.123', '2020/12/13 12:12:13.123456')") - tk.MustExec("insert into t values('12:12:00', '12:12:01.1', null, '12:12:03.123456', '20221212', '2020/12/10 12:12:10', '2020/12/11 12:12:11.1', null, '2020/12/13 12:12:13.123456')") - tk.MustExec("insert into t values('12:12:00', '12:12:01.1', '12:12:02.123', null, '20221212', '2020/12/10 12:12:10', '2020/12/11 12:12:11.1', '2020/12/12 12:12:12.123', null)") - tk.MustQuery("select coalesce(null, tm_fsp0, tm_fsp1, tm_fsp3, tm_fsp6) from t").Check([][]interface{}{ - {"12:12:01.100000"}, - {"12:12:00.000000"}, - {"12:12:00.000000"}, - {"12:12:00.000000"}, - }) - tk.MustQuery("select coalesce(tm_fsp1, tm_fsp0, tm_fsp3) from t").Check([][]interface{}{ - {"12:12:01.100"}, - {"12:12:00.000"}, - {"12:12:01.100"}, - {"12:12:01.100"}, - }) - tk.MustQuery("select coalesce(tm_fsp3, tm_fsp0) from t").Check([][]interface{}{ - {"12:12:02.123"}, - {"12:12:02.123"}, - {"12:12:00.000"}, - {"12:12:02.123"}, - }) - tk.MustQuery("select coalesce(tm_fsp6) from t").Check([][]interface{}{ - {"12:12:03.123456"}, - {"12:12:03.123456"}, - {"12:12:03.123456"}, - {""}, - }) - - tk.MustQuery("select coalesce(null, dt_fsp0, dt_fsp1, dt_fsp3, dt_fsp6) from t").Check([][]interface{}{ - {"2020-12-11 12:12:11.100000"}, - {"2020-12-10 12:12:10.000000"}, - {"2020-12-10 12:12:10.000000"}, - {"2020-12-10 12:12:10.000000"}, - }) - tk.MustQuery("select coalesce(dt_fsp0, dt_fsp1, dt_fsp3) from t").Check([][]interface{}{ - {"2020-12-11 12:12:11.100"}, - {"2020-12-10 12:12:10.000"}, - {"2020-12-10 12:12:10.000"}, - {"2020-12-10 12:12:10.000"}, - }) - tk.MustQuery("select coalesce(dt_fsp3, dt_fsp0) from t").Check([][]interface{}{ - {"2020-12-12 12:12:12.123"}, - {"2020-12-12 12:12:12.123"}, - {"2020-12-10 12:12:10.000"}, - {"2020-12-12 12:12:12.123"}, - }) - tk.MustQuery("select coalesce(dt_fsp6) from t").Check([][]interface{}{ - {"2020-12-13 12:12:13.123456"}, - {"2020-12-13 12:12:13.123456"}, - {"2020-12-13 12:12:13.123456"}, - {""}, - }) - - tk.MustQuery("select coalesce(null, d) from t").Check([][]interface{}{ - {"2022-12-12"}, - {"2022-12-12"}, - {"2022-12-12"}, - {"2022-12-12"}, - }) - - tk.MustExec("drop table t") -} - -func TestIssue31569(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c int primary key, c2 enum('a', 'b'))") - tk.MustExec("set session sql_mode = ''") - tk.MustExec("insert into t values(4, 'a')") - tk.MustExec("insert into t values(4, 0) on duplicate key update c=values(c), c2=values(c2)") - // tidb produces two warnings here (when eval (4, 0) & values(c2)), which is slightly incompatible with mysql - tk.MustQuery("show warnings").Check([][]interface{}{ - {"Warning", "1265", "Data truncated for column 'c2' at row 1"}, - {"Warning", "1265", "Data truncated for column 'c2' at row 1"}, - }) - tk.MustExec("insert into t values(4, 'a') on duplicate key update c=values(c), c2=values(c2)") - tk.MustQuery("show warnings").Check([][]interface{}{}) - tk.MustExec("drop table t") -} - func TestTimestampAddWithFractionalSecond(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -7388,57 +5463,6 @@ func TestDateAddForNonExistingTimestamp(t *testing.T) { tk.MustExec("drop table t") } -func TestIssue31640(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("create table t(a json);") - tk.MustExec(`insert into t values ('"a"'), ('"B"'), ('"c"'), ('"D"'), ('{"a": 1}'), ('1'), ('{"b": 2}'), ('[1, 2]'), ('[3, 4]');`) - tk.MustQuery("select min(a) from t;").Check(testkit.Rows("1")) - tk.MustQuery("select max(a) from t;").Check(testkit.Rows("[3, 4]")) - tk.MustQuery("select min(a collate utf8mb4_bin) from t;").Check(testkit.Rows("\"B\"")) - tk.MustQuery("select max(a collate utf8mb4_bin) from t;").Check(testkit.Rows("{\"b\": 2}")) - tk.MustQuery("select min(a collate utf8mb4_unicode_ci) from t;").Check(testkit.Rows("\"a\"")) - tk.MustQuery("select max(a collate utf8mb4_unicode_ci) from t;").Check(testkit.Rows("1")) -} - -func TestIssue36279(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("SET timestamp=UNIX_TIMESTAMP('2011-11-01 17:48:00')") - - // test const - tk.MustQuery("SELECT cast(cast('12:12:12' as time) as datetime(6))").Check(testkit.Rows("2011-11-01 12:12:12.000000")) - - // test vec - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (tm time(6))") - tk.MustExec("insert into t values('23:59:59')") - tk.MustQuery("SELECT cast(tm as datetime(6)) from t").Check(testkit.Rows("2011-11-01 23:59:59.000000")) -} - -func TestIssue34998(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `PK_S_MULTI_43`(`COL1` time(2) NOT NULL, `COL2` time(2) NOT NULL, `COL3` time(2) DEFAULT NULL, PRIMARY KEY(`COL1`,`COL2`))") - tk.MustExec("insert into PK_S_MULTI_43(col1, col2) values('-512:37:22.00', '-512:37:22.00')") - tk.MustQuery("select extract(day_microsecond from '-512:37:22.00')").Check(testkit.Rows("-5123722000000")) - tk.MustQuery("select extract(day_microsecond from col1) from PK_S_MULTI_43").Check(testkit.Rows("-5123722000000")) -} - -func TestIssue36358(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(c datetime(6))") - tk.MustExec("insert into t values('2001-01-01 02:03:04.050607')") - tk.MustQuery("select extract(day_microsecond from cast('2001-01-01 02:03:04.050607' as datetime(6))) from t").Check(testkit.Rows("1020304050607")) - tk.MustQuery("select extract(day_microsecond from c) from t").Check(testkit.Rows("1020304050607")) -} - func TestJSONObjectWithBinaryCharset(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -7617,92 +5641,6 @@ func TestRegexpPushdown(t *testing.T) { " └─TableFullScan_6 10000.00 cop[tikv] table:regbin keep order:false, stats:pseudo")) } -func TestIssue35184(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar char(44))") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - tk.MustExec("insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789')") - - result := tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - unixTime1 := "1973-11-30 08:38:10.123400" - unixTime2 := "1973-11-30 08:38:10.123457" - result.Check(testkit.Rows(unixTime1, unixTime2)) - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar varchar(44))") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - tk.MustExec("insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows(unixTime1, unixTime2)) - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar blob)") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - tk.MustExec("insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows(unixTime1, unixTime2)) - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar tinyblob)") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - tk.MustExec("insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows(unixTime1, unixTime2)) - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar mediumblob)") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - tk.MustExec("insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows(unixTime1, unixTime2)) - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar longblob)") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - tk.MustExec("insert into ft values(1234567890,123467890.123456789,123467890.123456789,'123467890.123456789')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows(unixTime1, unixTime2)) - - tk.MustExec("truncate table ft") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234000000000000000000100111111111')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows(unixTime1)) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect DECIMAL value: '123467890.1234000000000000000000100111111111'")) - - tk.MustExec("truncate table ft") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'11111123467890.1234')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft") - result.Check(testkit.Rows("")) - - tk.MustExec("drop table if exists ft") - tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar char(44))") - tk.MustExec("insert into ft values(1234567890,123467890.1234,123467890.1234,'123467890.1234')") - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar) from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ") - result.Check(testkit.Rows(unixTime1)) - - result = tk.MustQuery("SELECT FROM_UNIXTIME(cast(tchar as decimal(44,1))) from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ") - result.Check(testkit.Rows("1973-11-30 08:38:10.1")) - - result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar,'%Y%m%d') from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ") - result.Check(testkit.Rows("19731130")) -} - -func TestFix38127(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(dou double, varc varchar(100))") - tk.MustExec("insert into t values (1.23e23, '111111111111111111111111111111111111111111111111111111111111111111111111111')") - tk.MustQuery("select from_unixtime(dou) from t").Check(testkit.Rows("")) - tk.MustQuery("select from_unixtime(varc) from t").Check(testkit.Rows("")) - tk.MustQuery("select from_unixtime(dou, '%Y-%m-%d') from t").Check(testkit.Rows("")) - tk.MustQuery("select from_unixtime(varc, '%Y-%m-%d') from t").Check(testkit.Rows("")) -} - func TestJSONStorageFree(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -7715,23 +5653,6 @@ func TestJSONStorageFree(t *testing.T) { require.Error(t, err, "[json:3140]Invalid JSON text: The document root must not be followed by other values.") } -func TestIssue38736(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE t0(c0 BOOL, c1 INT);") - tk.MustExec("CREATE TABLE t1 LIKE t0;") - tk.MustExec("CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT IS_IPV4(t0.c1) FROM t0, t1;") - tk.MustExec("INSERT INTO t0(c0, c1) VALUES (true, 0);") - tk.MustExec("INSERT INTO t1(c0, c1) VALUES (true, 2);") - - // The filter is evaled as false. - tk.MustQuery("SELECT v0.c0 FROM v0 WHERE (v0.c0)NOT LIKE(BINARY v0.c0);").Check(testkit.Rows()) - - // Also the filter is evaled as false. - tk.MustQuery("SELECT v0.c0 FROM v0 WHERE (v0.c0)NOT LIKE(BINARY v0.c0) or v0.c0 > 0").Check(testkit.Rows()) -} - func TestJSONExtractFromLast(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -7764,28 +5685,6 @@ func TestIfNullParamMarker(t *testing.T) { tk.MustExec(`execute pr1 using @a,@b;`) } -func TestIssue39146(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `sun` ( `dest` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("insert into sun values('20231020');") - tk.MustExec("set @@sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';") - tk.MustExec("set @@tidb_enable_vectorized_expression = on;") - tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10")) - tk.MustExec("set @@tidb_enable_vectorized_expression = off;") - tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10")) -} - -func TestIssue40536(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `6bf9e76d-ab44-4031-8a07-418b10741580` (\n `e0b5f703-6cfe-49b4-bc21-16a6455e43a7` set('7','va','ung60','ow','1g','gxwz5','uhnh','k','5la1','q8d9c','1f') NOT NULL DEFAULT '7,1g,uhnh,5la1,q8d9c',\n `fbc3527f-9617-4b9d-a5dc-4be31c00d8a5` datetime DEFAULT '6449-09-28 14:39:04',\n PRIMARY KEY (`e0b5f703-6cfe-49b4-bc21-16a6455e43a7`) /*T![clustered_index] CLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;") - tk.MustExec("CREATE TABLE `8919f3f4-25be-4a1a-904a-bb5e863d8fc8` (\n `9804d5f2-cbc7-43b7-b241-ea2656dc941a` enum('s951','36d','ua65','49yru','6l2em','4ea','jf2d2','vprsc','3yl7n','hz','ov') DEFAULT '4ea',\n `323cdbcb-0c14-4362-90ab-ea42caaed6a5` year(4) NOT NULL DEFAULT '1983',\n `b9b70f39-1a02-4114-9d7d-fa6259c1b691` time DEFAULT '20:18:04',\n PRIMARY KEY (`323cdbcb-0c14-4362-90ab-ea42caaed6a5`) /*T![clustered_index] CLUSTERED */,\n KEY `a704d6bb-772b-44ea-8cb0-6f7491c1aaa6` (`323cdbcb-0c14-4362-90ab-ea42caaed6a5`,`9804d5f2-cbc7-43b7-b241-ea2656dc941a`)\n) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin;") - tk.MustExec("delete from `6bf9e76d-ab44-4031-8a07-418b10741580` where not( `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( select `9804d5f2-cbc7-43b7-b241-ea2656dc941a` from `8919f3f4-25be-4a1a-904a-bb5e863d8fc8` where `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( '1f' ) and `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` in ( '1g' ,'va' ,'uhnh' ) ) ) and not( IsNull( `6bf9e76d-ab44-4031-8a07-418b10741580`.`e0b5f703-6cfe-49b4-bc21-16a6455e43a7` ) );\n") -} - func TestIssue40015(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -7800,69 +5699,3 @@ func TestIssue40015(t *testing.T) { "", )) } - -func TestAesDecryptionVecEvalWithZeroChunk(t *testing.T) { - // see issue: https://github.com/pingcap/tidb/issues/43063 - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table test (name1 blob,name2 blob)") - tk.MustExec("insert into test values(aes_encrypt('a', 'x'), aes_encrypt('b', 'x'))") - tk.MustQuery("SELECT * FROM test WHERE CAST(AES_DECRYPT(name1, 'x') AS CHAR) = '00' AND CAST(AES_DECRYPT(name2, 'x') AS CHAR) = '1'").Check(testkit.Rows()) -} - -func TestIfFunctionWithNull(t *testing.T) { - // issue 43805 - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists ordres;") - tk.MustExec("CREATE TABLE orders (id bigint(20) unsigned NOT NULL ,account_id bigint(20) unsigned NOT NULL DEFAULT '0' ,loan bigint(20) unsigned NOT NULL DEFAULT '0' ,stage_num int(20) unsigned NOT NULL DEFAULT '0' ,apply_time bigint(20) unsigned NOT NULL DEFAULT '0' ,PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */,KEY idx_orders_account_id (account_id),KEY idx_orders_apply_time (apply_time));") - tk.MustExec("insert into orders values (20, 210802010000721168, 20000 , 2 , 1682484268727), (22, 210802010000721168, 35100 , 4 , 1650885615002);") - tk.MustQuery("select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1;").Sort().Check( - testkit.Rows("20000 35100")) -} - -func TestIssue41733AndIssue45410(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database testIssue41733") - defer tk.MustExec("drop database testIssue41733") - tk.MustExec("use testIssue41733") - - tk.MustExec("create table t_tiny (c0 TINYINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_tiny(c0) VALUES (1E9)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_tiny;").Check(testkit.Rows("255")) - - tk.MustExec("create table t_small (c0 SMALLINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_small(c0) VALUES (1E9)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_small;").Check(testkit.Rows("65535")) - - tk.MustExec("create table t_medium (c0 MEDIUMINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_medium(c0) VALUES (1E9)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_medium;").Check(testkit.Rows("16777215")) - - tk.MustExec("create table t_int (c0 INT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_int(c0) VALUES (1E20)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_int;").Check(testkit.Rows("4294967295")) - - tk.MustExec("create table t_big (c0 BIGINT UNSIGNED)") - tk.MustExec("INSERT IGNORE INTO t_big(c0) VALUES (1E20)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1")) - tk.MustQuery("select * from t_big;").Check(testkit.Rows("18446744073709551615")) - - // Issue 45410 - tk.MustExec("create database testIssue45410") - defer tk.MustExec("drop database testIssue45410") - tk.MustExec("use testIssue45410") - - tk.MustExec("DROP TABLE IF EXISTS t1;") - tk.MustExec("CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL );") - tk.MustExec("INSERT INTO t1 VALUES (0);") - tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1")) -}