Commit 607ef786 authored by Alexander Barkov's avatar Alexander Barkov

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

(A dependency task for MDEV-4912 Add a plugin to field types)
parent e3fed3b9
...@@ -630,48 +630,6 @@ void Item::rename(char *new_name) ...@@ -630,48 +630,6 @@ void Item::rename(char *new_name)
name= 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). Traverse item tree possibly transforming it (replacing items).
...@@ -5392,7 +5350,7 @@ void Item_empty_string::make_field(THD *thd, Send_field *tmp_field) ...@@ -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()) { switch (result_type()) {
case STRING_RESULT: return string_field_type(); case STRING_RESULT: return string_field_type();
......
...@@ -755,16 +755,20 @@ class Item: public Value_source, ...@@ -755,16 +755,20 @@ class Item: public Value_source,
{ 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
{
return get_handler_by_field_type(field_type());
}
/* 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 REAL_RESULT; } Item_result result_type() const { return type_handler()->result_type(); }
/* ... while cmp_type() specifies how it should be compared */ /* ... 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(); } 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
{ {
return Type_handler::string_type_handler(max_length)->field_type(); 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; virtual enum Type type() const =0;
/* /*
real_type() is the type of base item. This is same as type() for real_type() is the type of base item. This is same as type() for
...@@ -2111,6 +2115,7 @@ class Item_case_expr :public Item_sp_variable ...@@ -2111,6 +2115,7 @@ class Item_case_expr :public Item_sp_variable
inline enum Type type() const; inline enum Type type() const;
inline Item_result result_type() const; inline Item_result result_type() const;
enum_field_types field_type() const { return this_item()->field_type(); }
public: public:
/* /*
...@@ -2171,6 +2176,11 @@ class Item_name_const : public Item ...@@ -2171,6 +2176,11 @@ class Item_name_const : public Item
bool is_null(); bool is_null();
virtual void print(String *str, enum_query_type query_type); 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 Item_result result_type() const
{ {
return value_item->result_type(); return value_item->result_type();
...@@ -2328,6 +2338,7 @@ class Item_ident_for_show :public Item ...@@ -2328,6 +2338,7 @@ class Item_ident_for_show :public Item
void make_field(THD *thd, Send_field *tmp_field); void make_field(THD *thd, Send_field *tmp_field);
CHARSET_INFO *charset_for_protocol(void) const CHARSET_INFO *charset_for_protocol(void) const
{ return field->charset_for_protocol(); } { return field->charset_for_protocol(); }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
}; };
......
...@@ -376,6 +376,7 @@ class Item_real_func :public Item_func ...@@ -376,6 +376,7 @@ class Item_real_func :public Item_func
longlong val_int() longlong val_int()
{ DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); } { DBUG_ASSERT(fixed == 1); return (longlong) rint(val_real()); }
enum Item_result result_type () const { return REAL_RESULT; } enum Item_result result_type () const { return REAL_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
void fix_length_and_dec() void fix_length_and_dec()
{ decimals= NOT_FIXED_DEC; max_length= float_length(decimals); } { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
}; };
...@@ -595,6 +596,7 @@ class Item_int_func :public Item_func ...@@ -595,6 +596,7 @@ class Item_int_func :public Item_func
double val_real(); double val_real();
String *val_str(String*str); String *val_str(String*str);
enum Item_result result_type () const { return INT_RESULT; } enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() {} void fix_length_and_dec() {}
}; };
...@@ -1115,6 +1117,7 @@ class Item_func_rollup_const :public Item_func ...@@ -1115,6 +1117,7 @@ class Item_func_rollup_const :public Item_func
const char *func_name() const { return "rollup_const"; } const char *func_name() const { return "rollup_const"; }
bool const_item() const { return 0; } bool const_item() const { return 0; }
Item_result result_type() const { return args[0]->result_type(); } 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() void fix_length_and_dec()
{ {
collation= args[0]->collation; collation= args[0]->collation;
...@@ -1473,6 +1476,7 @@ class Item_func_udf_float :public Item_udf_func ...@@ -1473,6 +1476,7 @@ class Item_func_udf_float :public Item_udf_func
} }
double val_real(); double val_real();
String *val_str(String *str); 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(); } void fix_length_and_dec() { fix_num_length_and_dec(); }
}; };
...@@ -1489,6 +1493,7 @@ class Item_func_udf_int :public Item_udf_func ...@@ -1489,6 +1493,7 @@ class Item_func_udf_int :public Item_udf_func
double val_real() { return (double) Item_func_udf_int::val_int(); } double val_real() { return (double) Item_func_udf_int::val_int(); }
String *val_str(String *str); String *val_str(String *str);
enum Item_result result_type () const { return INT_RESULT; } 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; } void fix_length_and_dec() { decimals= 0; max_length= 21; }
}; };
...@@ -1505,6 +1510,7 @@ class Item_func_udf_decimal :public Item_udf_func ...@@ -1505,6 +1510,7 @@ class Item_func_udf_decimal :public Item_udf_func
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
String *val_str(String *str); String *val_str(String *str);
enum Item_result result_type () const { return DECIMAL_RESULT; } 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(); } void fix_length_and_dec() { fix_num_length_and_dec(); }
}; };
...@@ -1542,6 +1548,7 @@ class Item_func_udf_str :public Item_udf_func ...@@ -1542,6 +1548,7 @@ class Item_func_udf_str :public Item_udf_func
return dec_buf; return dec_buf;
} }
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return string_field_type(); }
void fix_length_and_dec(); void fix_length_and_dec();
}; };
...@@ -1851,6 +1858,7 @@ class Item_user_var_as_out_param :public Item ...@@ -1851,6 +1858,7 @@ class Item_user_var_as_out_param :public Item
void print_for_load(THD *thd, String *str); void print_for_load(THD *thd, String *str);
void set_null_value(CHARSET_INFO* cs); void set_null_value(CHARSET_INFO* cs);
void set_value(const char *str, uint length, CHARSET_INFO* cs); void set_value(const char *str, uint length, CHARSET_INFO* cs);
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
}; };
......
...@@ -82,6 +82,11 @@ class Item_row: public Item, ...@@ -82,6 +82,11 @@ class Item_row: public Item,
bool const_item() const { return const_item_cache; }; bool const_item() const { return const_item_cache; };
enum Item_result result_type() const { return ROW_RESULT; } enum Item_result result_type() const { return ROW_RESULT; }
Item_result cmp_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() void update_used_tables()
{ {
used_tables_and_const_cache_init(); used_tables_and_const_cache_init();
......
...@@ -65,6 +65,7 @@ class Item_str_func :public Item_func ...@@ -65,6 +65,7 @@ class Item_str_func :public Item_func
double val_real(); double val_real();
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return string_field_type(); }
void left_right_max_length(); void left_right_max_length();
bool fix_fields(THD *thd, Item **ref); bool fix_fields(THD *thd, Item **ref);
void update_null_value() void update_null_value()
......
...@@ -378,6 +378,7 @@ class Item_exists_subselect :public Item_subselect ...@@ -378,6 +378,7 @@ class Item_exists_subselect :public Item_subselect
void no_rows_in_result(); void no_rows_in_result();
enum Item_result result_type() const { return INT_RESULT;} enum Item_result result_type() const { return INT_RESULT;}
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
longlong val_int(); longlong val_int();
double val_real(); double val_real();
String *val_str(String*); String *val_str(String*);
......
...@@ -715,6 +715,7 @@ class Item_sum_int :public Item_sum_num ...@@ -715,6 +715,7 @@ class Item_sum_int :public Item_sum_num
String *val_str(String*str); String *val_str(String*str);
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return INT_RESULT; } enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() void fix_length_and_dec()
{ decimals=0; max_length=21; maybe_null=null_value=0; } { decimals=0; max_length=21; maybe_null=null_value=0; }
}; };
...@@ -747,6 +748,10 @@ class Item_sum_sum :public Item_sum_num ...@@ -747,6 +748,10 @@ class Item_sum_sum :public Item_sum_num
String *val_str(String*str); String *val_str(String*str);
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return hybrid_type; } 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 reset_field();
void update_field(); void update_field();
void no_rows_in_result() {} void no_rows_in_result() {}
...@@ -1258,6 +1263,9 @@ class Item_sum_udf_float :public Item_udf_sum ...@@ -1258,6 +1263,9 @@ class Item_sum_udf_float :public Item_udf_sum
double val_real(); double val_real();
String *val_str(String*str); String *val_str(String*str);
my_decimal *val_decimal(my_decimal *); 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(); } void fix_length_and_dec() { fix_num_length_and_dec(); }
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
}; };
...@@ -1278,6 +1286,7 @@ class Item_sum_udf_int :public Item_udf_sum ...@@ -1278,6 +1286,7 @@ class Item_sum_udf_int :public Item_udf_sum
String *val_str(String*str); String *val_str(String*str);
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return INT_RESULT; } 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; } void fix_length_and_dec() { decimals=0; max_length=21; }
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
}; };
...@@ -1317,6 +1326,7 @@ class Item_sum_udf_str :public Item_udf_sum ...@@ -1317,6 +1326,7 @@ class Item_sum_udf_str :public Item_udf_sum
} }
my_decimal *val_decimal(my_decimal *dec); my_decimal *val_decimal(my_decimal *dec);
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return string_field_type(); }
void fix_length_and_dec(); void fix_length_and_dec();
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
}; };
...@@ -1336,6 +1346,7 @@ class Item_sum_udf_decimal :public Item_udf_sum ...@@ -1336,6 +1346,7 @@ class Item_sum_udf_decimal :public Item_udf_sum
longlong val_int(); longlong val_int();
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
enum Item_result result_type () const { return DECIMAL_RESULT; } 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(); } void fix_length_and_dec() { fix_num_length_and_dec(); }
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
}; };
...@@ -1484,6 +1495,7 @@ class Item_func_group_concat : public Item_sum ...@@ -1484,6 +1495,7 @@ class Item_func_group_concat : public Item_sum
enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;} enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;}
const char *func_name() const { return "group_concat"; } const char *func_name() const { return "group_concat"; }
virtual Item_result result_type () const { return STRING_RESULT; } 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); virtual Field *make_string_field(TABLE *table);
enum_field_types field_type() const enum_field_types field_type() const
{ {
......
...@@ -165,6 +165,7 @@ class Item_func_month :public Item_func ...@@ -165,6 +165,7 @@ class Item_func_month :public Item_func
} }
const char *func_name() const { return "month"; } const char *func_name() const { return "month"; }
enum Item_result result_type () const { return INT_RESULT; } enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() void fix_length_and_dec()
{ {
decimals= 0; decimals= 0;
...@@ -379,6 +380,7 @@ class Item_func_weekday :public Item_func ...@@ -379,6 +380,7 @@ class Item_func_weekday :public Item_func
return (odbc_type ? "dayofweek" : "weekday"); return (odbc_type ? "dayofweek" : "weekday");
} }
enum Item_result result_type () const { return INT_RESULT; } enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void fix_length_and_dec() void fix_length_and_dec()
{ {
decimals= 0; decimals= 0;
...@@ -401,6 +403,7 @@ class Item_func_dayname :public Item_func_weekday ...@@ -401,6 +403,7 @@ class Item_func_dayname :public Item_func_weekday
const char *func_name() const { return "dayname"; } const char *func_name() const { return "dayname"; }
String *val_str(String *str); String *val_str(String *str);
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
void fix_length_and_dec(); void fix_length_and_dec();
bool check_partition_func_processor(uchar *int_arg) {return TRUE;} bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
bool check_vcol_func_processor(uchar *int_arg) { return FALSE;} bool check_vcol_func_processor(uchar *int_arg) { return FALSE;}
......
...@@ -69,6 +69,7 @@ class Item_proc_real :public Item_proc ...@@ -69,6 +69,7 @@ class Item_proc_real :public Item_proc
decimals=dec; max_length=float_length(dec); decimals=dec; max_length=float_length(dec);
} }
enum Item_result result_type () const { return REAL_RESULT; } 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; } enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
void set(double nr) { value=nr; } void set(double nr) { value=nr; }
void set(longlong nr) { value=(double) nr; } void set(longlong nr) { value=(double) nr; }
...@@ -96,6 +97,7 @@ class Item_proc_int :public Item_proc ...@@ -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) Item_proc_int(THD *thd, const char *name_par): Item_proc(thd, name_par)
{ max_length=11; } { max_length=11; }
enum Item_result result_type () const { return INT_RESULT; } 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; } enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
void set(double nr) { value=(longlong) nr; } void set(double nr) { value=(longlong) nr; }
void set(longlong nr) { value=nr; } void set(longlong nr) { value=nr; }
...@@ -115,6 +117,7 @@ class Item_proc_string :public Item_proc ...@@ -115,6 +117,7 @@ class Item_proc_string :public Item_proc
Item_proc_string(THD *thd, const char *name_par, uint length): Item_proc_string(THD *thd, const char *name_par, uint length):
Item_proc(thd, name_par) { this->max_length=length; } Item_proc(thd, name_par) { this->max_length=length; }
enum Item_result result_type () const { return STRING_RESULT; } 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; } enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
void set(double nr) { str_value.set_real(nr, 2, default_charset()); } void set(double nr) { str_value.set_real(nr, 2, default_charset()); }
void set(longlong nr) { str_value.set(nr, default_charset()); } void set(longlong nr) { str_value.set(nr, default_charset()); }
......
...@@ -111,8 +111,7 @@ Type_handler_hybrid_field_type::Type_handler_hybrid_field_type() ...@@ -111,8 +111,7 @@ Type_handler_hybrid_field_type::Type_handler_hybrid_field_type()
const Type_handler * const Type_handler *
Type_handler_hybrid_field_type::get_handler_by_field_type(enum_field_types type) Type_handler::get_handler_by_field_type(enum_field_types type)
const
{ {
switch (type) { switch (type) {
case MYSQL_TYPE_DECIMAL: return &type_handler_olddecimal; case MYSQL_TYPE_DECIMAL: return &type_handler_olddecimal;
......
...@@ -28,6 +28,7 @@ class Type_handler ...@@ -28,6 +28,7 @@ class Type_handler
protected: protected:
const Type_handler *string_type_handler(uint max_octet_length) const; const Type_handler *string_type_handler(uint max_octet_length) const;
public: public:
static const Type_handler *get_handler_by_field_type(enum_field_types type);
virtual enum_field_types field_type() const= 0; virtual enum_field_types field_type() const= 0;
virtual Item_result result_type() const= 0; virtual Item_result result_type() const= 0;
virtual Item_result cmp_type() const= 0; virtual Item_result cmp_type() const= 0;
...@@ -306,7 +307,6 @@ class Type_handler_hybrid_field_type: public Type_handler ...@@ -306,7 +307,6 @@ class Type_handler_hybrid_field_type: public Type_handler
{ {
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;
const Type_handler *get_handler_by_field_type(enum_field_types type) const;
public: public:
Type_handler_hybrid_field_type(); Type_handler_hybrid_field_type();
Type_handler_hybrid_field_type(enum_field_types type) Type_handler_hybrid_field_type(enum_field_types type)
......
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