From c43a0e0a77246585fd99961110fbd9570acebf9b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 28 Mar 2018 20:52:06 +0200 Subject: [PATCH] bugfix: Item_cache_temporal::convert_to_basic_const_item assumed DATETIME this is a 10.3 version of 1c6f6dc8924 --- mysql-test/main/derived_cond_pushdown.result | 2 +- sql/item.cc | 29 +++++++++++++++----- sql/item.h | 4 +++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 32d3c88cc8d..dd5abde1548 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -11819,7 +11819,7 @@ EXPLAIN "access_type": "ALL", "rows": 3, "filtered": 100, - "attached_condition": "t1.i = TIMESTAMP'2007-05-28 00:00:00'" + "attached_condition": "t1.i = DATE'2007-05-28'" } } } diff --git a/sql/item.cc b/sql/item.cc index cfd7ea210d1..b32967e8944 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -10168,17 +10168,32 @@ Item *Item_cache_temporal::convert_to_basic_const_item(THD *thd) Item *new_item; DBUG_ASSERT(value_cached || example != 0); if (null_value) - new_item= (Item*) new (thd->mem_root) Item_null(thd); + return new (thd->mem_root) Item_null(thd); else - { - MYSQL_TIME ltime; - unpack_time(val_datetime_packed(), <ime, MYSQL_TIMESTAMP_DATETIME); - new_item= (Item*) new (thd->mem_root) Item_datetime_literal(thd, <ime, - decimals); - } + return make_literal(thd); return new_item; } +Item *Item_cache_datetime::make_literal(THD *thd) +{ + MYSQL_TIME ltime; + unpack_time(val_datetime_packed(), <ime, MYSQL_TIMESTAMP_DATETIME); + return new (thd->mem_root) Item_datetime_literal(thd, <ime, decimals); +} + +Item *Item_cache_date::make_literal(THD *thd) +{ + MYSQL_TIME ltime; + unpack_time(val_datetime_packed(), <ime, MYSQL_TIMESTAMP_DATE); + return new (thd->mem_root) Item_date_literal(thd, <ime); +} + +Item *Item_cache_time::make_literal(THD *thd) +{ + MYSQL_TIME ltime; + unpack_time(val_time_packed(), <ime, MYSQL_TIMESTAMP_TIME); + return new (thd->mem_root) Item_time_literal(thd, <ime, decimals); +} bool Item_cache_real::cache_value() { diff --git a/sql/item.h b/sql/item.h index d2789d40664..fcbfdfa1a02 100644 --- a/sql/item.h +++ b/sql/item.h @@ -6169,6 +6169,7 @@ public: */ Item *clone_item(THD *thd); Item *convert_to_basic_const_item(THD *thd); + virtual Item *make_literal(THD *) =0; }; @@ -6180,6 +6181,7 @@ public: bool cache_value(); Item *get_copy(THD *thd) { return get_item_copy(thd, this); } + Item *make_literal(THD *); }; @@ -6190,6 +6192,7 @@ public: :Item_cache_temporal(thd, &type_handler_datetime2) { } Item *get_copy(THD *thd) { return get_item_copy(thd, this); } + Item *make_literal(THD *); }; @@ -6200,6 +6203,7 @@ public: :Item_cache_temporal(thd, &type_handler_newdate) { } Item *get_copy(THD *thd) { return get_item_copy(thd, this); } + Item *make_literal(THD *); };