Commit 372bc22b authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-4265 5.5 is slower than 5.3 because of many str_to_datetime calls

get_datetime_value() should not double-cache its own Item_cache_temporal items,
but it *should* cache other Item_cache items, such as Item_cache_str.

sql/item.h:
  shortcut, to avoid going through the switch in Item::cmp_type()
sql/item_cmpfunc.cc:
  even if the item is Item_cache_str - it still needs to be converted and cached.
sql/item_timefunc.h:
  all descendants of Item_temporal_func always have cmp_type==TIME_RESULT.
  Even Item_date_add_interval, that might have field_type == MYSQL_TYPE_STRING.
parent d24c8d9a
create table t1 (a date);
insert t1 values ('2000-01-02'), ('2001-02-03'), ('2002-03-04');
set debug_dbug='d,str_to_datetime_warn';
select * from t1 where a > date_add('2000-01-01', interval 5 day);
a
2001-02-03
2002-03-04
Warnings:
Note 1003 2000-01-01
Note 1003 2000-01-06
drop table t1;
#
# MDEV-4265 5.5 is slower than 5.3 because of many str_to_datetime calls
#
--source include/have_debug.inc
create table t1 (a date);
insert t1 values ('2000-01-02'), ('2001-02-03'), ('2002-03-04');
set debug_dbug='d,str_to_datetime_warn';
select * from t1 where a > date_add('2000-01-01', interval 5 day);
drop table t1;
......@@ -4030,6 +4030,7 @@ public:
bool cache_value();
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
int save_in_field(Field *field, bool no_conversions);
Item_result cmp_type() const { return TIME_RESULT; }
void store_packed(longlong val_arg, Item *example);
/*
Having a clone_item method tells optimizer that this object
......
......@@ -906,7 +906,8 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
}
if ((*is_null= item->null_value))
return ~(ulonglong) 0;
if (cache_arg && item->const_item() && item->type() != Item::CACHE_ITEM)
if (cache_arg && item->const_item() &&
!(item->type() == Item::CACHE_ITEM && item->cmp_type() == TIME_RESULT))
{
Query_arena backup;
Query_arena *save_arena= thd->switch_to_arena_for_cached_items(&backup);
......
......@@ -491,6 +491,7 @@ public:
enum Item_result result_type () const { return STRING_RESULT; }
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
Item_result cmp_type() const { return TIME_RESULT; }
String *val_str(String *str);
longlong val_int();
double val_real();
......
......@@ -302,6 +302,9 @@ str_to_datetime_with_warn(CHARSET_INFO *cs,
make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
str, length, flags & TIME_TIME_ONLY ?
MYSQL_TIMESTAMP_TIME : ts_type, NullS);
DBUG_EXECUTE_IF("str_to_datetime_warn",
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_YES, str););
return ts_type;
}
......
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