Skip to content

Match a plain explode against an explode with ordinality - #4619

Draft
g31pranjal wants to merge 2 commits into
apple/g31pranjal/unnested/synthetic-type-expandfrom
apple/g31pranjal/unnested/explode-ordinality-matching
Draft

g31pranjal wants to merge 2 commits into
apple/g31pranjal/unnested/synthetic-type-expandfrom
apple/g31pranjal/unnested/explode-ordinality-matching

Conversation

@g31pranjal

Copy link
Copy Markdown
Member

An explode WITH ORDINALITY flows an anonymous (element, ordinal) struct. Until
now the value standing for that struct was a single opaque QueriedValue, which
made the element unreachable to MaxMatchMap: it descends into record
constructors, but an opaque value offers nothing to match against but itself. A
query that explodes a collection plainly therefore had no correspondence to a
candidate that explodes the same collection with ordinality, and any such match
was lost.

ExplodeExpression.explodeResultValue now builds the ordinality variant as a
RecordConstructorValue of two QueriedValues. The element stays the first
column deliberately: MaxMatchMap takes the first reachable candidate value that
compares equal, and a QueriedValue compares equal to any other, so an element
would just as happily match the ordinal if the ordinal came first. The record is
built nullable so its type stays the one explodeResultType already declares --
that type backs the protobuf descriptor the plan builds at run time.

Because a QueriedValue was equal to every other QueriedValue regardless of
type, the two columns of that record were indistinguishable, and pulling a value
up through the explode found both. QueriedValue.equalsWithoutChildren now also
compares the result type.

subsumedBy gains the case itself: a plain explode is subsumed by an explode with
ordinality over the same collection, since the candidate produces at least
everything the query may produce. exactlySubsumedBy cannot express it, as its
equalsWithoutChildren compares isWithOrdinality.

@g31pranjal g31pranjal added the enhancement New feature or request label Sep 14, 2026
@g31pranjal
g31pranjal added this pull request to stack #4620 September 14, 2026 15:01
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from e93765d to 5972e75 Compare September 14, 2026 15:11
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch 2 times, most recently from 457737a to 802b25c Compare September 14, 2026 15:59
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch 2 times, most recently from 9186c7b to d4ebb50 Compare September 15, 2026 10:07
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 802b25c to 66106af Compare September 15, 2026 10:07
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from d4ebb50 to 70913fd Compare September 15, 2026 13:46
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 66106af to cd8ca19 Compare September 15, 2026 13:46
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 70913fd to 51f14cb Compare September 16, 2026 11:10
Base automatically changed from apple/g31pranjal/unnested/synthetic-type-expand to apple/g31pranjal/unnested/zero-based-ordinality September 16, 2026 11:10
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from cd8ca19 to fe9b6d2 Compare September 16, 2026 11:10
@g31pranjal
g31pranjal removed this pull request from stack #4620 September 16, 2026 11:12
@g31pranjal
g31pranjal added this pull request to stack #4627 September 16, 2026 11:19
@g31pranjal
g31pranjal removed this pull request from stack #4627 September 16, 2026 13:16
@g31pranjal
g31pranjal changed the base branch from apple/g31pranjal/unnested/zero-based-ordinality to apple/g31pranjal/unnested/synthetic-type-expand September 16, 2026 13:16
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 51f14cb to 40cfe34 Compare September 16, 2026 13:16
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from fe9b6d2 to 4e19391 Compare September 16, 2026 13:16
@g31pranjal
g31pranjal added this pull request to stack #4628 September 16, 2026 13:17
@g31pranjal
g31pranjal removed this pull request from stack #4628 September 16, 2026 13:35
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 40cfe34 to 28a0ea8 Compare September 16, 2026 13:35
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 4e19391 to 4fb7006 Compare September 16, 2026 13:35
@g31pranjal
g31pranjal changed the base branch from apple/g31pranjal/unnested/synthetic-type-expand to apple/g31pranjal/unnested/zero-based-ordinality September 16, 2026 13:36
@g31pranjal
g31pranjal added this pull request to stack #4629 September 16, 2026 13:36
@github-actions

Copy link
Copy Markdown

📊 Metrics Diff Analysis Report

Summary

  • New queries: 0
  • Dropped queries: 0
  • Plan changed + metrics changed: 0
  • Plan unchanged + metrics changed: 0
ℹ️ About this analysis

This automated analysis compares query planner metrics between the base branch and this PR. It categorizes changes into:

  • New queries: Queries added in this PR
  • Dropped queries: Queries removed in this PR. These should be reviewed to ensure we are not losing coverage.
  • Plan changed + metrics changed: The query plan has changed along with planner metrics.
  • Metrics only changed: Same plan but different metrics

The last category in particular may indicate planner regressions that should be investigated.

@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from c597cea to 0848c7b Compare September 16, 2026 18:55
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 4fb7006 to b7db6bc Compare September 16, 2026 18:55
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from 0848c7b to 69399ce Compare September 16, 2026 20:29
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from b7db6bc to 1818a02 Compare September 16, 2026 20:29
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from 69399ce to b1a40b3 Compare September 16, 2026 21:21
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 1818a02 to f4a7009 Compare September 16, 2026 21:21
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from b1a40b3 to dd4d868 Compare September 16, 2026 23:11
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from f4a7009 to d84e4be Compare September 16, 2026 23:11
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from dd4d868 to a8f0925 Compare September 17, 2026 14:22
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from d84e4be to 92aaead Compare September 17, 2026 14:22
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from a8f0925 to 2a64cc4 Compare September 17, 2026 22:34
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 92aaead to 2979d09 Compare September 17, 2026 22:34
@g31pranjal
g31pranjal removed this pull request from stack #4629 September 17, 2026 22:35
@g31pranjal
g31pranjal added this pull request to stack #4632 September 17, 2026 22:35
@g31pranjal
g31pranjal removed this pull request from stack #4632 September 17, 2026 22:39
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/zero-based-ordinality branch from 2a64cc4 to d4a521c Compare September 17, 2026 22:39
Base automatically changed from apple/g31pranjal/unnested/zero-based-ordinality to apple/g31pranjal/unnested/synthetic-type-expand September 17, 2026 22:39
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from 2979d09 to c781f27 Compare September 17, 2026 22:39
@g31pranjal
g31pranjal added this pull request to stack #4634 September 17, 2026 22:44
@g31pranjal
g31pranjal removed this pull request from stack #4634 September 17, 2026 22:48
An explode `WITH ORDINALITY` flows an anonymous `(element, ordinal)` struct. Until
now the value standing for that struct was a single opaque `QueriedValue`, which
made the element unreachable to `MaxMatchMap`: it descends into record
constructors, but an opaque value offers nothing to match against but itself. A
query that explodes a collection plainly therefore had no correspondence to a
candidate that explodes the same collection with ordinality, and any such match
was lost.

`ExplodeExpression.explodeResultValue` now builds the ordinality variant as a
`RecordConstructorValue` of two `QueriedValue`s. The element stays the first
column deliberately: `MaxMatchMap` takes the first reachable candidate value that
compares equal, and a `QueriedValue` compares equal to any other, so an element
would just as happily match the ordinal if the ordinal came first. The record is
built nullable so its type stays the one `explodeResultType` already declares --
that type backs the protobuf descriptor the plan builds at run time.

Because a `QueriedValue` was equal to every other `QueriedValue` regardless of
type, the two columns of that record were indistinguishable, and pulling a value
up through the explode found both. `QueriedValue.equalsWithoutChildren` now also
compares the result type.

`subsumedBy` gains the case itself: a plain explode is subsumed by an explode with
ordinality over the same collection, since the candidate produces at least
everything the query may produce. `exactlySubsumedBy` cannot express it, as its
`equalsWithoutChildren` compares `isWithOrdinality`.
`RecordMetaData.getPlannerType` resolves a name against the stored record types
only, so it cannot describe a synthetic record type. Add overloads that take the
`RecordType`s themselves, which is what `recordTypesForIndex` hands back for an
index defined on a synthetic type, and let the name-taking ones delegate to them.

This is what expanding an index defined on an unnested record type into a match
candidate needs in order to describe the type the candidate flows.
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 24551d6 to a74faf7 Compare September 18, 2026 15:12
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-ordinality-matching branch from c781f27 to f3be10b Compare September 18, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant