Repository navigation
fix: support aggregation with non-equality conditions in scalar subqueries - #24034
Conversation
Review Summary by QodoSupport aggregation with non-equality conditions in scalar subqueries
WalkthroughsDescription• Remove NYI restriction blocking aggregation with non-equality correlated predicates in scalar subqueries • Delete unused findNonEqPred method that was checking for non-equality predicates • Add comprehensive BVT test cases covering scalar subqueries with aggregation and non-equal predicates • Update unit test to reflect the fix by moving previously failing case to passing tests Diagramflowchart LR
A["Scalar Subquery<br/>with Aggregation"] -->|Remove NYI Check| B["Allow Non-Equal<br/>Predicates"]
B -->|pullupCorrelatedPredicates| C["Outer Columns<br/>Added to GROUP BY"]
C -->|Correct Semantics| D["Single Row<br/>Per Outer Row"]
E["Delete findNonEqPred<br/>Method"] -.->|Cleanup| B
F["Add BVT Tests"] -.->|Validate| D
File Changes1. pkg/sql/plan/flatten_subquery.go
|
Code Review by Qodo
1.
|
|
@mergify refresh |
✅ Pull request refreshed |
Merge Queue Status
This pull request spent 57 minutes 9 seconds in the queue, including 56 minutes 49 seconds running CI. Required conditions to merge
|
…eries (matrixorigin#24034) When a scalar subquery contains an aggregate function with non-equality correlated predicates (e.g. `<`, `>=`), the planner incorrectly rejects it with a NYI error. However, `pullupCorrelatedPredicates` already handles this correctly — `pullupThroughAgg` adds the outer columns to GROUP BY, so the aggregation result is properly grouped per outer row combination. The SINGLE JOIN semantics remain correct since each outer row matches at most one aggregated row. This PR removes the unnecessary NYI restriction and the now-unused `findNonEqPred` method. Approved by: @ouyuanning, @heni02
What type of PR is this?
Which issue(s) does this PR fix or relate to?
Fixes #23942
What this PR does / why we need it:
When a scalar subquery contains an aggregate function with non-equality correlated predicates (e.g.
<,>=), the planner incorrectly rejects it with a NYI error.However,
pullupCorrelatedPredicatesalready handles this correctly —pullupThroughAggadds the outer columns to GROUP BY, so the aggregation result is properly grouped per outer row combination. The SINGLE JOIN semantics remain correct since each outer row matches at most one aggregated row.This PR removes the unnecessary NYI restriction and the now-unused
findNonEqPredmethod.What does this PR do?
flatten_subquery.go)findNonEqPredmethod