diff options
author | Igor Babaev <igor@askmonty.org> | 2017-04-28 21:58:04 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2017-04-28 21:59:11 -0700 |
commit | 7a29ca277698ffac757b2bd17c0977fb02b78557 (patch) | |
tree | e23dc1653e46c095d4488f614cbc26ed18dbb7d6 /sql/sql_derived.cc | |
parent | 4b24467ff37d6db82500e736e832d0a53842ac9b (diff) | |
download | mariadb-git-7a29ca277698ffac757b2bd17c0977fb02b78557.tar.gz |
Fixed the bug mdev-12563.
The bug happened when the specification of a recursive CTE had
no recursive references at the top level of the specification.
In this case the regular processing of derived table references
of the select containing a non-recursive reference to this
recursive CTE misses handling the specification unit.
At the preparation stage any non-recursive reference to a
recursive CTE must be handled after the preparation of the
specification unit for this CTE. So we have to force this
preparation when regular handling of derived tables does not
do it.
Diffstat (limited to 'sql/sql_derived.cc')
-rw-r--r-- | sql/sql_derived.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 916f7057607..8f0410b4284 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -646,6 +646,23 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) SELECT_LEX *first_select= unit->first_select(); + if (derived->is_recursive_with_table() && + !derived->is_with_table_recursive_reference() && + !derived->with->rec_result && derived->with->get_sq_rec_ref()) + { + /* + This is a non-recursive reference to a recursive CTE whose + specification unit has not been prepared at the regular processing of + derived table references. This can happen only in the case when + the specification unit has no recursive references at the top level. + Force the preparation of the specification unit. Use a recursive + table reference from a subquery for this. + */ + DBUG_ASSERT(derived->with->get_sq_rec_ref()); + if (mysql_derived_prepare(lex->thd, lex, derived->with->get_sq_rec_ref())) + DBUG_RETURN(TRUE); + } + if (unit->prepared && derived->is_recursive_with_table() && !derived->table) { |