Commit 61ab7333 authored by Igor Babaev's avatar Igor Babaev

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.
parent 018ac121
......@@ -1604,6 +1604,35 @@ id name dob father mother
8 Grandpa Ben 1940-10-21 NULL NULL
6 Grandgrandma Martha 1923-05-17 NULL NULL
drop table my_ancestors;
#
# MDEV-10883: execution of prepared statement from SELECT
# with recursive CTE that renames columns
#
prepare stmt from"
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 folks, ancestor_ids a where folks.id = a.id
union
select mother from folks, ancestor_ids a where folks.id = a.id
)
select p.* from folks as p, ancestor_ids as a where p.id = a.id;
";
execute stmt;
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
deallocate prepare stmt;
drop table folks;
#
# MDEV-10372: [bb-10.2-mdev9864 tree] EXPLAIN with recursive CTE enters endless recursion
......
......@@ -1200,6 +1200,30 @@ select * from my_ancestors;
drop table my_ancestors;
--echo #
--echo # MDEV-10883: execution of prepared statement from SELECT
--echo # with recursive CTE that renames columns
--echo #
prepare stmt from"
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 folks, ancestor_ids a where folks.id = a.id
union
select mother from folks, ancestor_ids a where folks.id = a.id
)
select p.* from folks as p, ancestor_ids as a where p.id = a.id;
";
execute stmt;
deallocate prepare stmt;
drop table folks;
--echo #
......
......@@ -350,6 +350,7 @@ void With_element::reset_recursive_for_exec()
owner->with_prepared_anchor&= ~mutually_recursive;
owner->cleaned&= ~get_elem_map();
cleanup_stabilized();
spec->columns_are_renamed= false;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment