[MDEV-14297] Lost name of a explicitly named CTE column used in a view created via prepared statement Created: 2017-11-06  Updated: 2018-04-22  Resolved: 2018-04-22

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.2
Fix Version/s: 10.2.14

Type: Bug Priority: Major
Reporter: Igor Babaev Assignee: Galina Shalygina (Inactive)
Resolution: Fixed Votes: 0
Labels: None


 Description   

The following demonstrates the problem:

MariaDB [test]> create view v1 as
    -> with cte(a) as (select 1 from dual) select * from cte;
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> select * from v1;
+---+
| a |
+---+
| 1 |
+---+
1 row in set (0.01 sec)
 
MariaDB [test]> set @view_def = "
    "> create view v2 as with cte(a) as (select 1 from dual) select * from cte
    "> ";
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> PREPARE stmt FROM @view_def;
Query OK, 0 rows affected (0.00 sec)
Statement prepared
 
MariaDB [test]> EXECUTE stmt;
ERROR 1054 (42S22): Unknown column 'cte.a' in 'field list'

Note that the definitions of v1 and v2 are identical.



 Comments   
Comment by Galina Shalygina (Inactive) [ 2018-02-18 ]

The problem occurs as the With_element::rename_columns_of_derived_unit procedure doesn't allocate the CTE column names in a permanent MEMROOT for prepared statements and stored procedures.

So the problem is more general and doesn't concern views only. The test below doesn't work also.

MariaDB [test]> prepare stmt from "with cte(a) as (select 1) select * from cte";
Query OK, 0 rows affected (0.00 sec)
Statement prepared
 
MariaDB [test]> execute stmt;
ERROR 1054 (42S22): Unknown column 'cte.a' in 'field list'

Comment by Igor Babaev [ 2018-02-19 ]

Ok to push into the 10.2 tree.

Comment by Galina Shalygina (Inactive) [ 2018-04-22 ]

Pushed in 10.2

Generated at Thu Feb 08 08:12:28 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.