Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not remove server constants from GROUP BY key for secondary query. #63047

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Planner/PlannerExpressionAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ std::optional<AggregationAnalysisResult> analyzeAggregation(const QueryTreeNodeP
bool group_by_use_nulls = planner_context->getQueryContext()->getSettingsRef().group_by_use_nulls &&
(query_node.isGroupByWithGroupingSets() || query_node.isGroupByWithRollup() || query_node.isGroupByWithCube());

bool is_secondary_query = planner_context->getQueryContext()->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY;

if (query_node.hasGroupBy())
{
if (query_node.isGroupByWithGroupingSets())
Expand All @@ -100,7 +102,7 @@ std::optional<AggregationAnalysisResult> analyzeAggregation(const QueryTreeNodeP
auto is_constant_key = grouping_set_key_node->as<ConstantNode>() != nullptr;
group_by_with_constant_keys |= is_constant_key;

if (is_constant_key && !aggregates_descriptions.empty())
if (!is_secondary_query && is_constant_key && !aggregates_descriptions.empty())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a comment.

continue;

auto expression_dag_nodes = actions_visitor.visit(before_aggregation_actions, grouping_set_key_node);
Expand Down Expand Up @@ -152,7 +154,7 @@ std::optional<AggregationAnalysisResult> analyzeAggregation(const QueryTreeNodeP
auto is_constant_key = group_by_key_node->as<ConstantNode>() != nullptr;
group_by_with_constant_keys |= is_constant_key;

if (is_constant_key && !aggregates_descriptions.empty())
if (!is_secondary_query && is_constant_key && !aggregates_descriptions.empty())
continue;

auto expression_dag_nodes = actions_visitor.visit(before_aggregation_actions, group_by_key_node);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
r1 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT serverUUID() AS s, count() FROM remote('127.0.0.{1,2}', system.one) GROUP BY s format Null;

select getMacro('replica') as s, count() from remote('127.0.0.{1,2}', system.one) group by s;

select uptime() as s, count() FROM remote('127.0.0.{1,2}', system.one) group by s format Null;