[Commits] ae185361f4ec4e1d8b1ae2833d3a0005d844ef74 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.

Igor Babaev igor at askmonty.org
Sun Sep 25 06:29:56 EEST 2016


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

    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.
---
 mysql-test/r/cte_recursive.result |   29 +++++++++++++++++++++++++++++
 mysql-test/t/cte_recursive.test   |   24 ++++++++++++++++++++++++
 sql/sql_cte.h                     |    1 +
 3 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/mysql-test/r/cte_recursive.result b/mysql-test/r/cte_recursive.result
index 1aa4690..7285ef2 100644
--- a/mysql-test/r/cte_recursive.result
+++ b/mysql-test/r/cte_recursive.result
@@ -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
diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test
index c2c02a6..ef0ed5c 100644
--- a/mysql-test/t/cte_recursive.test
+++ b/mysql-test/t/cte_recursive.test
@@ -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 #
diff --git a/sql/sql_cte.h b/sql/sql_cte.h
index 3844225..27d5923 100644
--- a/sql/sql_cte.h
+++ b/sql/sql_cte.h
@@ -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;
 }
 
 


More information about the commits mailing list