Skip to content

Commit 98ba2bf

Browse files
author
Alexander Barkov
committed
Clean-up: moving compare_collation() from Item to Item_bool_func.
1 parent 1bae0d9 commit 98ba2bf

File tree

6 files changed

+43
-32
lines changed

6 files changed

+43
-32
lines changed

sql/field.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ double Field::pos_in_interval_val_str(Field *min, Field *max, uint data_offset)
12491249
/*
12501250
This handles all numeric and BIT data types.
12511251
*/
1252-
bool Field::can_optimize_keypart_ref(const Item_func *cond,
1252+
bool Field::can_optimize_keypart_ref(const Item_bool_func *cond,
12531253
const Item *item) const
12541254
{
12551255
DBUG_ASSERT(cmp_type() != STRING_RESULT);
@@ -5289,7 +5289,7 @@ my_decimal *Field_temporal::val_decimal(my_decimal *d)
52895289
}
52905290

52915291

5292-
bool Field_temporal::can_optimize_keypart_ref(const Item_func *cond,
5292+
bool Field_temporal::can_optimize_keypart_ref(const Item_bool_func *cond,
52935293
const Item *value) const
52945294
{
52955295
return true; // Field is of TIME_RESULT, which supersedes everything else.
@@ -6488,7 +6488,7 @@ uint32 Field_longstr::max_data_length() const
64886488

64896489

64906490
bool
6491-
Field_longstr::cmp_to_string_with_same_collation(const Item_func *cond,
6491+
Field_longstr::cmp_to_string_with_same_collation(const Item_bool_func *cond,
64926492
const Item *item) const
64936493
{
64946494
return item->cmp_type() == STRING_RESULT &&
@@ -6497,7 +6497,7 @@ Field_longstr::cmp_to_string_with_same_collation(const Item_func *cond,
64976497

64986498

64996499
bool
6500-
Field_longstr::cmp_to_string_with_stricter_collation(const Item_func *cond,
6500+
Field_longstr::cmp_to_string_with_stricter_collation(const Item_bool_func *cond,
65016501
const Item *item) const
65026502
{
65036503
return item->cmp_type() == STRING_RESULT &&
@@ -6506,15 +6506,15 @@ Field_longstr::cmp_to_string_with_stricter_collation(const Item_func *cond,
65066506
}
65076507

65086508

6509-
bool Field_longstr::can_optimize_keypart_ref(const Item_func *cond,
6509+
bool Field_longstr::can_optimize_keypart_ref(const Item_bool_func *cond,
65106510
const Item *item) const
65116511
{
65126512
DBUG_ASSERT(cmp_type() == STRING_RESULT);
65136513
return cmp_to_string_with_stricter_collation(cond, item);
65146514
}
65156515

65166516

6517-
bool Field_longstr::can_optimize_hash_join(const Item_func *cond,
6517+
bool Field_longstr::can_optimize_hash_join(const Item_bool_func *cond,
65186518
const Item *item) const
65196519
{
65206520
DBUG_ASSERT(cmp_type() == STRING_RESULT);
@@ -8561,7 +8561,7 @@ uint Field_num::is_equal(Create_field *new_field)
85618561
}
85628562

85638563

8564-
bool Field_enum::can_optimize_keypart_ref(const Item_func *cond,
8564+
bool Field_enum::can_optimize_keypart_ref(const Item_bool_func *cond,
85658565
const Item *item) const
85668566
{
85678567
DBUG_ASSERT(cmp_type() == INT_RESULT);
@@ -8576,7 +8576,7 @@ bool Field_enum::can_optimize_keypart_ref(const Item_func *cond,
85768576
case REAL_RESULT:
85778577
return true;
85788578
case STRING_RESULT:
8579-
return charset() == ((Item_func*)cond)->compare_collation();
8579+
return charset() == cond->compare_collation();
85808580
case IMPOSSIBLE_RESULT:
85818581
case ROW_RESULT:
85828582
DBUG_ASSERT(0);

sql/field.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,16 +1012,16 @@ class Field
10121012
return (double) 0.5;
10131013
}
10141014

1015-
virtual bool can_optimize_keypart_ref(const Item_func *cond,
1015+
virtual bool can_optimize_keypart_ref(const Item_bool_func *cond,
10161016
const Item *item) const;
1017-
virtual bool can_optimize_hash_join(const Item_func *cond,
1017+
virtual bool can_optimize_hash_join(const Item_bool_func *cond,
10181018
const Item *item) const
10191019
{
10201020
return can_optimize_keypart_ref(cond, item);
10211021
}
10221022
virtual bool can_optimize_group_min_max(const Item_bool_func *cond,
10231023
const Item *const_item) const;
1024-
bool can_optimize_outer_join_table_elimination(const Item_func *cond,
1024+
bool can_optimize_outer_join_table_elimination(const Item_bool_func *cond,
10251025
const Item *item) const
10261026
{
10271027
// Exactly the same rules with REF access
@@ -1207,9 +1207,9 @@ class Field_longstr :public Field_str
12071207
return report_if_important_data(copier->source_end_pos(),
12081208
end, count_spaces);
12091209
}
1210-
bool cmp_to_string_with_same_collation(const Item_func *cond,
1210+
bool cmp_to_string_with_same_collation(const Item_bool_func *cond,
12111211
const Item *item) const;
1212-
bool cmp_to_string_with_stricter_collation(const Item_func *cond,
1212+
bool cmp_to_string_with_stricter_collation(const Item_bool_func *cond,
12131213
const Item *item) const;
12141214
public:
12151215
Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
@@ -1222,8 +1222,10 @@ class Field_longstr :public Field_str
12221222
int store_decimal(const my_decimal *d);
12231223
uint32 max_data_length() const;
12241224
bool match_collation_to_optimize_range() const { return true; }
1225-
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const;
1226-
bool can_optimize_hash_join(const Item_func *cond, const Item *item) const;
1225+
bool can_optimize_keypart_ref(const Item_bool_func *cond,
1226+
const Item *item) const;
1227+
bool can_optimize_hash_join(const Item_bool_func *cond,
1228+
const Item *item) const;
12271229
bool can_optimize_group_min_max(const Item_bool_func *cond,
12281230
const Item *const_item) const;
12291231
};
@@ -1653,7 +1655,8 @@ class Field_null :public Field_str {
16531655
uint size_of() const { return sizeof(*this); }
16541656
uint32 max_display_length() { return 4; }
16551657
void move_field_offset(my_ptrdiff_t ptr_diff) {}
1656-
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const
1658+
bool can_optimize_keypart_ref(const Item_bool_func *cond,
1659+
const Item *item) const
16571660
{
16581661
DBUG_ASSERT(0);
16591662
return false;
@@ -1696,7 +1699,8 @@ class Field_temporal: public Field {
16961699
{
16971700
return pos_in_interval_val_real(min, max);
16981701
}
1699-
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const;
1702+
bool can_optimize_keypart_ref(const Item_bool_func *cond,
1703+
const Item *item) const;
17001704
bool can_optimize_group_min_max(const Item_bool_func *cond,
17011705
const Item *const_item) const;
17021706
};
@@ -2773,7 +2777,8 @@ class Field_enum :public Field_str {
27732777
virtual const uchar *unpack(uchar *to, const uchar *from,
27742778
const uchar *from_end, uint param_data);
27752779

2776-
bool can_optimize_keypart_ref(const Item_func *cond, const Item *item) const;
2780+
bool can_optimize_keypart_ref(const Item_bool_func *cond,
2781+
const Item *item) const;
27772782
bool can_optimize_group_min_max(const Item_bool_func *cond,
27782783
const Item *const_item) const
27792784
{

sql/item.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,6 @@ class Item: public Type_std_attributes
12291229
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
12301230

12311231
static CHARSET_INFO *default_charset();
1232-
virtual CHARSET_INFO *compare_collation() const { return NULL; }
12331232

12341233
/*
12351234
For backward compatibility, to make numeric

sql/item_cmpfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class Item_bool_func :public Item_int_func
162162
Item_bool_func(THD *thd, List<Item> &list): Item_int_func(thd, list) { }
163163
Item_bool_func(THD *thd, Item_bool_func *item) :Item_int_func(thd, item) {}
164164
bool is_bool_type() { return true; }
165+
virtual CHARSET_INFO *compare_collation() const { return NULL; }
165166
void fix_length_and_dec() { decimals=0; max_length=1; }
166167
uint decimal_precision() const { return 1; }
167168
};

sql/opt_table_elimination.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ void build_eq_mods_for_cond(THD *thd, Dep_analysis_context *dac,
534534
Item *cond);
535535
static
536536
void check_equality(Dep_analysis_context *dac, Dep_module_expr **eq_mod,
537-
uint and_level, Item_func *cond, Item *left, Item *right);
537+
uint and_level, Item_bool_func *cond,
538+
Item *left, Item *right);
538539
static
539540
Dep_module_expr *merge_eq_mods(Dep_module_expr *start,
540541
Dep_module_expr *new_fields,
@@ -1199,27 +1200,30 @@ void build_eq_mods_for_cond(THD *thd, Dep_analysis_context *ctx,
11991200
case Item_func::BETWEEN:
12001201
{
12011202
Item *fld;
1202-
if (!((Item_func_between*)cond)->negated &&
1203+
Item_func_between *func= (Item_func_between *) cond_func;
1204+
if (!func->negated &&
12031205
(fld= args[0]->real_item())->type() == Item::FIELD_ITEM &&
12041206
args[1]->eq(args[2], ((Item_field*)fld)->field->binary()))
12051207
{
1206-
check_equality(ctx, eq_mod, *and_level, cond_func, args[0], args[1]);
1207-
check_equality(ctx, eq_mod, *and_level, cond_func, args[1], args[0]);
1208+
check_equality(ctx, eq_mod, *and_level, func, args[0], args[1]);
1209+
check_equality(ctx, eq_mod, *and_level, func, args[1], args[0]);
12081210
}
12091211
break;
12101212
}
12111213
case Item_func::EQ_FUNC:
12121214
case Item_func::EQUAL_FUNC:
12131215
{
1214-
check_equality(ctx, eq_mod, *and_level, cond_func, args[0], args[1]);
1215-
check_equality(ctx, eq_mod, *and_level, cond_func, args[1], args[0]);
1216+
Item_bool_rowready_func2 *func= (Item_bool_rowready_func2*) cond_func;
1217+
check_equality(ctx, eq_mod, *and_level, func, args[0], args[1]);
1218+
check_equality(ctx, eq_mod, *and_level, func, args[1], args[0]);
12161219
break;
12171220
}
12181221
case Item_func::ISNULL_FUNC:
12191222
{
12201223
Item *tmp=new (thd->mem_root) Item_null(thd);
12211224
if (tmp)
1222-
check_equality(ctx, eq_mod, *and_level, cond_func, args[0], tmp);
1225+
check_equality(ctx, eq_mod, *and_level,
1226+
(Item_func_isnull*) cond_func, args[0], tmp);
12231227
break;
12241228
}
12251229
case Item_func::MULT_EQUAL_FUNC:
@@ -1479,7 +1483,8 @@ Dep_module_expr *merge_eq_mods(Dep_module_expr *start,
14791483

14801484
static
14811485
void check_equality(Dep_analysis_context *ctx, Dep_module_expr **eq_mod,
1482-
uint and_level, Item_func *cond, Item *left, Item *right)
1486+
uint and_level, Item_bool_func *cond,
1487+
Item *left, Item *right)
14831488
{
14841489
if ((left->used_tables() & ctx->usable_tables) &&
14851490
!(right->used_tables() & RAND_TABLE_BIT) &&

sql/sql_select.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,7 +4147,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
41474147
/// Used when finding key fields
41484148
struct KEY_FIELD {
41494149
Field *field;
4150-
Item_func *cond;
4150+
Item_bool_func *cond;
41514151
Item *val; ///< May be empty if diff constant
41524152
uint level;
41534153
uint optimize;
@@ -4400,7 +4400,7 @@ static uint get_semi_join_select_list_index(Field *field)
44004400

44014401
static void
44024402
add_key_field(JOIN *join,
4403-
KEY_FIELD **key_fields,uint and_level, Item_func *cond,
4403+
KEY_FIELD **key_fields,uint and_level, Item_bool_func *cond,
44044404
Field *field, bool eq_func, Item **value, uint num_values,
44054405
table_map usable_tables, SARGABLE_PARAM **sargables)
44064406
{
@@ -4552,7 +4552,7 @@ add_key_field(JOIN *join,
45524552

45534553
static void
45544554
add_key_equal_fields(JOIN *join, KEY_FIELD **key_fields, uint and_level,
4555-
Item_func *cond, Item *field_item,
4555+
Item_bool_func *cond, Item *field_item,
45564556
bool eq_func, Item **val,
45574557
uint num_values, table_map usable_tables,
45584558
SARGABLE_PARAM **sargables)
@@ -12511,7 +12511,8 @@ Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field,
1251112511
*/
1251212512

1251312513
static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item,
12514-
Item *item, COND_EQUAL *cond_equal)
12514+
const Item_bool_func *item,
12515+
COND_EQUAL *cond_equal)
1251512516
{
1251612517
Item *orig_left_item= left_item;
1251712518
Item *orig_right_item= right_item;
@@ -12653,7 +12654,7 @@ static bool check_simple_equality(THD *thd, Item *left_item, Item *right_item,
1265312654
eq_item->quick_fix_field();
1265412655
item= eq_item;
1265512656
}
12656-
if ((cs != ((Item_func *) item)->compare_collation()) ||
12657+
if ((cs != item->compare_collation()) ||
1265712658
!cs->coll->propagate(cs, 0, 0))
1265812659
return FALSE;
1265912660
}

0 commit comments

Comments
 (0)