diff options
-rw-r--r-- | sql/item.h | 7 | ||||
-rw-r--r-- | sql/item_func.h | 8 | ||||
-rw-r--r-- | sql/item_subselect.cc | 5 | ||||
-rw-r--r-- | sql/opt_range.cc | 6 | ||||
-rw-r--r-- | sql/opt_subselect.cc | 5 | ||||
-rw-r--r-- | sql/opt_sum.cc | 7 | ||||
-rw-r--r-- | sql/sql_select.cc | 21 |
7 files changed, 37 insertions, 22 deletions
diff --git a/sql/item.h b/sql/item.h index 1db4e62051c..e662eed4a71 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2224,7 +2224,12 @@ public: ~Item_result_field() {} /* Required with gcc 2.95 */ Field *get_tmp_table_field() { return result_field; } Field *tmp_table_field(TABLE *t_arg) { return result_field; } - table_map used_tables() const { return true; } + /* + This implementation of used_tables() used by Item_avg_field and + Item_variance_field which work when only temporary table left, so theu + return table map of the temporary table. + */ + table_map used_tables() const { return 1; } void set_result_field(Field *field) { result_field= field; } bool is_result_field() { return true; } void save_in_result_field(bool no_conversions) diff --git a/sql/item_func.h b/sql/item_func.h index 7f301b6801e..6230550067b 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1348,7 +1348,7 @@ public: const char *func_name() const { return "sleep"; } table_map used_tables() const { - return Item_int_func::used_tables() | RAND_TABLE_BIT; + return used_tables_cache | RAND_TABLE_BIT; } bool is_expensive() { return 1; } longlong val_int(); @@ -1610,7 +1610,7 @@ class Item_func_get_lock :public Item_int_func void fix_length_and_dec() { max_length=1; maybe_null=1;} table_map used_tables() const { - return Item_int_func::used_tables() | RAND_TABLE_BIT; + return used_tables_cache | RAND_TABLE_BIT; } bool const_item() const { return 0; } bool is_expensive() { return 1; } @@ -1630,7 +1630,7 @@ public: void fix_length_and_dec() { max_length= 1; maybe_null= 1;} table_map used_tables() const { - return Item_int_func::used_tables() | RAND_TABLE_BIT; + return used_tables_cache | RAND_TABLE_BIT; } bool const_item() const { return 0; } bool is_expensive() { return 1; } @@ -1767,7 +1767,7 @@ public: } table_map used_tables() const { - return Item_func::used_tables() | RAND_TABLE_BIT; + return used_tables_cache | RAND_TABLE_BIT; } bool const_item() const { return 0; } bool is_expensive() { return 1; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 84c21bf2fad..3224362b7f7 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -5228,12 +5228,13 @@ double get_post_group_estimate(JOIN* join, double join_op_rows) for (ORDER *order= join->group_list; order; order= order->next) { Item *item= order->item[0]; - if (item->used_tables() & RAND_TABLE_BIT) + table_map item_used_tables= item->used_tables(); + if (item_used_tables & RAND_TABLE_BIT) { /* Each join output record will be in its own group */ return join_op_rows; } - tables_in_group_list|= item->used_tables(); + tables_in_group_list|= item_used_tables; } tables_in_group_list &= ~PSEUDO_TABLE_BITS; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 64d476c1327..860426c013a 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7585,8 +7585,10 @@ Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field, KEY_PART *key_part = param->key_parts; KEY_PART *end = param->key_parts_end; SEL_TREE *tree=0; + table_map value_used_tables= 0; if (value && - value->used_tables() & ~(param->prev_tables | param->read_tables)) + (value_used_tables= value->used_tables()) & + ~(param->prev_tables | param->read_tables)) DBUG_RETURN(0); for (; key_part != end ; key_part++) { @@ -7595,7 +7597,7 @@ Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field, SEL_ARG *sel_arg=0; if (!tree && !(tree=new (param->thd->mem_root) SEL_TREE())) DBUG_RETURN(0); // OOM - if (!value || !(value->used_tables() & ~param->read_tables)) + if (!value || !(value_used_tables & ~param->read_tables)) { /* We need to restore the runtime mem_root of the thread in this diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 1566ab43074..4b21ffebe1f 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1570,8 +1570,9 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) DBUG_RETURN(TRUE); thd->lex->current_select=save_lex; - sj_nest->nested_join->sj_corr_tables= subq_pred->used_tables(); - sj_nest->nested_join->sj_depends_on= subq_pred->used_tables() | + table_map subq_pred_used_tables= subq_pred->used_tables(); + sj_nest->nested_join->sj_corr_tables= subq_pred_used_tables; + sj_nest->nested_join->sj_depends_on= subq_pred_used_tables | subq_pred->left_expr->used_tables(); sj_nest->sj_on_expr= subq_lex->join->conds; diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 7a6685914a9..e8cff9e69ab 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -654,12 +654,13 @@ static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, if (!cond) DBUG_RETURN(TRUE); Field *field= field_part->field; - if (cond->used_tables() & OUTER_REF_TABLE_BIT) + table_map cond_used_tables= cond->used_tables(); + if (cond_used_tables & OUTER_REF_TABLE_BIT) { DBUG_RETURN(FALSE); } - if (!(cond->used_tables() & field->table->map) && - MY_TEST(cond->used_tables() & ~PSEUDO_TABLE_BITS)) + if (!(cond_used_tables & field->table->map) && + MY_TEST(cond_used_tables & ~PSEUDO_TABLE_BITS)) { /* Condition doesn't restrict the used table */ DBUG_RETURN(!cond->const_item()); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1949163c87a..1c27b659382 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4530,8 +4530,9 @@ add_key_field(JOIN *join, bool optimizable=0; for (uint i=0; i<num_values; i++) { - used_tables|=(value[i])->used_tables(); - if (!((value[i])->used_tables() & (field->table->map | RAND_TABLE_BIT))) + table_map value_used_tables= (value[i])->used_tables(); + used_tables|= value_used_tables; + if (!(value_used_tables & (field->table->map | RAND_TABLE_BIT))) optimizable=1; } if (!optimizable) @@ -14440,7 +14441,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, */ if (table->on_expr) { - table->dep_tables|= table->on_expr->used_tables(); + table_map table_on_expr_used_tables= table->on_expr->used_tables(); + table->dep_tables|= table_on_expr_used_tables; if (table->embedding) { table->dep_tables&= ~table->embedding->nested_join->used_tables; @@ -14448,7 +14450,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, Embedding table depends on tables used in embedded on expressions. */ - table->embedding->on_expr_dep_tables|= table->on_expr->used_tables(); + table->embedding->on_expr_dep_tables|= table_on_expr_used_tables; } else table->dep_tables&= ~table->get_map(); @@ -20160,10 +20162,13 @@ make_cond_after_sjm(THD *thd, Item *root_cond, Item *cond, table_map tables, We assume that conditions that refer to only join prefix tables or sjm_tables have already been checked. */ - if (!inside_or_clause && - (!(cond->used_tables() & ~tables) || - !(cond->used_tables() & ~sjm_tables))) - return (COND*) 0; // Already checked + if (!inside_or_clause) + { + table_map cond_used_tables= cond->used_tables(); + if((!(cond_used_tables & ~tables) || + !(cond_used_tables & ~sjm_tables))) + return (COND*) 0; // Already checked + } /* AND/OR recursive descent */ if (cond->type() == Item::COND_ITEM) |