Commit 192c748c authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9215 Detect cmp_type() and result_type() from field_type()

Part7: Derive Item_cache from Type_handler_hybrid_field_type
parent 8eefe57c
...@@ -8747,8 +8747,9 @@ Item_cache_temporal::Item_cache_temporal(THD *thd, ...@@ -8747,8 +8747,9 @@ Item_cache_temporal::Item_cache_temporal(THD *thd,
enum_field_types field_type_arg): enum_field_types field_type_arg):
Item_cache_int(thd, field_type_arg) Item_cache_int(thd, field_type_arg)
{ {
if (mysql_type_to_time_type(cached_field_type) == MYSQL_TIMESTAMP_ERROR) if (mysql_type_to_time_type(Item_cache_temporal::field_type()) ==
cached_field_type= MYSQL_TYPE_DATETIME; MYSQL_TIMESTAMP_ERROR)
set_handler_by_field_type(MYSQL_TYPE_DATETIME);
} }
...@@ -8891,7 +8892,7 @@ void Item_cache_temporal::store_packed(longlong val_arg, Item *example_arg) ...@@ -8891,7 +8892,7 @@ void Item_cache_temporal::store_packed(longlong val_arg, Item *example_arg)
Item *Item_cache_temporal::clone_item(THD *thd) Item *Item_cache_temporal::clone_item(THD *thd)
{ {
Item_cache_temporal *item= new (thd->mem_root) Item_cache_temporal *item= new (thd->mem_root)
Item_cache_temporal(thd, cached_field_type); Item_cache_temporal(thd, Item_cache_temporal::field_type());
item->store_packed(value, example); item->store_packed(value, example);
return item; return item;
} }
......
...@@ -4978,7 +4978,8 @@ class Item_trigger_field : public Item_field, ...@@ -4978,7 +4978,8 @@ class Item_trigger_field : public Item_field,
for any value. for any value.
*/ */
class Item_cache: public Item_basic_constant class Item_cache: public Item_basic_constant,
public Type_handler_hybrid_field_type
{ {
protected: protected:
Item *example; Item *example;
...@@ -4988,7 +4989,6 @@ class Item_cache: public Item_basic_constant ...@@ -4988,7 +4989,6 @@ class Item_cache: public Item_basic_constant
by IN->EXISTS transformation. by IN->EXISTS transformation.
*/ */
Field *cached_field; Field *cached_field;
enum enum_field_types cached_field_type;
/* /*
TRUE <=> cache holds value of the last stored item (i.e actual value). TRUE <=> cache holds value of the last stored item (i.e actual value).
store() stores item to be cached and sets this flag to FALSE. store() stores item to be cached and sets this flag to FALSE.
...@@ -5000,18 +5000,19 @@ class Item_cache: public Item_basic_constant ...@@ -5000,18 +5000,19 @@ class Item_cache: public Item_basic_constant
public: public:
Item_cache(THD *thd): Item_cache(THD *thd):
Item_basic_constant(thd), Item_basic_constant(thd),
Type_handler_hybrid_field_type(MYSQL_TYPE_STRING),
example(0), cached_field(0), example(0), cached_field(0),
cached_field_type(MYSQL_TYPE_STRING),
value_cached(0) value_cached(0)
{ {
fixed= 1; fixed= 1;
maybe_null= 1; maybe_null= 1;
null_value= 1; null_value= 1;
} }
protected:
Item_cache(THD *thd, enum_field_types field_type_arg): Item_cache(THD *thd, enum_field_types field_type_arg):
Item_basic_constant(thd), Item_basic_constant(thd),
Type_handler_hybrid_field_type(field_type_arg),
example(0), cached_field(0), example(0), cached_field(0),
cached_field_type(field_type_arg),
value_cached(0) value_cached(0)
{ {
fixed= 1; fixed= 1;
...@@ -5019,6 +5020,7 @@ class Item_cache: public Item_basic_constant ...@@ -5019,6 +5020,7 @@ class Item_cache: public Item_basic_constant
null_value= 1; null_value= 1;
} }
public:
virtual bool allocate(THD *thd, uint i) { return 0; } virtual bool allocate(THD *thd, uint i) { return 0; }
virtual bool setup(THD *thd, Item *item) virtual bool setup(THD *thd, Item *item)
{ {
...@@ -5029,7 +5031,14 @@ class Item_cache: public Item_basic_constant ...@@ -5029,7 +5031,14 @@ class Item_cache: public Item_basic_constant
return 0; return 0;
}; };
enum Type type() const { return CACHE_ITEM; } enum Type type() const { return CACHE_ITEM; }
enum_field_types field_type() const { return cached_field_type; }
enum_field_types field_type() const
{ return Type_handler_hybrid_field_type::field_type(); }
enum Item_result result_type () const
{ return Type_handler_hybrid_field_type::result_type(); }
enum Item_result cmp_type () const
{ return Type_handler_hybrid_field_type::cmp_type(); }
static Item_cache* get_cache(THD *thd, const Item *item); static Item_cache* get_cache(THD *thd, const Item *item);
static Item_cache* get_cache(THD *thd, const Item* item, const Item_result type); static Item_cache* get_cache(THD *thd, const Item* item, const Item_result type);
virtual void keep_array() {} virtual void keep_array() {}
...@@ -5172,7 +5181,7 @@ class Item_cache_str: public Item_cache ...@@ -5172,7 +5181,7 @@ class Item_cache_str: public Item_cache
Item_cache_str(THD *thd, const Item *item): Item_cache_str(THD *thd, const Item *item):
Item_cache(thd, item->field_type()), value(0), Item_cache(thd, item->field_type()), value(0),
is_varbinary(item->type() == FIELD_ITEM && is_varbinary(item->type() == FIELD_ITEM &&
cached_field_type == MYSQL_TYPE_VARCHAR && Item_cache_str::field_type() == MYSQL_TYPE_VARCHAR &&
!((const Item_field *) item)->field->has_charset()) !((const Item_field *) item)->field->has_charset())
{ {
collation.set(const_cast<DTCollation&>(item->collation)); collation.set(const_cast<DTCollation&>(item->collation));
......
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