diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index 6b019609dd9..805392a9430 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -329,31 +329,27 @@ using ExistsExpressionVisitor = InDepthNodeVisitorgetSettingsRef().enable_positional_arguments) + if (select_query.groupBy()) { - if (select_query.groupBy()) + for (auto & expr : select_query.groupBy()->children) + replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::GROUP_BY); + } + if (select_query.orderBy()) + { + for (auto & expr : select_query.orderBy()->children) { - for (auto & expr : select_query.groupBy()->children) - replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::GROUP_BY); - } - if (select_query.orderBy()) - { - for (auto & expr : select_query.orderBy()->children) - { - auto & elem = assert_cast(*expr).children.at(0); - replaceForPositionalArguments(elem, &select_query, ASTSelectQuery::Expression::ORDER_BY); - } - } - if (select_query.limitBy()) - { - for (auto & expr : select_query.limitBy()->children) - replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::LIMIT_BY); + auto & elem = assert_cast(*expr).children.at(0); + replaceForPositionalArguments(elem, &select_query, ASTSelectQuery::Expression::ORDER_BY); } } + if (select_query.limitBy()) + { + for (auto & expr : select_query.limitBy()->children) + replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::LIMIT_BY); + } } }; @@ -1508,8 +1504,11 @@ void TreeRewriter::normalize( ExistsExpressionVisitor::Data exists; ExistsExpressionVisitor(exists).visit(query); - ReplacePositionalArgumentsVisitor::Data data_replace_positional_arguments{context_}; - ReplacePositionalArgumentsVisitor(data_replace_positional_arguments).visit(query); + if (context_->getSettingsRef().enable_positional_arguments) + { + ReplacePositionalArgumentsVisitor::Data data_replace_positional_arguments; + ReplacePositionalArgumentsVisitor(data_replace_positional_arguments).visit(query); + } if (settings.transform_null_in) {