From 8ecc75373f18854550a8cc97fabb93fbaaf4b240 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 2 Aug 2018 17:49:28 +0400 Subject: [PATCH] MDEV-16884 Remove tests for field_type() in Item_cache_temporal --- sql/field.cc | 4 ++-- sql/item.cc | 28 +--------------------------- sql/item.h | 35 ++++++++++++++++++++++++++++------- sql/sql_type.h | 15 +++++++++++++-- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index d58ef8f03f4..97b61853a90 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5800,7 +5800,7 @@ 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, TIME_FUZZY_DATES | TIME_INVALID_DATES); + Datetime dt(thd, const_item, Datetime::comparison_flags_for_get_date()); if (!dt.is_valid_datetime()) return NULL; return new (thd->mem_root) @@ -6633,7 +6633,7 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, if (!is_temporal_type_with_date(const_item->field_type())) { // Get the value of const_item with conversion from TIME to DATETIME - Datetime dt(thd, const_item, TIME_FUZZY_DATES | TIME_INVALID_DATES); + Datetime dt(thd, const_item, Datetime::comparison_flags_for_get_date()); if (!dt.is_valid_datetime()) return NULL; /* diff --git a/sql/item.cc b/sql/item.cc index 6be086d507c..0089cbfa29e 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -118,7 +118,7 @@ void Item::push_note_converted_to_positive_complement(THD *thd) longlong Item::val_datetime_packed_result() { MYSQL_TIME ltime, tmp; - if (get_date_result(<ime, TIME_FUZZY_DATES | TIME_INVALID_DATES)) + if (get_date_result(<ime, Datetime::comparison_flags_for_get_date())) return 0; if (ltime.time_type != MYSQL_TIMESTAMP_TIME) return pack_time(<ime); @@ -9996,32 +9996,6 @@ Item_cache_temporal::Item_cache_temporal(THD *thd, const Type_handler *handler) } -longlong Item_cache_temporal::val_datetime_packed() -{ - if (Item_cache_temporal::field_type() == MYSQL_TYPE_TIME) - return Item::val_datetime_packed(); // TIME-to-DATETIME conversion needed - if ((!value_cached && !cache_value()) || null_value) - { - null_value= TRUE; - return 0; - } - return value; -} - - -longlong Item_cache_temporal::val_time_packed() -{ - if (Item_cache_temporal::field_type() != MYSQL_TYPE_TIME) - return Item::val_time_packed(); // DATETIME-to-TIME conversion needed - if ((!value_cached && !cache_value()) || null_value) - { - null_value= TRUE; - return 0; - } - return value; -} - - bool Item_cache_temporal::cache_value() { if (!example) diff --git a/sql/item.h b/sql/item.h index 8fbb3a2403e..64881543155 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1654,15 +1654,13 @@ public: // Get a DATE or DATETIME value in numeric packed format for comparison virtual longlong val_datetime_packed() { - ulonglong fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES; - Datetime dt(current_thd, this, fuzzydate); - return dt.is_valid_datetime() ? pack_time(dt.get_mysql_time()) : 0; + ulonglong fuzzydate= Datetime::comparison_flags_for_get_date(); + return Datetime(current_thd, this, fuzzydate).to_packed(); } // Get a TIME value in numeric packed format for comparison virtual longlong val_time_packed() { - Time tm(this, Time::comparison_flags_for_get_date()); - return tm.is_valid_time() ? pack_time(tm.get_mysql_time()) : 0; + return Time(this, Time::comparison_flags_for_get_date()).to_packed(); } longlong val_datetime_packed_result(); longlong val_time_packed_result() @@ -6491,8 +6489,6 @@ class Item_cache_temporal: public Item_cache_int protected: Item_cache_temporal(THD *thd, const Type_handler *handler); public: - longlong val_datetime_packed(); - longlong val_time_packed(); bool cache_value(); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); int save_in_field(Field *field, bool no_conversions); @@ -6517,6 +6513,15 @@ public: Item *get_copy(THD *thd) { return get_item_copy(thd, this); } Item *make_literal(THD *); + longlong val_datetime_packed() + { + ulonglong fuzzy= Datetime::comparison_flags_for_get_date(); + return has_value() ? Datetime(current_thd, this, fuzzy).to_longlong() : 0; + } + longlong val_time_packed() + { + return has_value() ? value : 0; + } longlong val_int() { return has_value() ? Time(this).to_longlong() : 0; @@ -6544,6 +6549,14 @@ public: Item *get_copy(THD *thd) { return get_item_copy(thd, this); } Item *make_literal(THD *); + longlong val_datetime_packed() + { + return has_value() ? value : 0; + } + longlong val_time_packed() + { + return Time(this, Time::comparison_flags_for_get_date()).to_packed(); + } longlong val_int() { return has_value() ? Datetime(this).to_longlong() : 0; @@ -6571,6 +6584,14 @@ public: Item *get_copy(THD *thd) { return get_item_copy(thd, this); } Item *make_literal(THD *); + longlong val_datetime_packed() + { + return has_value() ? value : 0; + } + longlong val_time_packed() + { + return Time(this, Time::comparison_flags_for_get_date()).to_packed(); + } longlong val_int() { return has_value() ? Date(this).to_longlong() : 0; } double val_real() { return has_value() ? Date(this).to_double() : 0; } String *val_str(String *to) diff --git a/sql/sql_type.h b/sql/sql_type.h index 8df308c58e6..d9989bdbc32 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -164,6 +164,7 @@ protected: double d= (double) num + frac / (double) TIME_SECOND_PART_FACTOR; return negate ? -d : d; } + longlong to_packed() const { return ::pack_time(this); } public: }; @@ -373,8 +374,8 @@ public: { DBUG_ASSERT(is_valid_time_slow()); DBUG_ASSERT(other->is_valid_time_slow()); - longlong p0= pack_time(this); - longlong p1= pack_time(other); + longlong p0= to_packed(); + longlong p1= other->to_packed(); if (p0 < p1) return -1; if (p0 > p1) @@ -415,6 +416,10 @@ public: { return is_valid_time() ? Temporal::to_decimal(to) : bad_to_decimal(to); } + longlong to_packed() const + { + return is_valid_time() ? Temporal::to_packed() : 0; + } }; @@ -459,6 +464,8 @@ public: { return ::check_date_with_warn(this, flags, MYSQL_TIMESTAMP_ERROR); } + static sql_mode_t comparison_flags_for_get_date() + { return TIME_INVALID_DATES | TIME_FUZZY_DATES; } }; @@ -666,6 +673,10 @@ public: { return is_valid_datetime() ? Temporal::to_decimal(to) : bad_to_decimal(to); } + longlong to_packed() const + { + return is_valid_datetime() ? Temporal::to_packed() : 0; + } }; /*