diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index c4938171a8f..97ab9173c2d 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -5301,7 +5301,6 @@ f1 Warnings: Warning 1292 Incorrect datetime value: 'zz' Warning 1292 Incorrect datetime value: 'aa' -Warning 1292 Incorrect datetime value: 'zz' SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index 61a8cb990cc..601fcc116b7 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -5312,7 +5312,6 @@ f1 Warnings: Warning 1292 Incorrect datetime value: 'zz' Warning 1292 Incorrect datetime value: 'aa' -Warning 1292 Incorrect datetime value: 'zz' SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index c4938171a8f..97ab9173c2d 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -5301,7 +5301,6 @@ f1 Warnings: Warning 1292 Incorrect datetime value: 'zz' Warning 1292 Incorrect datetime value: 'aa' -Warning 1292 Incorrect datetime value: 'zz' SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ; f1 0000-00-00 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 3d941eb28b0..6b3663489b0 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -402,13 +402,13 @@ EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03') EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; date 2002-08-03 diff --git a/mysql-test/r/subselect_no_exists_to_in.result b/mysql-test/r/subselect_no_exists_to_in.result index 3958fd6f5e4..b6984cac86f 100644 --- a/mysql-test/r/subselect_no_exists_to_in.result +++ b/mysql-test/r/subselect_no_exists_to_in.result @@ -406,13 +406,13 @@ EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03') EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; date 2002-08-03 diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 9244f7eced1..a0922b95e35 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -409,13 +409,13 @@ EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03') EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; date 2002-08-03 diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 79afacc5145..9b38ab43d26 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -405,13 +405,13 @@ EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03') EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; date 2002-08-03 diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index f52129d7cfb..672999922fa 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -408,13 +408,13 @@ EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03') EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; date 2002-08-03 diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 40fbf9c285b..5247de1144e 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -405,13 +405,13 @@ EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03') EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = DATE'2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; date 2002-08-03 diff --git a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result index f14b37ff390..aa9a8193d56 100644 --- a/mysql-test/r/type_date.result +++ b/mysql-test/r/type_date.result @@ -503,12 +503,12 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a BETWEEN '2001-01-01 id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '2001-01-01') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = DATE'2001-01-01') EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a IN ('2001-01-01','2001-01-02'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '2001-01-01') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = DATE'2001-01-01') DROP TABLE t1; # # End of 10.1 tests @@ -546,7 +546,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Warning 1292 Truncated incorrect date value: '2001-01-01x' -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '2001-01-01x') and ((hex(DATE'2001-01-01')) <> concat('xx',rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'2001-01-01') and ((hex(DATE'2001-01-01')) <> concat('xx',rand()))) DROP TABLE t1; CREATE TABLE t1 (a DATE); INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-02'); @@ -565,14 +565,14 @@ SELECT * FROM t1 WHERE LENGTH(a)=11+RAND() AND a=' 2001-01-01'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' 2001-01-01') and ((length(DATE'2001-01-01')) = (11 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'2001-01-01') and ((length(DATE'2001-01-01')) = (11 + rand()))) EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=11+RAND() AND a=' garbage '; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Warning 1292 Incorrect datetime value: ' garbage ' -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' garbage ') and (length(`test`.`t1`.`a`) = (11 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'0000-00-00') and ((length(DATE'0000-00-00')) = (11 + rand()))) DROP TABLE t1; CREATE TABLE t1 (a DATE); INSERT INTO t1 VALUES ('2001-01-01'),('2001-01-01'); @@ -591,8 +591,162 @@ SELECT * FROM t1 WHERE LENGTH(a)=8+RAND() AND a='20010101'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '20010101') and ((length(DATE'2001-01-01')) = (8 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'2001-01-01') and ((length(DATE'2001-01-01')) = (8 + rand()))) DROP TABLE t1; # +# MDEV-8706 Wrong result for SELECT..WHERE time_column=TIMESTAMP'2015-08-30 00:00:00' AND time_column='00:00:00' +# +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIME'00:00:00'; +a +2015-08-30 +SELECT * FROM t1 WHERE LENGTH(a)=10; +a +2015-08-30 +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'00:00:00'; +a +2015-08-30 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = DATE'2015-08-30') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIME'00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'2015-08-30') and ((length(DATE'2015-08-30')) = (30 + rand()))) +DROP TABLE t1; +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIME'24:00:00'; +a +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10; +a +2015-08-30 +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'24:00:00'; +a +2015-08-31 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'24:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = DATE'2015-08-31') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIME'24:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'2015-08-31') and ((length(DATE'2015-08-31')) = (30 + rand()))) +DROP TABLE t1; +# In this example '00:00:00' is not recognized as TIME'00:00:00' +# and is treated as DATE'0000-00-00'. +# This may change after MDEV-8322 Distinguish between time and date strings more carefully +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a='00:00:00'; +a +SELECT * FROM t1 WHERE LENGTH(a)=10; +a +2015-08-30 +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='00:00:00'; +a +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = DATE'0000-00-00') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'0000-00-00') and ((length(DATE'0000-00-00')) = (30 + rand()))) +DROP TABLE t1; +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00'; +a +2015-08-30 +SELECT * FROM t1 WHERE LENGTH(a)=10; +a +2015-08-30 +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00'; +a +2015-08-30 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2015-08-30 00:00:00') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2015-08-30 00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2015-08-30 00:00:00') and ((length(DATE'2015-08-30')) = (30 + rand()))) +DROP TABLE t1; +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00.1'; +a +SELECT * FROM t1 WHERE LENGTH(a)=10; +a +2015-08-30 +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00.1'; +a +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00.1'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2015-08-30 00:00:00.1') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2015-08-30 00:00:00.1'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2015-08-30 00:00:00.1') and ((length(DATE'2015-08-30')) = (30 + rand()))) +DROP TABLE t1; +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a='2015-08-30 00:00:00'; +a +2015-08-30 +SELECT * FROM t1 WHERE LENGTH(a)=10; +a +2015-08-30 +2015-08-31 +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='2015-08-30 00:00:00'; +a +2015-08-30 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='2015-08-30 00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = DATE'2015-08-30') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='2015-08-30 00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = DATE'2015-08-30') and ((length(DATE'2015-08-30')) = (30 + rand()))) +DROP TABLE t1; +SET timestamp=DEFAULT; +# # End of 10.1 tests # diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index d96317408b0..7f748275809 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -411,21 +411,20 @@ a 00:00:00 Warnings: Warning 1292 Truncated incorrect time value: '00:00:00x' -Warning 1292 Truncated incorrect time value: '00:00:00x' EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=8 AND a='00:00:00x'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Warning 1292 Truncated incorrect time value: '00:00:00x' -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '00:00:00x') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='00:00:00x'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Warning 1292 Truncated incorrect time value: '00:00:00x' -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '00:00:00x') and ((length(TIME'00:00:00')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and ((length(TIME'00:00:00')) = (30 + rand()))) DROP TABLE t1; # Trailing fractional digits in string literals CREATE TABLE t1 (a TIME); @@ -442,13 +441,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a='00:00:00.000000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '00:00:00.000000') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='00:00:00.000000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '00:00:00.000000') and ((length(TIME'00:00:00')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and ((length(TIME'00:00:00')) = (30 + rand()))) DROP TABLE t1; # Trailing fractional digits in temporal literals CREATE TABLE t1 (a TIME); @@ -508,13 +507,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a=' 00:00:00'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = ' 00:00:00') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=' 00:00:00'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = ' 00:00:00') and ((length(TIME'00:00:00')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and ((length(TIME'00:00:00')) = (30 + rand()))) DROP TABLE t1; # Numeric format in string literals CREATE TABLE t1 (a TIME); @@ -531,13 +530,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a='000000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '000000') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='000000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '000000') and ((length(TIME'00:00:00')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and ((length(TIME'00:00:00')) = (30 + rand()))) DROP TABLE t1; # # MDEV-8766 Wrong result for SELECT..WHERE LENGTH(time_column)=8 AND time_column=TIMESTAMP'2001-01-01 10:20:31' @@ -560,13 +559,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a=TIMESTAMP'2001-01-01 10:20:31'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:31') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2001-01-01 10:20:31'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31') and ((length(TIME'10:20:31')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31') and ((length(TIME'10:20:31')) = (30 + rand()))) DROP TABLE t1; # TIMESTAMP literal with a bigger scale and fractional second truncation # Ok to propagate with precision truncation @@ -584,13 +583,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a=TIMESTAMP'2001-01-01 10:20:31.123'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31.123') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:31.123000') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2001-01-01 10:20:31.123'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31.123') and ((length(TIME'10:20:31')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31.123000') and ((length(TIME'10:20:31')) = (30 + rand()))) DROP TABLE t1; # TIMESTAMP literal with a bigger scale and no fractional second truncation # Ok to propagate @@ -610,13 +609,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a=TIMESTAMP'2001-01-01 10:20:31.000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31.000') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:31') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2001-01-01 10:20:31.000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31.000') and ((length(TIME'10:20:31')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31') and ((length(TIME'10:20:31')) = (30 + rand()))) DROP TABLE t1; # TIMESTAMP literal with a smaller scale # Ok to propagate @@ -639,7 +638,7 @@ SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2001-01-01 10:20:31.1 id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'2001-01-01 10:20:31.123') and ((length(TIME'10:20:31.123000')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31.123000') and ((length(TIME'10:20:31.123000')) = (30 + rand()))) DROP TABLE t1; # TIME literal with a bigger scale and fractional second truncation # Ok to propagate with precision truncation @@ -730,13 +729,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a='10:20:31.123'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '10:20:31.123') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:31.123000') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='10:20:31.123'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '10:20:31.123') and ((length(TIME'10:20:31')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31.123000') and ((length(TIME'10:20:31')) = (30 + rand()))) DROP TABLE t1; # TIME-alike string literal with a bigger scale and no fractional second truncation # Ok to propagate @@ -756,13 +755,13 @@ SELECT * FROM t1 WHERE LENGTH(a)=8 AND a='10:20:31.000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '10:20:31.000') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:31') EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='10:20:31.000'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '10:20:31.000') and ((length(TIME'10:20:31')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31') and ((length(TIME'10:20:31')) = (30 + rand()))) DROP TABLE t1; # TIME-alike string literal with a smaller scale # Ok to propagate @@ -785,7 +784,7 @@ SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='10:20:31.123'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '10:20:31.123') and ((length(TIME'10:20:31.123000')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:31.123000') and ((length(TIME'10:20:31.123000')) = (30 + rand()))) DROP TABLE t1; SET timestamp=DEFAULT; SET @@old_mode=zero_date_time_cast; @@ -816,13 +815,13 @@ SELECT * FROM t1 WHERE a=TIMESTAMP'0000-00-00 10:20:30' AND LENGTH(a)=8; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIMESTAMP'0000-00-00 10:20:30') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:30') EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=TIMESTAMP'0000-00-00 10:20:30' AND LENGTH(a)=30+RAND(); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIMESTAMP'0000-00-00 10:20:30') and ((length(TIME'10:20:30')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:30') and ((length(TIME'10:20:30')) = (30 + rand()))) # Old mode, TIMESTAMP literal, zon-zero YYYYMMDD, no propagation SELECT * FROM t1 WHERE a=TIMESTAMP'0000-00-01 10:20:30'; a @@ -854,13 +853,13 @@ SELECT * FROM t1 WHERE a='0000-00-00 10:20:30' AND LENGTH(a)=8; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '0000-00-00 10:20:30') +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'10:20:30') EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='0000-00-00 10:20:30' AND LENGTH(a)=30+RAND(); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = '0000-00-00 10:20:30') and ((length(TIME'10:20:30')) = (30 + rand()))) +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'10:20:30') and ((length(TIME'10:20:30')) = (30 + rand()))) # Old mode, TIMESTAMP-alike literal, zon-zero YYYYMMDD, no propagation SELECT * FROM t1 WHERE a='0000-00-01 10:20:30'; a @@ -883,5 +882,81 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` DROP TABLE t1; SET @@old_mode=DEFAULT; # +# MDEV-8706 Wrong result for SELECT..WHERE time_column=TIMESTAMP'2015-08-30 00:00:00' AND time_column='00:00:00' +# +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('00:00:00'),('00:00:01'); +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00'; +a +00:00:00 +SELECT * FROM t1 WHERE a='00:00:00'; +a +00:00:00 +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00' AND a='00:00:00'; +a +00:00:00 +SELECT * FROM t1 WHERE a>=TIMESTAMP'2015-08-30 00:00:00' AND a='00:00:00'; +a +00:00:00 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a>=TIMESTAMP'2015-08-30 00:00:00' AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') +DROP TABLE t1; +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('00:00:00'),('00:00:01'); +SELECT * FROM t1 WHERE DATE(a)<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00'; +a +00:00:00 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE DATE(a)<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and (timestamp('2015-08-08',(TIME'00:00:00' + rand())) <= TIMESTAMP'2015-08-30 00:00:00.1')) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00.1'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00.100000') and (timestamp('2015-08-08',(TIME'00:00:00' + rand())) <= TIMESTAMP'2015-08-30 00:00:00.1')) +DROP TABLE t1; +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('00:00:00'),('00:00:01'); +SELECT * FROM t1 WHERE DATE(a)<=DATE'2015-08-30' AND a='00:00:00'; +a +00:00:00 +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE DATE(a)<=DATE'2015-08-30' AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = TIME'00:00:00') +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=DATE'2015-08-30' AND a='00:00:00'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00') and (timestamp('2015-08-08',(TIME'00:00:00' + rand())) <= DATE'2015-08-30')) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=DATE'2015-08-30' AND a='00:00:00.1'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = TIME'00:00:00.100000') and (timestamp('2015-08-08',(TIME'00:00:00' + rand())) <= DATE'2015-08-30')) +DROP TABLE t1; +SET timestamp=DEFAULT; +# # End of 10.1 tests # diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test index e67bc47f1d7..1b8cd89b998 100644 --- a/mysql-test/t/type_date.test +++ b/mysql-test/t/type_date.test @@ -451,6 +451,85 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)=8+RAND() AND a='20010101'; DROP TABLE t1; +--echo # +--echo # MDEV-8706 Wrong result for SELECT..WHERE time_column=TIMESTAMP'2015-08-30 00:00:00' AND time_column='00:00:00' +--echo # +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); + +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIME'00:00:00'; +SELECT * FROM t1 WHERE LENGTH(a)=10; +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIME'00:00:00'; +DROP TABLE t1; + +# Special case: zero TIME part after conversion to DATETIME +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIME'24:00:00'; +SELECT * FROM t1 WHERE LENGTH(a)=10; +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'24:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIME'24:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIME'24:00:00'; +DROP TABLE t1; + +--echo # In this example '00:00:00' is not recognized as TIME'00:00:00' +--echo # and is treated as DATE'0000-00-00'. +--echo # This may change after MDEV-8322 Distinguish between time and date strings more carefully +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a='00:00:00'; +SELECT * FROM t1 WHERE LENGTH(a)=10; +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='00:00:00'; +DROP TABLE t1; + +# DATETIME native literal +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00'; +SELECT * FROM t1 WHERE LENGTH(a)=10; +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2015-08-30 00:00:00'; +DROP TABLE t1; + +# DATETIME native literal with non-zero time +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00.1'; +SELECT * FROM t1 WHERE LENGTH(a)=10; +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00.1'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a=TIMESTAMP'2015-08-30 00:00:00.1'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=TIMESTAMP'2015-08-30 00:00:00.1'; +DROP TABLE t1; + +# DATETIME-alike string literal +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2015-08-30'),('2015-08-31'); +SELECT * FROM t1 WHERE a='2015-08-30 00:00:00'; +SELECT * FROM t1 WHERE LENGTH(a)=10; +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='2015-08-30 00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=10 AND a='2015-08-30 00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a='2015-08-30 00:00:00'; +DROP TABLE t1; + +SET timestamp=DEFAULT; --echo # --echo # End of 10.1 tests diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index c54f019e33c..f655ebdb87c 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -534,6 +534,48 @@ DROP TABLE t1; SET @@old_mode=DEFAULT; +--echo # +--echo # MDEV-8706 Wrong result for SELECT..WHERE time_column=TIMESTAMP'2015-08-30 00:00:00' AND time_column='00:00:00' +--echo # +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('00:00:00'),('00:00:01'); +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00'; +SELECT * FROM t1 WHERE a='00:00:00'; +SELECT * FROM t1 WHERE a=TIMESTAMP'2015-08-30 00:00:00' AND a='00:00:00'; +SELECT * FROM t1 WHERE a>=TIMESTAMP'2015-08-30 00:00:00' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a>=TIMESTAMP'2015-08-30 00:00:00' AND a='00:00:00'; +DROP TABLE t1; + +# TIMESTAMP literal with fractional seconds +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('00:00:00'),('00:00:01'); +SELECT * FROM t1 WHERE DATE(a)<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE DATE(a)<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=TIMESTAMP'2015-08-30 00:00:00.1' AND a='00:00:00.1'; +DROP TABLE t1; + +# DATE literal +SET timestamp=UNIX_TIMESTAMP('2015-08-30 10:20:30'); +CREATE TABLE t1 (a TIME); +INSERT INTO t1 VALUES ('00:00:00'),('00:00:01'); +SELECT * FROM t1 WHERE DATE(a)<=DATE'2015-08-30' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE DATE(a)<=DATE'2015-08-30' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=DATE'2015-08-30' AND a='00:00:00'; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE TIMESTAMP('2015-08-08',a+RAND())<=DATE'2015-08-30' AND a='00:00:00.1'; +DROP TABLE t1; + +SET timestamp=DEFAULT; + --echo # --echo # End of 10.1 tests --echo # diff --git a/sql/field.cc b/sql/field.cc index dcbea63f5c0..e9c20d1d92a 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5841,7 +5841,30 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx, Item *const_item) { switch (ctx.subst_constraint()) { - case IDENTITY_SUBST: + case ANY_SUBST: + if (const_item->field_type() != MYSQL_TYPE_TIME) + { + MYSQL_TIME ltime; + // Get the value of const_item with conversion from DATETIME to TIME + if (const_item->get_time_with_conversion(thd, <ime, TIME_TIME_ONLY)) + return NULL; + /* + Replace a DATE/DATETIME constant to a TIME constant: + WHERE LENGTH(time_column)=8 + AND time_column=TIMESTAMP'2015-08-30 10:20:30'; + to: + WHERE LENGTH(time_column)=10 + AND time_column=TIME'10:20:30' + + (assuming CURRENT_DATE is '2015-08-30' + */ + return new (thd->mem_root) Item_time_literal(thd, <ime, + ltime.second_part ? + TIME_SECOND_PART_DIGITS : + 0); + } + break; + case IDENTITY_SUBST: if (const_item->field_type() != MYSQL_TYPE_TIME || const_item->decimals != decimals()) { @@ -5865,8 +5888,6 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx, return new (thd->mem_root) Item_time_literal(thd, <ime, decimals()); } break; - case ANY_SUBST: - break; } return const_item; } @@ -6308,6 +6329,35 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, Item *const_item) { switch (ctx.subst_constraint()) { + case ANY_SUBST: + if (!is_temporal_type_with_date(const_item->field_type())) + { + MYSQL_TIME ltime; + // Get the value of const_item with conversion from TIME to DATETIME + if (const_item->get_date_with_conversion(<ime, + TIME_FUZZY_DATES | TIME_INVALID_DATES)) + return NULL; + /* + Replace the constant to a DATE or DATETIME constant. + Example: + WHERE LENGTH(date_column)=10 + AND date_column=TIME'10:20:30'; + to: + WHERE LENGTH(date_column)=10 + AND date_column=TIMESTAMP'2015-08-30 10:20:30' + + (assuming CURRENT_DATE is '2015-08-30' + */ + if (non_zero_hhmmssuu(<ime)) + return new (thd->mem_root) + Item_datetime_literal_for_invalid_dates(thd, <ime, + ltime.second_part ? + TIME_SECOND_PART_DIGITS : 0); + datetime_to_date(<ime); + return new (thd->mem_root) + Item_date_literal_for_invalid_dates(thd, <ime); + } + break; case IDENTITY_SUBST: if (const_item->field_type() != MYSQL_TYPE_DATE) { @@ -6316,11 +6366,10 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, const_item->get_date_with_conversion(<ime, 0) : const_item->get_date(<ime, 0)) return NULL; + datetime_to_date(<ime); return new (thd->mem_root) Item_date_literal(thd, <ime); } break; - case ANY_SUBST: - break; } return const_item; } diff --git a/sql/item.h b/sql/item.h index b356a1db4bb..3dfb7d8ec06 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3385,6 +3385,62 @@ public: }; +/** + An error-safe counterpart for Item_date_literal +*/ +class Item_date_literal_for_invalid_dates: public Item_date_literal +{ + /** + During equal field propagation we can replace non-temporal constants + found in equalities to their native temporal equivalents: + WHERE date_column='2001-01-01' ... -> + WHERE date_column=DATE'2001-01-01' ... + + This is done to make the eqial field propagation code handle mixtures of + different temporal types in the same expressions easier (MDEV-8706), e.g. + WHERE LENGTH(date_column)=10 AND date_column=TIME'00:00:00' + + Item_date_literal_for_invalid_dates::get_date() + (unlike the regular Item_date_literal::get_date()) + does not check the result for NO_ZERO_IN_DATE and NO_ZER_DATE, + always returns success (false), and does not produce error/warning messages. + + We need these _for_invalid_dates classes to be able to rewrite: + SELECT * FROM t1 WHERE date_column='0000-00-00' ... + to: + SELECT * FROM t1 WHERE date_column=DATE'0000-00-00' ... + + to avoid returning NULL value instead of '0000-00-00' even + in sql_mode=TRADITIONAL. + */ +public: + Item_date_literal_for_invalid_dates(THD *thd, MYSQL_TIME *ltime) + :Item_date_literal(thd, ltime) { } + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) + { + *ltime= cached_time; + return (null_value= false); + } +}; + + +/** + An error-safe counterpart for Item_datetime_literal + (see Item_date_literal_for_invalid_dates for comments) +*/ +class Item_datetime_literal_for_invalid_dates: public Item_datetime_literal +{ +public: + Item_datetime_literal_for_invalid_dates(THD *thd, + MYSQL_TIME *ltime, uint dec_arg) + :Item_datetime_literal(thd, ltime, dec_arg) { } + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) + { + *ltime= cached_time; + return (null_value= false); + } +}; + /** Array of items, e.g. function or aggerate function arguments. diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index fe4084d0402..e5d20e6e33c 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -125,6 +125,7 @@ public: ((Item_func*)owner)->functype() == Item_func::EQUAL_FUNC); } Item_result compare_type() const { return m_compare_type; } + Arg_comparator *subcomparators() const { return comparators; } void cleanup() { delete [] comparators; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3f2c2ead09c..6e4b9aeba6b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12522,7 +12522,8 @@ finish: FALSE otherwise */ -static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item, +static bool check_simple_equality(THD *thd, const Item::Context &ctx, + Item *left_item, Item *right_item, COND_EQUAL *cond_equal) { Item *orig_left_item= left_item; @@ -12686,6 +12687,11 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item, cond_equal->current_level.push_back(item_equal, thd->mem_root); item_equal->set_context_field(field_item); } + Item *const_item2= field_item->field->get_equal_const_item(thd, ctx, + const_item); + if (!const_item2) + return false; + if (item_equal) { /* @@ -12693,11 +12699,11 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item, already contains a constant and its value is not equal to the value of const_item. */ - item_equal->add_const(thd, const_item, orig_field_item); + item_equal->add_const(thd, const_item2, orig_field_item); } else { - item_equal= new (thd->mem_root) Item_equal(thd, const_item, + item_equal= new (thd->mem_root) Item_equal(thd, const_item2, orig_field_item, TRUE); item_equal->set_context_field(field_item); cond_equal->current_level.push_back(item_equal, thd->mem_root); @@ -12735,7 +12741,8 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item, FALSE otherwise */ -static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row, +static bool check_row_equality(THD *thd, const Arg_comparator *comparators, + Item *left_row, Item_row *right_row, COND_EQUAL *cond_equal, List* eq_list) { uint n= left_row->cols(); @@ -12747,14 +12754,20 @@ static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row, if (left_item->type() == Item::ROW_ITEM && right_item->type() == Item::ROW_ITEM) { - is_converted= check_row_equality(thd, + is_converted= check_row_equality(thd, + comparators[i].subcomparators(), (Item_row *) left_item, (Item_row *) right_item, cond_equal, eq_list); } else { - is_converted= check_simple_equality(thd, left_item, right_item, + const Arg_comparator *tmp= &comparators[i]; + is_converted= check_simple_equality(thd, + Item::Context(Item::ANY_SUBST, + tmp->compare_type(), + tmp->cmp_collation.collation), + left_item, right_item, cond_equal); } @@ -12812,11 +12825,16 @@ bool Item_func_eq::check_equality(THD *thd, COND_EQUAL *cond_equal, right_item->type() == Item::ROW_ITEM) { return check_row_equality(thd, + cmp.subcomparators(), (Item_row *) left_item, (Item_row *) right_item, cond_equal, eq_list); } - return check_simple_equality(thd, left_item, right_item, cond_equal); + return check_simple_equality(thd, + Context(ANY_SUBST, + compare_type(), + compare_collation()), + left_item, right_item, cond_equal); }