Commit 8ecc7537 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-16884 Remove tests for field_type() in Item_cache_temporal

parent c7115428
......@@ -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;
/*
......
......@@ -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(&ltime, TIME_FUZZY_DATES | TIME_INVALID_DATES))
if (get_date_result(&ltime, Datetime::comparison_flags_for_get_date()))
return 0;
if (ltime.time_type != MYSQL_TIMESTAMP_TIME)
return pack_time(&ltime);
......@@ -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)
......
......@@ -1654,15 +1654,13 @@ class Item: public Value_source,
// 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 @@ class Item_cache_time: public Item_cache_temporal
Item *get_copy(THD *thd)
{ return get_item_copy<Item_cache_time>(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 @@ class Item_cache_datetime: public Item_cache_temporal
Item *get_copy(THD *thd)
{ return get_item_copy<Item_cache_datetime>(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 @@ class Item_cache_date: public Item_cache_temporal
Item *get_copy(THD *thd)
{ return get_item_copy<Item_cache_date>(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)
......
......@@ -164,6 +164,7 @@ class Temporal: protected MYSQL_TIME
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 @@ class Time: private Temporal
{
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 @@ class Time: private Temporal
{
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 @@ class Temporal_with_date: protected Temporal
{
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 @@ class Datetime: public Temporal_with_date
{
return is_valid_datetime() ? Temporal::to_decimal(to) : bad_to_decimal(to);
}
longlong to_packed() const
{
return is_valid_datetime() ? Temporal::to_packed() : 0;
}
};
/*
......
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