summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc19
-rw-r--r--sql/field.h2
2 files changed, 19 insertions, 2 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 7ff07540538..2c768527ced 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1276,6 +1276,21 @@ bool Field::can_be_substituted_to_equal_item(const Context &ctx,
}
+bool Field::cmp_is_done_using_type_handler_of_this(const Item_bool_func *cond,
+ const Item *item) const
+{
+ /*
+ We could eventually take comparison_type_handler() from cond,
+ instead of calculating it again. But only some descendants of
+ Item_bool_func has this method. So this needs some hierarchy changes.
+ Another option is to pass "class Context" to this method.
+ */
+ Type_handler_hybrid_field_type cmp(type_handler_for_comparison());
+ return !cmp.aggregate_for_comparison(item->type_handler_for_comparison()) &&
+ cmp.type_handler() == type_handler_for_comparison();
+}
+
+
/*
This handles all numeric and BIT data types.
*/
@@ -7356,7 +7371,7 @@ bool
Field_longstr::cmp_to_string_with_same_collation(const Item_bool_func *cond,
const Item *item) const
{
- return item->cmp_type() == STRING_RESULT &&
+ return cmp_is_done_using_type_handler_of_this(cond, item) &&
charset() == cond->compare_collation();
}
@@ -7365,7 +7380,7 @@ bool
Field_longstr::cmp_to_string_with_stricter_collation(const Item_bool_func *cond,
const Item *item) const
{
- return item->cmp_type() == STRING_RESULT &&
+ return cmp_is_done_using_type_handler_of_this(cond, item) &&
(charset() == cond->compare_collation() ||
cond->compare_collation()->state & MY_CS_BINSORT);
}
diff --git a/sql/field.h b/sql/field.h
index 6747f8070dc..47a85efc43e 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1648,6 +1648,8 @@ protected:
}
int warn_if_overflow(int op_result);
Copy_func *get_identical_copy_func() const;
+ bool cmp_is_done_using_type_handler_of_this(const Item_bool_func *cond,
+ const Item *item) const;
bool can_optimize_scalar_range(const RANGE_OPT_PARAM *param,
const KEY_PART *key_part,
const Item_bool_func *cond,