MDEV-10811 Change design from "Item is Type_handler" to "Item has Type_handler"
This commit is contained in:
parent
e5dfe04da0
commit
8b4f181c60
@ -1183,7 +1183,8 @@ static void make_sortkey(register Sort_param *param,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Item
|
{ // Item
|
||||||
sort_field->item->make_sort_key(to, sort_field->item, sort_field, param);
|
sort_field->item->type_handler()->make_sort_key(to, sort_field->item,
|
||||||
|
sort_field, param);
|
||||||
if ((maybe_null= sort_field->item->maybe_null))
|
if ((maybe_null= sort_field->item->maybe_null))
|
||||||
to++;
|
to++;
|
||||||
}
|
}
|
||||||
@ -1983,7 +1984,8 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sortorder->item->sortlength(thd, sortorder->item, sortorder);
|
sortorder->item->type_handler()->sortlength(thd, sortorder->item,
|
||||||
|
sortorder);
|
||||||
if (use_strnxfrm(sortorder->item->collation.collation))
|
if (use_strnxfrm(sortorder->item->collation.collation))
|
||||||
{
|
{
|
||||||
*multi_byte_charset= true;
|
*multi_byte_charset= true;
|
||||||
|
44
sql/item.h
44
sql/item.h
@ -642,8 +642,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
class Item: public Value_source,
|
class Item: public Value_source,
|
||||||
public Type_std_attributes,
|
public Type_std_attributes
|
||||||
public Type_handler
|
|
||||||
{
|
{
|
||||||
void operator=(Item &);
|
void operator=(Item &);
|
||||||
/**
|
/**
|
||||||
@ -855,35 +854,20 @@ public:
|
|||||||
{ return save_in_field(field, 1); }
|
{ return save_in_field(field, 1); }
|
||||||
virtual bool send(Protocol *protocol, String *str);
|
virtual bool send(Protocol *protocol, String *str);
|
||||||
virtual bool eq(const Item *, bool binary_cmp) const;
|
virtual bool eq(const Item *, bool binary_cmp) const;
|
||||||
const Type_handler *type_handler() const
|
virtual enum_field_types field_type() const= 0;
|
||||||
|
virtual const Type_handler *type_handler() const
|
||||||
{
|
{
|
||||||
return get_handler_by_field_type(field_type());
|
return Type_handler::get_handler_by_field_type(field_type());
|
||||||
}
|
|
||||||
Field *make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
|
|
||||||
const Item *item) const
|
|
||||||
{
|
|
||||||
return type_handler()->make_num_distinct_aggregator_field(mem_root, this);
|
|
||||||
}
|
|
||||||
Field *make_conversion_table_field(TABLE *table,
|
|
||||||
uint metadata, const Field *target) const
|
|
||||||
{
|
|
||||||
DBUG_ASSERT(0); // Should not be called in Item context
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
/* result_type() of an item specifies how the value should be returned */
|
/* result_type() of an item specifies how the value should be returned */
|
||||||
Item_result result_type() const { return type_handler()->result_type(); }
|
virtual Item_result result_type() const
|
||||||
/* ... while cmp_type() specifies how it should be compared */
|
|
||||||
Item_result cmp_type() const { return type_handler()->cmp_type(); }
|
|
||||||
void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field,
|
|
||||||
Sort_param *param) const
|
|
||||||
{
|
{
|
||||||
type_handler()->make_sort_key(to, item, sort_field, param);
|
return type_handler()->result_type();
|
||||||
}
|
}
|
||||||
void sortlength(THD *thd,
|
/* ... while cmp_type() specifies how it should be compared */
|
||||||
const Type_std_attributes *item,
|
virtual Item_result cmp_type() const
|
||||||
SORT_FIELD_ATTR *attr) const
|
|
||||||
{
|
{
|
||||||
type_handler()->sortlength(thd, item, attr);
|
return type_handler()->cmp_type();
|
||||||
}
|
}
|
||||||
virtual Item_result cast_to_int_type() const { return cmp_type(); }
|
virtual Item_result cast_to_int_type() const { return cmp_type(); }
|
||||||
enum_field_types string_field_type() const
|
enum_field_types string_field_type() const
|
||||||
@ -2182,6 +2166,8 @@ public:
|
|||||||
inline uint get_var_idx() const;
|
inline uint get_var_idx() const;
|
||||||
|
|
||||||
inline enum Type type() const;
|
inline enum Type type() const;
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
@ -2840,6 +2826,8 @@ public:
|
|||||||
|
|
||||||
enum Type item_type;
|
enum Type item_type;
|
||||||
|
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
@ -4835,6 +4823,8 @@ public:
|
|||||||
/** All of the subclasses should have the same type tag */
|
/** All of the subclasses should have the same type tag */
|
||||||
enum Type type() const { return COPY_STR_ITEM; }
|
enum Type type() const { return COPY_STR_ITEM; }
|
||||||
|
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
@ -5356,6 +5346,8 @@ public:
|
|||||||
};
|
};
|
||||||
enum Type type() const { return CACHE_ITEM; }
|
enum Type type() const { return CACHE_ITEM; }
|
||||||
|
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
@ -5669,6 +5661,8 @@ protected:
|
|||||||
public:
|
public:
|
||||||
Item_type_holder(THD*, Item*);
|
Item_type_holder(THD*, Item*);
|
||||||
|
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_real_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_real_field_type::field_type(); }
|
{ return Type_handler_hybrid_real_field_type::field_type(); }
|
||||||
enum_field_types real_field_type() const
|
enum_field_types real_field_type() const
|
||||||
|
@ -399,6 +399,8 @@ public:
|
|||||||
Item_hybrid_func(THD *thd, List<Item> &list): Item_func(thd, list) { }
|
Item_hybrid_func(THD *thd, List<Item> &list): Item_func(thd, list) { }
|
||||||
Item_hybrid_func(THD *thd, Item_hybrid_func *item)
|
Item_hybrid_func(THD *thd, Item_hybrid_func *item)
|
||||||
:Item_func(thd, item), Type_handler_hybrid_field_type(item) { }
|
:Item_func(thd, item), Type_handler_hybrid_field_type(item) { }
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
|
@ -867,7 +867,8 @@ bool Aggregator_distinct::setup(THD *thd)
|
|||||||
if (always_null)
|
if (always_null)
|
||||||
DBUG_RETURN(FALSE);
|
DBUG_RETURN(FALSE);
|
||||||
|
|
||||||
Field *field= arg->make_num_distinct_aggregator_field(thd->mem_root, arg);
|
Field *field= arg->type_handler()->
|
||||||
|
make_num_distinct_aggregator_field(thd->mem_root, arg);
|
||||||
if (!field || !(table= create_virtual_tmp_table(thd, field)))
|
if (!field || !(table= create_virtual_tmp_table(thd, field)))
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
|
@ -755,6 +755,8 @@ public:
|
|||||||
longlong val_int();
|
longlong val_int();
|
||||||
String *val_str(String*str);
|
String *val_str(String*str);
|
||||||
my_decimal *val_decimal(my_decimal *);
|
my_decimal *val_decimal(my_decimal *);
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
@ -1012,6 +1014,8 @@ protected:
|
|||||||
void reset_field();
|
void reset_field();
|
||||||
String *val_str(String *);
|
String *val_str(String *);
|
||||||
bool keep_field_type(void) const { return 1; }
|
bool keep_field_type(void) const { return 1; }
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
{ return Type_handler_hybrid_field_type::result_type(); }
|
{ return Type_handler_hybrid_field_type::result_type(); }
|
||||||
enum Item_result cmp_type () const
|
enum Item_result cmp_type () const
|
||||||
|
@ -565,6 +565,8 @@ protected:
|
|||||||
public:
|
public:
|
||||||
Item_temporal_hybrid_func(THD *thd, Item *a, Item *b):
|
Item_temporal_hybrid_func(THD *thd, Item *a, Item *b):
|
||||||
Item_temporal_func(thd, a, b) {}
|
Item_temporal_func(thd, a, b) {}
|
||||||
|
const Type_handler *type_handler() const
|
||||||
|
{ return Type_handler_hybrid_field_type::type_handler(); }
|
||||||
enum_field_types field_type() const
|
enum_field_types field_type() const
|
||||||
{ return Type_handler_hybrid_field_type::field_type(); }
|
{ return Type_handler_hybrid_field_type::field_type(); }
|
||||||
enum Item_result result_type () const
|
enum Item_result result_type () const
|
||||||
|
@ -68,7 +68,7 @@ static Type_handler_set type_handler_set;
|
|||||||
all around the code.
|
all around the code.
|
||||||
*/
|
*/
|
||||||
const Type_handler *
|
const Type_handler *
|
||||||
Type_handler::string_type_handler(uint max_octet_length) const
|
Type_handler::string_type_handler(uint max_octet_length)
|
||||||
{
|
{
|
||||||
if (max_octet_length >= 16777216)
|
if (max_octet_length >= 16777216)
|
||||||
return &type_handler_long_blob;
|
return &type_handler_long_blob;
|
||||||
|
@ -33,12 +33,12 @@ struct SORT_FIELD_ATTR;
|
|||||||
class Type_handler
|
class Type_handler
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
const Type_handler *string_type_handler(uint max_octet_length) const;
|
|
||||||
void make_sort_key_longlong(uchar *to,
|
void make_sort_key_longlong(uchar *to,
|
||||||
bool maybe_null, bool null_value,
|
bool maybe_null, bool null_value,
|
||||||
bool unsigned_flag,
|
bool unsigned_flag,
|
||||||
longlong value) const;
|
longlong value) const;
|
||||||
public:
|
public:
|
||||||
|
static const Type_handler *string_type_handler(uint max_octet_length);
|
||||||
static const Type_handler *get_handler_by_field_type(enum_field_types type);
|
static const Type_handler *get_handler_by_field_type(enum_field_types type);
|
||||||
static const Type_handler *get_handler_by_real_type(enum_field_types type);
|
static const Type_handler *get_handler_by_real_type(enum_field_types type);
|
||||||
virtual enum_field_types field_type() const= 0;
|
virtual enum_field_types field_type() const= 0;
|
||||||
@ -499,7 +499,7 @@ public:
|
|||||||
Makes sure that field_type(), cmp_type() and result_type()
|
Makes sure that field_type(), cmp_type() and result_type()
|
||||||
are always in sync to each other for hybrid functions.
|
are always in sync to each other for hybrid functions.
|
||||||
*/
|
*/
|
||||||
class Type_handler_hybrid_field_type: public Type_handler
|
class Type_handler_hybrid_field_type
|
||||||
{
|
{
|
||||||
const Type_handler *m_type_handler;
|
const Type_handler *m_type_handler;
|
||||||
const Type_handler *get_handler_by_result_type(Item_result type) const;
|
const Type_handler *get_handler_by_result_type(Item_result type) const;
|
||||||
@ -509,11 +509,12 @@ public:
|
|||||||
:m_type_handler(handler)
|
:m_type_handler(handler)
|
||||||
{ }
|
{ }
|
||||||
Type_handler_hybrid_field_type(enum_field_types type)
|
Type_handler_hybrid_field_type(enum_field_types type)
|
||||||
:m_type_handler(get_handler_by_field_type(type))
|
:m_type_handler(Type_handler::get_handler_by_field_type(type))
|
||||||
{ }
|
{ }
|
||||||
Type_handler_hybrid_field_type(const Type_handler_hybrid_field_type *other)
|
Type_handler_hybrid_field_type(const Type_handler_hybrid_field_type *other)
|
||||||
:m_type_handler(other->m_type_handler)
|
:m_type_handler(other->m_type_handler)
|
||||||
{ }
|
{ }
|
||||||
|
const Type_handler *type_handler() const { return m_type_handler; }
|
||||||
enum_field_types field_type() const { return m_type_handler->field_type(); }
|
enum_field_types field_type() const { return m_type_handler->field_type(); }
|
||||||
enum_field_types real_field_type() const
|
enum_field_types real_field_type() const
|
||||||
{
|
{
|
||||||
@ -540,42 +541,12 @@ public:
|
|||||||
}
|
}
|
||||||
const Type_handler *set_handler_by_field_type(enum_field_types type)
|
const Type_handler *set_handler_by_field_type(enum_field_types type)
|
||||||
{
|
{
|
||||||
return (m_type_handler= get_handler_by_field_type(type));
|
return (m_type_handler= Type_handler::get_handler_by_field_type(type));
|
||||||
}
|
}
|
||||||
const Type_handler *set_handler_by_real_type(enum_field_types type)
|
const Type_handler *set_handler_by_real_type(enum_field_types type)
|
||||||
{
|
{
|
||||||
return (m_type_handler= get_handler_by_real_type(type));
|
return (m_type_handler= Type_handler::get_handler_by_real_type(type));
|
||||||
}
|
}
|
||||||
const Type_handler *
|
|
||||||
type_handler_adjusted_to_max_octet_length(uint max_octet_length,
|
|
||||||
CHARSET_INFO *cs) const
|
|
||||||
{
|
|
||||||
return
|
|
||||||
m_type_handler->type_handler_adjusted_to_max_octet_length(max_octet_length,
|
|
||||||
cs);
|
|
||||||
}
|
|
||||||
Field *make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
|
|
||||||
const Item *item) const
|
|
||||||
{
|
|
||||||
return m_type_handler->make_num_distinct_aggregator_field(mem_root, item);
|
|
||||||
}
|
|
||||||
Field *make_conversion_table_field(TABLE *table, uint metadata,
|
|
||||||
const Field *target) const
|
|
||||||
{
|
|
||||||
return m_type_handler->make_conversion_table_field(table, metadata, target);
|
|
||||||
}
|
|
||||||
void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field,
|
|
||||||
Sort_param *param) const
|
|
||||||
{
|
|
||||||
m_type_handler->make_sort_key(to, item, sort_field, param);
|
|
||||||
}
|
|
||||||
void sortlength(THD *thd,
|
|
||||||
const Type_std_attributes *item,
|
|
||||||
SORT_FIELD_ATTR *attr) const
|
|
||||||
{
|
|
||||||
m_type_handler->sortlength(thd, item, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -587,7 +558,8 @@ class Type_handler_hybrid_real_field_type:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Type_handler_hybrid_real_field_type(enum_field_types type)
|
Type_handler_hybrid_real_field_type(enum_field_types type)
|
||||||
:Type_handler_hybrid_field_type(get_handler_by_real_type(type))
|
:Type_handler_hybrid_field_type(Type_handler::
|
||||||
|
get_handler_by_real_type(type))
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user