summaryrefslogtreecommitdiff
path: root/mysql-test/t/cte_nonrecursive.test
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2017-04-06 12:08:14 -0700
committerIgor Babaev <igor@askmonty.org>2017-04-06 12:08:58 -0700
commit428a922cd0284b5fbdf97f74118209a6a9b4fb4c (patch)
tree8168bbab6297b04fb294331787ab33da54551191 /mysql-test/t/cte_nonrecursive.test
parent1759e91986e4370eede029e0fc39168a6fffd57b (diff)
downloadmariadb-git-428a922cd0284b5fbdf97f74118209a6a9b4fb4c.tar.gz
Fixed the bug mdev-12440.
When a CTE referring to another CTE from the same with clause was used twice then the server could not find the second CTE and reported a bogus error message. This happened because for any unit that was created as a clone of a CTE specification the pointer to the WITH clause that owned this CTE was not set.
Diffstat (limited to 'mysql-test/t/cte_nonrecursive.test')
-rw-r--r--mysql-test/t/cte_nonrecursive.test24
1 files changed, 24 insertions, 0 deletions
diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test
index 700111d5507..bcdc06afbad 100644
--- a/mysql-test/t/cte_nonrecursive.test
+++ b/mysql-test/t/cte_nonrecursive.test
@@ -642,3 +642,27 @@ select * from v1;
show create view v1;
drop view v1;
+
+--echo #
+--echo # MDEV-12440: the same CTE table is used in twice
+--echo #
+
+create table t1 (a int, b varchar(32));
+insert into t1 values
+ (4,'aaaa' ), (7,'bb'), (1,'ccc'), (4,'dd');
+
+--echo # cte2 is used in the main query and in the spec for ct3
+with
+cte1 as (select * from t1 where b >= 'c'),
+cte2 as (select * from cte1 where a < 7),
+cte3 as (select * from cte2 where a > 1)
+select * from cte2, cte3 where cte2.a = cte3.a;
+
+--echo # cte2 is used twice in the spec for ct3
+with
+cte1 as (select * from t1 where b >= 'b'),
+cte2 as (select * from cte1 where b > 'c'),
+cte3 as (select * from cte2 where a > 1 union select * from cte2 where a > 1)
+select * from cte3;
+
+drop table t1; \ No newline at end of file