Commit 2fd0bc63 authored by Evgeny Potemkin's avatar Evgeny Potemkin

Bug#57095: Wrongly chosen expression cache type led to a wrong result.

The coalesce function returned DATETIME type due to a DATETIME argument, but
since it's not a date/time function it can't return correct int value for
it. Nevertheless Item_datetime_cache was chosen to cache coalesce's result
and that led to a wrong result.

Now Item_datetime_cache is used only for those function that could return
correct int representation of DATETIME values.
parent fbfbc7ee
......@@ -680,5 +680,17 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 8 const 1 Using index
DROP TABLE t1,t2;
#
# Bug#57095: Wrongly chosen expression cache type led to a wrong
# result.
#
CREATE TABLE t1 (`b` datetime );
INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00');
SELECT * FROM t1 WHERE b <= coalesce(NULL, now());
b
2010-01-01 00:00:00
2010-01-01 00:00:00
DROP TABLE t1;
#
#
# End of 5.5 tests
#
......@@ -484,6 +484,16 @@ explain select * from t2 where f1=STR_TO_DATE('4/1/2010', '%m/%d/%Y');
DROP TABLE t1,t2;
--echo #
--echo # Bug#57095: Wrongly chosen expression cache type led to a wrong
--echo # result.
--echo #
CREATE TABLE t1 (`b` datetime );
INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00');
SELECT * FROM t1 WHERE b <= coalesce(NULL, now());
DROP TABLE t1;
--echo #
--echo #
--echo # End of 5.5 tests
--echo #
......@@ -7356,9 +7356,11 @@ Item_cache* Item_cache::get_cache(const Item *item, const Item_result type)
case DECIMAL_RESULT:
return new Item_cache_decimal();
case STRING_RESULT:
if (item->field_type() == MYSQL_TYPE_DATE ||
item->field_type() == MYSQL_TYPE_DATETIME ||
item->field_type() == MYSQL_TYPE_TIME)
/* Not all functions that return DATE/TIME are actually DATE/TIME funcs. */
if ((item->field_type() == MYSQL_TYPE_DATE ||
item->field_type() == MYSQL_TYPE_DATETIME ||
item->field_type() == MYSQL_TYPE_TIME) &&
(const_cast<Item*>(item))->result_as_longlong())
return new Item_cache_datetime(item->field_type());
return new Item_cache_str(item);
case ROW_RESULT:
......
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