Skip to content
Permalink
Browse files
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.
  • Loading branch information
igorbabaev committed May 17, 2018
1 parent ab9d420 commit d309c2f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
@@ -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'
@@ -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;
@@ -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 */

0 comments on commit d309c2f

Please sign in to comment.