diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 62ebc100d90..faf8f23ffa1 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2032,7 +2032,6 @@ void Item_func_between::fix_after_pullout(st_select_lex *new_parent, Item **ref) void Item_func_between::fix_length_and_dec() { - THD *thd= current_thd; max_length= 1; /* @@ -2044,14 +2043,16 @@ void Item_func_between::fix_length_and_dec() if (m_comparator.aggregate_for_comparison(Item_func_between::func_name(), args, 3, true)) { - DBUG_ASSERT(thd->is_error()); + DBUG_ASSERT(current_thd->is_error()); return; } - if (m_comparator.cmp_type() == STRING_RESULT && - agg_arg_charsets_for_comparison(cmp_collation, args, 3)) - return; + m_comparator.type_handler()->Item_func_between_fix_length_and_dec(this); +} + +bool Item_func_between::fix_length_and_dec_numeric(THD *thd) +{ /* See the comment about the similar block in Item_bool_func2 */ if (args[0]->real_item()->type() == FIELD_ITEM && !thd->lex->is_ps_or_view_context_analysis()) @@ -2069,6 +2070,7 @@ void Item_func_between::fix_length_and_dec() } } } + return false; } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index e9d4426d919..db2f0cf02b4 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -885,6 +885,11 @@ public: const char *func_name() const { return "between"; } enum precedence precedence() const { return BETWEEN_PRECEDENCE; } void fix_length_and_dec(); + bool fix_length_and_dec_string(THD *) + { + return agg_arg_charsets_for_comparison(cmp_collation, args, 3); + } + bool fix_length_and_dec_numeric(THD *); virtual void print(String *str, enum_query_type query_type); bool eval_not_null_tables(void *opt_arg); void fix_after_pullout(st_select_lex *new_parent, Item **ref); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index ed9e78e8529..f52d09cd669 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2713,6 +2713,25 @@ Type_handler_string_result::Item_func_hybrid_field_type_get_date( /***************************************************************************/ +bool Type_handler_numeric:: + Item_func_between_fix_length_and_dec(Item_func_between *func) const +{ + return func->fix_length_and_dec_numeric(current_thd); +} + +bool Type_handler_temporal_result:: + Item_func_between_fix_length_and_dec(Item_func_between *func) const +{ + return func->fix_length_and_dec_numeric(current_thd); +} + +bool Type_handler_string_result:: + Item_func_between_fix_length_and_dec(Item_func_between *func) const +{ + return func->fix_length_and_dec_string(current_thd); +} + + longlong Type_handler_row:: Item_func_between_val_int(Item_func_between *func) const { diff --git a/sql/sql_type.h b/sql/sql_type.h index 53822737593..4c507671f47 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -779,6 +779,8 @@ public: virtual bool Item_func_min_max_get_date(Item_func_min_max*, MYSQL_TIME *, ulonglong fuzzydate) const= 0; + virtual bool + Item_func_between_fix_length_and_dec(Item_func_between *func) const= 0; virtual longlong Item_func_between_val_int(Item_func_between *func) const= 0; @@ -1012,6 +1014,11 @@ public: DBUG_ASSERT(0); return true; } + bool Item_func_between_fix_length_and_dec(Item_func_between *func) const + { + DBUG_ASSERT(0); + return true; + } longlong Item_func_between_val_int(Item_func_between *func) const; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const; in_vector *make_in_vector(THD *thd, const Item_func_in *f, uint nargs) const; @@ -1093,6 +1100,7 @@ public: Item *target_expr, Item *target_value, Item_bool_func2 *source, Item *source_expr, Item *source_const) const; + bool Item_func_between_fix_length_and_dec(Item_func_between *func) const; bool Item_char_typecast_fix_length_and_dec(Item_char_typecast *) const; }; @@ -1321,6 +1329,7 @@ public: my_decimal *) const; bool Item_func_min_max_get_date(Item_func_min_max*, MYSQL_TIME *, ulonglong fuzzydate) const; + bool Item_func_between_fix_length_and_dec(Item_func_between *func) const; longlong Item_func_between_val_int(Item_func_between *func) const; bool Item_func_in_fix_comparator_compatible_types(THD *thd, Item_func_in *) const; @@ -1406,6 +1415,7 @@ public: my_decimal *) const; bool Item_func_min_max_get_date(Item_func_min_max*, MYSQL_TIME *, ulonglong fuzzydate) const; + bool Item_func_between_fix_length_and_dec(Item_func_between *func) const; longlong Item_func_between_val_int(Item_func_between *func) const; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const; in_vector *make_in_vector(THD *, const Item_func_in *, uint nargs) const;