diff options
author | Alexander Barkov <bar@mariadb.com> | 2020-06-08 14:00:19 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2020-06-08 14:00:19 +0400 |
commit | 86c50a255a8319a4c89399b9c2d4f416b4973815 (patch) | |
tree | 982935b44adf0aa856b6786409deaeb918f147bd | |
parent | 57022dfb25b931a329905364d7056ac61950d300 (diff) | |
download | mariadb-git-86c50a255a8319a4c89399b9c2d4f416b4973815.tar.gz |
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).
-rw-r--r-- | mysql-test/main/type_timestamp.result | 15 | ||||
-rw-r--r-- | mysql-test/main/type_timestamp.test | 8 | ||||
-rw-r--r-- | sql/field.cc | 4 |
3 files changed, 24 insertions, 3 deletions
diff --git a/mysql-test/main/type_timestamp.result b/mysql-test/main/type_timestamp.result index d8c74f15c57..11d27e77a3d 100644 --- a/mysql-test/main/type_timestamp.result +++ b/mysql-test/main/type_timestamp.result @@ -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 # diff --git a/mysql-test/main/type_timestamp.test b/mysql-test/main/type_timestamp.test index 7b2311eaac3..be3803618e1 100644 --- a/mysql-test/main/type_timestamp.test +++ b/mysql-test/main/type_timestamp.test @@ -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 diff --git a/sql/field.cc b/sql/field.cc index 2986442ad5e..3f4e1e73029 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -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) |