Projection & optimize_aggregators_of_group_by_keys

Fix projection with optimize_aggregators_of_group_by_keys = true
This commit is contained in:
Amos Bird 2023-05-10 02:26:32 +08:00
parent 49c1beb870
commit 1739bb306a
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 15 additions and 0 deletions

View File

@ -142,6 +142,13 @@ ASTPtr ASTProjectionSelectQuery::cloneToASTSelect() const
}
if (groupBy())
select_query->setExpression(ASTSelectQuery::Expression::GROUP_BY, groupBy()->clone());
auto settings_query = std::make_shared<ASTSetQuery>();
SettingsChanges settings_changes;
settings_changes.insertSetting("optimize_aggregators_of_group_by_keys", false);
settings_query->changes = std::move(settings_changes);
settings_query->is_standalone = false;
select_query->setExpression(ASTSelectQuery::Expression::SETTINGS, std::move(settings_query));
return node;
}

View File

@ -0,0 +1,7 @@
drop table if exists proj;
CREATE TABLE proj(date Date, PROJECTION maxdate( SELECT max(date) GROUP BY date )) ENGINE = MergeTree ORDER BY tuple() as select toDate('2012-10-24')-number%100 from numbers(1e2);
SELECT max(date) FROM proj PREWHERE date != '2012-10-24';
drop table proj;