Commit a1b4eadf authored by Sergey Petrunya's avatar Sergey Petrunya

BUG#868908: Crash in check_simple_equality() with semijoin + materialization + prepared statement

- Part2: safety and code cleanup
parent 8e25dcfc
......@@ -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<Item> *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() ||
......
......@@ -491,7 +491,7 @@ class Item_in_subselect :public Item_exists_subselect
: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();
......
......@@ -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;
......
......@@ -832,12 +832,12 @@ TABLE *create_dummy_tmp_table(THD *thd)
void
inject_jtbm_conds(JOIN *join, List<TABLE_LIST> *join_list, Item **join_where)
setup_jtbm_semi_joins(JOIN *join, List<TABLE_LIST> *join_list, Item **join_where)
{
TABLE_LIST *table;
NESTED_JOIN *nested_join;
List_iterator<TABLE_LIST> 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<TABLE_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<TABLE_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<TABLE_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);
......
......@@ -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)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment