• Igor Babaev's avatar
    MDEV-20229 CTE defined with table value constructor cannot be used in views · ba7725da
    Igor Babaev authored
    A CTE can be defined as a table values constructor. In this case the CTE is
    always materialized in a temporary table.
    If the definition of the CTE contains a list of the names of the CTE
    columns then the query expression that uses this CTE can refer to the CTE
    columns by these names. Otherwise the names of the columns are taken from
    the names of the columns in the result set of the query that specifies the
    CTE.
    Thus if the column names of a CTE are provided in the definition the
    columns of result set should be renamed. In a general case renaming of
    the columns is done in the select lists of the query specifying the CTE.
    If a CTE is specified by a table value constructor then there are no such
    select lists and renaming is actually done for the columns of the result
    of materialization.
    Now if a view is specified by a query expression that uses a CTE specified
    by a table value constructor saving the column names of the CTE in the
    stored view definition becomes critical: without these names the query
    expression is not able to refer to the columns of the CTE.
    
    This patch saves the given column names of CTEs in stored view definitions
    that use them.
    ba7725da
cte_recursive.result 108 KB