summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-09-07 20:10:04 -0700
committerIgor Babaev <igor@askmonty.org>2018-09-07 20:10:45 -0700
commit4d991abd4fc7f60e758ec46301b0dd2bee71245c (patch)
tree3e8762387f950f8adb62910da5b274a49e01dbec /sql/sql_class.h
parent59950df533ab7231c77a59ec3e27cef855318939 (diff)
downloadmariadb-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_class.h')
-rw-r--r--sql/sql_class.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 4888b38bc30..1d8730ae008 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -5095,10 +5095,16 @@ class select_union_recursive :public select_union
TABLE *first_rec_table_to_update;
/* The temporary tables used for recursive table references */
List<TABLE> rec_tables;
+ /*
+ The count of how many times cleanup() was called with cleaned==false
+ for the unit specifying the recursive CTE for which this object was created
+ or for the unit specifying a CTE that mutually recursive with this CTE.
+ */
+ uint cleanup_count;
select_union_recursive(THD *thd_arg):
select_union(thd_arg),
- incr_table(0), first_rec_table_to_update(0) {};
+ incr_table(0), first_rec_table_to_update(0), cleanup_count(0) {};
int send_data(List<Item> &items);
bool create_result_table(THD *thd, List<Item> *column_types,