Allow EXPLODE WITH ORDINALITY to flow 0-based ordinals - #4625
Merged
g31pranjal merged 2 commits intoSep 16, 2026
Merged
Conversation
g31pranjal
added this pull request to stack #4627
September 16, 2026 11:19
g31pranjal
removed this pull request from stack #4627
September 16, 2026 13:16
g31pranjal
force-pushed
the
apple/g31pranjal/unnested/opt-in-zero-based-ordinality
branch
from
September 16, 2026 13:16
4d2d403 to
9b5aca6
Compare
g31pranjal
added this pull request to stack #4628
September 16, 2026 13:17
📊 Metrics Diff Analysis ReportSummary
ℹ️ About this analysisThis automated analysis compares query planner metrics between the base branch and this PR. It categorizes changes into:
The last category in particular may indicate planner regressions that should be investigated. |
An index defined on an unnested record type has to reconstruct the `__positions`
field of the synthetic records it covers, and positions are 0-based. The
ordinals `EXPLODE ... WITH ORDINALITY` flows are 1-based, as the SQL standard
requires of `WITH ORDINALITY`, so expressing a position means subtracting one
from an ordinal, and arithmetic in a candidate's values is arithmetic that has
to be matched away again on the query side.
So let the plan flow its ordinals 0-based when the caller asks for it. The
choice is a property of the plan, serialized as `zero_based_ordinality`:
- Unset or false means 1-based, which is what every plan serialized before
this field existed flows, so an old plan keeps its meaning when a newer
version reads it -- a continuation created by an older server resumes on a
newer one unchanged.
- A plan that flows 1-based ordinals does not set the field at all, so it
serializes to exactly the bytes, and hashes to exactly the plan hash, that
it did before. SQL `AT` keeps asking for 1-based ordinals, so no query plan
that exists today changes.
The ordinal base is part of a plan's and an expression's identity: the two
variants flow different ordinals for the same array, so neither may stand in
for the other, and the 0-based variant explains itself as
`WITH ZERO BASED ORDINALITY`.
g31pranjal
removed this pull request from stack #4628
September 16, 2026 13:35
g31pranjal
force-pushed
the
apple/g31pranjal/unnested/opt-in-zero-based-ordinality
branch
from
September 16, 2026 13:35
9b5aca6 to
f1509aa
Compare
g31pranjal
added this pull request to stack #4629
September 16, 2026 13:36
g31pranjal
marked this pull request as ready for review
September 16, 2026 14:10
alecgrieser
approved these changes
Sep 16, 2026
alecgrieser
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. I had a few minor comments that don't affect functional code. If you want this in to get it into a release sooner rather than later, they seem fine to do as a follow up
Comment on lines
-319
to
+341
| return withOrdinality ? PlanHashable.objectsPlanHash(mode, BASE_HASH, result, true) | ||
| : PlanHashable.objectsPlanHash(mode, BASE_HASH, result); | ||
| if (!withOrdinality) { | ||
| return PlanHashable.objectsPlanHash(mode, BASE_HASH, result); | ||
| } | ||
| return zeroBasedOrdinality ? PlanHashable.objectsPlanHash(mode, BASE_HASH, result, true, true) | ||
| : PlanHashable.objectsPlanHash(mode, BASE_HASH, result, true); |
Collaborator
There was a problem hiding this comment.
I think this makes sense (for now). We may also want to guard a simpler creation of the hash (just: PlanHashable.objectsPlanHash(mode, BASE_HASH, result, withOrdinality, zeroBasedOrdinality)) on a new plan hash version so that we don't need to keep it like this forever.
alecgrieser
approved these changes
Sep 16, 2026
g31pranjal
deleted the
apple/g31pranjal/unnested/opt-in-zero-based-ordinality
branch
September 16, 2026 18:55
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.
The ordinals
EXPLODE ... WITH ORDINALITYflows are 1-based, as the SQL standard requires ofWITH ORDINALITY, so expressing a position from it means subtracting one from an ordinal.This PR allows the
RecordQueryExplodePlanflow its ordinals 0-based when the caller asks for it. The choice is a property of the plan, serialized aszero_based_ordinality:ATkeeps asking for 1-based ordinals here, so no query plan that exists today changes.Future PRs:
truevalue forzero_based_ordinality. At this point, we change the semantics to treat unsetzero_based_ordinalityas 0-based. change plan to be unset.