Skip to content

Commit c84a6f5

Browse files
committed
Bug#35654240: A Recursive CTE Causing MySQL Server Crash
Problem: Right-nested UNIONs are not supported for recursive query blocks in CTEs. A check for this is missing. In WL#11350, we started allowing right-nested set operations. The missing check resulted in a crash. Solution: If there are right-nested UNIONs of recursive query blocks that cannot be safely flattened, we throw an error indicating that the operation is not yet supported. Change-Id: I8ac01f91bf63e81fe7393179a3d01f9ba1eaa4e2
1 parent 1b5dcfb commit c84a6f5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sql/sql_derived.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,17 @@ bool Table_ref::resolve_derived(THD *thd, bool apply_semijoin) {
365365
if (sl->parent()->term_type() != QT_UNION) {
366366
my_error(ER_CTE_RECURSIVE_NOT_UNION, MYF(0));
367367
return true;
368+
} else if (sl->parent()->parent() != nullptr) {
369+
/*
370+
Right-nested UNIONs with recursive query blocks are not allowed. It
371+
is expected that all possible flattening of UNION blocks is done
372+
beforehand. Any nested UNION indicates a mixing of UNION DISTINCT
373+
and UNION ALL, which cannot be flattened further.
374+
*/
375+
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
376+
"right nested recursive query blocks, in "
377+
"Common Table Expression");
378+
return true;
368379
}
369380
if (sl->is_ordered() || sl->has_limit() || sl->is_distinct()) {
370381
/*

0 commit comments

Comments
 (0)