PHOENIX-7903 Functional index match rule EXPLAIN disclosure - #2523
Merged
Conversation
Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances optimizer EXPLAIN disclosure for functional indexes by surfacing which query path expression(s) matched a functional index and by using a more specific rejection reason when a functional index’s expression matches nothing in the query.
Changes:
- Track and disclose functional-index expression substitutions that actually fired, enabling
matches <expr>rule labeling for the chosen functional index. - Re-tag certain functional-index rejections as
path expression does not matchwhen no query expression matched the functional index expression. - Add unit tests covering functional-index rule labeling and rejection reason behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java | Adds tests asserting functional-index matches <expr> rule labeling and updated rejection reasons. |
| phoenix-core-client/src/main/java/org/apache/phoenix/parse/IndexExpressionParseNodeRewriter.java | Tracks which functional substitutions actually fired during rewrite to support EXPLAIN disclosure. |
| phoenix-core-client/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java | Records fired matches into the rewrite context and adjusts rule/rejection labels for functional indexes. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.java | Stores per-index “applied expression matches” and marks indexes as functional during rewriting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
Test ResultsUnit tests — PASS
New tests added by the commit (all passing):
Integration tests (
|
| Test class | Tests | Failures | Errors | Skipped |
|---|---|---|---|---|
IndexUsageIT (functional indexes `s2 |
'_' | s3, k1/k2`) |
||
JsonFunctionsIT (JSON path functional indexes) |
15 | 0 | 0 | 0 |
| Total | 54 | 0 | 0 | 0 |
Both IT classes exercise the changed optimizer code paths via real plan compilation against a minicluster and assert on indexRule / indexRejected.
asf-gitbox-commits
pushed a commit
that referenced
this pull request
Jul 24, 2026
Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>
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.
Disclose
OptimizerReasonsfor functional indexes.The chosen functional index's per-scan
INDEXline gains the rulematches <expr>where<expr>is the user's original path expression. Candidates discarded because no query expression matched their indexed expression are taggedpath expression does not match.QueryOptimizer.recordDecision,labelComparatorRule, and theRULE_ONLY_CANDIDATEpath ingetApplicablePlansForSingleFlatQueryoverride the rule label withOptimizerReasons.matches(sourceExpression.toString())when the winning candidate is a functional index, sourcingsourceExpressionfromStatementContext.getIndexExpressionSubstitutions()of the winning index.QueryOptimizer.addPlanandtagComparatorRejectionsswitch the rejection tag for functional index candidates toREASON_PATH_EXPRESSION_DOES_NOT_MATCH.A functional index is detected by an index column with a non-null
PColumn.getExpressionStr().Co-authored-by: Claude Opus 4.8[1m] noreply@anthropic.com