Skip to content
Permalink
Browse files

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

Part7: Derive Item_cache from Type_handler_hybrid_field_type
  • Loading branch information
abarkov committed Dec 3, 2015
1 parent 8eefe57 commit 192c748c246284e199b6a697f4d1e1adf00cf39d
Showing with 19 additions and 9 deletions.
  1. +4 −3 sql/item.cc
  2. +15 −6 sql/item.h
@@ -8747,8 +8747,9 @@ Item_cache_temporal::Item_cache_temporal(THD *thd,
enum_field_types field_type_arg):
Item_cache_int(thd, field_type_arg)
{
if (mysql_type_to_time_type(cached_field_type) == MYSQL_TIMESTAMP_ERROR)
cached_field_type= MYSQL_TYPE_DATETIME;
if (mysql_type_to_time_type(Item_cache_temporal::field_type()) ==
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)
Item *Item_cache_temporal::clone_item(THD *thd)
{
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);
return item;
}
@@ -4978,7 +4978,8 @@ class Item_trigger_field : public Item_field,
for any value.
*/

class Item_cache: public Item_basic_constant
class Item_cache: public Item_basic_constant,
public Type_handler_hybrid_field_type
{
protected:
Item *example;
@@ -4988,7 +4989,6 @@ class Item_cache: public Item_basic_constant
by IN->EXISTS transformation.
*/
Field *cached_field;
enum enum_field_types cached_field_type;
/*
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.
@@ -5000,25 +5000,27 @@ class Item_cache: public Item_basic_constant
public:
Item_cache(THD *thd):
Item_basic_constant(thd),
Type_handler_hybrid_field_type(MYSQL_TYPE_STRING),
example(0), cached_field(0),
cached_field_type(MYSQL_TYPE_STRING),
value_cached(0)
{
fixed= 1;
maybe_null= 1;
null_value= 1;
}
protected:
Item_cache(THD *thd, enum_field_types field_type_arg):
Item_basic_constant(thd),
Type_handler_hybrid_field_type(field_type_arg),
example(0), cached_field(0),
cached_field_type(field_type_arg),
value_cached(0)
{
fixed= 1;
maybe_null= 1;
null_value= 1;
}

public:
virtual bool allocate(THD *thd, uint i) { return 0; }
virtual bool setup(THD *thd, Item *item)
{
@@ -5029,7 +5031,14 @@ class Item_cache: public Item_basic_constant
return 0;
};
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, const Item_result type);
virtual void keep_array() {}
@@ -5172,7 +5181,7 @@ class Item_cache_str: public Item_cache
Item_cache_str(THD *thd, const Item *item):
Item_cache(thd, item->field_type()), value(0),
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())
{
collation.set(const_cast<DTCollation&>(item->collation));

0 comments on commit 192c748

Please sign in to comment.
You can’t perform that action at this time.