diff options
author | Igor Babaev <igor@askmonty.org> | 2021-07-16 22:46:50 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2021-07-19 10:35:23 -0700 |
commit | f053349797a1dca5206a3b8d5ff33353f45430d8 (patch) | |
tree | d4b1b15af1198f499be889c9ec293b2f459fbcec /sql/sql_union.cc | |
parent | b7886f55eb707c4cf7d8a5d94e79a87909f153e7 (diff) | |
download | mariadb-git-f053349797a1dca5206a3b8d5ff33353f45430d8.tar.gz |
MDEV-26135 Assertion failure when executing PS with a hanging recursive CTE
The bug affected execution of queries with With clauses containing so-called
hanging recursive CTEs in PREPARE mode. A CTE is hanging if it's not used
in the query. Preparation of a prepared statement from a query with a
hanging CTE caused a leak in the server and execution of this prepared
statement led to an assert failure of the server built in the debug mode.
This happened because the units specifying recursive CTEs erroneously were
not cleaned up if those CTEs were hanging.
The patch enforces cleanup of hanging recursive CTEs in the same way as
other hanging CTEs.
Approved by dmitry.shulga@mariadb.com
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r-- | sql/sql_union.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 7baedfb259c..e5648e6989b 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1382,7 +1382,8 @@ bool st_select_lex_unit::cleanup() { DBUG_RETURN(FALSE); } - if (with_element && with_element->is_recursive && union_result) + if (with_element && with_element->is_recursive && union_result && + with_element->rec_outer_references) { select_union_recursive *result= with_element->rec_result; if (++result->cleanup_count == with_element->rec_outer_references) @@ -1584,7 +1585,8 @@ bool st_select_lex::cleanup() for (SELECT_LEX_UNIT *lex_unit= first_inner_unit(); lex_unit ; lex_unit= lex_unit->next_unit()) { - if (lex_unit->with_element && lex_unit->with_element->is_recursive) + if (lex_unit->with_element && lex_unit->with_element->is_recursive && + lex_unit->with_element->rec_outer_references) continue; error= (bool) ((uint) error | (uint) lex_unit->cleanup()); } |