Skip to content

Commit

Permalink
MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) r…
Browse files Browse the repository at this point in the history
…eturn different results

MDEV-8660 TIME(int_zerofill_column) returns a wrong result
  • Loading branch information
Alexander Barkov committed Sep 23, 2015
1 parent b9da3ba commit 3ad035f
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 123 deletions.
8 changes: 4 additions & 4 deletions mysql-test/r/func_set.result
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 )
8
8
Warnings:
Warning 1292 Incorrect datetime value: '10'
Warning 1292 Incorrect datetime value: '11'
Warning 1292 Incorrect datetime value: '10' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '11' for column 'pk' at row 2
DROP TABLE t1;
#
# End of 5.3 tests
Expand Down Expand Up @@ -233,8 +233,8 @@ INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 )
8
8
Warnings:
Warning 1292 Incorrect datetime value: '10'
Warning 1292 Incorrect datetime value: '11'
Warning 1292 Incorrect datetime value: '10' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '11' for column 'pk' at row 2
DROP TABLE t1;
#
# End of 5.3 tests
Expand Down
13 changes: 0 additions & 13 deletions mysql-test/r/func_time.result
Original file line number Diff line number Diff line change
Expand Up @@ -1834,25 +1834,14 @@ select last_day(f2) from t1;
last_day(f2)
NULL
NULL
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
select last_day(f2) from t1 where last_day(f2) is null;
last_day(f2)
NULL
NULL
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
select * from t1 order by last_day (f2);
f2
0
0
Warnings:
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '0'
drop table t1;
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow');
Expand Down Expand Up @@ -1908,8 +1897,6 @@ insert ignore t1 values ('04:38:11','0000-00-00 00:00:00',0,'0000-00-00 00:00:00
select least(greatest(f3, f2, f4), f5) from t1;
least(greatest(f3, f2, f4), f5)
0000-00-00 00:00:00
Warnings:
Warning 1292 Incorrect datetime value: '0'
drop table t1;
select day(coalesce(null));
day(coalesce(null))
Expand Down
2 changes: 0 additions & 2 deletions mysql-test/r/subselect_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ INSERT INTO t1 VALUES ('2011-05-13', 0);
SELECT * FROM t1 WHERE b < (SELECT CAST(a as date) FROM t1 GROUP BY a);
a b
2011-05-13 0
Warnings:
Warning 1292 Incorrect datetime value: '0'
DROP TABLE t1;
#
# Bug #11766300 59387: FAILING ASSERTION: CURSOR->POS_STATE == 1997660512 (BTR_PCUR_IS_POSITIONE
Expand Down
43 changes: 43 additions & 0 deletions mysql-test/r/type_date.result
Original file line number Diff line number Diff line change
Expand Up @@ -759,5 +759,48 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (coalesce(`test`.`t1`.`a`) = DATE'2001-01-01')
DROP TABLE t1;
#
# MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) return different results
#
CREATE TABLE t1 (a INT(6) ZEROFILL, b DECIMAL(6) ZEROFILL, c DOUBLE(6,0) ZEROFILL);
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (10101,10101,10101);
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
DATE(a) DATE(b) DATE(c)
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'a' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'b' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'c' at row 1
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
DATE(COALESCE(a)) DATE(COALESCE(b)) DATE(COALESCE(c))
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
DROP TABLE t1;
CREATE TABLE t1 (a INT(6), b DECIMAL(6), c DOUBLE(6,0));
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (10101,10101,10101);
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
DATE(a) DATE(b) DATE(c)
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'a' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'b' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'c' at row 1
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
DATE(COALESCE(a)) DATE(COALESCE(b)) DATE(COALESCE(c))
NULL NULL NULL
2001-01-01 2001-01-01 2001-01-01
Warnings:
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
Warning 1292 Incorrect datetime value: '1'
DROP TABLE t1;
#
# End of 10.1 tests
#
14 changes: 0 additions & 14 deletions mysql-test/r/type_newdecimal.result
Original file line number Diff line number Diff line change
Expand Up @@ -2042,33 +2042,19 @@ SELECT t1.* FROM t1 JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
ALTER TABLE t2 ADD PRIMARY KEY(a);
SELECT t1.* FROM t1 JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
a
10:20:30.000000
10:20:30.000000
Warnings:
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000000'
Note 1292 Truncated incorrect time value: '102030.0000000010'
# t2 should NOT be eliminated
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
id select_type table type possible_keys key key_len ref rows Extra
Expand Down
53 changes: 53 additions & 0 deletions mysql-test/r/type_time.result
Original file line number Diff line number Diff line change
Expand Up @@ -1153,5 +1153,58 @@ SELECT * FROM t1 WHERE a>TIME('00:00:00');
a
DROP TABLE t1;
#
# MDEV-8660 TIME(int_zerofill_column) returns a wrong result
#
CREATE TABLE t1 (a BIGINT(15), b BIGINT(15) ZEROFILL);
INSERT INTO t1 VALUES (9,9);
SELECT TIME(a),TIME(b) FROM t1;
TIME(a) TIME(b)
00:00:09 00:00:09
DROP TABLE t1;
CREATE TABLE t1 (a BIGINT);
INSERT INTO t1 VALUES (-9223372036854775808);
SELECT CAST(a AS TIME), CAST(-9223372036854775808 AS TIME) FROM t1;
CAST(a AS TIME) CAST(-9223372036854775808 AS TIME)
-838:59:59 -838:59:59
Warnings:
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'a' at row 1
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
DROP TABLE t1;
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
INSERT INTO t1 VALUES (-9000000,-9000000,-9000000);
INSERT INTO t1 VALUES (-1,-1,-1);
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
INSERT INTO t1 VALUES (9000000,9000000,9000000);
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
a TIME(a) TIME(b) TIME(c)
-9000000 -838:59:59 -838:59:59 -838:59:59.999999
-1 -00:00:01 -00:00:01 -00:00:01.000000
0 00:00:00 00:00:00 00:00:00.000000
1 00:00:01 00:00:01 00:00:01.000000
9 00:00:09 00:00:09 00:00:09.000000
9000000 838:59:59 838:59:59 838:59:59.999999
Warnings:
Warning 1292 Incorrect time value: '-9000000' for column 'a' at row 1
Warning 1292 Incorrect time value: '-9000000' for column 'b' at row 1
Warning 1292 Incorrect time value: '-9000000' for column 'c' at row 1
Warning 1292 Incorrect time value: '9000000' for column 'a' at row 6
Warning 1292 Incorrect time value: '9000000' for column 'b' at row 6
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 6
DROP TABLE t1;
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
INSERT INTO t1 VALUES (9000000,9000000,9000000);
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
a TIME(a) TIME(b) TIME(c)
0 00:00:00 00:00:00 00:00:00.000000
1 00:00:01 00:00:01 00:00:01.000000
9 00:00:09 00:00:09 00:00:09.000000
9000000 838:59:59 838:59:59 838:59:59.999999
Warnings:
Warning 1292 Incorrect time value: '9000000' for column 'a' at row 4
Warning 1292 Incorrect time value: '9000000' for column 'b' at row 4
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 4
DROP TABLE t1;
#
# End of 10.1 tests
#
56 changes: 26 additions & 30 deletions mysql-test/suite/funcs_1/r/innodb_func_view.result
Original file line number Diff line number Diff line change
Expand Up @@ -3743,14 +3743,14 @@ my_bigint, id FROM t1_values
WHERE select_id = 52 OR select_id IS NULL order by id;
CAST(my_bigint AS TIME) my_bigint id
NULL NULL 1
NULL -9223372036854775808 2
NULL 9223372036854775807 3
-838:59:59 -9223372036854775808 2
838:59:59 9223372036854775807 3
00:00:00 0 4
-00:00:01 -1 5
00:17:58 1758 24
Warnings:
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
Warning 1292 Truncated incorrect time value: '9223372036854775807'
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'my_bigint' at row 2
Warning 1292 Incorrect time value: '9223372036854775807' for column 'my_bigint' at row 3
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_bigint` as time) AS `CAST(my_bigint AS TIME)`,`t1_values`.`my_bigint` AS `my_bigint`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci
Expand All @@ -3759,14 +3759,14 @@ WHERE v1.id IN (SELECT id FROM t1_values
WHERE select_id = 52 OR select_id IS NULL) order by id;
CAST(my_bigint AS TIME) my_bigint id
NULL NULL 1
NULL -9223372036854775808 2
NULL 9223372036854775807 3
-838:59:59 -9223372036854775808 2
838:59:59 9223372036854775807 3
00:00:00 0 4
-00:00:01 -1 5
00:17:58 1758 24
Warnings:
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
Warning 1292 Truncated incorrect time value: '9223372036854775807'
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'my_bigint' at row 1
Warning 1292 Incorrect time value: '9223372036854775807' for column 'my_bigint' at row 1
DROP VIEW v1;


Expand Down Expand Up @@ -4095,15 +4095,14 @@ CAST(my_bigint AS DATETIME) my_bigint id
NULL NULL 1
NULL -9223372036854775808 2
NULL 9223372036854775807 3
NULL 0 4
0000-00-00 00:00:00 0 4
NULL -1 5
NULL 200506271758 18
Warnings:
Warning 1292 Incorrect datetime value: '-9223372036854775808'
Warning 1292 Incorrect datetime value: '9223372036854775807'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '-1'
Warning 1292 Incorrect datetime value: '200506271758'
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 2
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 3
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 5
Warning 1292 Incorrect datetime value: '200506271758' for column 'my_bigint' at row 18
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_bigint` as datetime) AS `CAST(my_bigint AS DATETIME)`,`t1_values`.`my_bigint` AS `my_bigint`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci
Expand All @@ -4114,15 +4113,14 @@ CAST(my_bigint AS DATETIME) my_bigint id
NULL NULL 1
NULL -9223372036854775808 2
NULL 9223372036854775807 3
NULL 0 4
0000-00-00 00:00:00 0 4
NULL -1 5
NULL 200506271758 18
Warnings:
Warning 1292 Incorrect datetime value: '-9223372036854775808'
Warning 1292 Incorrect datetime value: '9223372036854775807'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '-1'
Warning 1292 Incorrect datetime value: '200506271758'
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 1
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 1
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 1
Warning 1292 Incorrect datetime value: '200506271758' for column 'my_bigint' at row 1
DROP VIEW v1;


Expand Down Expand Up @@ -4455,14 +4453,13 @@ CAST(my_bigint AS DATE) my_bigint id
NULL NULL 1
NULL -9223372036854775808 2
NULL 9223372036854775807 3
NULL 0 4
0000-00-00 0 4
NULL -1 5
2005-06-27 20050627 12
Warnings:
Warning 1292 Incorrect datetime value: '-9223372036854775808'
Warning 1292 Incorrect datetime value: '9223372036854775807'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '-1'
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 2
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 3
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 5
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_bigint` as date) AS `CAST(my_bigint AS DATE)`,`t1_values`.`my_bigint` AS `my_bigint`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci
Expand All @@ -4473,14 +4470,13 @@ CAST(my_bigint AS DATE) my_bigint id
NULL NULL 1
NULL -9223372036854775808 2
NULL 9223372036854775807 3
NULL 0 4
0000-00-00 0 4
NULL -1 5
2005-06-27 20050627 12
Warnings:
Warning 1292 Incorrect datetime value: '-9223372036854775808'
Warning 1292 Incorrect datetime value: '9223372036854775807'
Warning 1292 Incorrect datetime value: '0'
Warning 1292 Incorrect datetime value: '-1'
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 1
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 1
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 1
DROP VIEW v1;


Expand Down
Loading

0 comments on commit 3ad035f

Please sign in to comment.