@@ -952,7 +952,6 @@ static SEL_TREE * get_mm_parts(RANGE_OPT_PARAM *param,COND *cond_func,Field *fie
952
952
static SEL_ARG *get_mm_leaf (RANGE_OPT_PARAM *param,COND *cond_func,Field *field,
953
953
KEY_PART *key_part,
954
954
Item_func::Functype type,Item *value);
955
- static SEL_TREE *get_mm_tree (RANGE_OPT_PARAM *param, Item **cond);
956
955
957
956
static bool is_key_scan_ror (PARAM *param, uint keynr, uint8 nparts);
958
957
static ha_rows check_quick_select (PARAM *param, uint idx, bool index_only,
@@ -3131,7 +3130,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
3131
3130
3132
3131
if (cond)
3133
3132
{
3134
- if ((tree= get_mm_tree (¶m, &cond)))
3133
+ if ((tree= cond-> get_mm_tree (¶m, &cond)))
3135
3134
{
3136
3135
if (tree->type == SEL_TREE::IMPOSSIBLE)
3137
3136
{
@@ -3628,7 +3627,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
3628
3627
3629
3628
thd->no_errors =1 ;
3630
3629
3631
- tree= get_mm_tree (¶m, cond);
3630
+ tree= cond[ 0 ]-> get_mm_tree (¶m, cond);
3632
3631
3633
3632
if (!tree)
3634
3633
goto free_alloc;
@@ -4061,7 +4060,7 @@ bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond)
4061
4060
SEL_TREE *tree;
4062
4061
int res;
4063
4062
4064
- tree= get_mm_tree (range_par, &pprune_cond);
4063
+ tree= pprune_cond-> get_mm_tree (range_par, &pprune_cond);
4065
4064
if (!tree)
4066
4065
goto all_used;
4067
4066
@@ -7967,104 +7966,106 @@ static SEL_TREE *get_full_func_mm_tree(RANGE_OPT_PARAM *param,
7967
7966
NULL - Could not infer anything from condition cond.
7968
7967
SEL_TREE with type=IMPOSSIBLE - condition can never be true.
7969
7968
*/
7970
-
7971
- static SEL_TREE *get_mm_tree (RANGE_OPT_PARAM *param, Item **cond_ptr)
7969
+ SEL_TREE *Item_cond_and::get_mm_tree (RANGE_OPT_PARAM *param, Item **cond_ptr)
7972
7970
{
7973
- SEL_TREE *tree=0 ;
7974
- SEL_TREE *ftree= 0 ;
7975
- Item_field *field_item= 0 ;
7976
- bool inv= FALSE ;
7977
- Item *value= 0 ;
7978
- Item *cond= *cond_ptr;
7979
- DBUG_ENTER (" get_mm_tree" );
7980
-
7981
- if (cond->type () == Item::COND_ITEM)
7971
+ DBUG_ENTER (" Item_cond_and::get_mm_tree" );
7972
+ SEL_TREE *tree= NULL ;
7973
+ List_iterator<Item> li (*argument_list ());
7974
+ Item *item;
7975
+ while ((item= li++))
7982
7976
{
7983
- List_iterator<Item> li (*((Item_cond*) cond)->argument_list ());
7977
+ SEL_TREE *new_tree= li.ref ()[0 ]->get_mm_tree (param,li.ref ());
7978
+ if (param->statement_should_be_aborted ())
7979
+ DBUG_RETURN (NULL );
7980
+ tree= tree_and (param, tree, new_tree);
7981
+ if (tree && tree->type == SEL_TREE::IMPOSSIBLE)
7982
+ {
7983
+ /*
7984
+ Do not remove 'item' from 'cond'. We return a SEL_TREE::IMPOSSIBLE
7985
+ and that is sufficient for the caller to see that the whole
7986
+ condition is never true.
7987
+ */
7988
+ break ;
7989
+ }
7990
+ }
7991
+ DBUG_RETURN (tree);
7992
+ }
7984
7993
7985
- if (((Item_cond*) cond)->functype () == Item_func::COND_AND_FUNC)
7994
+
7995
+ SEL_TREE *Item_cond::get_mm_tree (RANGE_OPT_PARAM *param, Item **cond_ptr)
7996
+ {
7997
+ DBUG_ENTER (" Item_cond::get_mm_tree" );
7998
+ List_iterator<Item> li (*argument_list ());
7999
+ bool replace_cond= false ;
8000
+ Item *replacement_item= li++;
8001
+ SEL_TREE *tree= li.ref ()[0 ]->get_mm_tree (param, li.ref ());
8002
+ if (param->statement_should_be_aborted ())
8003
+ DBUG_RETURN (NULL );
8004
+ if (tree)
8005
+ {
8006
+ if (tree->type == SEL_TREE::IMPOSSIBLE &&
8007
+ param->remove_false_where_parts )
7986
8008
{
7987
- tree= NULL ;
7988
- Item *item;
7989
- while ((item=li++))
7990
- {
7991
- SEL_TREE *new_tree= get_mm_tree (param,li.ref ());
7992
- if (param->statement_should_be_aborted ())
7993
- DBUG_RETURN (NULL );
7994
- tree= tree_and (param,tree,new_tree);
7995
- if (tree && tree->type == SEL_TREE::IMPOSSIBLE)
7996
- {
7997
- /*
7998
- Do not remove 'item' from 'cond'. We return a SEL_TREE::IMPOSSIBLE
7999
- and that is sufficient for the caller to see that the whole
8000
- condition is never true.
8001
- */
8002
- break ;
8003
- }
8004
- }
8009
+ /* See the other li.remove() call below */
8010
+ li.remove ();
8011
+ if (argument_list ()->elements <= 1 )
8012
+ replace_cond= true ;
8005
8013
}
8006
- else
8007
- { // COND OR
8008
- bool replace_cond= false ;
8009
- Item *replacement_item= li++;
8010
- tree= get_mm_tree (param, li.ref ());
8011
- if (param->statement_should_be_aborted ())
8014
+
8015
+ Item *item;
8016
+ while ((item= li++))
8017
+ {
8018
+ SEL_TREE *new_tree= li. ref ()[ 0 ]-> get_mm_tree (param, li.ref ());
8019
+ if (new_tree == NULL || param->statement_should_be_aborted ())
8012
8020
DBUG_RETURN (NULL );
8013
- if (tree)
8021
+ tree= tree_or (param, tree, new_tree);
8022
+ if (tree == NULL || tree->type == SEL_TREE::ALWAYS)
8014
8023
{
8015
- if (tree->type == SEL_TREE::IMPOSSIBLE &&
8016
- param->remove_false_where_parts )
8017
- {
8018
- /* See the other li.remove() call below */
8019
- li.remove ();
8020
- if (((Item_cond*)cond)->argument_list ()->elements <= 1 )
8021
- replace_cond= true ;
8022
- }
8023
-
8024
- Item *item;
8025
- while ((item=li++))
8026
- {
8027
- SEL_TREE *new_tree=get_mm_tree (param,li.ref ());
8028
- if (new_tree == NULL || param->statement_should_be_aborted ())
8029
- DBUG_RETURN (NULL );
8030
- tree= tree_or (param,tree,new_tree);
8031
- if (tree == NULL || tree->type == SEL_TREE::ALWAYS)
8032
- {
8033
- replacement_item= *li.ref ();
8034
- break ;
8035
- }
8024
+ replacement_item= *li.ref ();
8025
+ break ;
8026
+ }
8036
8027
8037
- if (new_tree && new_tree->type == SEL_TREE::IMPOSSIBLE &&
8038
- param->remove_false_where_parts )
8039
- {
8040
- /*
8041
- This is a condition in form
8028
+ if (new_tree && new_tree->type == SEL_TREE::IMPOSSIBLE &&
8029
+ param->remove_false_where_parts )
8030
+ {
8031
+ /*
8032
+ This is a condition in form
8042
8033
8043
- cond = item1 OR ... OR item_i OR ... itemN
8034
+ cond = item1 OR ... OR item_i OR ... itemN
8044
8035
8045
- and item_i produces SEL_TREE(IMPOSSIBLE). We should remove item_i
8046
- from cond. This may cause 'cond' to become a degenerate,
8047
- one-way OR. In that case, we replace 'cond' with the remaining
8048
- item_i.
8049
- */
8050
- li.remove ();
8051
- if (((Item_cond*)cond)->argument_list ()->elements <= 1 )
8052
- replace_cond= true ;
8053
- }
8054
- else
8055
- replacement_item= *li.ref ();
8056
- }
8057
-
8058
- if (replace_cond)
8059
- *cond_ptr= replacement_item;
8036
+ and item_i produces SEL_TREE(IMPOSSIBLE). We should remove item_i
8037
+ from cond. This may cause 'cond' to become a degenerate,
8038
+ one-way OR. In that case, we replace 'cond' with the remaining
8039
+ item_i.
8040
+ */
8041
+ li.remove ();
8042
+ if (argument_list ()->elements <= 1 )
8043
+ replace_cond= true ;
8060
8044
}
8045
+ else
8046
+ replacement_item= *li.ref ();
8061
8047
}
8062
- DBUG_RETURN (tree);
8048
+
8049
+ if (replace_cond)
8050
+ *cond_ptr= replacement_item;
8063
8051
}
8052
+ DBUG_RETURN (tree);
8053
+ }
8054
+
8055
+
8056
+ SEL_TREE *Item::get_mm_tree (RANGE_OPT_PARAM *param, Item **cond_ptr)
8057
+ {
8058
+ SEL_TREE *tree=0 ;
8059
+ SEL_TREE *ftree= 0 ;
8060
+ Item_field *field_item= 0 ;
8061
+ bool inv= FALSE ;
8062
+ Item *value= 0 ;
8063
+ DBUG_ENTER (" Item::get_mm_tree" );
8064
+
8064
8065
/* Here when simple cond */
8065
- if (cond-> const_item ())
8066
+ if (const_item ())
8066
8067
{
8067
- if (cond-> is_expensive ())
8068
+ if (is_expensive ())
8068
8069
DBUG_RETURN (0 );
8069
8070
/*
8070
8071
During the cond->val_int() evaluation we can come across a subselect
@@ -8074,32 +8075,32 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr)
8074
8075
*/
8075
8076
MEM_ROOT *tmp_root= param->mem_root ;
8076
8077
param->thd ->mem_root = param->old_root ;
8077
- tree= cond-> val_int () ? new (tmp_root) SEL_TREE (SEL_TREE::ALWAYS) :
8078
- new (tmp_root) SEL_TREE (SEL_TREE::IMPOSSIBLE);
8078
+ tree= val_int () ? new (tmp_root) SEL_TREE (SEL_TREE::ALWAYS) :
8079
+ new (tmp_root) SEL_TREE (SEL_TREE::IMPOSSIBLE);
8079
8080
param->thd ->mem_root = tmp_root;
8080
8081
DBUG_RETURN (tree);
8081
8082
}
8082
8083
8083
8084
table_map ref_tables= 0 ;
8084
8085
table_map param_comp= ~(param->prev_tables | param->read_tables |
8085
8086
param->current_table );
8086
- if (cond-> type () != Item::FUNC_ITEM)
8087
+ if (type () != Item::FUNC_ITEM)
8087
8088
{ // Should be a field
8088
- ref_tables= cond-> used_tables ();
8089
+ ref_tables= used_tables ();
8089
8090
if ((ref_tables & param->current_table ) ||
8090
8091
(ref_tables & ~(param->prev_tables | param->read_tables )))
8091
8092
DBUG_RETURN (0 );
8092
8093
DBUG_RETURN (new SEL_TREE (SEL_TREE::MAYBE));
8093
8094
}
8094
8095
8095
- Item_func *cond_func= (Item_func*) cond ;
8096
+ Item_func *cond_func= (Item_func*) this ;
8096
8097
if (cond_func->functype () == Item_func::BETWEEN ||
8097
8098
cond_func->functype () == Item_func::IN_FUNC)
8098
8099
inv= ((Item_func_opt_neg *) cond_func)->negated ;
8099
8100
else if (cond_func->select_optimize () == Item_func::OPTIMIZE_NONE)
8100
8101
DBUG_RETURN (0 );
8101
8102
8102
- param->cond = cond ;
8103
+ param->cond = this ;
8103
8104
8104
8105
switch (cond_func->functype ()) {
8105
8106
case Item_func::BETWEEN:
@@ -8149,7 +8150,7 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr)
8149
8150
}
8150
8151
case Item_func::MULT_EQUAL_FUNC:
8151
8152
{
8152
- Item_equal *item_equal= (Item_equal *) cond;
8153
+ Item_equal *item_equal= (Item_equal *) this ;
8153
8154
if (!(value= item_equal->get_const ()) || value->is_expensive ())
8154
8155
DBUG_RETURN (0 );
8155
8156
Item_equal_fields_iterator it (*item_equal);
@@ -8160,7 +8161,7 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr)
8160
8161
Item_result cmp_type= field->cmp_type ();
8161
8162
if (!((ref_tables | field->table ->map ) & param_comp))
8162
8163
{
8163
- tree= get_mm_parts (param, cond , field, Item_func::EQ_FUNC,
8164
+ tree= get_mm_parts (param, this , field, Item_func::EQ_FUNC,
8164
8165
value,cmp_type);
8165
8166
ftree= !ftree ? tree : tree_and (param, ftree, tree);
8166
8167
}
0 commit comments