Skip to content

Commit b91bd82

Browse files
committed
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.
1 parent 1f1990a commit b91bd82

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

mysql-test/r/cte_recursive.result

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,3 +1769,40 @@ WITH RECURSIVE cte(f) AS
17691769
SELECT * FROM cte as t;
17701770
f
17711771
DROP TABLE t1;
1772+
#
1773+
# MDEV-10889: mergeable derived in the spec of recursive CTE
1774+
#
1775+
create table t1 (a int);
1776+
insert into t1 values
1777+
(0), (1), (2), (3), (4);
1778+
create table t2 (a int);
1779+
insert into t2 values
1780+
(1), (2), (3), (4), (5);
1781+
with recursive
1782+
t1 as
1783+
(
1784+
select x.a from (select a from t2 where t2.a=3) x
1785+
union
1786+
select t2.a from t1,t2 where t1.a+1=t2.a
1787+
)
1788+
select * from t1;
1789+
a
1790+
3
1791+
4
1792+
5
1793+
explain
1794+
with recursive
1795+
t1 as
1796+
(
1797+
select x.a from (select a from t2 where t2.a=3) x
1798+
union
1799+
select t2.a from t1,t2 where t1.a+1=t2.a
1800+
)
1801+
select * from t1;
1802+
id select_type table type possible_keys key key_len ref rows Extra
1803+
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5
1804+
2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where
1805+
4 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 5
1806+
4 RECURSIVE UNION t2 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1807+
NULL UNION RESULT <union2,4> ALL NULL NULL NULL NULL NULL
1808+
drop table t1,t2;

mysql-test/t/cte_recursive.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,3 +1304,35 @@ WITH RECURSIVE cte(f) AS
13041304
(SELECT t1.f FROM t1 UNION ALL SELECT cte.f FROM cte)
13051305
SELECT * FROM cte as t;
13061306
DROP TABLE t1;
1307+
1308+
--echo #
1309+
--echo # MDEV-10889: mergeable derived in the spec of recursive CTE
1310+
--echo #
1311+
1312+
create table t1 (a int);
1313+
insert into t1 values
1314+
(0), (1), (2), (3), (4);
1315+
create table t2 (a int);
1316+
insert into t2 values
1317+
(1), (2), (3), (4), (5);
1318+
1319+
with recursive
1320+
t1 as
1321+
(
1322+
select x.a from (select a from t2 where t2.a=3) x
1323+
union
1324+
select t2.a from t1,t2 where t1.a+1=t2.a
1325+
)
1326+
select * from t1;
1327+
1328+
explain
1329+
with recursive
1330+
t1 as
1331+
(
1332+
select x.a from (select a from t2 where t2.a=3) x
1333+
union
1334+
select t2.a from t1,t2 where t1.a+1=t2.a
1335+
)
1336+
select * from t1;
1337+
1338+
drop table t1,t2;

sql/sql_cte.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ bool With_element::check_unrestricted_recursive(st_select_lex *sel,
11061106
table_map &unrestricted,
11071107
table_map &encountered)
11081108
{
1109-
/* Check conditions 1-for restricted specification*/
1109+
/* Check conditions 1 for restricted specification*/
11101110
List_iterator<TABLE_LIST> ti(sel->leaf_tables);
11111111
TABLE_LIST *tbl;
11121112
while ((tbl= ti++))
@@ -1141,7 +1141,7 @@ bool With_element::check_unrestricted_recursive(st_select_lex *sel,
11411141
encountered|= with_elem->get_elem_map();
11421142
}
11431143
}
1144-
for (With_element *with_elem= sel->get_with_element()->owner->with_list.first;
1144+
for (With_element *with_elem= owner->with_list.first;
11451145
with_elem;
11461146
with_elem= with_elem->next)
11471147
{

0 commit comments

Comments
 (0)