Commit e835881c authored by Alexander Barkov's avatar Alexander Barkov

MDEV-21619 Server crash or assertion failures in my_datetime_to_str

Item_cache_datetime::decimals was always copied from example->decimals
without limiting to 6 (maximum possible fractional digits), so
val_str() later crashed on asserts inside my_time_to_str() and
my_datetime_to_str().
parent 1bcc5cd9
......@@ -914,3 +914,21 @@ DROP TABLE t1;
#
# End of 10.1 tests
#
#
# Start of 10.2 tests
#
#
# MDEV-21619 Server crash or assertion failures in my_datetime_to_str
#
CREATE TABLE t1 (f DATE, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01'),('2020-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index f f 4 NULL 2 50.00 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '1995.0000000'
Note 1003 select `test`.`t1`.`f` AS `f` from `test`.`t1` where '0000-00-00' between `test`.`t1`.`f` and <cache>('2012-12-12')
DROP TABLE t1;
#
# End of 10.2 tests
#
......@@ -1330,5 +1330,17 @@ a
2000-10-00 00:00:00
DROP TABLE t1;
#
# MDEV-21619 Server crash or assertion failures in my_datetime_to_str
#
CREATE TABLE t1 (f DATETIME, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01 00:00:00'),('2020-01-02 00:00:00');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index f f 6 NULL 2 50.00 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '1995.0000000'
Note 1003 select `test`.`t1`.`f` AS `f` from `test`.`t1` where '0000-00-00 00:00:00.000000' between `test`.`t1`.`f` and <cache>('2012-12-12')
DROP TABLE t1;
#
# End of 10.2 tests
#
......@@ -1356,5 +1356,17 @@ CAST(f1() AS TIME)
00:00:00
DROP FUNCTION f1;
#
# MDEV-21619 Server crash or assertion failures in my_datetime_to_str
#
CREATE TABLE t1 (f TIME, KEY(f));
INSERT INTO t1 VALUES ('10:10:10'),('20:20:20');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '23:59:59';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index f f 4 NULL 2 100.00 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '1995.0000000'
Note 1003 select `test`.`t1`.`f` AS `f` from `test`.`t1` where '00:00:00.000000' between `test`.`t1`.`f` and <cache>('23:59:59')
DROP TABLE t1;
#
# End of 10.2 tests
#
......@@ -627,3 +627,21 @@ DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #
--echo #
--echo # Start of 10.2 tests
--echo #
--echo #
--echo # MDEV-21619 Server crash or assertion failures in my_datetime_to_str
--echo #
CREATE TABLE t1 (f DATE, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01'),('2020-01-02');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -837,6 +837,15 @@ ALTER TABLE t1 MODIFY a DATETIME;
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-21619 Server crash or assertion failures in my_datetime_to_str
--echo #
CREATE TABLE t1 (f DATETIME, KEY(f));
INSERT INTO t1 VALUES ('2020-01-01 00:00:00'),('2020-01-02 00:00:00');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '2012-12-12';
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
......
......@@ -814,6 +814,15 @@ SELECT CAST(f1() AS TIME);
DROP FUNCTION f1;
--echo #
--echo # MDEV-21619 Server crash or assertion failures in my_datetime_to_str
--echo #
CREATE TABLE t1 (f TIME, KEY(f));
INSERT INTO t1 VALUES ('10:10:10'),('20:20:20');
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1995.0000000 BETWEEN f AND '23:59:59';
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -5803,6 +5803,13 @@ class Item_cache_temporal: public Item_cache_int
bool cache_value();
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
int save_in_field(Field *field, bool no_conversions);
bool setup(THD *thd, Item *item)
{
if (Item_cache_int::setup(thd, item))
return true;
set_if_smaller(decimals, TIME_SECOND_PART_DIGITS);
return false;
}
Item_result cmp_type() const { return TIME_RESULT; }
void store_packed(longlong val_arg, Item *example);
/*
......
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