Commit 98ba2bf4 authored by Alexander Barkov's avatar Alexander Barkov

Clean-up: moving compare_collation() from Item to Item_bool_func.

parent 1bae0d9e
......@@ -1249,7 +1249,7 @@ double Field::pos_in_interval_val_str(Field *min, Field *max, uint data_offset)
/*
This handles all numeric and BIT data types.
*/
bool Field::can_optimize_keypart_ref(const Item_func *cond,
bool Field::can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const
{
DBUG_ASSERT(cmp_type() != STRING_RESULT);
......@@ -5289,7 +5289,7 @@ my_decimal *Field_temporal::val_decimal(my_decimal *d)
}
bool Field_temporal::can_optimize_keypart_ref(const Item_func *cond,
bool Field_temporal::can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *value) const
{
return true; // Field is of TIME_RESULT, which supersedes everything else.
......@@ -6488,7 +6488,7 @@ uint32 Field_longstr::max_data_length() const
bool
Field_longstr::cmp_to_string_with_same_collation(const Item_func *cond,
Field_longstr::cmp_to_string_with_same_collation(const Item_bool_func *cond,
const Item *item) const
{
return item->cmp_type() == STRING_RESULT &&
......@@ -6497,7 +6497,7 @@ Field_longstr::cmp_to_string_with_same_collation(const Item_func *cond,
bool
Field_longstr::cmp_to_string_with_stricter_collation(const Item_func *cond,
Field_longstr::cmp_to_string_with_stricter_collation(const Item_bool_func *cond,
const Item *item) const
{
return item->cmp_type() == STRING_RESULT &&
......@@ -6506,7 +6506,7 @@ Field_longstr::cmp_to_string_with_stricter_collation(const Item_func *cond,
}
bool Field_longstr::can_optimize_keypart_ref(const Item_func *cond,
bool Field_longstr::can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const
{
DBUG_ASSERT(cmp_type() == STRING_RESULT);
......@@ -6514,7 +6514,7 @@ bool Field_longstr::can_optimize_keypart_ref(const Item_func *cond,
}
bool Field_longstr::can_optimize_hash_join(const Item_func *cond,
bool Field_longstr::can_optimize_hash_join(const Item_bool_func *cond,
const Item *item) const
{
DBUG_ASSERT(cmp_type() == STRING_RESULT);
......@@ -8561,7 +8561,7 @@ uint Field_num::is_equal(Create_field *new_field)
}
bool Field_enum::can_optimize_keypart_ref(const Item_func *cond,
bool Field_enum::can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const
{
DBUG_ASSERT(cmp_type() == INT_RESULT);
......@@ -8576,7 +8576,7 @@ bool Field_enum::can_optimize_keypart_ref(const Item_func *cond,
case REAL_RESULT:
return true;
case STRING_RESULT:
return charset() == ((Item_func*)cond)->compare_collation();
return charset() == cond->compare_collation();
case IMPOSSIBLE_RESULT:
case ROW_RESULT:
DBUG_ASSERT(0);
......
......@@ -1012,16 +1012,16 @@ class Field
return (double) 0.5;
}
virtual bool can_optimize_keypart_ref(const Item_func *cond,
virtual bool can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const;
virtual bool can_optimize_hash_join(const Item_func *cond,
virtual bool can_optimize_hash_join(const Item_bool_func *cond,
const Item *item) const
{
return can_optimize_keypart_ref(cond, item);
}
virtual bool can_optimize_group_min_max(const Item_bool_func *cond,
const Item *const_item) const;
bool can_optimize_outer_join_table_elimination(const Item_func *cond,
bool can_optimize_outer_join_table_elimination(const Item_bool_func *cond,
const Item *item) const
{
// Exactly the same rules with REF access
......@@ -1207,9 +1207,9 @@ class Field_longstr :public Field_str
return report_if_important_data(copier->source_end_pos(),
end, count_spaces);
}
bool cmp_to_string_with_same_collation(const Item_func *cond,
bool cmp_to_string_with_same_collation(const Item_bool_func *cond,
const Item *item) const;
bool cmp_to_string_with_stricter_collation(const Item_func *cond,
bool cmp_to_string_with_stricter_collation(const Item_bool_func *cond,
const Item *item) const;
public:
Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
......@@ -1222,8 +1222,10 @@ class Field_longstr :public Field_str
int store_decimal(const my_decimal *d);
uint32 max_data_length() const;
bool match_collation_to_optimize_range() const { return true; }
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const;
bool can_optimize_hash_join(const Item_func *cond, const Item *item) const;
bool can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const;
bool can_optimize_hash_join(const Item_bool_func *cond,
const Item *item) const;
bool can_optimize_group_min_max(const Item_bool_func *cond,
const Item *const_item) const;
};
......@@ -1653,7 +1655,8 @@ class Field_null :public Field_str {
uint size_of() const { return sizeof(*this); }
uint32 max_display_length() { return 4; }
void move_field_offset(my_ptrdiff_t ptr_diff) {}
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const
bool can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const
{
DBUG_ASSERT(0);
return false;
......@@ -1696,7 +1699,8 @@ class Field_temporal: public Field {
{
return pos_in_interval_val_real(min, max);
}
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const;
bool can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const;
bool can_optimize_group_min_max(const Item_bool_func *cond,
const Item *const_item) const;
};
......@@ -2773,7 +2777,8 @@ class Field_enum :public Field_str {
virtual const uchar *unpack(uchar *to, const uchar *from,
const uchar *from_end, uint param_data);
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const;
bool can_optimize_keypart_ref(const Item_bool_func *cond,
const Item *item) const;
bool can_optimize_group_min_max(const Item_bool_func *cond,
const Item *const_item) const
{
......
......@@ -1229,7 +1229,6 @@ class Item: public Type_std_attributes
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
static CHARSET_INFO *default_charset();
virtual CHARSET_INFO *compare_collation() const { return NULL; }
/*
For backward compatibility, to make numeric
......
......@@ -162,6 +162,7 @@ class Item_bool_func :public Item_int_func
Item_bool_func(THD *thd, List<Item> &list): Item_int_func(thd, list) { }
Item_bool_func(THD *thd, Item_bool_func *item) :Item_int_func(thd, item) {}
bool is_bool_type() { return true; }
virtual CHARSET_INFO *compare_collation() const { return NULL; }
void fix_length_and_dec() { decimals=0; max_length=1; }
uint decimal_precision() const { return 1; }
};
......
......@@ -534,7 +534,8 @@ void build_eq_mods_for_cond(THD *thd, Dep_analysis_context *dac,
Item *cond);
static
void check_equality(Dep_analysis_context *dac, Dep_module_expr **eq_mod,
uint and_level, Item_func *cond, Item *left, Item *right);
uint and_level, Item_bool_func *cond,
Item *left, Item *right);
static
Dep_module_expr *merge_eq_mods(Dep_module_expr *start,
Dep_module_expr *new_fields,
......@@ -1199,27 +1200,30 @@ void build_eq_mods_for_cond(THD *thd, Dep_analysis_context *ctx,
case Item_func::BETWEEN:
{
Item *fld;
if (!((Item_func_between*)cond)->negated &&
Item_func_between *func= (Item_func_between *) cond_func;
if (!func->negated &&
(fld= args[0]->real_item())->type() == Item::FIELD_ITEM &&
args[1]->eq(args[2], ((Item_field*)fld)->field->binary()))
{
check_equality(ctx, eq_mod, *and_level, cond_func, args[0], args[1]);
check_equality(ctx, eq_mod, *and_level, cond_func, args[1], args[0]);
check_equality(ctx, eq_mod, *and_level, func, args[0], args[1]);
check_equality(ctx, eq_mod, *and_level, func, args[1], args[0]);
}
break;
}
case Item_func::EQ_FUNC:
case Item_func::EQUAL_FUNC:
{
check_equality(ctx, eq_mod, *and_level, cond_func, args[0], args[1]);
check_equality(ctx, eq_mod, *and_level, cond_func, args[1], args[0]);
Item_bool_rowready_func2 *func= (Item_bool_rowready_func2*) cond_func;
check_equality(ctx, eq_mod, *and_level, func, args[0], args[1]);
check_equality(ctx, eq_mod, *and_level, func, args[1], args[0]);
break;
}
case Item_func::ISNULL_FUNC:
{
Item *tmp=new (thd->mem_root) Item_null(thd);
if (tmp)
check_equality(ctx, eq_mod, *and_level, cond_func, args[0], tmp);
check_equality(ctx, eq_mod, *and_level,
(Item_func_isnull*) cond_func, args[0], tmp);
break;
}
case Item_func::MULT_EQUAL_FUNC:
......@@ -1479,7 +1483,8 @@ Dep_module_expr *merge_eq_mods(Dep_module_expr *start,
static
void check_equality(Dep_analysis_context *ctx, Dep_module_expr **eq_mod,
uint and_level, Item_func *cond, Item *left, Item *right)
uint and_level, Item_bool_func *cond,
Item *left, Item *right)
{
if ((left->used_tables() & ctx->usable_tables) &&
!(right->used_tables() & RAND_TABLE_BIT) &&
......
......@@ -4147,7 +4147,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
/// Used when finding key fields
struct KEY_FIELD {
Field *field;
Item_func *cond;
Item_bool_func *cond;
Item *val; ///< May be empty if diff constant
uint level;
uint optimize;
......@@ -4400,7 +4400,7 @@ static uint get_semi_join_select_list_index(Field *field)
static void
add_key_field(JOIN *join,
KEY_FIELD **key_fields,uint and_level, Item_func *cond,
KEY_FIELD **key_fields,uint and_level, Item_bool_func *cond,
Field *field, bool eq_func, Item **value, uint num_values,
table_map usable_tables, SARGABLE_PARAM **sargables)
{
......@@ -4552,7 +4552,7 @@ add_key_field(JOIN *join,
static void
add_key_equal_fields(JOIN *join, KEY_FIELD **key_fields, uint and_level,
Item_func *cond, Item *field_item,
Item_bool_func *cond, Item *field_item,
bool eq_func, Item **val,
uint num_values, table_map usable_tables,
SARGABLE_PARAM **sargables)
......@@ -12511,7 +12511,8 @@ Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field,
*/
static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item,
Item *item, COND_EQUAL *cond_equal)
const Item_bool_func *item,
COND_EQUAL *cond_equal)
{
Item *orig_left_item= left_item;
Item *orig_right_item= right_item;
......@@ -12653,7 +12654,7 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item,
eq_item->quick_fix_field();
item= eq_item;
}
if ((cs != ((Item_func *) item)->compare_collation()) ||
if ((cs != item->compare_collation()) ||
!cs->coll->propagate(cs, 0, 0))
return FALSE;
}
......
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