Skip to content

Commit

Permalink
MDEV-9215 Detect cmp_type() and result_type() from field_type()
Browse files Browse the repository at this point in the history
(A dependency task for MDEV-4912 Add a plugin to field types)
  • Loading branch information
Alexander Barkov committed Dec 1, 2015
1 parent e3fed3b commit 607ef78
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 49 deletions.
44 changes: 1 addition & 43 deletions sql/item.cc
Expand Up @@ -630,48 +630,6 @@ void Item::rename(char *new_name)
name= new_name;
}

Item_result Item::cmp_type() const
{
switch (field_type()) {
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
return DECIMAL_RESULT;
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT:
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_INT24:
case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_BIT:
return INT_RESULT;
case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_DOUBLE:
return REAL_RESULT;
case MYSQL_TYPE_NULL:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_SET:
case MYSQL_TYPE_GEOMETRY:
return STRING_RESULT;
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_TIMESTAMP2:
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_TIME2:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_DATETIME2:
case MYSQL_TYPE_NEWDATE:
return TIME_RESULT;
};
DBUG_ASSERT(0);
return STRING_RESULT;
}

/**
Traverse item tree possibly transforming it (replacing items).
Expand Down Expand Up @@ -5392,7 +5350,7 @@ void Item_empty_string::make_field(THD *thd, Send_field *tmp_field)
}


enum_field_types Item::field_type() const
enum_field_types Item::field_type_by_result_type() const
{
switch (result_type()) {
case STRING_RESULT: return string_field_type();
Expand Down
17 changes: 14 additions & 3 deletions sql/item.h
Expand Up @@ -755,16 +755,20 @@ class Item: public Value_source,
{ return save_in_field(field, 1); }
virtual bool send(Protocol *protocol, String *str);
virtual bool eq(const Item *, bool binary_cmp) const;
const Type_handler *type_handler() const
{
return get_handler_by_field_type(field_type());
}
/* result_type() of an item specifies how the value should be returned */
Item_result result_type() const { return REAL_RESULT; }
Item_result result_type() const { return type_handler()->result_type(); }
/* ... while cmp_type() specifies how it should be compared */
Item_result cmp_type() const;
Item_result cmp_type() const { return type_handler()->cmp_type(); }
virtual Item_result cast_to_int_type() const { return cmp_type(); }
enum_field_types string_field_type() const
{
return Type_handler::string_type_handler(max_length)->field_type();
}
enum_field_types field_type() const;
enum_field_types field_type_by_result_type() const;
virtual enum Type type() const =0;
/*
real_type() is the type of base item. This is same as type() for
Expand Down Expand Up @@ -2111,6 +2115,7 @@ class Item_case_expr :public Item_sp_variable

inline enum Type type() const;
inline Item_result result_type() const;
enum_field_types field_type() const { return this_item()->field_type(); }

public:
/*
Expand Down Expand Up @@ -2171,6 +2176,11 @@ class Item_name_const : public Item
bool is_null();
virtual void print(String *str, enum_query_type query_type);

enum_field_types field_type() const
{
return value_item->field_type();
}

Item_result result_type() const
{
return value_item->result_type();
Expand Down Expand Up @@ -2328,6 +2338,7 @@ class Item_ident_for_show :public Item
void make_field(THD *thd, Send_field *tmp_field);
CHARSET_INFO *charset_for_protocol(void) const
{ return field->charset_for_protocol(); }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
};


Expand Down
8 changes: 8 additions & 0 deletions sql/item_func.h
Expand Up @@ -376,6 +376,7 @@ class Item_real_func :public Item_func
longlong val_int()
{ DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); }
enum Item_result result_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
void fix_length_and_dec()
{ decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
};
Expand Down Expand Up @@ -595,6 +596,7 @@ class Item_int_func :public Item_func
double val_real();
String *val_str(String*str);
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() {}
};

Expand Down Expand Up @@ -1115,6 +1117,7 @@ class Item_func_rollup_const :public Item_func
const char *func_name() const { return "rollup_const"; }
bool const_item() const { return 0; }
Item_result result_type() const { return args[0]->result_type(); }
enum_field_types field_type() const { return args[0]->field_type(); }
void fix_length_and_dec()
{
collation= args[0]->collation;
Expand Down Expand Up @@ -1473,6 +1476,7 @@ class Item_func_udf_float :public Item_udf_func
}
double val_real();
String *val_str(String *str);
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
void fix_length_and_dec() { fix_num_length_and_dec(); }
};

Expand All @@ -1489,6 +1493,7 @@ class Item_func_udf_int :public Item_udf_func
double val_real() { return (double) Item_func_udf_int::val_int(); }
String *val_str(String *str);
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() { decimals= 0; max_length= 21; }
};

Expand All @@ -1505,6 +1510,7 @@ class Item_func_udf_decimal :public Item_udf_func
my_decimal *val_decimal(my_decimal *);
String *val_str(String *str);
enum Item_result result_type () const { return DECIMAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
void fix_length_and_dec() { fix_num_length_and_dec(); }
};

Expand Down Expand Up @@ -1542,6 +1548,7 @@ class Item_func_udf_str :public Item_udf_func
return dec_buf;
}
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return string_field_type(); }
void fix_length_and_dec();
};

Expand Down Expand Up @@ -1851,6 +1858,7 @@ class Item_user_var_as_out_param :public Item
void print_for_load(THD *thd, String *str);
void set_null_value(CHARSET_INFO* cs);
void set_value(const char *str, uint length, CHARSET_INFO* cs);
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
};


Expand Down
5 changes: 5 additions & 0 deletions sql/item_row.h
Expand Up @@ -82,6 +82,11 @@ class Item_row: public Item,
bool const_item() const { return const_item_cache; };
enum Item_result result_type() const { return ROW_RESULT; }
Item_result cmp_type() const { return ROW_RESULT; }
enum_field_types field_type() const
{
DBUG_ASSERT(0);
return MYSQL_TYPE_DOUBLE;
}
void update_used_tables()
{
used_tables_and_const_cache_init();
Expand Down
1 change: 1 addition & 0 deletions sql/item_strfunc.h
Expand Up @@ -65,6 +65,7 @@ class Item_str_func :public Item_func
double val_real();
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return string_field_type(); }
void left_right_max_length();
bool fix_fields(THD *thd, Item **ref);
void update_null_value()
Expand Down
1 change: 1 addition & 0 deletions sql/item_subselect.h
Expand Up @@ -378,6 +378,7 @@ class Item_exists_subselect :public Item_subselect
void no_rows_in_result();

enum Item_result result_type() const { return INT_RESULT;}
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
longlong val_int();
double val_real();
String *val_str(String*);
Expand Down
12 changes: 12 additions & 0 deletions sql/item_sum.h
Expand Up @@ -715,6 +715,7 @@ class Item_sum_int :public Item_sum_num
String *val_str(String*str);
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec()
{ decimals=0; max_length=21; maybe_null=null_value=0; }
};
Expand Down Expand Up @@ -747,6 +748,10 @@ class Item_sum_sum :public Item_sum_num
String *val_str(String*str);
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return hybrid_type; }
enum_field_types field_type() const
{
return field_type_by_result_type();
}
void reset_field();
void update_field();
void no_rows_in_result() {}
Expand Down Expand Up @@ -1258,6 +1263,9 @@ class Item_sum_udf_float :public Item_udf_sum
double val_real();
String *val_str(String*str);
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return REAL_RESULT; }
enum Item_result cmp_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
void fix_length_and_dec() { fix_num_length_and_dec(); }
Item *copy_or_same(THD* thd);
};
Expand All @@ -1278,6 +1286,7 @@ class Item_sum_udf_int :public Item_udf_sum
String *val_str(String*str);
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() { decimals=0; max_length=21; }
Item *copy_or_same(THD* thd);
};
Expand Down Expand Up @@ -1317,6 +1326,7 @@ class Item_sum_udf_str :public Item_udf_sum
}
my_decimal *val_decimal(my_decimal *dec);
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return string_field_type(); }
void fix_length_and_dec();
Item *copy_or_same(THD* thd);
};
Expand All @@ -1336,6 +1346,7 @@ class Item_sum_udf_decimal :public Item_udf_sum
longlong val_int();
my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return DECIMAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
void fix_length_and_dec() { fix_num_length_and_dec(); }
Item *copy_or_same(THD* thd);
};
Expand Down Expand Up @@ -1484,6 +1495,7 @@ class Item_func_group_concat : public Item_sum
enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;}
const char *func_name() const { return "group_concat"; }
virtual Item_result result_type () const { return STRING_RESULT; }
virtual Item_result cmp_type () const { return STRING_RESULT; }
virtual Field *make_string_field(TABLE *table);
enum_field_types field_type() const
{
Expand Down
3 changes: 3 additions & 0 deletions sql/item_timefunc.h
Expand Up @@ -165,6 +165,7 @@ class Item_func_month :public Item_func
}
const char *func_name() const { return "month"; }
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec()
{
decimals= 0;
Expand Down Expand Up @@ -379,6 +380,7 @@ class Item_func_weekday :public Item_func
return (odbc_type ? "dayofweek" : "weekday");
}
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec()
{
decimals= 0;
Expand All @@ -401,6 +403,7 @@ class Item_func_dayname :public Item_func_weekday
const char *func_name() const { return "dayname"; }
String *val_str(String *str);
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
void fix_length_and_dec();
bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
bool check_vcol_func_processor(uchar *int_arg) { return FALSE;}
Expand Down
3 changes: 3 additions & 0 deletions sql/procedure.h
Expand Up @@ -69,6 +69,7 @@ class Item_proc_real :public Item_proc
decimals=dec; max_length=float_length(dec);
}
enum Item_result result_type () const { return REAL_RESULT; }
enum Item_result cmp_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
void set(double nr) { value=nr; }
void set(longlong nr) { value=(double) nr; }
Expand Down Expand Up @@ -96,6 +97,7 @@ class Item_proc_int :public Item_proc
Item_proc_int(THD *thd, const char *name_par): Item_proc(thd, name_par)
{ max_length=11; }
enum Item_result result_type () const { return INT_RESULT; }
enum Item_result cmp_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void set(double nr) { value=(longlong) nr; }
void set(longlong nr) { value=nr; }
Expand All @@ -115,6 +117,7 @@ class Item_proc_string :public Item_proc
Item_proc_string(THD *thd, const char *name_par, uint length):
Item_proc(thd, name_par) { this->max_length=length; }
enum Item_result result_type () const { return STRING_RESULT; }
enum Item_result cmp_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
void set(double nr) { str_value.set_real(nr, 2, default_charset()); }
void set(longlong nr) { str_value.set(nr, default_charset()); }
Expand Down
3 changes: 1 addition & 2 deletions sql/sql_type.cc
Expand Up @@ -111,8 +111,7 @@ Type_handler_hybrid_field_type::Type_handler_hybrid_field_type()


const Type_handler *
Type_handler_hybrid_field_type::get_handler_by_field_type(enum_field_types type)
const
Type_handler::get_handler_by_field_type(enum_field_types type)
{
switch (type) {
case MYSQL_TYPE_DECIMAL: return &type_handler_olddecimal;
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_type.h
Expand Up @@ -28,6 +28,7 @@ class Type_handler
protected:
const Type_handler *string_type_handler(uint max_octet_length) const;
public:
static const Type_handler *get_handler_by_field_type(enum_field_types type);
virtual enum_field_types field_type() const= 0;
virtual Item_result result_type() const= 0;
virtual Item_result cmp_type() const= 0;
Expand Down Expand Up @@ -306,7 +307,6 @@ class Type_handler_hybrid_field_type: public 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_field_type(enum_field_types type) const;
public:
Type_handler_hybrid_field_type();
Type_handler_hybrid_field_type(enum_field_types type)
Expand Down

0 comments on commit 607ef78

Please sign in to comment.