From a1b4eadf89a3940b80a6ed0eadd15ba456c2fa7a Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 7 Dec 2011 19:21:51 +0400 Subject: [PATCH] BUG#868908: Crash in check_simple_equality() with semijoin + materialization + prepared statement - Part2: safety and code cleanup --- sql/item_subselect.cc | 7 +++++-- sql/item_subselect.h | 2 +- sql/opt_subselect.cc | 10 ---------- sql/sql_select.cc | 11 ++++------- sql/table.cc | 4 ++-- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index f4dc7c6873a..a9488cc08c0 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -616,7 +616,7 @@ int Item_in_subselect::optimize(double *out_rows, double *cost) thd->lex->current_select= join->select_lex; if ((res= join->optimize())) DBUG_RETURN(res); -//psergey-todo: subq predicate can be made forced const! + /* Calculate #rows and cost of join execution */ join->get_partial_cost_and_fanout(join->table_count - join->const_tables, table_map(-1), @@ -1197,7 +1197,8 @@ Item_in_subselect::Item_in_subselect(Item * left_exp, Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0), pushed_cond_guards(NULL), emb_on_expr_nest(NULL), - is_jtbm_merged(FALSE), is_flattenable_semijoin(FALSE), + is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), + is_flattenable_semijoin(FALSE), is_registered_semijoin(FALSE), upper_item(0) { @@ -4182,6 +4183,8 @@ bool subselect_hash_sj_engine::init(List *tmp_columns, uint subquery_id) */ if (tmp_table->s->keys == 0) { + //fprintf(stderr, "Q: %s\n", current_thd->query()); + DBUG_ASSERT(0); DBUG_ASSERT( tmp_table->s->uniques || tmp_table->key_info->key_length >= tmp_table->file->max_key_length() || diff --git a/sql/item_subselect.h b/sql/item_subselect.h index ae096ac1a39..880b505a8d1 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -491,7 +491,7 @@ public: :Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE), abort_on_null(0), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0), pushed_cond_guards(NULL), func(NULL), emb_on_expr_nest(NULL), - is_jtbm_merged(FALSE), + is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), upper_item(0) {} void cleanup(); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 178d0bac3d3..82309c8cece 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1431,21 +1431,11 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, DBUG_ENTER("convert_subq_to_jtbm"); bool optimization_delayed= TRUE; subq_pred->set_strategy(SUBS_MATERIALIZATION); -// if (subq_pred->optimize(&rows, &read_time)) psergey-fix -// DBUG_RETURN(TRUE); subq_pred->jtbm_read_time= read_time; subq_pred->jtbm_record_count=rows; subq_pred->is_jtbm_merged= TRUE; -/* psergey-fix - if (subq_pred->engine->engine_type() != subselect_engine::HASH_SJ_ENGINE) - { - *remove_item= FALSE; - DBUG_RETURN(FALSE); - } -*/ - *remove_item= TRUE; TABLE_LIST *jtbm; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1c484b13233..5af287fbed0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -832,12 +832,12 @@ TABLE *create_dummy_tmp_table(THD *thd) void -inject_jtbm_conds(JOIN *join, List *join_list, Item **join_where) +setup_jtbm_semi_joins(JOIN *join, List *join_list, Item **join_where) { TABLE_LIST *table; NESTED_JOIN *nested_join; List_iterator li(*join_list); - DBUG_ENTER("inject_jtbm_conds"); + DBUG_ENTER("setup_jtbm_semi_joins"); while ((table= li++)) @@ -880,7 +880,6 @@ inject_jtbm_conds(JOIN *join, List *join_list, Item **join_where) table->table->pos_in_table_list= table; setup_table_map(table->table, table, table->jtbm_table_no); - } else { @@ -889,7 +888,6 @@ inject_jtbm_conds(JOIN *join, List *join_list, Item **join_where) subselect_hash_sj_engine *hash_sj_engine= ((subselect_hash_sj_engine*)item->engine); - //repeat of convert_subq_to_jtbm: table->table= hash_sj_engine->tmp_table; table->table->pos_in_table_list= table; @@ -900,13 +898,12 @@ inject_jtbm_conds(JOIN *join, List *join_list, Item **join_where) (*join_where)= and_items(*join_where, sj_conds); if (!(*join_where)->fixed) (*join_where)->fix_fields(join->thd, join_where); - //parent_join->select_lex->where= parent_join->conds; } } if ((nested_join= table->nested_join)) { - inject_jtbm_conds(join, &nested_join->join_list, join_where); + setup_jtbm_semi_joins(join, &nested_join->join_list, join_where); } } DBUG_VOID_RETURN; @@ -1036,7 +1033,7 @@ JOIN::optimize() thd->restore_active_arena(arena, &backup); } - inject_jtbm_conds(this, join_list, &conds); + setup_jtbm_semi_joins(this, join_list, &conds); conds= optimize_cond(this, conds, join_list, &cond_value, &cond_equal); diff --git a/sql/table.cc b/sql/table.cc index 28c45a77396..5c0d4a81384 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -5922,8 +5922,8 @@ bool TABLE_LIST::init_derived(THD *thd, bool init_view) int TABLE_LIST::fetch_number_of_rows() { int error= 0; - if (jtbm_subselect) /* psergey-todo: how did we work before? */ - return 0; /*psergey-todo: check if we still need to set it? */ + if (jtbm_subselect) + return 0; if (is_materialized_derived() && !fill_me) {