Skip to content

Reject non-indexable aggregates in GroupByExpression.subsumedBy() - #4643

Merged
robert-brunel merged 1 commit into
mainfrom
apple/robert-brunel/array-agg-aggregate-index-match
Sep 22, 2026
Merged

robert-brunel merged 1 commit into
mainfrom
apple/robert-brunel/array-agg-aggregate-index-match

Conversation

@robert-brunel

@robert-brunel robert-brunel commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

In GroupByExpression.subsumedBy(), rule out a candidate expression right away if the aggregate from the query is not indexable (i.e., not derived from IndexableAggregateValue) in the first place.

This hardens the method to gracefully handle the recently introduced ARRAY_AGG() aggregate function, which is special in that it has a non-primitive result type and is not indexable. Prior to this fix, the Values.primitiveAccessorsForType() decomposition inside subsumedBy() would raise an ORDERING_IS_OF_INCOMPATIBLE_TYPE semantic error for ARRAY_AGG() because it cannot handle arrays. This would cause any query featuring ARRAY_AGG() to fail if the schema contained a candidate aggregate index on the same table.

@robert-brunel robert-brunel self-assigned this Sep 18, 2026
@robert-brunel robert-brunel added bug fix Change that fixes a bug Run mixed-mode Label to add to Pull Requests to have it run mixed mode tests labels Sep 18, 2026
@robert-brunel
robert-brunel force-pushed the apple/robert-brunel/array-agg-aggregate-index-match branch 2 times, most recently from 5d34bbd to 1f8aede Compare September 21, 2026 14:45
@robert-brunel
robert-brunel marked this pull request as ready for review September 21, 2026 14:46
@robert-brunel
robert-brunel requested a review from hatyo September 21, 2026 14:46
In `GroupByExpression.subsumedBy()`, rule out a candidate expression right away if the aggregate from the query is not indexable (i.e., not derived from `IndexableAggregateValue`) in the first place.

This hardens the method to gracefully handle the recently introduced `ARRAY_AGG()` aggregate function, which is special in that it has a non-primitive result type and is not indexable. Prior to this fix, the `Values.primitiveAccessorsForType()` decomposition inside `subsumedBy()` would raise an `ORDERING_IS_OF_INCOMPATIBLE_TYPE` semantic error for `ARRAY_AGG()` because it cannot handle arrays. This would cause any query featuring `ARRAY_AGG()` to fail if the schema contained a candidate aggregate index on the same table.
@robert-brunel
robert-brunel force-pushed the apple/robert-brunel/array-agg-aggregate-index-match branch from 1f8aede to a97878a Compare September 21, 2026 15:02
@github-actions

Copy link
Copy Markdown

📊 Metrics Diff Analysis Report

Summary

  • New queries: 7
  • 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.

New Queries

Count of new queries by file:

  • yaml-tests/src/test/resources/array-agg-tests.metrics.yaml: 7

@hatyo hatyo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robert-brunel
robert-brunel merged commit 465a76e into main Sep 22, 2026
23 of 24 checks passed
@robert-brunel
robert-brunel deleted the apple/robert-brunel/array-agg-aggregate-index-match branch September 22, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Change that fixes a bug Run mixed-mode Label to add to Pull Requests to have it run mixed mode tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants