From 976a274f91d1a17ede41775fb74d79342c3a2572 Mon Sep 17 00:00:00 2001 From: vdimir Date: Fri, 13 May 2022 10:49:02 +0000 Subject: [PATCH] Add comment for visiting children of select in ApplyWithGlobalVisitor --- src/Interpreters/ApplyWithGlobalVisitor.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Interpreters/ApplyWithGlobalVisitor.cpp b/src/Interpreters/ApplyWithGlobalVisitor.cpp index 72333e2894b..55e5968b7c9 100644 --- a/src/Interpreters/ApplyWithGlobalVisitor.cpp +++ b/src/Interpreters/ApplyWithGlobalVisitor.cpp @@ -96,6 +96,16 @@ void ApplyWithGlobalVisitor::visit(ASTPtr & ast) } } + /* + * We need to visit all children recursively because the WITH statement may appear in the subquery at the nested level. + * Behavior of `WITH ... UNION ALL ...` should be the same at the top level and inside the subquery. + * + * For example: + * SELECT * FROM (WITH (SELECT ... ) AS t SELECT ... UNION ALL SELECT ...) + * ^^^^^^^^^^^^ should be visited ^^^^^^^^^^^^^^^^ + * or inside `WHERE .. IN` clause: + * SELECT * FROM ... WHERE x IN (WITH (SELECT ... ) AS t SELECT ... UNION ALL SELECT ...) + */ for (auto & child : node_union->list_of_selects->children) visit(child); }