[Commits] 8ae65920fabddb9157cddb547cf914b4a63539bf Fixed bug mdev-10737. This bug in st_select_lex_node::move_node could result in invalid select lists in recursive units that could cause falling into infinite loops when iterating over selects in such units.

Igor Babaev igor at askmonty.org
Tue Sep 6 09:07:31 EEST 2016


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

    Fixed bug mdev-10737.
    This bug in st_select_lex_node::move_node could result
    in invalid select lists in recursive units that could
    cause falling into infinite loops when iterating over
    selects in such units.
---
 mysql-test/r/cte_recursive.result |   12 ++++++++++++
 mysql-test/t/cte_recursive.test   |    7 +++++++
 sql/sql_lex.h                     |    2 ++
 3 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/mysql-test/r/cte_recursive.result b/mysql-test/r/cte_recursive.result
index cb1c243..da5f380 100644
--- a/mysql-test/r/cte_recursive.result
+++ b/mysql-test/r/cte_recursive.result
@@ -1611,3 +1611,15 @@ EXPLAIN
   }
 }
 drop table t1;
+#
+# MDEV-10737: recursive union with several anchors at the end
+#
+WITH RECURSIVE cte(n) AS
+( SELECT n+1 FROM cte WHERE n < 5 UNION SELECT 1 UNION SELECT 1 )
+SELECT * FROM cte;
+n
+1
+2
+3
+4
+5
diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test
index 4ca931f..bedbbe6 100644
--- a/mysql-test/t/cte_recursive.test
+++ b/mysql-test/t/cte_recursive.test
@@ -1177,3 +1177,10 @@ select  * from t;
 drop table t1;
 
 
+--echo #
+--echo # MDEV-10737: recursive union with several anchors at the end
+--echo #
+
+WITH RECURSIVE cte(n) AS
+  ( SELECT n+1 FROM cte WHERE n < 5 UNION SELECT 1 UNION SELECT 1 )
+SELECT * FROM cte;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index dbe7670..e034460 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -551,6 +551,8 @@ class st_select_lex_node {
   {
     if (where_to_move == this)
       return;
+    if (next)
+      next->prev= prev;
     *prev= next;
     *where_to_move->prev= this;
     next= where_to_move;


More information about the commits mailing list