summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-05-17 15:47:17 -0700
committerIgor Babaev <igor@askmonty.org>2018-05-17 15:47:48 -0700
commitd309c2fc885a5d50645ca9b43da2fda09f8b4418 (patch)
tree3700a16094b80de73e6ecb98fe7e74f4d0fd687f
parentab9d420df37d76a1ff68e6fd2d5bf53a797c4102 (diff)
downloadmariadb-git-d309c2fc885a5d50645ca9b43da2fda09f8b4418.tar.gz
MDEV-16212 Memory leak with recursive CTE that uses global ORDER BY
with recursive subquery There were two problems: 1. The code did not report that usage of global ORDER BY / LIMIT clauses was not supported yet. 2. The code just reset fake_select_lex of the the unit specifying a recursive CTE to NULL and that caused memory leaks in some cases.
-rw-r--r--mysql-test/r/cte_recursive.result10
-rw-r--r--mysql-test/t/cte_recursive.test12
-rw-r--r--sql/sql_union.cc13
3 files changed, 34 insertions, 1 deletions
diff --git a/mysql-test/r/cte_recursive.result b/mysql-test/r/cte_recursive.result
index d6dfdf1ec6a..b7516b88f9a 100644
--- a/mysql-test/r/cte_recursive.result
+++ b/mysql-test/r/cte_recursive.result
@@ -3233,3 +3233,13 @@ Parent Child Path
654 987 987,
321 654 987,654,
DROP TABLE t1;
+#
+# MDEV-16212: recursive CTE with global ORDER BY
+#
+set statement max_recursive_iterations = 2 for
+WITH RECURSIVE qn AS (
+SELECT 1 FROM dual UNION ALL
+SELECT 1 FROM qn
+ORDER BY (SELECT * FROM qn))
+SELECT count(*) FROM qn;
+ERROR 42000: This version of MariaDB doesn't yet support 'global ORDER_BY/LIMIT in recursive CTE spec'
diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test
index 3a8795e114a..b3276475fa4 100644
--- a/mysql-test/t/cte_recursive.test
+++ b/mysql-test/t/cte_recursive.test
@@ -2246,3 +2246,15 @@ FROM cte
ORDER BY Path;
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-16212: recursive CTE with global ORDER BY
+--echo #
+
+--error ER_NOT_SUPPORTED_YET
+set statement max_recursive_iterations = 2 for
+WITH RECURSIVE qn AS (
+SELECT 1 FROM dual UNION ALL
+SELECT 1 FROM qn
+ORDER BY (SELECT * FROM qn))
+SELECT count(*) FROM qn;
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 3fe90564000..39e7bcdf051 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -521,7 +521,18 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
with_element->rec_result=
new (thd_arg->mem_root) select_union_recursive(thd_arg);
union_result= with_element->rec_result;
- fake_select_lex= NULL;
+ if (fake_select_lex)
+ {
+ if (fake_select_lex->order_list.first ||
+ fake_select_lex->explicit_limit)
+ {
+ my_error(ER_NOT_SUPPORTED_YET, MYF(0),
+ "global ORDER_BY/LIMIT in recursive CTE spec");
+ goto err;
+ }
+ fake_select_lex->cleanup();
+ fake_select_lex= NULL;
+ }
}
if (!(tmp_result= union_result))
goto err; /* purecov: inspected */