summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2015-12-01 13:13:23 +0400
committerAlexander Barkov <bar@mariadb.org>2015-12-01 13:13:23 +0400
commit607ef786fc50b44b8e0cb4af8fdb3c79e4a327bb (patch)
tree72c8d7e9bc632b593e485f853a211cc839446ea7
parente3fed3b9b4f488e9ad1afa57333ae80249e6cb17 (diff)
downloadmariadb-git-607ef786fc50b44b8e0cb4af8fdb3c79e4a327bb.tar.gz
MDEV-9215 Detect cmp_type() and result_type() from field_type()
(A dependency task for MDEV-4912 Add a plugin to field types)
-rw-r--r--sql/item.cc44
-rw-r--r--sql/item.h17
-rw-r--r--sql/item_func.h8
-rw-r--r--sql/item_row.h5
-rw-r--r--sql/item_strfunc.h1
-rw-r--r--sql/item_subselect.h1
-rw-r--r--sql/item_sum.h12
-rw-r--r--sql/item_timefunc.h3
-rw-r--r--sql/procedure.h3
-rw-r--r--sql/sql_type.cc3
-rw-r--r--sql/sql_type.h2
11 files changed, 50 insertions, 49 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 18879a813b0..c03a64ba7e5 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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).
@@ -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();
diff --git a/sql/item.h b/sql/item.h
index 4a0629c2a11..3680c43cb28 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -755,16 +755,20 @@ public:
{ 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
@@ -2111,6 +2115,7 @@ public:
inline enum Type type() const;
inline Item_result result_type() const;
+ enum_field_types field_type() const { return this_item()->field_type(); }
public:
/*
@@ -2171,6 +2176,11 @@ public:
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();
@@ -2328,6 +2338,7 @@ public:
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; }
};
diff --git a/sql/item_func.h b/sql/item_func.h
index bb0c143d877..e59fd4abfea 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -376,6 +376,7 @@ public:
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); }
};
@@ -595,6 +596,7 @@ public:
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() {}
};
@@ -1115,6 +1117,7 @@ public:
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;
@@ -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(); }
};
@@ -1489,6 +1493,7 @@ public:
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; }
};
@@ -1505,6 +1510,7 @@ public:
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(); }
};
@@ -1542,6 +1548,7 @@ public:
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();
};
@@ -1851,6 +1858,7 @@ public:
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; }
};
diff --git a/sql/item_row.h b/sql/item_row.h
index c9e94ed2efe..bbb9a7f1f96 100644
--- a/sql/item_row.h
+++ b/sql/item_row.h
@@ -82,6 +82,11 @@ public:
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();
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index d2a83b2995b..dfa38d7eed6 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -65,6 +65,7 @@ public:
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()
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 670d0a66639..1b450044954 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -378,6 +378,7 @@ public:
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*);
diff --git a/sql/item_sum.h b/sql/item_sum.h
index db3312c42f4..151b913f121 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -715,6 +715,7 @@ public:
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; }
};
@@ -747,6 +748,10 @@ public:
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() {}
@@ -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);
};
@@ -1278,6 +1286,7 @@ public:
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);
};
@@ -1317,6 +1326,7 @@ public:
}
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);
};
@@ -1336,6 +1346,7 @@ public:
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);
};
@@ -1484,6 +1495,7 @@ public:
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
{
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index bb840987089..32ba8f221de 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -165,6 +165,7 @@ public:
}
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;
@@ -379,6 +380,7 @@ public:
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;
@@ -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;}
diff --git a/sql/procedure.h b/sql/procedure.h
index 2326f375721..1452f33652a 100644
--- a/sql/procedure.h
+++ b/sql/procedure.h
@@ -69,6 +69,7 @@ public:
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; }
@@ -96,6 +97,7 @@ public:
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; }
@@ -115,6 +117,7 @@ public:
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()); }
diff --git a/sql/sql_type.cc b/sql/sql_type.cc
index 7d52419ae18..6d1de5bbabc 100644
--- a/sql/sql_type.cc
+++ b/sql/sql_type.cc
@@ -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;
diff --git a/sql/sql_type.h b/sql/sql_type.h
index f5a42e8d97d..a68cce527e1 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -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;
@@ -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)