Skip to content

Commit 61ab733

Browse files
committed
Fixed bug mdev-10883.
When a prepared statement uses a CTE definition with a column list renaming of columns of the CTE expression must be performed for every execution of the prepared statement.
1 parent 018ac12 commit 61ab733

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

mysql-test/r/cte_recursive.result

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,35 @@ id name dob father mother
16041604
8 Grandpa Ben 1940-10-21 NULL NULL
16051605
6 Grandgrandma Martha 1923-05-17 NULL NULL
16061606
drop table my_ancestors;
1607+
#
1608+
# MDEV-10883: execution of prepared statement from SELECT
1609+
# with recursive CTE that renames columns
1610+
#
1611+
prepare stmt from"
1612+
with recursive
1613+
ancestor_ids (id)
1614+
as
1615+
(
1616+
select father from folks where name = 'Me'
1617+
union
1618+
select mother from folks where name = 'Me'
1619+
union
1620+
select father from folks, ancestor_ids a where folks.id = a.id
1621+
union
1622+
select mother from folks, ancestor_ids a where folks.id = a.id
1623+
)
1624+
select p.* from folks as p, ancestor_ids as a where p.id = a.id;
1625+
";
1626+
execute stmt;
1627+
id name dob father mother
1628+
20 Dad 1970-02-02 10 9
1629+
30 Mom 1975-03-03 8 7
1630+
10 Grandpa Bill 1940-04-05 NULL NULL
1631+
9 Grandma Ann 1941-10-15 NULL NULL
1632+
7 Grandma Sally 1943-08-23 NULL 6
1633+
8 Grandpa Ben 1940-10-21 NULL NULL
1634+
6 Grandgrandma Martha 1923-05-17 NULL NULL
1635+
deallocate prepare stmt;
16071636
drop table folks;
16081637
#
16091638
# MDEV-10372: [bb-10.2-mdev9864 tree] EXPLAIN with recursive CTE enters endless recursion

mysql-test/t/cte_recursive.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,30 @@ select * from my_ancestors;
12001200

12011201
drop table my_ancestors;
12021202

1203+
--echo #
1204+
--echo # MDEV-10883: execution of prepared statement from SELECT
1205+
--echo # with recursive CTE that renames columns
1206+
--echo #
1207+
1208+
prepare stmt from"
1209+
with recursive
1210+
ancestor_ids (id)
1211+
as
1212+
(
1213+
select father from folks where name = 'Me'
1214+
union
1215+
select mother from folks where name = 'Me'
1216+
union
1217+
select father from folks, ancestor_ids a where folks.id = a.id
1218+
union
1219+
select mother from folks, ancestor_ids a where folks.id = a.id
1220+
)
1221+
select p.* from folks as p, ancestor_ids as a where p.id = a.id;
1222+
";
1223+
execute stmt;
1224+
deallocate prepare stmt;
1225+
1226+
12031227
drop table folks;
12041228

12051229
--echo #

sql/sql_cte.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ void With_element::reset_recursive_for_exec()
350350
owner->with_prepared_anchor&= ~mutually_recursive;
351351
owner->cleaned&= ~get_elem_map();
352352
cleanup_stabilized();
353+
spec->columns_are_renamed= false;
353354
}
354355

355356

0 commit comments

Comments
 (0)