Commit d251cedd authored by Galina Shalygina's avatar Galina Shalygina

MDEV-15478: Lost name of a explicitly named CTE column used in

            the non-recursive CTE defined with UNION

The problem appears as the columns of the non-recursive CTE weren't renamed.
The renaming procedure was called for recursive CTEs only.

To fix it in the procedure st_select_lex_unit::prepare
With_element::rename_columns_of_derived_unit is called now for both CTEs:
recursive and non-recursive.
parent 8c8028ca
......@@ -1425,3 +1425,40 @@ a
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
DROP VIEW v1,v2;
#
# MDEV-15478: Lost name of a explicitly named CTE column used in
# the non-recursive CTE defined with UNION
#
CREATE TABLE t1 (x int, y int);
INSERT INTO t1 VALUES (1,2),(2,7),(3,3);
WITH cte(a) AS (SELECT 1 UNION SELECT 2) SELECT * FROM cte;
a
1
2
WITH cte(a) AS (SELECT 1 UNION SELECT 2) SELECT a FROM cte;
a
1
2
WITH cte(a) AS (SELECT 1 UNION ALL SELECT 1) SELECT a FROM cte;
a
1
1
WITH cte(a) AS (SELECT x from t1 UNION SELECT 4) SELECT a FROM cte;
a
1
2
3
4
WITH cte(a) AS (SELECT 4 UNION SELECT x FROM t1 UNION SELECT 5)
SELECT a FROM cte;
a
4
1
2
3
5
WITH cte(a,b) AS (SELECT 4,5 UNION SELECT 4,3) SELECT a,b FROM cte;
a b
4 5
4 3
DROP TABLE t1;
......@@ -989,3 +989,26 @@ DEALLOCATE PREPARE stmt;
DROP TABLE t1;
DROP VIEW v1,v2;
--echo #
--echo # MDEV-15478: Lost name of a explicitly named CTE column used in
--echo # the non-recursive CTE defined with UNION
--echo #
CREATE TABLE t1 (x int, y int);
INSERT INTO t1 VALUES (1,2),(2,7),(3,3);
WITH cte(a) AS (SELECT 1 UNION SELECT 2) SELECT * FROM cte;
WITH cte(a) AS (SELECT 1 UNION SELECT 2) SELECT a FROM cte;
WITH cte(a) AS (SELECT 1 UNION ALL SELECT 1) SELECT a FROM cte;
WITH cte(a) AS (SELECT x from t1 UNION SELECT 4) SELECT a FROM cte;
WITH cte(a) AS (SELECT 4 UNION SELECT x FROM t1 UNION SELECT 5)
SELECT a FROM cte;
WITH cte(a,b) AS (SELECT 4,5 UNION SELECT 4,3) SELECT a,b FROM cte;
DROP TABLE t1;
......@@ -598,7 +598,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
types= first_sl->item_list;
else if (sl == first_sl)
{
if (is_recursive)
if (with_element)
{
if (derived->with->rename_columns_of_derived_unit(thd, this))
goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment