Skip to content

Commit d4f3569

Browse files
committed
Item::eq: transform bool binary_cmp into struct Eq_config
Part of MDEV-34033
1 parent 0109312 commit d4f3569

File tree

11 files changed

+76
-66
lines changed

11 files changed

+76
-66
lines changed

sql/item.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ void Item::set_name_no_truncate(THD *thd, const char *str, uint length,
12761276
- When trying to find an ORDER BY/GROUP BY item in the SELECT part
12771277
*/
12781278

1279-
bool Item::eq(const Item *item, bool binary_cmp) const
1279+
bool Item::eq(const Item *item, const Eq_config &config) const
12801280
{
12811281
/*
12821282
Note, that this is never TRUE if item is a Item_param:
@@ -3550,7 +3550,7 @@ bool Item_field::is_null_result()
35503550
}
35513551

35523552

3553-
bool Item_field::eq(const Item *item, bool binary_cmp) const
3553+
bool Item_field::eq(const Item *item, const Eq_config &config) const
35543554
{
35553555
const Item *real_item2= item->real_item();
35563556
if (real_item2->type() != FIELD_ITEM)
@@ -3724,7 +3724,7 @@ void Item_field::set_refers_to_temp_table()
37243724
}
37253725

37263726

3727-
bool Item_basic_value::eq(const Item *item, bool binary_cmp) const
3727+
bool Item_basic_value::eq(const Item *item, const Eq_config &config) const
37283728
{
37293729
const Item_const *c0, *c1;
37303730
const Type_handler *h0, *h1;
@@ -3762,14 +3762,14 @@ bool Item_basic_value::eq(const Item *item, bool binary_cmp) const
37623762
res= false;
37633763
break;
37643764
case 0: // Two non-NULLs
3765-
res= h0->Item_const_eq(c0, c1, binary_cmp);
3765+
res= h0->Item_const_eq(c0, c1, config.binary_cmp);
37663766
}
37673767
}
37683768
DBUG_EXECUTE_IF("Item_basic_value",
37693769
push_warning_printf(current_thd,
37703770
Sql_condition::WARN_LEVEL_NOTE,
37713771
ER_UNKNOWN_ERROR, "%seq=%d a=%s b=%s",
3772-
binary_cmp ? "bin_" : "", (int) res,
3772+
config.binary_cmp ? "bin_" : "", (int) res,
37733773
DbugStringItemTypeValue(current_thd, this).c_ptr(),
37743774
DbugStringItemTypeValue(current_thd, item).c_ptr()
37753775
););
@@ -9575,15 +9575,15 @@ bool Item_outer_ref::check_inner_refs_processor(void *arg)
95759575
items are of the same type.
95769576
95779577
@param item item to compare with
9578-
@param binary_cmp make binary comparison
9578+
@param config comparison rules, see Item::Eq_config
95799579
95809580
@retval
95819581
TRUE Referenced item is equal to given item
95829582
@retval
95839583
FALSE otherwise
95849584
*/
95859585

9586-
bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const
9586+
bool Item_direct_view_ref::eq(const Item *item, const Eq_config &config) const
95879587
{
95889588
if (item->type() == REF_ITEM)
95899589
{
@@ -9804,10 +9804,10 @@ bool Item_direct_view_ref::val_bool_result()
98049804
}
98059805

98069806

9807-
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
9807+
bool Item_default_value::eq(const Item *item, const Eq_config &config) const
98089808
{
9809-
return item->type() == DEFAULT_VALUE_ITEM &&
9810-
((Item_default_value *)item)->arg->eq(arg, binary_cmp);
9809+
return item->type() == DEFAULT_VALUE_ITEM &&
9810+
((Item_default_value *)item)->arg->eq(arg, config);
98119811
}
98129812

98139813

@@ -10090,10 +10090,10 @@ bool Item_default_value::tie_field(THD *thd)
1009010090

1009110091
}
1009210092

10093-
bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
10093+
bool Item_insert_value::eq(const Item *item, const Eq_config &config) const
1009410094
{
1009510095
return item->type() == INSERT_VALUE_ITEM &&
10096-
((Item_insert_value *)item)->arg->eq(arg, binary_cmp);
10096+
((Item_insert_value *)item)->arg->eq(arg, config);
1009710097
}
1009810098

1009910099

@@ -10204,7 +10204,7 @@ void Item_trigger_field::setup_field(THD *thd, TABLE *table,
1020410204
}
1020510205

1020610206

10207-
bool Item_trigger_field::eq(const Item *item, bool binary_cmp) const
10207+
bool Item_trigger_field::eq(const Item *item, const Eq_config &config) const
1020810208
{
1020910209
return item->type() == TRIGGER_FIELD_ITEM &&
1021010210
row_version == ((Item_trigger_field *)item)->row_version &&

sql/item.h

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,12 @@ class Item :public Value_source,
12711271
{
12721272
return type_handler()->Item_send(this, protocol, buffer);
12731273
}
1274-
virtual bool eq(const Item *, bool binary_cmp) const;
1274+
struct Eq_config
1275+
{
1276+
bool binary_cmp; /**< Make binary comparison */
1277+
Eq_config(bool binary_cmp) : binary_cmp(binary_cmp) {}
1278+
};
1279+
virtual bool eq(const Item *, const Eq_config &config) const;
12751280
enum_field_types field_type() const
12761281
{
12771282
return type_handler()->field_type();
@@ -2907,11 +2912,11 @@ class Item_args
29072912
return true;
29082913
}
29092914
bool excl_dep_on_grouping_fields(st_select_lex *sel);
2910-
bool eq(const Item_args *other, bool binary_cmp) const
2915+
bool eq(const Item_args *other, const Item::Eq_config &config) const
29112916
{
29122917
for (uint i= 0; i < arg_count ; i++)
29132918
{
2914-
if (!args[i]->eq(other->args[i], binary_cmp))
2919+
if (!args[i]->eq(other->args[i], config))
29152920
return false;
29162921
}
29172922
return true;
@@ -3131,7 +3136,7 @@ class Item_basic_value :public Item,
31313136
table, src, param,
31323137
type() == Item::NULL_ITEM);
31333138
}
3134-
bool eq(const Item *item, bool binary_cmp) const override;
3139+
bool eq(const Item *item, const Eq_config &config) const override;
31353140
const Type_all_attributes *get_type_all_attributes_from_const() const
31363141
override
31373142
{ return this; }
@@ -3737,7 +3742,7 @@ class Item_field :public Item_ident,
37373742
*/
37383743
Item_field(THD *thd, Field *field);
37393744
Type type() const override { return FIELD_ITEM; }
3740-
bool eq(const Item *item, bool binary_cmp) const override;
3745+
bool eq(const Item *item, const Eq_config &config) const override;
37413746
double val_real() override;
37423747
longlong val_int() override;
37433748
my_decimal *val_decimal(my_decimal *) override;
@@ -5870,10 +5875,10 @@ class Item_ref :public Item_ident
58705875
enum Type type() const override { return REF_ITEM; }
58715876
enum Type real_type() const override
58725877
{ return ref ? (*ref)->type() : REF_ITEM; }
5873-
bool eq(const Item *item, bool binary_cmp) const override
5878+
bool eq(const Item *item, const Eq_config &config) const override
58745879
{
58755880
const Item *it= item->real_item();
5876-
return ref && (*ref)->eq(it, binary_cmp);
5881+
return ref && (*ref)->eq(it, config);
58775882
}
58785883
void save_val(Field *to) override;
58795884
void save_result(Field *to) override;
@@ -6224,10 +6229,10 @@ class Item_cache_wrapper :public Item_result_field
62246229
{ return orig_item->full_name_cstring(); }
62256230
void make_send_field(THD *thd, Send_field *field) override
62266231
{ orig_item->make_send_field(thd, field); }
6227-
bool eq(const Item *item, bool binary_cmp) const override
6232+
bool eq(const Item *item, const Eq_config &config) const override
62286233
{
62296234
const Item *it= item->real_item();
6230-
return orig_item->eq(it, binary_cmp);
6235+
return orig_item->eq(it, config);
62316236
}
62326237
void fix_after_pullout(st_select_lex *new_parent, Item **refptr, bool merge)
62336238
override
@@ -6336,7 +6341,7 @@ class Item_direct_view_ref :public Item_direct_ref
63366341
}
63376342

63386343
bool fix_fields(THD *, Item **) override;
6339-
bool eq(const Item *item, bool binary_cmp) const override;
6344+
bool eq(const Item *item, const Eq_config &config) const override;
63406345
Item *get_tmp_table_item(THD *thd) override
63416346
{
63426347
if (const_item())
@@ -7002,7 +7007,7 @@ class Item_default_value : public Item_field
70027007
m_share_field= false;
70037008
}
70047009
Type type() const override { return DEFAULT_VALUE_ITEM; }
7005-
bool eq(const Item *item, bool binary_cmp) const override;
7010+
bool eq(const Item *item, const Eq_config &config) const override;
70067011
bool fix_fields(THD *, Item **) override;
70077012
void cleanup() override;
70087013
void print(String *str, enum_query_type query_type) override;
@@ -7093,7 +7098,7 @@ class Item_contextually_typed_value_specification: public Item
70937098
{ }
70947099
Type type() const override { return CONTEXTUALLY_TYPED_VALUE_ITEM; }
70957100
bool vcol_assignment_allowed_value() const override { return true; }
7096-
bool eq(const Item *item, bool binary_cmp) const override { return false; }
7101+
bool eq(const Item *item, const Eq_config &config) const override { return false; }
70977102
bool is_evaluable_expression() const override { return false; }
70987103
Field *create_tmp_field_ex(MEM_ROOT *,
70997104
TABLE *, Tmp_field_src *,
@@ -7233,7 +7238,7 @@ class Item_insert_value : public Item_field
72337238
Item_insert_value(THD *thd, Name_resolution_context *context_arg, Item *a)
72347239
:Item_field(thd, context_arg),
72357240
arg(a) {}
7236-
bool eq(const Item *item, bool binary_cmp) const override;
7241+
bool eq(const Item *item, const Eq_config &config) const override;
72377242
bool fix_fields(THD *, Item **) override;
72387243
void print(String *str, enum_query_type query_type) override;
72397244
int save_in_field(Field *field_arg, bool no_conversions) override
@@ -7325,7 +7330,7 @@ Item_trigger_field(THD *thd, Name_resolution_context *context_arg,
73257330
}
73267331
void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info);
73277332
Type type() const override { return TRIGGER_FIELD_ITEM; }
7328-
bool eq(const Item *item, bool binary_cmp) const override;
7333+
bool eq(const Item *item, const Eq_config &config) const override;
73297334
bool fix_fields(THD *, Item **) override;
73307335
void print(String *str, enum_query_type query_type) override;
73317336
table_map used_tables() const override { return (table_map)0L; }
@@ -7454,7 +7459,7 @@ class Item_cache: public Item_fixed_hybrid,
74547459
{
74557460
return cached_field ? cached_field->eq_def (field) : FALSE;
74567461
}
7457-
bool eq(const Item *item, bool binary_cmp) const override
7462+
bool eq(const Item *item, const Eq_config &config) const override
74587463
{
74597464
return this == item;
74607465
}
@@ -8218,10 +8223,10 @@ class Item_direct_ref_to_item : public Item_direct_ref
82188223
{ return m_item->full_name_cstring(); }
82198224
void make_send_field(THD *thd, Send_field *field) override
82208225
{ m_item->make_send_field(thd, field); }
8221-
bool eq(const Item *item, bool binary_cmp) const override
8226+
bool eq(const Item *item, const Eq_config &config) const override
82228227
{
82238228
const Item *it= item->real_item();
8224-
return m_item->eq(it, binary_cmp);
8229+
return m_item->eq(it, config);
82258230
}
82268231
void fix_after_pullout(st_select_lex *new_parent, Item **refptr, bool merge) override
82278232
{ m_item->fix_after_pullout(new_parent, &m_item, merge); }

sql/item_cmpfunc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ longlong Item_func_strcmp::val_int()
19281928
}
19291929

19301930

1931-
bool Item_func_opt_neg::eq(const Item *item, bool binary_cmp) const
1931+
bool Item_func_opt_neg::eq(const Item *item, const Eq_config &config) const
19321932
{
19331933
/* Assume we don't have rtti */
19341934
if (this == item)
@@ -1941,7 +1941,7 @@ bool Item_func_opt_neg::eq(const Item *item, bool binary_cmp) const
19411941
return 0;
19421942
if (negated != ((Item_func_opt_neg *) item_func)->negated)
19431943
return 0;
1944-
return Item_args::eq(item_func, binary_cmp);
1944+
return Item_args::eq(item_func, config);
19451945
}
19461946

19471947

sql/item_cmpfunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ class Item_func_opt_neg :public Item_bool_func
992992
negated= !negated;
993993
return this;
994994
}
995-
bool eq(const Item *item, bool binary_cmp) const override;
995+
bool eq(const Item *item, const Eq_config &config) const override;
996996
CHARSET_INFO *compare_collation() const override
997997
{
998998
return cmp_collation.collation;

sql/item_func.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ void Item_func::print_op(String *str, enum_query_type query_type)
691691
}
692692

693693

694-
bool Item_func::eq(const Item *item, bool binary_cmp) const
694+
bool Item_func::eq(const Item *item, const Eq_config &config) const
695695
{
696696
/* Assume we don't have rtti */
697697
if (this == item)
@@ -711,7 +711,7 @@ bool Item_func::eq(const Item *item, bool binary_cmp) const
711711
(func_type == Item_func::FUNC_SP &&
712712
my_strcasecmp(system_charset_info, func_name(), item_func->func_name())))
713713
return 0;
714-
return Item_args::eq(item_func, binary_cmp);
714+
return Item_args::eq(item_func, config);
715715
}
716716

717717

@@ -5799,7 +5799,7 @@ void Item_func_get_user_var::print(String *str, enum_query_type query_type)
57995799
}
58005800

58015801

5802-
bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const
5802+
bool Item_func_get_user_var::eq(const Item *item, const Eq_config &config) const
58035803
{
58045804
/* Assume we don't have rtti */
58055805
if (this == item)
@@ -6192,7 +6192,7 @@ double Item_func_get_system_var::val_real()
61926192
}
61936193

61946194

6195-
bool Item_func_get_system_var::eq(const Item *item, bool binary_cmp) const
6195+
bool Item_func_get_system_var::eq(const Item *item, const Eq_config &config) const
61966196
{
61976197
/* Assume we don't have rtti */
61986198
if (this == item)
@@ -6477,7 +6477,7 @@ bool Item_func_match::fix_index()
64776477
}
64786478

64796479

6480-
bool Item_func_match::eq(const Item *item, bool binary_cmp) const
6480+
bool Item_func_match::eq(const Item *item, const Eq_config &config) const
64816481
{
64826482
if (item->type() != FUNC_ITEM ||
64836483
((Item_func*)item)->functype() != FT_FUNC ||
@@ -6487,7 +6487,7 @@ bool Item_func_match::eq(const Item *item, bool binary_cmp) const
64876487
Item_func_match *ifm=(Item_func_match*) item;
64886488

64896489
if (key == ifm->key && table == ifm->table &&
6490-
key_item()->eq(ifm->key_item(), binary_cmp))
6490+
key_item()->eq(ifm->key_item(), config))
64916491
return 1;
64926492

64936493
return 0;

sql/item_func.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Item_func :public Item_func_or_sum
226226
DBUG_ENTER("Item_func::get_mm_tree");
227227
DBUG_RETURN(const_item() ? get_mm_tree_for_const(param) : NULL);
228228
}
229-
bool eq(const Item *item, bool binary_cmp) const override;
229+
bool eq(const Item *item, const Eq_config &config) const override;
230230
virtual Item *key_item() const { return args[0]; }
231231
void set_arguments(THD *thd, List<Item> &list)
232232
{
@@ -3545,7 +3545,7 @@ class Item_func_get_user_var :public Item_func_user_var,
35453545
bool const_item() const override;
35463546
table_map used_tables() const override
35473547
{ return const_item() ? 0 : RAND_TABLE_BIT; }
3548-
bool eq(const Item *item, bool binary_cmp) const override;
3548+
bool eq(const Item *item, const Eq_config &config) const override;
35493549
Item *do_get_copy(THD *thd) const override
35503550
{ return get_item_copy<Item_func_get_user_var>(thd, this); }
35513551
private:
@@ -3689,7 +3689,7 @@ class Item_func_get_system_var :public Item_func
36893689
@return true if the variable is written to the binlog, false otherwise.
36903690
*/
36913691
bool is_written_to_binlog();
3692-
bool eq(const Item *item, bool binary_cmp) const override;
3692+
bool eq(const Item *item, const Eq_config &config) const override;
36933693

36943694
void cleanup() override;
36953695
bool check_vcol_func_processor(void *arg) override;
@@ -3744,7 +3744,7 @@ class Item_func_match :public Item_real_func
37443744
return false;
37453745
}
37463746
bool fix_fields(THD *thd, Item **ref) override;
3747-
bool eq(const Item *, bool binary_cmp) const override;
3747+
bool eq(const Item *, const Eq_config &config) const override;
37483748
/* The following should be safe, even if we compare doubles */
37493749
longlong val_int() override { DBUG_ASSERT(fixed()); return val_real() != 0.0; }
37503750
double val_real() override;

sql/item_strfunc.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,9 +3910,10 @@ bool Item_func_set_collation::fix_length_and_dec(THD *thd)
39103910
}
39113911

39123912

3913-
bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
3913+
bool Item_func_set_collation::eq(const Item *item,
3914+
const Eq_config &config) const
39143915
{
3915-
return Item_func::eq(item, binary_cmp) &&
3916+
return Item_func::eq(item, config) &&
39163917
collation.collation == item->collation.collation;
39173918
}
39183919

0 commit comments

Comments
 (0)