From 4e48e1ffad477ff78aa2a3e6d68c73ea332321ef Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Tue, 28 Oct 2025 11:47:15 +0200 Subject: [PATCH] Make an exception for Expr::SubqueryResult in collect_result_columns() --- core/translate/group_by.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/translate/group_by.rs b/core/translate/group_by.rs index 19f91c5bc..5d7524d40 100644 --- a/core/translate/group_by.rs +++ b/core/translate/group_by.rs @@ -321,6 +321,8 @@ fn collect_non_aggregate_expressions<'a>( Ok(()) } +/// Collects columns from different parts of a SELECT that are needed for +/// GROUP BY. fn collect_result_columns<'a>( root_expr: &'a ast::Expr, plan: &SelectPlan, @@ -337,6 +339,13 @@ fn collect_result_columns<'a>( result_columns.push(expr); } } + // SubqueryResult is an exception because we can't "extract" columns from it + // unlike other expressions like function calls or direct column references, + // so we must add it so that the subquery result gets collected to the GROUP BY + // columns. + ast::Expr::SubqueryResult { .. } => { + result_columns.push(expr); + } _ => { if plan.aggregates.iter().any(|a| a.original_expr == *expr) { return Ok(WalkControl::SkipChildren);