1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Fixed the bug mdev-13796.

A reference to a CTE may occur not in the master of the CTE
specification. In this case if the reference to the CTE is
the first one the specification should be detached from its
master and attached to the referencing select.

Also fixed the TYPE column in the lines of the EXPLAIN output
created for CTE tables.
This commit is contained in:
Igor Babaev
2017-10-11 08:37:35 -07:00
parent dc8ac122bb
commit 4c9d19ee65
6 changed files with 98 additions and 21 deletions

View File

@ -991,7 +991,7 @@ With_element *st_select_lex::find_table_def_in_with_clauses(TABLE_LIST *table)
been done yet.
*/
if (with_elem && sl->master_unit() == with_elem->spec)
break;
break;
With_clause *with_clause=sl->get_with_clause();
if (with_clause)
{
@ -1039,13 +1039,21 @@ bool TABLE_LIST::set_as_with_table(THD *thd, With_element *with_elem)
}
with= with_elem;
if (!with_elem->is_referenced() || with_elem->is_recursive)
{
derived= with_elem->spec;
if (derived->get_master() != select_lex &&
!is_with_table_recursive_reference())
{
derived->move_as_slave(select_lex);
}
}
else
{
if(!(derived= with_elem->clone_parsed_spec(thd, this)))
return true;
derived->with_element= with_elem;
}
derived->first_select()->linkage= DERIVED_TABLE_TYPE;
with_elem->inc_references();
return false;
}