summaryrefslogtreecommitdiff
path: root/sql/opt_subselect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/opt_subselect.cc')
-rw-r--r--sql/opt_subselect.cc75
1 files changed, 42 insertions, 33 deletions
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index a7449b1c995..dac607195f0 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -691,7 +691,8 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
{
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
- select_lex->outer_select()->sj_subselects.push_back(in_subs);
+ select_lex->outer_select()->sj_subselects.push_back(in_subs,
+ thd->mem_root);
if (arena)
thd->restore_active_arena(arena, &backup);
in_subs->is_registered_semijoin= TRUE;
@@ -728,7 +729,8 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
{
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
- select_lex->outer_select()->sj_subselects.push_back(in_subs);
+ select_lex->outer_select()->sj_subselects.push_back(in_subs,
+ thd->mem_root);
if (arena)
thd->restore_active_arena(arena, &backup);
in_subs->is_registered_semijoin= TRUE;
@@ -1425,7 +1427,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
A3: changes in the TABLE_LIST::outer_join will make everything work
automatically.
*/
- if (!(wrap_nest= alloc_join_nest(parent_join->thd)))
+ if (!(wrap_nest= alloc_join_nest(thd)))
{
DBUG_RETURN(TRUE);
}
@@ -1434,7 +1436,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
wrap_nest->alias= (char*) "(sj-wrap)";
wrap_nest->nested_join->join_list.empty();
- wrap_nest->nested_join->join_list.push_back(outer_tbl);
+ wrap_nest->nested_join->join_list.push_back(outer_tbl, thd->mem_root);
outer_tbl->embedding= wrap_nest;
outer_tbl->join_list= &wrap_nest->nested_join->join_list;
@@ -1470,7 +1472,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
TABLE_LIST *sj_nest;
NESTED_JOIN *nested_join;
- if (!(sj_nest= alloc_join_nest(parent_join->thd)))
+ if (!(sj_nest= alloc_join_nest(thd)))
{
DBUG_RETURN(TRUE);
}
@@ -1484,7 +1486,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
subq_pred->left_expr->used_tables();
/* Nests do not participate in those 'chains', so: */
/* sj_nest->next_leaf= sj_nest->next_local= sj_nest->next_global == NULL*/
- emb_join_list->push_back(sj_nest);
+ emb_join_list->push_back(sj_nest, thd->mem_root);
/*
nested_join->used_tables and nested_join->not_null_tables are
@@ -1503,7 +1505,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
{
tl->embedding= sj_nest;
tl->join_list= &nested_join->join_list;
- nested_join->join_list.push_back(tl);
+ nested_join->join_list.push_back(tl, thd->mem_root);
}
/*
@@ -1593,10 +1595,11 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
if (subq_pred->left_expr->cols() == 1)
{
- nested_join->sj_outer_expr_list.push_back(subq_pred->left_expr);
+ nested_join->sj_outer_expr_list.push_back(subq_pred->left_expr,
+ thd->mem_root);
Item_func_eq *item_eq=
new (thd->mem_root) Item_func_eq(thd, subq_pred->left_expr,
- subq_lex->ref_pointer_array[0]);
+ subq_lex->ref_pointer_array[0]);
item_eq->in_equality_no= 0;
sj_nest->sj_on_expr= and_items(thd, sj_nest->sj_on_expr, item_eq);
}
@@ -1605,10 +1608,12 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
for (uint i= 0; i < subq_pred->left_expr->cols(); i++)
{
nested_join->sj_outer_expr_list.push_back(subq_pred->left_expr->
- element_index(i));
+ element_index(i),
+ thd->mem_root);
Item_func_eq *item_eq=
- new (thd->mem_root) Item_func_eq(thd, subq_pred->left_expr->element_index(i),
- subq_lex->ref_pointer_array[i]);
+ new (thd->mem_root)
+ Item_func_eq(thd, subq_pred->left_expr->element_index(i),
+ subq_lex->ref_pointer_array[i]);
item_eq->in_equality_no= i;
sj_nest->sj_on_expr= and_items(thd, sj_nest->sj_on_expr, item_eq);
}
@@ -1623,7 +1628,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
we have in here).
*/
if (!sj_nest->sj_on_expr->fixed &&
- sj_nest->sj_on_expr->fix_fields(parent_join->thd, &sj_nest->sj_on_expr))
+ sj_nest->sj_on_expr->fix_fields(thd, &sj_nest->sj_on_expr))
{
DBUG_RETURN(TRUE);
}
@@ -1649,7 +1654,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
sj_nest->sj_on_expr);
emb_tbl_nest->on_expr->top_level_item();
if (!emb_tbl_nest->on_expr->fixed &&
- emb_tbl_nest->on_expr->fix_fields(parent_join->thd,
+ emb_tbl_nest->on_expr->fix_fields(thd,
&emb_tbl_nest->on_expr))
{
DBUG_RETURN(TRUE);
@@ -1667,7 +1672,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
save_lex= thd->lex->current_select;
thd->lex->current_select=parent_join->select_lex;
if (!parent_join->conds->fixed &&
- parent_join->conds->fix_fields(parent_join->thd,
+ parent_join->conds->fix_fields(thd,
&parent_join->conds))
{
DBUG_RETURN(1);
@@ -1681,7 +1686,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
Item_func_match *ifm;
List_iterator_fast<Item_func_match> li(*(subq_lex->ftfunc_list));
while ((ifm= li++))
- parent_lex->ftfunc_list->push_front(ifm);
+ parent_lex->ftfunc_list->push_front(ifm, thd->mem_root);
}
parent_lex->have_merged_subqueries= TRUE;
@@ -1723,16 +1728,16 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
List<TABLE_LIST> *emb_join_list= &parent_lex->top_join_list;
TABLE_LIST *emb_tbl_nest= NULL; // will change when we learn to handle outer joins
TABLE_LIST *tl;
- DBUG_ENTER("convert_subq_to_jtbm");
bool optimization_delayed= TRUE;
- subq_pred->set_strategy(SUBS_MATERIALIZATION);
+ TABLE_LIST *jtbm;
+ char *tbl_alias;
+ DBUG_ENTER("convert_subq_to_jtbm");
+ subq_pred->set_strategy(SUBS_MATERIALIZATION);
subq_pred->is_jtbm_merged= TRUE;
*remove_item= TRUE;
- TABLE_LIST *jtbm;
- char *tbl_alias;
if (!(tbl_alias= (char*)parent_join->thd->calloc(SUBQERY_TEMPTABLE_NAME_MAX_LEN)) ||
!(jtbm= alloc_join_nest(parent_join->thd))) //todo: this is not a join nest!
{
@@ -1746,13 +1751,13 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
/* Nests do not participate in those 'chains', so: */
/* jtbm->next_leaf= jtbm->next_local= jtbm->next_global == NULL*/
- emb_join_list->push_back(jtbm);
+ emb_join_list->push_back(jtbm, parent_join->thd->mem_root);
/*
Inject the jtbm table into TABLE_LIST::next_leaf list, so that
make_join_statistics() and co. can find it.
*/
- parent_lex->leaf_tables.push_back(jtbm);
+ parent_lex->leaf_tables.push_back(jtbm, parent_join->thd->mem_root);
if (subq_pred->unit->first_select()->options & OPTION_SCHEMA_TABLE)
parent_lex->options |= OPTION_SCHEMA_TABLE;
@@ -2073,7 +2078,7 @@ int pull_out_semijoin_tables(JOIN *join)
*/
child_li.remove();
sj_nest->nested_join->used_tables &= ~tbl->table->map;
- upper_join_list->push_back(tbl);
+ upper_join_list->push_back(tbl, join->thd->mem_root);
tbl->join_list= upper_join_list;
tbl->embedding= sj_nest->embedding;
}
@@ -3512,16 +3517,19 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join)
bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab)
{
- DBUG_ENTER("setup_sj_materialization");
JOIN_TAB *tab= sjm_tab->bush_children->start;
TABLE_LIST *emb_sj_nest= tab->table->pos_in_table_list->embedding;
+ SJ_MATERIALIZATION_INFO *sjm;
+ THD *thd;
+
+ DBUG_ENTER("setup_sj_materialization");
/* Walk out of outer join nests until we reach the semi-join nest we're in */
while (!emb_sj_nest->sj_mat_info)
emb_sj_nest= emb_sj_nest->embedding;
- SJ_MATERIALIZATION_INFO *sjm= emb_sj_nest->sj_mat_info;
- THD *thd= tab->join->thd;
+ sjm= emb_sj_nest->sj_mat_info;
+ thd= tab->join->thd;
/* First the calls come to the materialization function */
//List<Item> &item_list= emb_sj_nest->sj_subq_pred->unit->first_select()->item_list;
@@ -3537,8 +3545,8 @@ bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab)
Item **p_end= p_item + subq_select->item_list.elements;
//while((right_expr= it++))
for(;p_item != p_end; p_item++)
- sjm->sjm_table_cols.push_back(*p_item);
-
+ sjm->sjm_table_cols.push_back(*p_item, thd->mem_root);
+
sjm->sjm_table_param.field_count= subq_select->item_list.elements;
sjm->sjm_table_param.force_not_null_cols= TRUE;
@@ -3554,8 +3562,8 @@ bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab)
sjm->table->file->extra(HA_EXTRA_WRITE_CACHE);
sjm->table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
- tab->join->sj_tmp_tables.push_back(sjm->table);
- tab->join->sjm_info_list.push_back(sjm);
+ tab->join->sj_tmp_tables.push_back(sjm->table, thd->mem_root);
+ tab->join->sjm_info_list.push_back(sjm, thd->mem_root);
sjm->materialized= FALSE;
sjm_tab->table= sjm->table;
@@ -4338,7 +4346,7 @@ int init_dups_weedout(JOIN *join, uint first_table, int first_fanout_table, uint
sjtbl->null_bytes= (jt_null_bits + 7)/8;
if (sjtbl->create_sj_weedout_tmp_table(thd))
DBUG_RETURN(TRUE);
- join->sj_tmp_tables.push_back(sjtbl->tmp_table);
+ join->sj_tmp_tables.push_back(sjtbl->tmp_table, thd->mem_root);
}
else
{
@@ -5103,12 +5111,13 @@ TABLE *create_dummy_tmp_table(THD *thd)
sjm_table_param.field_count= 1;
List<Item> sjm_table_cols;
Item *column_item= new (thd->mem_root) Item_int(thd, 1);
- sjm_table_cols.push_back(column_item);
+ sjm_table_cols.push_back(column_item, thd->mem_root);
if (!(table= create_tmp_table(thd, &sjm_table_param,
sjm_table_cols, (ORDER*) 0,
TRUE /* distinct */,
1, /*save_sum_fields*/
- thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS,
+ thd->variables.option_bits |
+ TMP_TABLE_ALL_COLUMNS,
HA_POS_ERROR /*rows_limit */,
(char*)"dummy", TRUE /* Do not open */)))
{