Commit 86c50a25 authored by Alexander Barkov's avatar Alexander Barkov

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).
parent 57022dfb
......@@ -884,8 +884,9 @@ SELECT * FROM t1 WHERE LENGTH(a)=30+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 Truncated incorrect datetime value: ' garbage '
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()
Warning 1292 Incorrect datetime value: ' garbage '
Warning 1292 Incorrect datetime value: ' garbage '
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where octet_length(`test`.`t1`.`a`) = 30 + rand() and `test`.`t1`.`a` = ' garbage '
DROP TABLE t1;
CREATE TABLE t1 (a TIMESTAMP);;
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;
-20030101000000.0000
DROP TABLE t1;
#
# MDEV-22734 Assertion `mon > 0 && mon < 13' failed in sec_since_epoch
#
SET time_zone="-02:00";
CREATE TABLE t1(c TIMESTAMP KEY);
SELECT * FROM t1 WHERE c='2010-00-01 00:00:00';
c
Warnings:
Warning 1292 Incorrect datetime value: '2010-00-01 00:00:00'
DROP TABLE t1;
#
# End of 10.4 tests
#
......@@ -854,6 +854,14 @@ SELECT * FROM t1 WHERE (SELECT MIN(b) FROM t1) - a;
SELECT (SELECT MIN(b) FROM t1) - a FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-22734 Assertion `mon > 0 && mon < 13' failed in sec_since_epoch
--echo #
SET time_zone="-02:00";
CREATE TABLE t1(c TIMESTAMP KEY);
SELECT * FROM t1 WHERE c='2010-00-01 00:00:00';
DROP TABLE t1;
--echo #
--echo # End of 10.4 tests
......
......@@ -5798,7 +5798,9 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd,
case ANY_SUBST:
if (!is_temporal_type_with_date(const_item->field_type()))
{
Datetime dt(thd, const_item, Datetime::Options_cmp(thd));
Datetime dt= type_handler()->field_type() == MYSQL_TYPE_TIMESTAMP ?
Datetime(thd, const_item, Timestamp::DatetimeOptions(thd)) :
Datetime(thd, const_item, Datetime::Options_cmp(thd));
if (!dt.is_valid_datetime())
return NULL;
return new (thd->mem_root)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment