[Commits] 010958a3fd9c2883bc954fbd8d17a6eb58383c56 Fixed bug mdev-10933. The bug was caused by a misplaced construct opt_with_clause for one of the variants of CREATE ... SELECT.

Igor Babaev igor at askmonty.org
Sat Oct 1 03:39:55 EEST 2016


commit 010958a3fd9c2883bc954fbd8d17a6eb58383c56
Author: Igor Babaev <igor at askmonty.org>
Commit: Igor Babaev <igor at askmonty.org>

    Fixed bug mdev-10933.
    The bug was caused by a misplaced construct opt_with_clause
    for one of the variants of CREATE ... SELECT.
---
 mysql-test/r/cte_recursive.result |   30 ++++++++++++++++++++++++++++++
 mysql-test/t/cte_recursive.test   |   26 ++++++++++++++++++++++++++
 sql/sql_yacc.yy                   |    4 ++--
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/mysql-test/r/cte_recursive.result b/mysql-test/r/cte_recursive.result
index ac48bf0..f223708 100644
--- a/mysql-test/r/cte_recursive.result
+++ b/mysql-test/r/cte_recursive.result
@@ -1693,6 +1693,36 @@ id	name	dob	father	mother
 8	Grandpa Ben	1940-10-21	NULL	NULL
 6	Grandgrandma Martha	1923-05-17	NULL	NULL
 drop table my_ancestors;
+#
+# MDEV-10933: WITH clause together with SELECT in parenthesis
+#             CREATE SELECT      
+#
+create table my_ancestors
+(
+with recursive
+ancestor_ids (id)
+as
+(
+select father from folks where name = 'Me'
+  union
+select mother from folks where name = 'Me'
+  union
+select father from folks, ancestor_ids a  where folks.id = a.id
+union
+select mother from folks, ancestor_ids a  where folks.id = a.id
+)
+select p.* from folks as p, ancestor_ids as a where p.id = a.id
+);
+select * from my_ancestors;
+id	name	dob	father	mother
+20	Dad	1970-02-02	10	9
+30	Mom	1975-03-03	8	7
+10	Grandpa Bill	1940-04-05	NULL	NULL
+9	Grandma Ann	1941-10-15	NULL	NULL
+7	Grandma Sally	1943-08-23	NULL	6
+8	Grandpa Ben	1940-10-21	NULL	NULL
+6	Grandgrandma Martha	1923-05-17	NULL	NULL
+drop table my_ancestors;
 drop table folks;
 #
 # MDEV-10372: [bb-10.2-mdev9864 tree] EXPLAIN with recursive CTE enters endless recursion
diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test
index d6e6948..8a07b3a 100644
--- a/mysql-test/t/cte_recursive.test
+++ b/mysql-test/t/cte_recursive.test
@@ -1272,6 +1272,30 @@ select * from my_ancestors;
 
 drop table my_ancestors;
 
+--echo #
+--echo # MDEV-10933: WITH clause together with SELECT in parenthesis
+--echo #             CREATE SELECT      
+--echo #
+
+create table my_ancestors
+(
+with recursive
+ancestor_ids (id)
+as
+(
+  select father from folks where name = 'Me'
+  union
+  select mother from folks where name = 'Me'
+  union
+  select father from folks, ancestor_ids a  where folks.id = a.id
+  union
+  select mother from folks, ancestor_ids a  where folks.id = a.id
+)
+select p.* from folks as p, ancestor_ids as a where p.id = a.id
+);
+select * from my_ancestors;
+drop table my_ancestors;
+
 drop table folks;
 
 --echo #
@@ -1336,3 +1360,5 @@ select t2.a from t1,t2 where t1.a+1=t2.a
 select * from t1;
 
 drop table t1,t2;
+
+
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index b833ade..1865f2e 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -5529,10 +5529,10 @@ opt_part_option:
 */
 
 create_select_query_specification:
-          SELECT_SYM opt_with_clause create_select_part2 create_select_part3
+          opt_with_clause SELECT_SYM create_select_part2 create_select_part3
           create_select_part4
           {
-            Select->set_with_clause($2);
+            Select->set_with_clause($1);
           }
         ;
 


More information about the commits mailing list