mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Merge branch '10.3' into 10.4
This commit is contained in:
@@ -1600,6 +1600,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
{
|
||||
SELECT_LEX *parent_lex= parent_join->select_lex;
|
||||
TABLE_LIST *emb_tbl_nest= NULL;
|
||||
TABLE_LIST *orig_tl;
|
||||
List<TABLE_LIST> *emb_join_list= &parent_lex->top_join_list;
|
||||
THD *thd= parent_join->thd;
|
||||
DBUG_ENTER("convert_subq_to_sj");
|
||||
@@ -1761,17 +1762,17 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
because view's tables are inserted after the view)
|
||||
*/
|
||||
|
||||
for (tl= (TABLE_LIST*)(parent_lex->table_list.first); tl->next_local; tl= tl->next_local)
|
||||
for (orig_tl= (TABLE_LIST*)(parent_lex->table_list.first);
|
||||
orig_tl->next_local;
|
||||
orig_tl= orig_tl->next_local)
|
||||
{}
|
||||
|
||||
tl->next_local= subq_lex->join->tables_list;
|
||||
orig_tl->next_local= subq_lex->join->tables_list;
|
||||
|
||||
/* A theory: no need to re-connect the next_global chain */
|
||||
|
||||
/* 3. Remove the original subquery predicate from the WHERE/ON */
|
||||
|
||||
// The subqueries were replaced for Item_int(1) earlier
|
||||
subq_pred->reset_strategy(SUBS_SEMI_JOIN); // for subsequent executions
|
||||
/*TODO: also reset the 'm_with_subquery' there. */
|
||||
|
||||
/* n. Adjust the parent_join->table_count counter */
|
||||
@@ -1804,12 +1805,14 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
Add the subquery-induced equalities too.
|
||||
*/
|
||||
SELECT_LEX *save_lex= thd->lex->current_select;
|
||||
table_map subq_pred_used_tables;
|
||||
|
||||
thd->lex->current_select=subq_lex;
|
||||
if (subq_pred->left_expr->fix_fields_if_needed(thd, &subq_pred->left_expr))
|
||||
DBUG_RETURN(TRUE);
|
||||
goto restore_tl_and_exit;
|
||||
thd->lex->current_select=save_lex;
|
||||
|
||||
table_map subq_pred_used_tables= subq_pred->used_tables();
|
||||
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();
|
||||
@@ -1852,7 +1855,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
new (thd->mem_root) Item_func_eq(thd, subq_pred->left_expr_orig,
|
||||
subq_lex->ref_pointer_array[0]);
|
||||
if (!item_eq)
|
||||
DBUG_RETURN(TRUE);
|
||||
goto restore_tl_and_exit;
|
||||
if (subq_pred->left_expr_orig != subq_pred->left_expr)
|
||||
thd->change_item_tree(item_eq->arguments(), subq_pred->left_expr);
|
||||
item_eq->in_equality_no= 0;
|
||||
@@ -1873,7 +1876,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
Item_func_eq(thd, subq_pred->left_expr_orig->element_index(i),
|
||||
subq_lex->ref_pointer_array[i]);
|
||||
if (!item_eq)
|
||||
DBUG_RETURN(TRUE);
|
||||
goto restore_tl_and_exit;
|
||||
DBUG_ASSERT(subq_pred->left_expr->element_index(i)->is_fixed());
|
||||
if (subq_pred->left_expr_orig->element_index(i) !=
|
||||
subq_pred->left_expr->element_index(i))
|
||||
@@ -1892,13 +1895,13 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
Item_row *row= new (thd->mem_root) Item_row(thd, subq_lex->pre_fix);
|
||||
/* fix fields on subquery was call so they should be the same */
|
||||
if (!row)
|
||||
DBUG_RETURN(TRUE);
|
||||
goto restore_tl_and_exit;
|
||||
DBUG_ASSERT(subq_pred->left_expr->cols() == row->cols());
|
||||
nested_join->sj_outer_expr_list.push_back(&subq_pred->left_expr);
|
||||
Item_func_eq *item_eq=
|
||||
new (thd->mem_root) Item_func_eq(thd, subq_pred->left_expr_orig, row);
|
||||
if (!item_eq)
|
||||
DBUG_RETURN(TRUE);
|
||||
goto restore_tl_and_exit;
|
||||
for (uint i= 0; i < row->cols(); i++)
|
||||
{
|
||||
if (row->element_index(i) != subq_lex->ref_pointer_array[i])
|
||||
@@ -1917,9 +1920,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->fix_fields_if_needed(thd, &sj_nest->sj_on_expr))
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
goto restore_tl_and_exit;
|
||||
|
||||
/*
|
||||
Walk through sj nest's WHERE and ON expressions and call
|
||||
@@ -1944,9 +1945,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
emb_tbl_nest->on_expr->top_level_item();
|
||||
if (emb_tbl_nest->on_expr->fix_fields_if_needed(thd,
|
||||
&emb_tbl_nest->on_expr))
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
goto restore_tl_and_exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1960,9 +1959,8 @@ 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->fix_fields_if_needed(thd, &parent_join->conds))
|
||||
{
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
goto restore_tl_and_exit;
|
||||
|
||||
thd->lex->current_select=save_lex;
|
||||
parent_join->select_lex->where= parent_join->conds;
|
||||
}
|
||||
@@ -1975,9 +1973,16 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
|
||||
parent_lex->ftfunc_list->push_front(ifm, thd->mem_root);
|
||||
}
|
||||
|
||||
// The subqueries were replaced for Item_int(1) earlier
|
||||
subq_pred->reset_strategy(SUBS_SEMI_JOIN); // for subsequent executions
|
||||
|
||||
parent_lex->have_merged_subqueries= TRUE;
|
||||
/* Fatal error may have been set to by fix_after_pullout() */
|
||||
DBUG_RETURN(thd->is_fatal_error);
|
||||
|
||||
restore_tl_and_exit:
|
||||
orig_tl->next_local= NULL;
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user