Skip to content

Commit 86c50a2

Browse files
committed
MDEV-22734 Assertion `mon > 0 && mon < 13' failed in sec_since_epoch
When processing a condition like: WHERE timestamp_column='2010-00-01 00:00:00' don't replace the constant to Item_datetime_literal if the constant it has zeros (in the month or in the day).
1 parent 57022df commit 86c50a2

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

mysql-test/main/type_timestamp.result

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,9 @@ SELECT * FROM t1 WHERE LENGTH(a)=30+RAND() AND a=' garbage ';
884884
id select_type table type possible_keys key key_len ref rows filtered Extra
885885
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
886886
Warnings:
887-
Warning 1292 Truncated incorrect datetime value: ' garbage '
888-
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = TIMESTAMP'0000-00-00 00:00:00' and <cache>(octet_length(TIMESTAMP'0000-00-00 00:00:00')) = 30 + rand()
887+
Warning 1292 Incorrect datetime value: ' garbage '
888+
Warning 1292 Incorrect datetime value: ' garbage '
889+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where octet_length(`test`.`t1`.`a`) = 30 + rand() and `test`.`t1`.`a` = ' garbage '
889890
DROP TABLE t1;
890891
CREATE TABLE t1 (a TIMESTAMP);;
891892
INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2001-01-01 00:00:01');
@@ -1297,5 +1298,15 @@ SELECT (SELECT MIN(b) FROM t1) - a FROM t1;
12971298
-20030101000000.0000
12981299
DROP TABLE t1;
12991300
#
1301+
# MDEV-22734 Assertion `mon > 0 && mon < 13' failed in sec_since_epoch
1302+
#
1303+
SET time_zone="-02:00";
1304+
CREATE TABLE t1(c TIMESTAMP KEY);
1305+
SELECT * FROM t1 WHERE c='2010-00-01 00:00:00';
1306+
c
1307+
Warnings:
1308+
Warning 1292 Incorrect datetime value: '2010-00-01 00:00:00'
1309+
DROP TABLE t1;
1310+
#
13001311
# End of 10.4 tests
13011312
#

mysql-test/main/type_timestamp.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,14 @@ SELECT * FROM t1 WHERE (SELECT MIN(b) FROM t1) - a;
854854
SELECT (SELECT MIN(b) FROM t1) - a FROM t1;
855855
DROP TABLE t1;
856856

857+
--echo #
858+
--echo # MDEV-22734 Assertion `mon > 0 && mon < 13' failed in sec_since_epoch
859+
--echo #
860+
SET time_zone="-02:00";
861+
CREATE TABLE t1(c TIMESTAMP KEY);
862+
SELECT * FROM t1 WHERE c='2010-00-01 00:00:00';
863+
DROP TABLE t1;
864+
857865

858866
--echo #
859867
--echo # End of 10.4 tests

sql/field.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5798,7 +5798,9 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd,
57985798
case ANY_SUBST:
57995799
if (!is_temporal_type_with_date(const_item->field_type()))
58005800
{
5801-
Datetime dt(thd, const_item, Datetime::Options_cmp(thd));
5801+
Datetime dt= type_handler()->field_type() == MYSQL_TYPE_TIMESTAMP ?
5802+
Datetime(thd, const_item, Timestamp::DatetimeOptions(thd)) :
5803+
Datetime(thd, const_item, Datetime::Options_cmp(thd));
58025804
if (!dt.is_valid_datetime())
58035805
return NULL;
58045806
return new (thd->mem_root)

0 commit comments

Comments
 (0)