diff options
Diffstat (limited to 'sql/sql_cte.cc')
-rw-r--r-- | sql/sql_cte.cc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index e1af30123f6..6fe08e3c0ed 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -349,7 +349,10 @@ void With_element::check_dependencies_in_select(st_select_lex *sl, /* Now look for the dependencies in the subqueries of sl */ st_select_lex_unit *inner_unit= sl->first_inner_unit(); for (; inner_unit; inner_unit= inner_unit->next_unit()) - check_dependencies_in_unit(inner_unit, ctxt, in_subq, dep_map); + { + if (!inner_unit->with_element) + check_dependencies_in_unit(inner_unit, ctxt, in_subq, dep_map); + } } @@ -838,7 +841,6 @@ st_select_lex_unit *With_element::clone_parsed_spec(THD *thd, with_table->next_global= spec_tables; } res= &lex->unit; - res->set_with_clause(owner); lex->unit.include_down(with_table->select_lex); lex->unit.set_slave(with_select); @@ -847,6 +849,8 @@ st_select_lex_unit *With_element::clone_parsed_spec(THD *thd, insert_chain_before( (st_select_lex_node **) &(old_lex->all_selects_list), with_select)); + if (check_dependencies_in_with_clauses(lex->with_clauses_list)) + res= NULL; lex_end(lex); err: if (arena) @@ -990,14 +994,18 @@ With_element *st_select_lex::find_table_def_in_with_clauses(TABLE_LIST *table) and it was unsuccesful. Yet for units cloned from the spec it has not been done yet. */ - if (with_elem && sl->master_unit() == with_elem->spec) + With_clause *attached_with_clause=sl->get_with_clause(); + if (attached_with_clause && + (found= attached_with_clause->find_table_def(table, NULL))) break; - With_clause *with_clause=sl->get_with_clause(); - if (with_clause) + if (with_elem) { - With_element *barrier= with_clause->with_recursive ? NULL : with_elem; - if ((found= with_clause->find_table_def(table, barrier))) + With_clause *containing_with_clause= with_elem->get_owner(); + With_element *barrier= containing_with_clause->with_recursive ? + NULL : with_elem; + if ((found= containing_with_clause->find_table_def(table, barrier))) break; + sl= sl->master_unit()->outer_select(); } master_unit= sl->master_unit(); /* Do not look for the table's definition beyond the scope of the view */ |