diff options
author | Igor Babaev <igor@askmonty.org> | 2018-09-07 20:10:04 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2018-09-07 20:10:45 -0700 |
commit | 4d991abd4fc7f60e758ec46301b0dd2bee71245c (patch) | |
tree | 3e8762387f950f8adb62910da5b274a49e01dbec /sql/sql_cte.h | |
parent | 59950df533ab7231c77a59ec3e27cef855318939 (diff) | |
download | mariadb-git-4d991abd4fc7f60e758ec46301b0dd2bee71245c.tar.gz |
MDEV-17024 Crash on large query
This problem manifested itself when a join query used two or more
materialized CTE such that each of them employed the same recursive CTE.
The bug caused a crash. The crash happened because the cleanup()
function was performed premature for recursive CTE. This clean up was
induced by the cleanup of the first CTE referenced the recusrsive CTE.
This cleanup destroyed the structures that would allow to read from the
temporary table containing the rows of the recursive CTE and an attempt to read
these rows for the second CTE referencing the recursive CTE triggered a
crash.
The clean up for a recursive CTE R should be performed after the cleanup
of the last materialized CTE that uses R.
Diffstat (limited to 'sql/sql_cte.h')
-rw-r--r-- | sql/sql_cte.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sql/sql_cte.h b/sql/sql_cte.h index 70526e862dc..6351b65a07c 100644 --- a/sql/sql_cte.h +++ b/sql/sql_cte.h @@ -98,7 +98,14 @@ public: for the definition of this element */ bool is_recursive; - + /* + For a simple recursive CTE: the number of references to the CTE from + outside of the CTE specification. + For a CTE mutually recursive with other CTEs : the total number of + references to all these CTEs outside of their specification. + Each of these mutually recursive CTEs has the same value in this field. + */ + uint rec_outer_references; /* Any non-recursive select in the specification of a recursive with element is a called anchor. In the case mutually recursive @@ -140,7 +147,7 @@ public: top_level_dep_map(0), sq_rec_ref(NULL), next_mutually_recursive(NULL), references(0), query_name(name), column_list(list), spec(unit), - is_recursive(false), with_anchor(false), + is_recursive(false), rec_outer_references(0), with_anchor(false), level(0), rec_result(NULL) { unit->with_element= this; } |