Skip to content

Commit 6e091dc

Browse files
author
Alexander Barkov
committed
Splitting a static function get_func_mm_tree() into virtual
methods in Item_bool_func descendants, which gives some advantages: - Removing the "bool inv" parameter, as its now available through "this" for Item_func_between and Item_func_in, and is not needed for the other Item_func_xxx. - Removing casts - Making a step to data types plugings
1 parent 9a64262 commit 6e091dc

File tree

2 files changed

+264
-260
lines changed

2 files changed

+264
-260
lines changed

sql/item_cmpfunc.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ class Arg_comparator: public Sql_alloc
122122

123123
class Item_bool_func :public Item_int_func
124124
{
125+
protected:
126+
/*
127+
Build a SEL_TREE for a simple predicate
128+
@param param PARAM from SQL_SELECT::test_quick_select
129+
@param field field in the predicate
130+
@param value constant in the predicate
131+
@param cmp_type compare type for the field
132+
@return Pointer to the tree built tree
133+
*/
134+
virtual SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
135+
Field *field, Item *value,
136+
Item_result cmp_type)
137+
{
138+
DBUG_ENTER("Item_bool_func2::get_func_mm_tree");
139+
DBUG_ASSERT(0);
140+
DBUG_RETURN(0);
141+
}
142+
SEL_TREE *get_full_func_mm_tree(RANGE_OPT_PARAM *param,
143+
Item_field *field_item, Item *value);
144+
SEL_TREE *get_mm_parts(RANGE_OPT_PARAM *param, Field *field,
145+
Item_func::Functype type,
146+
Item *value, Item_result cmp_type);
147+
SEL_TREE *get_ne_mm_tree(RANGE_OPT_PARAM *param,
148+
Field *field, Item *lt_value, Item *gt_value,
149+
Item_result cmp_type);
125150
public:
126151
Item_bool_func() :Item_int_func() {}
127152
Item_bool_func(Item *a) :Item_int_func(a) {}
@@ -291,6 +316,21 @@ class Item_bool_func2 :public Item_bool_func
291316
void add_key_fields_optimize_op(JOIN *join, KEY_FIELD **key_fields,
292317
uint *and_level, table_map usable_tables,
293318
SARGABLE_PARAM **sargables, bool equal_func);
319+
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
320+
Field *field, Item *value, Item_result cmp_type)
321+
{
322+
DBUG_ENTER("Item_bool_func2::get_func_mm_tree");
323+
/*
324+
Here the function for the following predicates are processed:
325+
<, <=, =, <=>, >=, >, LIKE, spatial relations
326+
If the predicate is of the form (value op field) it is handled
327+
as the equivalent predicate (field rev_op value), e.g.
328+
2 <= a is handled as a >= 2.
329+
*/
330+
Item_func::Functype func_type=
331+
(value != arguments()[0]) ? functype() : rev_functype();
332+
DBUG_RETURN(get_mm_parts(param, field, func_type, value, cmp_type));
333+
}
294334
public:
295335
Item_bool_func2(Item *a,Item *b)
296336
:Item_bool_func(a,b) { }
@@ -587,6 +627,13 @@ class Item_func_lt :public Item_bool_rowready_func2
587627

588628
class Item_func_ne :public Item_bool_rowready_func2
589629
{
630+
protected:
631+
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
632+
Field *field, Item *value, Item_result cmp_type)
633+
{
634+
DBUG_ENTER("Item_func_ne::get_func_mm_tree");
635+
DBUG_RETURN(get_ne_mm_tree(param, field, value, value, cmp_type));
636+
}
590637
public:
591638
Item_func_ne(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {}
592639
longlong val_int();
@@ -635,6 +682,9 @@ class Item_func_opt_neg :public Item_bool_func
635682
class Item_func_between :public Item_func_opt_neg
636683
{
637684
DTCollation cmp_collation;
685+
protected:
686+
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
687+
Field *field, Item *value, Item_result cmp_type);
638688
public:
639689
Item_result cmp_type;
640690
String value0,value1,value2;
@@ -1292,6 +1342,9 @@ class Item_func_case :public Item_func_hybrid_field_type
12921342
*/
12931343
class Item_func_in :public Item_func_opt_neg
12941344
{
1345+
protected:
1346+
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
1347+
Field *field, Item *value, Item_result cmp_type);
12951348
public:
12961349
/*
12971350
an array of values when the right hand arguments of IN
@@ -1377,6 +1430,13 @@ class in_row :public in_vector
13771430
/* Functions used by where clause */
13781431
class Item_func_null_predicate :public Item_bool_func
13791432
{
1433+
protected:
1434+
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
1435+
Field *field, Item *value, Item_result cmp_type)
1436+
{
1437+
DBUG_ENTER("Item_func_null_predicate::get_func_mm_tree");
1438+
DBUG_RETURN(get_mm_parts(param, field, functype(), value, cmp_type));
1439+
}
13801440
public:
13811441
Item_func_null_predicate(Item *a) :Item_bool_func(a) { }
13821442
void add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level,

0 commit comments

Comments
 (0)