Skip to content

Cover indexes on unnested record types with several unnestings and other definitions in yaml-tests - #4870

Open
g31pranjal wants to merge 8 commits into
apple/g31pranjal/unnested/syn-relational-integrationfrom
apple/g31pranjal/unnested/multi-unnesting-tests
Open

g31pranjal wants to merge 8 commits into
apple/g31pranjal/unnested/syn-relational-integrationfrom
apple/g31pranjal/unnested/multi-unnesting-tests

Conversation

@g31pranjal

@g31pranjal g31pranjal commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Extends unnested-record-type-indexes.yamsql, which so far tests indexes with a single unnesting, so that it also covers the index definitions of the relational DDL tests (UnnestedSyntheticTableIndexTest) with queries, and fixes two cases in which such an index was never matched.

Fixes:

  • Chained unnestings: the collection a nested constituent explodes was built as (q._0).inner rather than q._0.inner, as a query writes it, so the explodes never compared equal (UnnestedRecordType.constituentQuantifier).
  • A scalar array fanned out in the key of an index on a synthetic type: mergeWithBaseIfNeeded re-expressed the key's predicates and placeholders over the base record but not the graphs of its quantifiers, leaving explode(base.parent.labels) correlated to a dropped quantifier (ValueIndexExpansionVisitor).

Tests: indexes over sibling, repeated, nested and chained unnestings, and over a view, DESC/NULLS LAST keys and a value column; queries scan the index (covering, or ISCAN when a column must be fetched). An index over a struct array and a scalar array is used only when the scalar element is not returned (#4871).

Rejected definitions (unsupported-index-definitions, UNSUPPORTED_OPERATION): an aggregate, a predicate, the row version, a computed column, a scalar array at two key positions, and an unnesting combined with a join.

For each shape, a query that unnests fewer arrays than the index does not use it, as the index has an entry per combination of elements (and none for a row with an empty array).

Two existing mv_split range queries that only flip the comparison of another are dropped; the other existing queries keep their expectations, and their metrics only move to new line numbers. The metrics of the grouped PartiQL query that #4641 commented out are dropped.

Stacked on #4641.

@g31pranjal g31pranjal added the testing improvement Change that improves our testing label Nov 10, 2026
@g31pranjal g31pranjal changed the title Test indexes on unnested record types with more than one unnesting Cover indexes on unnested record types with several unnestings and other definitions in yaml-tests Nov 10, 2026
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/multi-unnesting-tests branch from f9e184a to 6f0d71f Compare November 10, 2026 15:56
@g31pranjal
g31pranjal marked this pull request as ready for review November 10, 2026 16:14
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/syn-relational-integration branch from 23fc442 to 37d978f Compare November 10, 2026 16:17
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/multi-unnesting-tests branch from 0cc09aa to d70cbc2 Compare November 10, 2026 16:17
Covers sibling unnestings, the same array unnested twice, and an unnesting
nested in another one. The index on the nested unnesting is not matched yet,
which the tests document.
…amsql

The file now covers indexes on unnested record types with one unnesting and
with several, so the separate file and its registration are dropped.
…s in unnested-record-type-indexes.yamsql

Adds an index over a view, DESC and NULLS LAST ordering, a value column with a
composite primary key and an ARRAY NOT NULL column, a struct array mixed with a
scalar array, three sibling arrays, chained unnestings, and the index
definitions that an unnested synthetic table rejects. The indexes over a struct
and a scalar array, and over chained unnestings, are not matched yet, which the
tests document.
…t access

The collection a nested constituent explodes was built as a field access on top
of the owner's element, (q._0).inner, while a query navigating the same
unnestings writes it as a single field access, q._0.inner. The two values do not
compare equal, so the explodes, and with them indexes over chained unnestings,
were never matched.
…ynthetic type

The key of an index on a synthetic type is expanded over a temporary base
quantifier that does not survive the merge with the base expansion. Predicates
and placeholders were re-expressed over the base record, but the graphs of the
key's quantifiers were not, so the explode of a scalar array fanned out in the
key kept explode(base.parent.labels), correlated to the dropped quantifier,
and could not match the explode(parent.labels) of a query.
… array to be used

The queries over chained unnestings now use covering scans of their indexes.
The index over a struct array and a scalar array answers queries that only join
the scalar array or bind its element by an equality; returning or ordering by
the element is not supported, as with a fan-out index on a stored type (#4871).
Adds queries over the indexes on `trip`, `team` and `chain` that read a column
held by the synthetic record but not by the index key, so the index entries are
fetched rather than covering the query. Also condenses the header of the file
into one list of the tables and what each covers, and regenerates the metrics
so that their references point at the shifted lines.
…cord-type-indexes.yamsql

Removes the LESS_THAN variants of two mv_split range tests, which only flip the
comparison of the tests before them, and the equality on the leading column of
trip_place_city_rider_mins, which the test binding the whole key prefix
subsumes. Regenerates the metrics for the shifted lines.
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/syn-relational-integration branch from 37d978f to d3d906f Compare November 10, 2026 18:33
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/multi-unnesting-tests branch from d70cbc2 to f91a614 Compare November 10, 2026 18:33
@github-actions

Copy link
Copy Markdown

📊 Metrics Diff Analysis Report

Summary

  • New queries: 85
  • Dropped queries: 0
  • Plan changed + metrics changed: 11
  • Plan unchanged + metrics changed: 4
ℹ️ 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.

New Queries

Count of new queries by file:

  • yaml-tests/src/test/resources/unnested-record-type-indexes.metrics.yaml: 85

Plan and Metrics Changed

These queries experienced both plan and metrics changes. This generally indicates that there was some planner change
that means the planning for this query may be substantially different. Some amount of query plan metrics change is expected,
but the reviewer should still validate that these changes are not excessive.

Total: 11 queries

Statistical Summary (Plan and Metrics Changed)

task_count:

  • Average change: -5.0
  • Average regression: +7.7
  • Median change: -4
  • Median regression: +6
  • Standard deviation: 9.5
  • Standard deviation of regressions: 2.4
  • Range: -20 to +11
  • Range of regressions: +6 to +11
  • Queries changed: 11
  • Queries regressed: 3

task_count % change distribution (11 queries, bin = 2%):

     Range                                  n
----------  ------------------------------  ---
[-8%, -6%)  ████                            1
[-6%, -4%)                                  0
[-4%, -2%)                                  0
[-2%, +0%)  ██████████████████████████████  7
[+0%, +2%)  ████                            1
[+2%, +4%)                                  0
[+4%, +6%)  █████████                       2

transform_count:

  • Average change: -1.8
  • Average regression: +1.0
  • Median change: -2
  • Median regression: +1
  • Standard deviation: 1.6
  • Standard deviation of regressions: 0.0
  • Range: -5 to +1
  • Range of regressions: +1 to +1
  • Queries changed: 8
  • Queries regressed: 1

transform_count % change distribution (8 queries, bin = 2%):

     Range                                  n
----------  ------------------------------  ---
[-8%, -6%)  ███████████████████████         3
[-6%, -4%)                                  0
[-4%, -2%)                                  0
[-2%, +0%)  ██████████████████████████████  4
[+0%, +2%)  ████████                        1

transform_yield_count:

  • Average change: -1.0
  • Average regression: +1.0
  • Median change: -1
  • Median regression: +1
  • Standard deviation: 1.0
  • Standard deviation of regressions: 0.0
  • Range: -2 to +1
  • Range of regressions: +1 to +1
  • Queries changed: 6
  • Queries regressed: 1

transform_yield_count % change distribution (6 queries, bin = 2%):

       Range                                  n
------------  ------------------------------  ---
[-12%, -10%)  ████████                        1
 [-10%, -8%)                                  0
  [-8%, -6%)                                  0
  [-6%, -4%)                                  0
  [-4%, -2%)                                  0
  [-2%, +0%)  ██████████████████████████████  4
  [+0%, +2%)  ████████                        1

insert_new_count:

  • Average change: -0.9
  • Average regression: +1.0
  • Median change: -1
  • Median regression: +1
  • Standard deviation: 1.9
  • Standard deviation of regressions: 0.0
  • Range: -5 to +1
  • Range of regressions: +1 to +1
  • Queries changed: 8
  • Queries regressed: 3

insert_new_count % change distribution (8 queries, bin = 2%):

       Range                                  n
------------  ------------------------------  ---
[-20%, -18%)  ████████                        1
[-18%, -16%)                                  0
[-16%, -14%)                                  0
[-14%, -12%)                                  0
[-12%, -10%)                                  0
 [-10%, -8%)                                  0
  [-8%, -6%)                                  0
  [-6%, -4%)                                  0
  [-4%, -2%)                                  0
  [-2%, +0%)  ██████████████████████████████  4
  [+0%, +2%)  ████████                        1
  [+2%, +4%)                                  0
  [+4%, +6%)                                  0
  [+6%, +8%)                                  0
 [+8%, +10%)                                  0
[+10%, +12%)                                  0
[+12%, +14%)  ███████████████                 2

There were no queries with significant regressions detected.

Minor Changes (Plan and Metrics Changed)

In addition, there were 11 queries with minor changes.

Only Metrics Changed

These queries experienced only metrics changes without any plan changes. If these metrics have substantially changed,
then a planner change has been made which affects planner performance but does not correlate with any new outcomes,
which could indicate a regression.

Total: 4 queries

Statistical Summary (Only Metrics Changed)

task_count:

  • Average change: -173.8
  • Average regression: +11.0
  • Median change: +11
  • Median regression: +11
  • Standard deviation: 225.8
  • Standard deviation of regressions: 0.0
  • Range: -542 to +11
  • Range of regressions: +11 to +11
  • Queries changed: 4
  • Queries regressed: 2

task_count % change distribution (4 queries, bin = 2%):

       Range                                  n
------------  ------------------------------  ---
[-52%, -50%)  ███████████████                 1
[-50%, -48%)                                  0
[-48%, -46%)                                  0
[-46%, -44%)                                  0
[-44%, -42%)                                  0
[-42%, -40%)                                  0
[-40%, -38%)                                  0
[-38%, -36%)                                  0
[-36%, -34%)                                  0
[-34%, -32%)                                  0
[-32%, -30%)                                  0
[-30%, -28%)                                  0
[-28%, -26%)                                  0
[-26%, -24%)                                  0
[-24%, -22%)                                  0
[-22%, -20%)                                  0
[-20%, -18%)  ███████████████                 1
[-18%, -16%)                                  0
[-16%, -14%)                                  0
[-14%, -12%)                                  0
[-12%, -10%)                                  0
 [-10%, -8%)                                  0
  [-8%, -6%)                                  0
  [-6%, -4%)                                  0
  [-4%, -2%)                                  0
  [-2%, +0%)                                  0
  [+0%, +2%)  ██████████████████████████████  2

transform_count:

  • Average change: -52.3
  • Average regression: +1.0
  • Median change: +1
  • Median regression: +1
  • Standard deviation: 63.3
  • Standard deviation of regressions: 0.0
  • Range: -154 to +1
  • Range of regressions: +1 to +1
  • Queries changed: 4
  • Queries regressed: 2

transform_count % change distribution (4 queries, bin = 2%):

       Range                                  n
------------  ------------------------------  ---
[-56%, -54%)  ███████████████                 1
[-54%, -52%)                                  0
[-52%, -50%)                                  0
[-50%, -48%)                                  0
[-48%, -46%)                                  0
[-46%, -44%)                                  0
[-44%, -42%)                                  0
[-42%, -40%)                                  0
[-40%, -38%)                                  0
[-38%, -36%)                                  0
[-36%, -34%)                                  0
[-34%, -32%)                                  0
[-32%, -30%)                                  0
[-30%, -28%)                                  0
[-28%, -26%)                                  0
[-26%, -24%)                                  0
[-24%, -22%)                                  0
[-22%, -20%)                                  0
[-20%, -18%)                                  0
[-18%, -16%)  ███████████████                 1
[-16%, -14%)                                  0
[-14%, -12%)                                  0
[-12%, -10%)                                  0
 [-10%, -8%)                                  0
  [-8%, -6%)                                  0
  [-6%, -4%)                                  0
  [-4%, -2%)                                  0
  [-2%, +0%)                                  0
  [+0%, +2%)  ██████████████████████████████  2

transform_yield_count:

  • Average change: -25.5
  • Median change: -9
  • Standard deviation: 16.5
  • Range: -42 to -9
  • Queries changed: 2
  • No regressions! 🎉

insert_new_count:

  • Average change: -28.5
  • Average regression: +1.0
  • Median change: +1
  • Median regression: +1
  • Standard deviation: 39.4
  • Standard deviation of regressions: 0.0
  • Range: -95 to +1
  • Range of regressions: +1 to +1
  • Queries changed: 4
  • Queries regressed: 2

insert_new_count % change distribution (4 queries, bin = 2%):

       Range                                  n
------------  ------------------------------  ---
[-62%, -60%)  ███████████████                 1
[-60%, -58%)                                  0
[-58%, -56%)                                  0
[-56%, -54%)                                  0
[-54%, -52%)                                  0
[-52%, -50%)                                  0
[-50%, -48%)                                  0
[-48%, -46%)                                  0
[-46%, -44%)                                  0
[-44%, -42%)                                  0
[-42%, -40%)                                  0
[-40%, -38%)                                  0
[-38%, -36%)                                  0
[-36%, -34%)                                  0
[-34%, -32%)                                  0
[-32%, -30%)                                  0
[-30%, -28%)                                  0
[-28%, -26%)                                  0
[-26%, -24%)                                  0
[-24%, -22%)  ███████████████                 1
[-22%, -20%)                                  0
[-20%, -18%)                                  0
[-18%, -16%)                                  0
[-16%, -14%)                                  0
[-14%, -12%)                                  0
[-12%, -10%)                                  0
 [-10%, -8%)                                  0
  [-8%, -6%)                                  0
  [-6%, -4%)                                  0
  [-4%, -2%)                                  0
  [-2%, +0%)                                  0
  [+0%, +2%)  ██████████████████████████████  2

insert_reused_count:

  • Average change: -3.0
  • Median change: -3
  • Standard deviation: 0.0
  • Range: -3 to -3
  • Queries changed: 1
  • No regressions! 🎉

There were no queries with significant regressions detected.

Minor Changes (Only Metrics Changed)

In addition, there were 4 queries with minor changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing improvement Change that improves our testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant