[MDEV-15119] CTE, referencing another CTE, that is declared after, does not return error Created: 2018-01-30  Updated: 2018-07-31  Resolved: 2018-03-12

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - CTE
Affects Version/s: 10.2
Fix Version/s: 10.2.13

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None


 Description   

CREATE TABLE t1 (i int);
INSERT INTO t1 VALUES (1),(2),(3);
 
WITH c1 AS (SELECT * FROM c2),
     c2 AS (SELECT * FROM t1)
SELECT * FROM c1;
 
WITH c1 AS (WITH c3 AS (SELECT * FROM c2) SELECT * FROM c3),
     c2 AS (SELECT * FROM t1)
SELECT * FROM c1;

MariaDB [test]> CREATE TABLE t1 (i int);
Query OK, 0 rows affected (0.16 sec)
 
MariaDB [test]> INSERT INTO t1 VALUES (1),(2),(3);
Query OK, 3 rows affected (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 0
 
MariaDB [test]> WITH c1 AS (SELECT * FROM c2),
    ->      c2 AS (SELECT * FROM t1)
    -> SELECT * FROM c1;
ERROR 1146 (42S02): Table 'test.c2' doesn't exist
 
MariaDB [test]> WITH c1 AS (WITH c3 AS (SELECT * FROM c2) SELECT * FROM c3),
    ->      c2 AS (SELECT * FROM t1)
    -> SELECT * FROM c1;
+------+
| i    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    3 |   100.00 |       |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)
 
MariaDB [test]> show warnings;
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                                                                                                                                      |
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Note  | 1003 | with c1 as (with c3 as (select `test`.`t1`.`i` AS `i` from `test`.`t1`)select `test`.`t1`.`i` AS `i` from `test`.`t1`), c2 as (select `test`.`t1`.`i` AS `i` from `test`.`t1`)select `test`.`t1`.`i` AS `i` from `test`.`t1` |
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+



 Comments   
Comment by Igor Babaev [ 2018-03-12 ]

A fix for this bug was pushed into the 10.2 tree.

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