Repository navigation
better CTE and with global - #18684
Conversation
|
Test failure doesn't look like related |
|
See also #18705 (comment) |
Ah, it's broken after union distinct refactoring. I've fixed it and also enables the |
ec2884f to
366e601
Compare
|
For some reason all |
There was a problem hiding this comment.
Right now the following query will lead to endless recursion and eventually fails due to memory limits:
SELECT *
FROM
(
WITH
(
SELECT 1
) AS r1,
(
SELECT 2
) AS r2,
(
SELECT 3
) AS r3
SELECT 10
)
SETTINGS max_ast_elements = 1000, max_memory_usage = '10Mi'And this is because of ExecuteScalarSubqueriesMatcher, that visits AST and create InterpreterSelectQuery for each subquery (ASTSubquery), while ApplyWithAliasVisitor will create more each time.
So how about the following patch?
$ git di src/Interpreters/ExecuteScalarSubqueriesVisitor.cpp
diff --git a/src/Interpreters/ExecuteScalarSubqueriesVisitor.cpp b/src/Interpreters/ExecuteScalarSubqueriesVisitor.cpp
index b3e8af90f2..4a6ec3505c 100644
--- a/src/Interpreters/ExecuteScalarSubqueriesVisitor.cpp
+++ b/src/Interpreters/ExecuteScalarSubqueriesVisitor.cpp
@@ -92,6 +92,12 @@ void ExecuteScalarSubqueriesMatcher::visit(const ASTSubquery & subquery, ASTPtr
Settings subquery_settings = data.context.getSettings();
subquery_settings.max_result_rows = 1;
subquery_settings.extremes = false;
+ /// Otherwise ApplyWithAliasVisitor will be applied and this will
+ /// create new nodes in AST over and over and lead to endless recursion,
+ /// which eventually lead to one of the following errors:
+ /// - Memory limit exceeded
+ /// - AST too big
+ subquery_settings.enable_global_with_statement = false;
subquery_context.setSettings(subquery_settings);
ASTPtr subquery_select = subquery.children.at(0);Also not that there is also DB::JoinedTables::resolveTables that will create InterpreterSelectQuery, and so it will also expand aliases one more time, which is pointless.
So maybe it is worth disabling enable_global_with_statement once ApplyWithAliasVisitor was applied (with changed=false)? Since there are also other places where interpreter will be created multiple times.
There was a problem hiding this comment.
Yeah, I'm fixing this and other related issues. Thanks for the suggestion. Actually we can just disable with propagation when subquery_depth is not zero.
|
all |
fixes in #19344 |
|
Let's merge / rebase with master to rerun tests. |
|
fuzzer error looks real |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Allow CTE to be further aliased. Propagate CSE to subqueries in the same level when
enable_global_with_statement = 1. This fixes #17378 . This fixes #16575 (comment) .Detailed description / Documentation draft:
.