Merge pull request #37724 from CurtizJ/fix-ast-optimizations-remote

Fix `optimize_monotonous_functions_in_order_by` in distributed queries
This commit is contained in:
Alexey Milovidov 2022-06-01 11:54:45 +03:00 committed by GitHub
commit a0020cb55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 4 deletions

View File

@ -135,7 +135,7 @@ struct SelectQueryOptions
return *this;
}
SelectQueryOptions & ignoreASTOptimizationsAlias(bool value = true)
SelectQueryOptions & ignoreASTOptimizations(bool value = true)
{
ignore_ast_optimizations = value;
return *this;

View File

@ -46,8 +46,15 @@ std::unique_ptr<QueryPlan> createLocalPlan(
checkStackSize();
auto query_plan = std::make_unique<QueryPlan>();
/// Do not apply AST optimizations, because query
/// is already optimized and some optimizations
/// can be applied only for non-distributed tables
/// and we can produce query, inconsistent with remote plans.
auto interpreter = InterpreterSelectQuery(
query_ast, context, SelectQueryOptions(processed_stage).setShardInfo(shard_num, shard_count));
query_ast, context,
SelectQueryOptions(processed_stage)
.setShardInfo(shard_num, shard_count)
.ignoreASTOptimizations());
interpreter.setProperClientInfo();
if (coordinator)

View File

@ -109,7 +109,7 @@ ProjectionDescription::getProjectionFromAST(const ASTPtr & definition_ast, const
InterpreterSelectQuery select(
result.query_ast, query_context, storage, {},
/// Here we ignore ast optimizations because otherwise aggregation keys may be removed from result header as constants.
SelectQueryOptions{QueryProcessingStage::WithMergeableState}.modify().ignoreAlias().ignoreASTOptimizationsAlias());
SelectQueryOptions{QueryProcessingStage::WithMergeableState}.modify().ignoreAlias().ignoreASTOptimizations());
result.required_columns = select.getRequiredColumns();
result.sample_block = select.getSampleBlock();
@ -221,7 +221,7 @@ ProjectionDescription ProjectionDescription::getMinMaxCountProjection(
InterpreterSelectQuery select(
result.query_ast, query_context, storage, {},
/// Here we ignore ast optimizations because otherwise aggregation keys may be removed from result header as constants.
SelectQueryOptions{QueryProcessingStage::WithMergeableState}.modify().ignoreAlias().ignoreASTOptimizationsAlias());
SelectQueryOptions{QueryProcessingStage::WithMergeableState}.modify().ignoreAlias().ignoreASTOptimizations());
result.required_columns = select.getRequiredColumns();
result.sample_block = select.getSampleBlock();

View File

@ -0,0 +1,6 @@
SET prefer_localhost_replica = 1;
SET optimize_monotonous_functions_in_order_by = 1;
SELECT *
FROM cluster(test_cluster_two_shards_localhost, system, one)
ORDER BY toDateTime(dummy);