Skip to content

Commit 3ad035f

Browse files
author
Alexander Barkov
committed
MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) return different results
MDEV-8660 TIME(int_zerofill_column) returns a wrong result
1 parent b9da3ba commit 3ad035f

13 files changed

+241
-123
lines changed

mysql-test/r/func_set.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 )
172172
8
173173
8
174174
Warnings:
175-
Warning 1292 Incorrect datetime value: '10'
176-
Warning 1292 Incorrect datetime value: '11'
175+
Warning 1292 Incorrect datetime value: '10' for column 'pk' at row 1
176+
Warning 1292 Incorrect datetime value: '11' for column 'pk' at row 2
177177
DROP TABLE t1;
178178
#
179179
# End of 5.3 tests
@@ -233,8 +233,8 @@ INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 )
233233
8
234234
8
235235
Warnings:
236-
Warning 1292 Incorrect datetime value: '10'
237-
Warning 1292 Incorrect datetime value: '11'
236+
Warning 1292 Incorrect datetime value: '10' for column 'pk' at row 1
237+
Warning 1292 Incorrect datetime value: '11' for column 'pk' at row 2
238238
DROP TABLE t1;
239239
#
240240
# End of 5.3 tests

mysql-test/r/func_time.result

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,25 +1834,14 @@ select last_day(f2) from t1;
18341834
last_day(f2)
18351835
NULL
18361836
NULL
1837-
Warnings:
1838-
Warning 1292 Incorrect datetime value: '0'
1839-
Warning 1292 Incorrect datetime value: '0'
18401837
select last_day(f2) from t1 where last_day(f2) is null;
18411838
last_day(f2)
18421839
NULL
18431840
NULL
1844-
Warnings:
1845-
Warning 1292 Incorrect datetime value: '0'
1846-
Warning 1292 Incorrect datetime value: '0'
1847-
Warning 1292 Incorrect datetime value: '0'
1848-
Warning 1292 Incorrect datetime value: '0'
18491841
select * from t1 order by last_day (f2);
18501842
f2
18511843
0
18521844
0
1853-
Warnings:
1854-
Warning 1292 Incorrect datetime value: '0'
1855-
Warning 1292 Incorrect datetime value: '0'
18561845
drop table t1;
18571846
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
18581847
select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow');
@@ -1908,8 +1897,6 @@ insert ignore t1 values ('04:38:11','0000-00-00 00:00:00',0,'0000-00-00 00:00:00
19081897
select least(greatest(f3, f2, f4), f5) from t1;
19091898
least(greatest(f3, f2, f4), f5)
19101899
0000-00-00 00:00:00
1911-
Warnings:
1912-
Warning 1292 Incorrect datetime value: '0'
19131900
drop table t1;
19141901
select day(coalesce(null));
19151902
day(coalesce(null))

mysql-test/r/subselect_innodb.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ INSERT INTO t1 VALUES ('2011-05-13', 0);
296296
SELECT * FROM t1 WHERE b < (SELECT CAST(a as date) FROM t1 GROUP BY a);
297297
a b
298298
2011-05-13 0
299-
Warnings:
300-
Warning 1292 Incorrect datetime value: '0'
301299
DROP TABLE t1;
302300
#
303301
# Bug #11766300 59387: FAILING ASSERTION: CURSOR->POS_STATE == 1997660512 (BTR_PCUR_IS_POSITIONE

mysql-test/r/type_date.result

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,5 +759,48 @@ Warnings:
759759
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (coalesce(`test`.`t1`.`a`) = DATE'2001-01-01')
760760
DROP TABLE t1;
761761
#
762+
# MDEV-8658 DATE(zerofill_column) and DATE(COALESCE(zerofill_column)) return different results
763+
#
764+
CREATE TABLE t1 (a INT(6) ZEROFILL, b DECIMAL(6) ZEROFILL, c DOUBLE(6,0) ZEROFILL);
765+
INSERT INTO t1 VALUES (1,1,1);
766+
INSERT INTO t1 VALUES (10101,10101,10101);
767+
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
768+
DATE(a) DATE(b) DATE(c)
769+
NULL NULL NULL
770+
2001-01-01 2001-01-01 2001-01-01
771+
Warnings:
772+
Warning 1292 Incorrect datetime value: '1' for column 'a' at row 1
773+
Warning 1292 Incorrect datetime value: '1' for column 'b' at row 1
774+
Warning 1292 Incorrect datetime value: '1' for column 'c' at row 1
775+
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
776+
DATE(COALESCE(a)) DATE(COALESCE(b)) DATE(COALESCE(c))
777+
NULL NULL NULL
778+
2001-01-01 2001-01-01 2001-01-01
779+
Warnings:
780+
Warning 1292 Incorrect datetime value: '1'
781+
Warning 1292 Incorrect datetime value: '1'
782+
Warning 1292 Incorrect datetime value: '1'
783+
DROP TABLE t1;
784+
CREATE TABLE t1 (a INT(6), b DECIMAL(6), c DOUBLE(6,0));
785+
INSERT INTO t1 VALUES (1,1,1);
786+
INSERT INTO t1 VALUES (10101,10101,10101);
787+
SELECT DATE(a), DATE(b), DATE(c) FROM t1;
788+
DATE(a) DATE(b) DATE(c)
789+
NULL NULL NULL
790+
2001-01-01 2001-01-01 2001-01-01
791+
Warnings:
792+
Warning 1292 Incorrect datetime value: '1' for column 'a' at row 1
793+
Warning 1292 Incorrect datetime value: '1' for column 'b' at row 1
794+
Warning 1292 Incorrect datetime value: '1' for column 'c' at row 1
795+
SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1;
796+
DATE(COALESCE(a)) DATE(COALESCE(b)) DATE(COALESCE(c))
797+
NULL NULL NULL
798+
2001-01-01 2001-01-01 2001-01-01
799+
Warnings:
800+
Warning 1292 Incorrect datetime value: '1'
801+
Warning 1292 Incorrect datetime value: '1'
802+
Warning 1292 Incorrect datetime value: '1'
803+
DROP TABLE t1;
804+
#
762805
# End of 10.1 tests
763806
#

mysql-test/r/type_newdecimal.result

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,33 +2042,19 @@ SELECT t1.* FROM t1 JOIN t2 USING(a);
20422042
a
20432043
10:20:30.000000
20442044
10:20:30.000000
2045-
Warnings:
2046-
Note 1292 Truncated incorrect time value: '102030.0000000000'
2047-
Note 1292 Truncated incorrect time value: '102030.0000000010'
20482045
SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
20492046
a
20502047
10:20:30.000000
20512048
10:20:30.000000
2052-
Warnings:
2053-
Note 1292 Truncated incorrect time value: '102030.0000000000'
2054-
Note 1292 Truncated incorrect time value: '102030.0000000000'
2055-
Note 1292 Truncated incorrect time value: '102030.0000000010'
20562049
ALTER TABLE t2 ADD PRIMARY KEY(a);
20572050
SELECT t1.* FROM t1 JOIN t2 USING(a);
20582051
a
20592052
10:20:30.000000
20602053
10:20:30.000000
2061-
Warnings:
2062-
Note 1292 Truncated incorrect time value: '102030.0000000000'
2063-
Note 1292 Truncated incorrect time value: '102030.0000000010'
20642054
SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
20652055
a
20662056
10:20:30.000000
20672057
10:20:30.000000
2068-
Warnings:
2069-
Note 1292 Truncated incorrect time value: '102030.0000000000'
2070-
Note 1292 Truncated incorrect time value: '102030.0000000000'
2071-
Note 1292 Truncated incorrect time value: '102030.0000000010'
20722058
# t2 should NOT be eliminated
20732059
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
20742060
id select_type table type possible_keys key key_len ref rows Extra

mysql-test/r/type_time.result

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,5 +1153,58 @@ SELECT * FROM t1 WHERE a>TIME('00:00:00');
11531153
a
11541154
DROP TABLE t1;
11551155
#
1156+
# MDEV-8660 TIME(int_zerofill_column) returns a wrong result
1157+
#
1158+
CREATE TABLE t1 (a BIGINT(15), b BIGINT(15) ZEROFILL);
1159+
INSERT INTO t1 VALUES (9,9);
1160+
SELECT TIME(a),TIME(b) FROM t1;
1161+
TIME(a) TIME(b)
1162+
00:00:09 00:00:09
1163+
DROP TABLE t1;
1164+
CREATE TABLE t1 (a BIGINT);
1165+
INSERT INTO t1 VALUES (-9223372036854775808);
1166+
SELECT CAST(a AS TIME), CAST(-9223372036854775808 AS TIME) FROM t1;
1167+
CAST(a AS TIME) CAST(-9223372036854775808 AS TIME)
1168+
-838:59:59 -838:59:59
1169+
Warnings:
1170+
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'a' at row 1
1171+
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
1172+
DROP TABLE t1;
1173+
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
1174+
INSERT INTO t1 VALUES (-9000000,-9000000,-9000000);
1175+
INSERT INTO t1 VALUES (-1,-1,-1);
1176+
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
1177+
INSERT INTO t1 VALUES (9000000,9000000,9000000);
1178+
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
1179+
a TIME(a) TIME(b) TIME(c)
1180+
-9000000 -838:59:59 -838:59:59 -838:59:59.999999
1181+
-1 -00:00:01 -00:00:01 -00:00:01.000000
1182+
0 00:00:00 00:00:00 00:00:00.000000
1183+
1 00:00:01 00:00:01 00:00:01.000000
1184+
9 00:00:09 00:00:09 00:00:09.000000
1185+
9000000 838:59:59 838:59:59 838:59:59.999999
1186+
Warnings:
1187+
Warning 1292 Incorrect time value: '-9000000' for column 'a' at row 1
1188+
Warning 1292 Incorrect time value: '-9000000' for column 'b' at row 1
1189+
Warning 1292 Incorrect time value: '-9000000' for column 'c' at row 1
1190+
Warning 1292 Incorrect time value: '9000000' for column 'a' at row 6
1191+
Warning 1292 Incorrect time value: '9000000' for column 'b' at row 6
1192+
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 6
1193+
DROP TABLE t1;
1194+
CREATE TABLE t1 (a INT, b DECIMAL, c DOUBLE);
1195+
INSERT INTO t1 VALUES (0,0,0),(1,1,1),(9,9,9);
1196+
INSERT INTO t1 VALUES (9000000,9000000,9000000);
1197+
SELECT a, TIME(a),TIME(b),TIME(c) FROM t1 ORDER BY a;
1198+
a TIME(a) TIME(b) TIME(c)
1199+
0 00:00:00 00:00:00 00:00:00.000000
1200+
1 00:00:01 00:00:01 00:00:01.000000
1201+
9 00:00:09 00:00:09 00:00:09.000000
1202+
9000000 838:59:59 838:59:59 838:59:59.999999
1203+
Warnings:
1204+
Warning 1292 Incorrect time value: '9000000' for column 'a' at row 4
1205+
Warning 1292 Incorrect time value: '9000000' for column 'b' at row 4
1206+
Warning 1292 Incorrect time value: '9000000' for column 'c' at row 4
1207+
DROP TABLE t1;
1208+
#
11561209
# End of 10.1 tests
11571210
#

mysql-test/suite/funcs_1/r/innodb_func_view.result

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,14 +3743,14 @@ my_bigint, id FROM t1_values
37433743
WHERE select_id = 52 OR select_id IS NULL order by id;
37443744
CAST(my_bigint AS TIME) my_bigint id
37453745
NULL NULL 1
3746-
NULL -9223372036854775808 2
3747-
NULL 9223372036854775807 3
3746+
-838:59:59 -9223372036854775808 2
3747+
838:59:59 9223372036854775807 3
37483748
00:00:00 0 4
37493749
-00:00:01 -1 5
37503750
00:17:58 1758 24
37513751
Warnings:
3752-
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
3753-
Warning 1292 Truncated incorrect time value: '9223372036854775807'
3752+
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'my_bigint' at row 2
3753+
Warning 1292 Incorrect time value: '9223372036854775807' for column 'my_bigint' at row 3
37543754
SHOW CREATE VIEW v1;
37553755
View Create View character_set_client collation_connection
37563756
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
@@ -3759,14 +3759,14 @@ WHERE v1.id IN (SELECT id FROM t1_values
37593759
WHERE select_id = 52 OR select_id IS NULL) order by id;
37603760
CAST(my_bigint AS TIME) my_bigint id
37613761
NULL NULL 1
3762-
NULL -9223372036854775808 2
3763-
NULL 9223372036854775807 3
3762+
-838:59:59 -9223372036854775808 2
3763+
838:59:59 9223372036854775807 3
37643764
00:00:00 0 4
37653765
-00:00:01 -1 5
37663766
00:17:58 1758 24
37673767
Warnings:
3768-
Warning 1292 Truncated incorrect time value: '-9223372036854775808'
3769-
Warning 1292 Truncated incorrect time value: '9223372036854775807'
3768+
Warning 1292 Incorrect time value: '-9223372036854775808' for column 'my_bigint' at row 1
3769+
Warning 1292 Incorrect time value: '9223372036854775807' for column 'my_bigint' at row 1
37703770
DROP VIEW v1;
37713771

37723772

@@ -4095,15 +4095,14 @@ CAST(my_bigint AS DATETIME) my_bigint id
40954095
NULL NULL 1
40964096
NULL -9223372036854775808 2
40974097
NULL 9223372036854775807 3
4098-
NULL 0 4
4098+
0000-00-00 00:00:00 0 4
40994099
NULL -1 5
41004100
NULL 200506271758 18
41014101
Warnings:
4102-
Warning 1292 Incorrect datetime value: '-9223372036854775808'
4103-
Warning 1292 Incorrect datetime value: '9223372036854775807'
4104-
Warning 1292 Incorrect datetime value: '0'
4105-
Warning 1292 Incorrect datetime value: '-1'
4106-
Warning 1292 Incorrect datetime value: '200506271758'
4102+
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 2
4103+
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 3
4104+
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 5
4105+
Warning 1292 Incorrect datetime value: '200506271758' for column 'my_bigint' at row 18
41074106
SHOW CREATE VIEW v1;
41084107
View Create View character_set_client collation_connection
41094108
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
@@ -4114,15 +4113,14 @@ CAST(my_bigint AS DATETIME) my_bigint id
41144113
NULL NULL 1
41154114
NULL -9223372036854775808 2
41164115
NULL 9223372036854775807 3
4117-
NULL 0 4
4116+
0000-00-00 00:00:00 0 4
41184117
NULL -1 5
41194118
NULL 200506271758 18
41204119
Warnings:
4121-
Warning 1292 Incorrect datetime value: '-9223372036854775808'
4122-
Warning 1292 Incorrect datetime value: '9223372036854775807'
4123-
Warning 1292 Incorrect datetime value: '0'
4124-
Warning 1292 Incorrect datetime value: '-1'
4125-
Warning 1292 Incorrect datetime value: '200506271758'
4120+
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 1
4121+
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 1
4122+
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 1
4123+
Warning 1292 Incorrect datetime value: '200506271758' for column 'my_bigint' at row 1
41264124
DROP VIEW v1;
41274125

41284126

@@ -4455,14 +4453,13 @@ CAST(my_bigint AS DATE) my_bigint id
44554453
NULL NULL 1
44564454
NULL -9223372036854775808 2
44574455
NULL 9223372036854775807 3
4458-
NULL 0 4
4456+
0000-00-00 0 4
44594457
NULL -1 5
44604458
2005-06-27 20050627 12
44614459
Warnings:
4462-
Warning 1292 Incorrect datetime value: '-9223372036854775808'
4463-
Warning 1292 Incorrect datetime value: '9223372036854775807'
4464-
Warning 1292 Incorrect datetime value: '0'
4465-
Warning 1292 Incorrect datetime value: '-1'
4460+
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 2
4461+
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 3
4462+
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 5
44664463
SHOW CREATE VIEW v1;
44674464
View Create View character_set_client collation_connection
44684465
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
@@ -4473,14 +4470,13 @@ CAST(my_bigint AS DATE) my_bigint id
44734470
NULL NULL 1
44744471
NULL -9223372036854775808 2
44754472
NULL 9223372036854775807 3
4476-
NULL 0 4
4473+
0000-00-00 0 4
44774474
NULL -1 5
44784475
2005-06-27 20050627 12
44794476
Warnings:
4480-
Warning 1292 Incorrect datetime value: '-9223372036854775808'
4481-
Warning 1292 Incorrect datetime value: '9223372036854775807'
4482-
Warning 1292 Incorrect datetime value: '0'
4483-
Warning 1292 Incorrect datetime value: '-1'
4477+
Warning 1292 Incorrect datetime value: '-9223372036854775808' for column 'my_bigint' at row 1
4478+
Warning 1292 Incorrect datetime value: '9223372036854775807' for column 'my_bigint' at row 1
4479+
Warning 1292 Incorrect datetime value: '-1' for column 'my_bigint' at row 1
44844480
DROP VIEW v1;
44854481

44864482

0 commit comments

Comments
 (0)