Skip to content

Support CARDINALITY() in indexes#4100

Open
RobertBrunel wants to merge 1 commit intoFoundationDB:mainfrom
RobertBrunel:cardinality-index
Open

Support CARDINALITY() in indexes#4100
RobertBrunel wants to merge 1 commit intoFoundationDB:mainfrom
RobertBrunel:cardinality-index

Conversation

@RobertBrunel
Copy link
Copy Markdown
Contributor

  • Introduce a CardinalityFunctionKeyExpression to make it possible to define indexes with a function("cardinality", …) key expression.
  • In MaterializedViewIndexGenerator, add the necessary logic to convert CardinalityValue into a key expression.

For a nullable ARRAY field, the key expression produced from a CARDINALITY(int_arr) SQL expression will look as follows:

function("cardinality",
         field("int_arr").nest(field("values", Concatenate)))

The use of the Concatenate fan-out type currently runs into some gaps in the code that we also fix with this PR.

Testing:

  • Integration tests in arrays_cardinality.yamsql.
  • Unit tests in IndexTest.java and KeyExpressionTest.java.

@RobertBrunel RobertBrunel self-assigned this Apr 21, 2026
@RobertBrunel RobertBrunel added the enhancement New feature or request label Apr 21, 2026
@RobertBrunel RobertBrunel requested a review from g31pranjal April 21, 2026 17:24
@normen662 normen662 self-requested a review April 22, 2026 07:34
* Introduce a `CardinalityFunctionKeyExpression` to make it possible to
  define indexes with a `function("cardinality", …)` key expression.
* In `MaterializedViewIndexGenerator`, add the necessary logic to
  convert `CardinalityValue` into a key expression.

For a nullable ARRAY field, the key expression produced from a
`CARDINALITY(int_arr)` SQL expression will look as follows:

  function("cardinality",
           field("int_arr").nest(field("values", Concatenate)))

The use of the Concatenate fan-out type currently runs into some gaps
in the code that we also fix with this PR.

Testing:
* Integration tests in `arrays_cardinality.yamsql`.
* Unit tests in `IndexTest.java` and `KeyExpressionTest.java`.
@github-actions
Copy link
Copy Markdown

📊 Metrics Diff Analysis Report

Summary

  • New queries: 17
  • 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/arrays_cardinality.metrics.yaml: 17

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.

2 participants