summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorEvgeny Potemkin <epotemkin@mysql.com>2010-10-07 20:16:30 +0400
committerEvgeny Potemkin <epotemkin@mysql.com>2010-10-07 20:16:30 +0400
commit731dcfc7ff5f787f391553f31ea5bcdca3ed13e5 (patch)
tree699abf6cc4b1270557dbb42acd47ceb8fe8eac18 /sql/item.cc
parent029657be0ef0a2530793a55f0f00401a3cc32122 (diff)
downloadmariadb-git-731dcfc7ff5f787f391553f31ea5bcdca3ed13e5.tar.gz
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. mysql-test/r/type_datetime.result: Added a test case for the bug#57095. mysql-test/t/type_datetime.test: Added a test case for the bug#57095. sql/item.cc: Bug#57095: Wrongly chosen expression cache type led to a wrong result. Now Item_datetime_cache is used only for those function that could return correct int representation of DATETIME values.
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/sql/item.cc b/sql/item.cc
index e782e90b874..fff7511015f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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: