summaryrefslogtreecommitdiff
path: root/sql/sql_cte.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2017-11-05 18:45:12 -0800
committerIgor Babaev <igor@askmonty.org>2017-11-05 18:46:05 -0800
commite0cd6f4b0767b62723f9e332b94d8f34f59edbbc (patch)
tree5a402814d48cc560130c8fd6bc8fc2171fd4595a /sql/sql_cte.cc
parent8f2e8cf0cb9e427fa6d9b85b0c0c805e992eb385 (diff)
downloadmariadb-git-e0cd6f4b0767b62723f9e332b94d8f34f59edbbc.tar.gz
Fixed bugs: mdev-13780 CTE not found, mdev-14184 recursive CTE not found
The support of embedded CTEs was not correct in the cases when embedded CTEs were used multiple times. The problems occurred with both non-recursive (bug mdev-13780) and recursive (bug mdev-14184) embedded CTEs.
Diffstat (limited to 'sql/sql_cte.cc')
-rw-r--r--sql/sql_cte.cc22
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 */