Skip to content

Commit 8b4f181

Browse files
author
Alexander Barkov
committed
MDEV-10811 Change design from "Item is Type_handler" to "Item has Type_handler"
1 parent e5dfe04 commit 8b4f181

File tree

8 files changed

+42
-65
lines changed

8 files changed

+42
-65
lines changed

sql/filesort.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,8 @@ static void make_sortkey(register Sort_param *param,
11831183
}
11841184
else
11851185
{ // Item
1186-
sort_field->item->make_sort_key(to, sort_field->item, sort_field, param);
1186+
sort_field->item->type_handler()->make_sort_key(to, sort_field->item,
1187+
sort_field, param);
11871188
if ((maybe_null= sort_field->item->maybe_null))
11881189
to++;
11891190
}
@@ -1983,7 +1984,8 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
19831984
}
19841985
else
19851986
{
1986-
sortorder->item->sortlength(thd, sortorder->item, sortorder);
1987+
sortorder->item->type_handler()->sortlength(thd, sortorder->item,
1988+
sortorder);
19871989
if (use_strnxfrm(sortorder->item->collation.collation))
19881990
{
19891991
*multi_byte_charset= true;

sql/item.h

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,7 @@ class Type_std_attributes
642642

643643

644644
class Item: public Value_source,
645-
public Type_std_attributes,
646-
public Type_handler
645+
public Type_std_attributes
647646
{
648647
void operator=(Item &);
649648
/**
@@ -855,35 +854,20 @@ class Item: public Value_source,
855854
{ return save_in_field(field, 1); }
856855
virtual bool send(Protocol *protocol, String *str);
857856
virtual bool eq(const Item *, bool binary_cmp) const;
858-
const Type_handler *type_handler() const
857+
virtual enum_field_types field_type() const= 0;
858+
virtual const Type_handler *type_handler() const
859859
{
860-
return get_handler_by_field_type(field_type());
861-
}
862-
Field *make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
863-
const Item *item) const
864-
{
865-
return type_handler()->make_num_distinct_aggregator_field(mem_root, this);
866-
}
867-
Field *make_conversion_table_field(TABLE *table,
868-
uint metadata, const Field *target) const
869-
{
870-
DBUG_ASSERT(0); // Should not be called in Item context
871-
return NULL;
860+
return Type_handler::get_handler_by_field_type(field_type());
872861
}
873862
/* result_type() of an item specifies how the value should be returned */
874-
Item_result result_type() const { return type_handler()->result_type(); }
875-
/* ... while cmp_type() specifies how it should be compared */
876-
Item_result cmp_type() const { return type_handler()->cmp_type(); }
877-
void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field,
878-
Sort_param *param) const
863+
virtual Item_result result_type() const
879864
{
880-
type_handler()->make_sort_key(to, item, sort_field, param);
865+
return type_handler()->result_type();
881866
}
882-
void sortlength(THD *thd,
883-
const Type_std_attributes *item,
884-
SORT_FIELD_ATTR *attr) const
867+
/* ... while cmp_type() specifies how it should be compared */
868+
virtual Item_result cmp_type() const
885869
{
886-
type_handler()->sortlength(thd, item, attr);
870+
return type_handler()->cmp_type();
887871
}
888872
virtual Item_result cast_to_int_type() const { return cmp_type(); }
889873
enum_field_types string_field_type() const
@@ -2182,6 +2166,8 @@ class Item_splocal :public Item_sp_variable,
21822166
inline uint get_var_idx() const;
21832167

21842168
inline enum Type type() const;
2169+
const Type_handler *type_handler() const
2170+
{ return Type_handler_hybrid_field_type::type_handler(); }
21852171
enum_field_types field_type() const
21862172
{ return Type_handler_hybrid_field_type::field_type(); }
21872173
enum Item_result result_type () const
@@ -2840,6 +2826,8 @@ class Item_param :public Item_basic_value,
28402826

28412827
enum Type item_type;
28422828

2829+
const Type_handler *type_handler() const
2830+
{ return Type_handler_hybrid_field_type::type_handler(); }
28432831
enum_field_types field_type() const
28442832
{ return Type_handler_hybrid_field_type::field_type(); }
28452833
enum Item_result result_type () const
@@ -4835,6 +4823,8 @@ class Item_copy :public Item,
48354823
/** All of the subclasses should have the same type tag */
48364824
enum Type type() const { return COPY_STR_ITEM; }
48374825

4826+
const Type_handler *type_handler() const
4827+
{ return Type_handler_hybrid_field_type::type_handler(); }
48384828
enum_field_types field_type() const
48394829
{ return Type_handler_hybrid_field_type::field_type(); }
48404830
enum Item_result result_type () const
@@ -5356,6 +5346,8 @@ class Item_cache: public Item_basic_constant,
53565346
};
53575347
enum Type type() const { return CACHE_ITEM; }
53585348

5349+
const Type_handler *type_handler() const
5350+
{ return Type_handler_hybrid_field_type::type_handler(); }
53595351
enum_field_types field_type() const
53605352
{ return Type_handler_hybrid_field_type::field_type(); }
53615353
enum Item_result result_type () const
@@ -5669,6 +5661,8 @@ class Item_type_holder: public Item,
56695661
public:
56705662
Item_type_holder(THD*, Item*);
56715663

5664+
const Type_handler *type_handler() const
5665+
{ return Type_handler_hybrid_real_field_type::type_handler(); }
56725666
enum_field_types field_type() const
56735667
{ return Type_handler_hybrid_real_field_type::field_type(); }
56745668
enum_field_types real_field_type() const

sql/item_func.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ class Item_hybrid_func: public Item_func,
399399
Item_hybrid_func(THD *thd, List<Item> &list): Item_func(thd, list) { }
400400
Item_hybrid_func(THD *thd, Item_hybrid_func *item)
401401
:Item_func(thd, item), Type_handler_hybrid_field_type(item) { }
402+
const Type_handler *type_handler() const
403+
{ return Type_handler_hybrid_field_type::type_handler(); }
402404
enum_field_types field_type() const
403405
{ return Type_handler_hybrid_field_type::field_type(); }
404406
enum Item_result result_type () const

sql/item_sum.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ bool Aggregator_distinct::setup(THD *thd)
867867
if (always_null)
868868
DBUG_RETURN(FALSE);
869869

870-
Field *field= arg->make_num_distinct_aggregator_field(thd->mem_root, arg);
870+
Field *field= arg->type_handler()->
871+
make_num_distinct_aggregator_field(thd->mem_root, arg);
871872
if (!field || !(table= create_virtual_tmp_table(thd, field)))
872873
DBUG_RETURN(TRUE);
873874

sql/item_sum.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ class Item_sum_sum :public Item_sum_num,
755755
longlong val_int();
756756
String *val_str(String*str);
757757
my_decimal *val_decimal(my_decimal *);
758+
const Type_handler *type_handler() const
759+
{ return Type_handler_hybrid_field_type::type_handler(); }
758760
enum_field_types field_type() const
759761
{ return Type_handler_hybrid_field_type::field_type(); }
760762
enum Item_result result_type () const
@@ -1012,6 +1014,8 @@ class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
10121014
void reset_field();
10131015
String *val_str(String *);
10141016
bool keep_field_type(void) const { return 1; }
1017+
const Type_handler *type_handler() const
1018+
{ return Type_handler_hybrid_field_type::type_handler(); }
10151019
enum Item_result result_type () const
10161020
{ return Type_handler_hybrid_field_type::result_type(); }
10171021
enum Item_result cmp_type () const

sql/item_timefunc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ class Item_temporal_hybrid_func: public Item_temporal_func,
565565
public:
566566
Item_temporal_hybrid_func(THD *thd, Item *a, Item *b):
567567
Item_temporal_func(thd, a, b) {}
568+
const Type_handler *type_handler() const
569+
{ return Type_handler_hybrid_field_type::type_handler(); }
568570
enum_field_types field_type() const
569571
{ return Type_handler_hybrid_field_type::field_type(); }
570572
enum Item_result result_type () const

sql/sql_type.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static Type_handler_set type_handler_set;
6868
all around the code.
6969
*/
7070
const Type_handler *
71-
Type_handler::string_type_handler(uint max_octet_length) const
71+
Type_handler::string_type_handler(uint max_octet_length)
7272
{
7373
if (max_octet_length >= 16777216)
7474
return &type_handler_long_blob;

sql/sql_type.h

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ struct SORT_FIELD_ATTR;
3333
class Type_handler
3434
{
3535
protected:
36-
const Type_handler *string_type_handler(uint max_octet_length) const;
3736
void make_sort_key_longlong(uchar *to,
3837
bool maybe_null, bool null_value,
3938
bool unsigned_flag,
4039
longlong value) const;
4140
public:
41+
static const Type_handler *string_type_handler(uint max_octet_length);
4242
static const Type_handler *get_handler_by_field_type(enum_field_types type);
4343
static const Type_handler *get_handler_by_real_type(enum_field_types type);
4444
virtual enum_field_types field_type() const= 0;
@@ -499,7 +499,7 @@ class Type_handler_set: public Type_handler_string_result
499499
Makes sure that field_type(), cmp_type() and result_type()
500500
are always in sync to each other for hybrid functions.
501501
*/
502-
class Type_handler_hybrid_field_type: public Type_handler
502+
class Type_handler_hybrid_field_type
503503
{
504504
const Type_handler *m_type_handler;
505505
const Type_handler *get_handler_by_result_type(Item_result type) const;
@@ -509,11 +509,12 @@ class Type_handler_hybrid_field_type: public Type_handler
509509
:m_type_handler(handler)
510510
{ }
511511
Type_handler_hybrid_field_type(enum_field_types type)
512-
:m_type_handler(get_handler_by_field_type(type))
512+
:m_type_handler(Type_handler::get_handler_by_field_type(type))
513513
{ }
514514
Type_handler_hybrid_field_type(const Type_handler_hybrid_field_type *other)
515515
:m_type_handler(other->m_type_handler)
516516
{ }
517+
const Type_handler *type_handler() const { return m_type_handler; }
517518
enum_field_types field_type() const { return m_type_handler->field_type(); }
518519
enum_field_types real_field_type() const
519520
{
@@ -540,42 +541,12 @@ class Type_handler_hybrid_field_type: public Type_handler
540541
}
541542
const Type_handler *set_handler_by_field_type(enum_field_types type)
542543
{
543-
return (m_type_handler= get_handler_by_field_type(type));
544+
return (m_type_handler= Type_handler::get_handler_by_field_type(type));
544545
}
545546
const Type_handler *set_handler_by_real_type(enum_field_types type)
546547
{
547-
return (m_type_handler= get_handler_by_real_type(type));
548+
return (m_type_handler= Type_handler::get_handler_by_real_type(type));
548549
}
549-
const Type_handler *
550-
type_handler_adjusted_to_max_octet_length(uint max_octet_length,
551-
CHARSET_INFO *cs) const
552-
{
553-
return
554-
m_type_handler->type_handler_adjusted_to_max_octet_length(max_octet_length,
555-
cs);
556-
}
557-
Field *make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
558-
const Item *item) const
559-
{
560-
return m_type_handler->make_num_distinct_aggregator_field(mem_root, item);
561-
}
562-
Field *make_conversion_table_field(TABLE *table, uint metadata,
563-
const Field *target) const
564-
{
565-
return m_type_handler->make_conversion_table_field(table, metadata, target);
566-
}
567-
void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field,
568-
Sort_param *param) const
569-
{
570-
m_type_handler->make_sort_key(to, item, sort_field, param);
571-
}
572-
void sortlength(THD *thd,
573-
const Type_std_attributes *item,
574-
SORT_FIELD_ATTR *attr) const
575-
{
576-
m_type_handler->sortlength(thd, item, attr);
577-
}
578-
579550
};
580551

581552

@@ -587,7 +558,8 @@ class Type_handler_hybrid_real_field_type:
587558
{
588559
public:
589560
Type_handler_hybrid_real_field_type(enum_field_types type)
590-
:Type_handler_hybrid_field_type(get_handler_by_real_type(type))
561+
:Type_handler_hybrid_field_type(Type_handler::
562+
get_handler_by_real_type(type))
591563
{ }
592564
};
593565

0 commit comments

Comments
 (0)