Repository navigation
fix: SQL bind a scalar subquery's aggregate to its own relation - #28939
Merged
Merged
Conversation
The correlated scalar-subquery lowering parsed its aggregate projection directly, without the check every other conjunct it handles goes through. A qualifier naming a registered table the subquery does not read was therefore dropped rather than refused, and the aggregate silently took a column of the subquery's own relation: SELECT k, (SELECT SUM(foo.a) FROM t2 x WHERE x.b = t1.k) FROM t1 summed `x.a`, giving an answer for a question that was never asked. DuckDB rejects the same query. Parse the projection through `try_parse_inner_only_expr`, as the WHERE conjuncts already are, so a qualifier that names no relation of the subquery declines the lowering instead. That subsumes the separate nested-subquery check, which the same helper already makes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012PeS5DzwijVsijK68XXPsw
ritchie46
requested review from
MarcoGorelli,
alexander-beedie,
c-peters and
orlp
as code owners
August 24, 2026 11:26
The two decorrelators that take an outer-query operand (`IN` as a join and `IN` as a correlated lowering) each repeated the same parse-then-validate block; both now go through `try_parse_outer_only_expr`, mirroring the existing `try_parse_inner_only_expr`. `binds_to_inner_relation` walked the expression twice, once to reject nested subqueries and once to resolve identifiers. Both are per-node decisions, so they fold into a single walk; the subquery match moves to a shared `is_subquery_expr` that `expr_contains_subquery` also uses. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012PeS5DzwijVsijK68XXPsw
Contributor
|
The uncompressed lib size after this PR is 60.9203 MB. |
Contributor
|
The uncompressed lib size after this PR is 60.9200 MB. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #28939 +/- ##
==========================================
+ Coverage 81.56% 81.60% +0.04%
==========================================
Files 1888 1889 +1
Lines 268247 268577 +330
Branches 3263 3263
==========================================
+ Hits 218785 219169 +384
+ Misses 48617 48563 -54
Partials 845 845 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Made with opus 5