mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
BUG#868908: Crash in check_simple_equality() with semijoin + materialization + prepared statement
- Part2: safety and code cleanup
This commit is contained in:
@ -616,7 +616,7 @@ int Item_in_subselect::optimize(double *out_rows, double *cost)
|
|||||||
thd->lex->current_select= join->select_lex;
|
thd->lex->current_select= join->select_lex;
|
||||||
if ((res= join->optimize()))
|
if ((res= join->optimize()))
|
||||||
DBUG_RETURN(res);
|
DBUG_RETURN(res);
|
||||||
//psergey-todo: subq predicate can be made forced const!
|
|
||||||
/* Calculate #rows and cost of join execution */
|
/* Calculate #rows and cost of join execution */
|
||||||
join->get_partial_cost_and_fanout(join->table_count - join->const_tables,
|
join->get_partial_cost_and_fanout(join->table_count - join->const_tables,
|
||||||
table_map(-1),
|
table_map(-1),
|
||||||
@ -1197,7 +1197,8 @@ Item_in_subselect::Item_in_subselect(Item * left_exp,
|
|||||||
Item_exists_subselect(),
|
Item_exists_subselect(),
|
||||||
left_expr_cache(0), first_execution(TRUE), in_strategy(SUBS_NOT_TRANSFORMED),
|
left_expr_cache(0), first_execution(TRUE), in_strategy(SUBS_NOT_TRANSFORMED),
|
||||||
optimizer(0), pushed_cond_guards(NULL), emb_on_expr_nest(NULL),
|
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),
|
is_registered_semijoin(FALSE),
|
||||||
upper_item(0)
|
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)
|
if (tmp_table->s->keys == 0)
|
||||||
{
|
{
|
||||||
|
//fprintf(stderr, "Q: %s\n", current_thd->query());
|
||||||
|
DBUG_ASSERT(0);
|
||||||
DBUG_ASSERT(
|
DBUG_ASSERT(
|
||||||
tmp_table->s->uniques ||
|
tmp_table->s->uniques ||
|
||||||
tmp_table->key_info->key_length >= tmp_table->file->max_key_length() ||
|
tmp_table->key_info->key_length >= tmp_table->file->max_key_length() ||
|
||||||
|
@ -491,7 +491,7 @@ public:
|
|||||||
:Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
|
:Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
|
||||||
abort_on_null(0), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0),
|
abort_on_null(0), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0),
|
||||||
pushed_cond_guards(NULL), func(NULL), emb_on_expr_nest(NULL),
|
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)
|
upper_item(0)
|
||||||
{}
|
{}
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
@ -1431,21 +1431,11 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
|
|||||||
DBUG_ENTER("convert_subq_to_jtbm");
|
DBUG_ENTER("convert_subq_to_jtbm");
|
||||||
bool optimization_delayed= TRUE;
|
bool optimization_delayed= TRUE;
|
||||||
subq_pred->set_strategy(SUBS_MATERIALIZATION);
|
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_read_time= read_time;
|
||||||
subq_pred->jtbm_record_count=rows;
|
subq_pred->jtbm_record_count=rows;
|
||||||
subq_pred->is_jtbm_merged= TRUE;
|
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;
|
*remove_item= TRUE;
|
||||||
|
|
||||||
TABLE_LIST *jtbm;
|
TABLE_LIST *jtbm;
|
||||||
|
@ -832,12 +832,12 @@ TABLE *create_dummy_tmp_table(THD *thd)
|
|||||||
|
|
||||||
|
|
||||||
void
|
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;
|
TABLE_LIST *table;
|
||||||
NESTED_JOIN *nested_join;
|
NESTED_JOIN *nested_join;
|
||||||
List_iterator<TABLE_LIST> li(*join_list);
|
List_iterator<TABLE_LIST> li(*join_list);
|
||||||
DBUG_ENTER("inject_jtbm_conds");
|
DBUG_ENTER("setup_jtbm_semi_joins");
|
||||||
|
|
||||||
|
|
||||||
while ((table= li++))
|
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;
|
table->table->pos_in_table_list= table;
|
||||||
|
|
||||||
setup_table_map(table->table, table, table->jtbm_table_no);
|
setup_table_map(table->table, table, table->jtbm_table_no);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
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 *hash_sj_engine=
|
||||||
((subselect_hash_sj_engine*)item->engine);
|
((subselect_hash_sj_engine*)item->engine);
|
||||||
|
|
||||||
//repeat of convert_subq_to_jtbm:
|
|
||||||
table->table= hash_sj_engine->tmp_table;
|
table->table= hash_sj_engine->tmp_table;
|
||||||
table->table->pos_in_table_list= 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);
|
(*join_where)= and_items(*join_where, sj_conds);
|
||||||
if (!(*join_where)->fixed)
|
if (!(*join_where)->fixed)
|
||||||
(*join_where)->fix_fields(join->thd, join_where);
|
(*join_where)->fix_fields(join->thd, join_where);
|
||||||
//parent_join->select_lex->where= parent_join->conds;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nested_join= table->nested_join))
|
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;
|
DBUG_VOID_RETURN;
|
||||||
@ -1036,7 +1033,7 @@ JOIN::optimize()
|
|||||||
thd->restore_active_arena(arena, &backup);
|
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);
|
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 TABLE_LIST::fetch_number_of_rows()
|
||||||
{
|
{
|
||||||
int error= 0;
|
int error= 0;
|
||||||
if (jtbm_subselect) /* psergey-todo: how did we work before? */
|
if (jtbm_subselect)
|
||||||
return 0; /*psergey-todo: check if we still need to set it? */
|
return 0;
|
||||||
if (is_materialized_derived() && !fill_me)
|
if (is_materialized_derived() && !fill_me)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user