Support CARDINALITY() in indexes#4100
Open
RobertBrunel wants to merge 1 commit intoFoundationDB:mainfrom
Open
Conversation
pengpeng-lu
reviewed
Apr 21, 2026
pengpeng-lu
reviewed
Apr 21, 2026
* 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`.
3d9ec65 to
dc19c5c
Compare
📊 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. New QueriesCount of new queries by file:
|
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.
CardinalityFunctionKeyExpressionto make it possible to define indexes with afunction("cardinality", …)key expression.MaterializedViewIndexGenerator, add the necessary logic to convertCardinalityValueinto a key expression.For a nullable ARRAY field, the key expression produced from a
CARDINALITY(int_arr)SQL expression will look as follows:The use of the Concatenate fan-out type currently runs into some gaps in the code that we also fix with this PR.
Testing:
arrays_cardinality.yamsql.IndexTest.javaandKeyExpressionTest.java.