diff options
-rw-r--r-- | mysql-test/r/range.result | 2 | ||||
-rw-r--r-- | sql/opt_range.cc | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index 5a4d2228778..4e0476fdacd 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -232,7 +232,7 @@ update t1 set y=x; explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 7 and t1.y+0; table type possible_keys key key_len ref rows Extra t1 ref y y 5 const 1 Using where -t2 ALL x NULL NULL NULL 9 Using where +t2 range x x 5 NULL 4 Using where explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 7 and t2.x <= t1.y+0; table type possible_keys key key_len ref rows Extra t1 ref y y 5 const 1 Using where diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 2d949810b63..c7bad3b18f3 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -794,18 +794,15 @@ static SEL_TREE *get_mm_tree(PARAM *param,COND *cond) DBUG_RETURN(new SEL_TREE(SEL_TREE::ALWAYS)); DBUG_RETURN(new SEL_TREE(SEL_TREE::IMPOSSIBLE)); } + table_map ref_tables=cond->used_tables(); - if (ref_tables & ~(param->prev_tables | param->read_tables | - param->current_table)) - DBUG_RETURN(0); // Can't be calculated yet if (cond->type() != Item::FUNC_ITEM) { // Should be a field if (ref_tables & param->current_table) DBUG_RETURN(0); DBUG_RETURN(new SEL_TREE(SEL_TREE::MAYBE)); } - if (!(ref_tables & param->current_table)) - DBUG_RETURN(new SEL_TREE(SEL_TREE::MAYBE)); // This may be false or true + Item_func *cond_func= (Item_func*) cond; if (cond_func->select_optimize() == Item_func::OPTIMIZE_NONE) DBUG_RETURN(0); // Can't be calculated @@ -847,6 +844,12 @@ static SEL_TREE *get_mm_tree(PARAM *param,COND *cond) DBUG_RETURN(0); // Can't optimize this IN } + if (ref_tables & ~(param->prev_tables | param->read_tables | + param->current_table)) + DBUG_RETURN(0); // Can't be calculated yet + if (!(ref_tables & param->current_table)) + DBUG_RETURN(new SEL_TREE(SEL_TREE::MAYBE)); // This may be false or true + /* check field op const */ /* btw, ft_func's arguments()[0] isn't FIELD_ITEM. SerG*/ if (cond_func->arguments()[0]->type() == Item::FIELD_ITEM) |