fix(optimizer)!: stop pruning implicit GROUP BY ALL keys during projection pushdown - #8129
Merged
georgesittas merged 4 commits intoAug 12, 2026
Merged
Conversation
Contributor
SQLGlot Integration Test Results❌ 1 regression — see details belowComparing:
By Dialect
Overallmain: 182937 total, 160863 passed (pass rate: 87.9%) sqlglot:optimizer/fix-pushdown-prunes-group-by-all-keys: 170743 total, 149710 passed (pass rate: 87.7%) Transitions: Dialect pair changes: 0 previous results not found, 3 current results not found ❌ 1 regression (view logs) |
georgesittas
approved these changes
Aug 11, 2026
Collaborator
There was a problem hiding this comment.
LGTM, one nit re: reintroducing short-circuiting on the AggFunc search.
@fivetran-kwoodbeck the same bug exists for ORDER BY ALL:
-- input
SELECT t.a, t.c FROM (SELECT a, b, c FROM x ORDER BY ALL LIMIT 1) t
-- optimizer output: b is pruned
WITH "t" AS (SELECT "x"."a" AS "a", "x"."c" AS "c" FROM "x" AS "x" ORDER BY ALL LIMIT 1) ...- This is only observable when the subquery's ordering matters, i.e. with LIMIT/OFFSET
- Unlike
GROUP BY ALL, there's no aggregate exemption: withORDER BY ALLevery projection is a sort key - We should check for a
Varpresence wrapping"ALL"to capture dialects that actually support this
Collaborator
|
I'll get this in and do a quick clean up - I wanna release shortly. |
georgesittas
force-pushed
the
optimizer/fix-pushdown-prunes-group-by-all-keys
branch
from
August 12, 2026 16:18
d6a3038 to
9139c4d
Compare
georgesittas
deleted the
optimizer/fix-pushdown-prunes-group-by-all-keys
branch
August 12, 2026 16:27
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.
pushdown_projectionsprunes columns that aren't referenced by an outer query. But a bareGROUP BY ALLinfers its grouping keys from projections in theSELECTlist, so pruning an "unused" column silently changes which columns are grouped by, corrupting the aggregation.Input:
Wrong output (b and s are dropped):
Expected output
Fix
We now check whether the scope has a
GROUP BY ALLand keeps projections regardless of outer references.