[Commits] b91bd822fa4da326f7a47aa55eec4c96774a8a8c Fixed bug mdev-10889 The bug was in the code of the recursive method With_element::check_unrestricted_recursive. For recursive calls of this method sel->get_with_element()->owner != owner.

Igor Babaev igor at askmonty.org
Mon Sep 26 20:40:44 EEST 2016


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

    Fixed bug mdev-10889
    The bug was in the code of the recursive method
    With_element::check_unrestricted_recursive. For recursive
    calls of this method sel->get_with_element()->owner != owner.
---
 mysql-test/r/cte_recursive.result |   37 +++++++++++++++++++++++++++++++++++++
 mysql-test/t/cte_recursive.test   |   32 ++++++++++++++++++++++++++++++++
 sql/sql_cte.cc                    |    4 ++--
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/mysql-test/r/cte_recursive.result b/mysql-test/r/cte_recursive.result
index 569f892..1b26a77 100644
--- a/mysql-test/r/cte_recursive.result
+++ b/mysql-test/r/cte_recursive.result
@@ -1769,3 +1769,40 @@ WITH RECURSIVE cte(f) AS
 SELECT * FROM cte as t;
 f
 DROP TABLE t1;
+#
+# MDEV-10889: mergeable derived in the spec of recursive CTE
+#
+create table t1 (a int);
+insert into t1 values
+(0), (1), (2), (3), (4);
+create table t2 (a int);
+insert into t2 values
+(1), (2), (3), (4), (5);
+with recursive
+t1 as
+(
+select x.a from (select a from t2 where t2.a=3) x
+union
+select t2.a from t1,t2 where t1.a+1=t2.a
+)
+select * from t1;
+a
+3
+4
+5
+explain
+with recursive
+t1 as
+(
+select x.a from (select a from t2 where t2.a=3) x
+union
+select t2.a from t1,t2 where t1.a+1=t2.a
+)
+select * from t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	5	
+2	SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+4	RECURSIVE UNION	<derived2>	ALL	NULL	NULL	NULL	NULL	5	
+4	RECURSIVE UNION	t2	ALL	NULL	NULL	NULL	NULL	5	Using where; Using join buffer (flat, BNL join)
+NULL	UNION RESULT	<union2,4>	ALL	NULL	NULL	NULL	NULL	NULL	
+drop table t1,t2;
diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test
index 1fc27ff..8b7f40c 100644
--- a/mysql-test/t/cte_recursive.test
+++ b/mysql-test/t/cte_recursive.test
@@ -1304,3 +1304,35 @@ WITH RECURSIVE cte(f) AS
   (SELECT t1.f FROM t1 UNION ALL SELECT cte.f FROM cte) 
 SELECT * FROM cte as t;
 DROP TABLE t1;
+
+--echo #
+--echo # MDEV-10889: mergeable derived in the spec of recursive CTE
+--echo #
+
+create table t1 (a int);
+insert into t1 values
+  (0), (1), (2), (3), (4);
+create table t2 (a int);
+insert into t2 values
+  (1), (2), (3), (4), (5);
+
+with recursive
+t1 as
+(
+select x.a from (select a from t2 where t2.a=3) x
+union
+select t2.a from t1,t2 where t1.a+1=t2.a
+)
+select * from t1;
+
+explain
+with recursive
+t1 as
+(
+select x.a from (select a from t2 where t2.a=3) x
+union
+select t2.a from t1,t2 where t1.a+1=t2.a
+)
+select * from t1;
+
+drop table t1,t2;
diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc
index f6447b2..f203c33 100644
--- a/sql/sql_cte.cc
+++ b/sql/sql_cte.cc
@@ -1106,7 +1106,7 @@ bool With_element::check_unrestricted_recursive(st_select_lex *sel,
 					        table_map &unrestricted, 
 						table_map &encountered)
 {
-  /* Check conditions 1-for restricted specification*/
+  /* Check conditions 1 for restricted specification*/
   List_iterator<TABLE_LIST> ti(sel->leaf_tables);
   TABLE_LIST *tbl;
   while ((tbl= ti++))
@@ -1141,7 +1141,7 @@ bool With_element::check_unrestricted_recursive(st_select_lex *sel,
         encountered|= with_elem->get_elem_map();
     }
   } 
-  for (With_element *with_elem= sel->get_with_element()->owner->with_list.first;
+  for (With_element *with_elem= owner->with_list.first;
        with_elem;
        with_elem= with_elem->next)
   {


More information about the commits mailing list