[Commits] 752422f: Fixed bug mdev-12360.

IgorBabaev igor at mariadb.com
Sat Mar 25 07:04:19 EET 2017


revision-id: 752422f1a7d71f80883603ee6984a55a92e5d5f9 (mariadb-10.2.4-81-g752422f)
parent(s): 23d72bf3aa9b16c0b1250ed1a04bdf18eea9754a
author: Igor Babaev
committer: Igor Babaev
timestamp: 2017-03-24 22:04:19 -0700
message:

Fixed bug mdev-12360.

The method With_element::check_unrestricted_recursive() icorrectly performed
the check that no recursive reference is not encountered in inner parts of
outer joins. As a result the server reported errors for valid specifications
with outer joins.

---
 mysql-test/r/cte_recursive.result | 45 +++++++++++++++++++++++++++++++++++++++
 mysql-test/t/cte_recursive.test   | 42 ++++++++++++++++++++++++++++++++++++
 sql/sql_cte.cc                    |  2 ++
 3 files changed, 89 insertions(+)

diff --git a/mysql-test/r/cte_recursive.result b/mysql-test/r/cte_recursive.result
index ed4fb7c..6d59d67 100644
--- a/mysql-test/r/cte_recursive.result
+++ b/mysql-test/r/cte_recursive.result
@@ -2408,3 +2408,48 @@ ANALYZE
     }
   }
 }
+#
+# mdev-12360: recursive reference in left operand of LEFT JOIN
+#
+create table  folks(id int, name char(32), dob date, father int, mother int);
+insert into folks values
+(100, 'Me', '2000-01-01', 20, 30),
+(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),
+(25, 'Uncle Jim', '1968-11-18', 8, 7),
+(98, 'Sister Amy', '2001-06-20', 20, 30),
+(7, 'Grandma Sally', '1943-08-23', null, 6),
+(8, 'Grandpa Ben', '1940-10-21', null, null),
+(6, 'Grandgrandma Martha', '1923-05-17', null, null),
+(67, 'Cousin Eddie', '1992-02-28', 25, 27),
+(27, 'Auntie Melinda', '1971-03-29', null, null);
+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 ancestor_ids as a left join folks on folks.id = a.id
+union
+select mother from ancestor_ids as a left join folks on folks.id = a.id
+),
+ancestors 
+as
+(
+select p.* from folks as p, ancestor_ids as a
+where p.id = a.id
+)
+select * from 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 folks;
diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test
index e8954bf..37f66bb 100644
--- a/mysql-test/t/cte_recursive.test
+++ b/mysql-test/t/cte_recursive.test
@@ -1517,3 +1517,45 @@ with recursive src(counter) as
  union 
  select counter+1 from src where counter<10
 ) select * from src;
+
+--echo #
+--echo # mdev-12360: recursive reference in left operand of LEFT JOIN
+--echo #
+
+create table  folks(id int, name char(32), dob date, father int, mother int);
+
+insert into folks values
+(100, 'Me', '2000-01-01', 20, 30),
+(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),
+(25, 'Uncle Jim', '1968-11-18', 8, 7),
+(98, 'Sister Amy', '2001-06-20', 20, 30),
+(7, 'Grandma Sally', '1943-08-23', null, 6),
+(8, 'Grandpa Ben', '1940-10-21', null, null),
+(6, 'Grandgrandma Martha', '1923-05-17', null, null),
+(67, 'Cousin Eddie', '1992-02-28', 25, 27),
+(27, 'Auntie Melinda', '1971-03-29', null, null); 
+
+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 ancestor_ids as a left join folks on folks.id = a.id
+  union
+  select mother from ancestor_ids as a left join folks on folks.id = a.id
+),
+ancestors 
+as
+(
+  select p.* from folks as p, ancestor_ids as a
+    where p.id = a.id
+)
+select * from ancestors;
+
+drop table folks;
diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc
index 3011b51..1dded86 100644
--- a/sql/sql_cte.cc
+++ b/sql/sql_cte.cc
@@ -1168,6 +1168,8 @@ bool With_element::check_unrestricted_recursive(st_select_lex *sel,
   ti.rewind();
   while ((tbl= ti++))
   {
+    if (!tbl->is_with_table_recursive_reference())
+      continue;
     for (TABLE_LIST *tab= tbl; tab; tab= tab->embedding)
     {
       if (tab->outer_join & (JOIN_TYPE_LEFT | JOIN_TYPE_RIGHT))


More information about the commits mailing list