PHOENIX-7896 EXPLAIN top-of-plan disclosures - #2517
Merged
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 Phoenix EXPLAIN output by introducing a “top-of-plan” disclosure block (tenant/view/CDC/txn + rewrite breadcrumbs) and plumbing structured attributes so both JSON explain attributes and JDBC EXPLAIN text can surface these diagnostics consistently.
Changes:
- Add top-of-plan disclosure attributes to
ExplainPlanAttributesand populate them for root plans across plan types. - Record optimizer/parser rewrite “breadcrumbs” in
StatementContextand render them asREWRITE ...lines at the top of JDBCEXPLAINoutput. - Expand/adjust unit + integration tests to validate the new attributes and rendered disclosure text.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainPlanTestUtil.java | Adds fluent assertions for new disclosure + rewrite attributes. |
| phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainPlanTest.java | Updates expected explain attributes and adds tests for rewrite/disclosure rendering. |
| phoenix-core/src/test/java/org/apache/phoenix/compile/TenantSpecificViewIndexCompileTest.java | Minor formatting-only change. |
| phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexIT.java | Updates EXPLAIN assertions to use ExplainPlanTestUtil.getPlanSteps. |
| phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.java | Removes a stray blank line. |
| phoenix-core-client/src/main/java/org/apache/phoenix/util/ParseNodeUtil.java | Changes rewrite API to accept StatementContext so rewrite breadcrumbs can be recorded. |
| phoenix-core-client/src/main/java/org/apache/phoenix/parse/IndexExpressionParseNodeRewriter.java | Optionally records index-expression substitution breadcrumbs into the provided context. |
| phoenix-core-client/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java | Carries rewrite state across recompile and adds partial-index applicability breadcrumbs. |
| phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java | Prepends disclosure text to JDBC EXPLAIN rows and threads rewrite context into compilation. |
| phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ExplainTable.java | Populates top-of-plan attributes and renders disclosure text lines. |
| phoenix-core-client/src/main/java/org/apache/phoenix/execute/UnionPlan.java | Populates top-of-plan attributes for root union plans. |
| phoenix-core-client/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java | Populates top-of-plan attributes for root SMJ plans. |
| phoenix-core-client/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java | Populates top-of-plan attributes for root hash join plans. |
| phoenix-core-client/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java | Populates top-of-plan attributes for root scan plans. |
| phoenix-core-client/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java | Populates top-of-plan attributes for root aggregate plans. |
| phoenix-core-client/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java | Populates top-of-plan attributes for root V2 explain-plan assembly. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java | Threads rewrite context into early rewrite passes and populates top-of-plan attributes for root DML plans. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/UnionCompiler.java | Records a breadcrumb when UNION ORDER BY merge optimization is preserved. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/SubselectRewriter.java | Adds optional context parameter to increment derived-table flatten counter. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/SubqueryRewriter.java | Adds optional context parameter and records subquery-to-join rewrite breadcrumbs. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.java | Adds breadcrumb storage, derived-table flatten counter, and partial-index dedupe tracking. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/RVCOffsetCompiler.java | Records an RVC offset breadcrumb. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/QueryCompiler.java | Adopts prebuilt rewrite state during compilation; passes context into join compilation; records RIGHT JOIN swap breadcrumb. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/OrderByCompiler.java | Records reverse-scan substitution breadcrumb. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/JoinCompiler.java | Threads context for breadcrumb recording; records star-join breadcrumb; passes context into derived-table flattening. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/HavingCompiler.java | Records HAVING→WHERE rewrite breadcrumb. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/ExplainPlanAttributes.java | Adds disclosure + rewrites fields to structured explain attributes and builder. |
| phoenix-core-client/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java | Threads rewrite context into early rewrite pass; populates top-of-plan attributes for root DML plans. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
Test Results
|
apurtell
added a commit
to apurtell/phoenix
that referenced
this pull request
Jun 17, 2026
Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>
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>
apurtell
added a commit
to apurtell/phoenix
that referenced
this pull request
Aug 4, 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.
Top-of-plan disclosures rendered as clause style lines before the first operator.
A new
ExplainTable.explainTopOfPlan(planSteps, ...)static helper is invoked fromExecutableExplainStatement.compilePlanafterplan.getExplainPlan(). The block emitsTENANT '<id>'whengetTenantId()is non-null,VIEW <viewName> OVER <baseTableName>whentableRef.getTable().getType() == PTableType.VIEW, with the user visible view name resolved fromplan.getStatement().getFrom()and the base fromPTable.getParentName()orgetBaseTableLogicalName(), a CDC scope line when the table type isCDCorStatementContext.getCDCIncludeScopes()is not null, andTXN OMIDwhenisTransactional().Parse tree and optimizer rewrites are surfaced as
REWRITE <description>lines in the same block, fed by a newappliedRewriteslist inStatementContext.BaseQueryPlan.getExplainPlanwalks the query planning context, dedupes, preserving first occurrence order, and prepends oneREWRITEline per breadcrumb.ExplainPlanAttributesgains arewritesattribute.SubqueryRewriteremits one ofIN SUBQUERY AS SEMI JOIN/EXISTS SUBQUERY AS SEMI JOIN/NOT EXISTS SUBQUERY AS ANTI JOIN/SCALAR SUBQUERY AS INNER JOIN/CORRELATED SUBQUERY AS LEFT JOINper decorrelation.JoinCompiler.JoinTable.getStarJoinVector()emitsSTAR JOIN ON <n> RIGHT LEGSwhen there are at least two right legs.HavingCompileremitsHAVING PREDICATE AS WHERE.RVCOffsetCompileremitsRVC OFFSET 0x<hex>.OrderByCompiler.compileemitsREVERSE SCAN SUBSTITUTION.QueryCompiler.compileJoinQueryandSortMergeJoinPlanemitRIGHT JOIN AS LEFT JOINwhen the swap fires.IndexExpressionParseNodeRewriteremitsINDEX EXPRESSION <expr> AS <indexcol>.QueryOptimizer.isPartialIndexUsableemitsPARTIAL INDEX APPLICABLEorPARTIAL INDEX NOT APPLICABLE -- <reason>, deduped per table and per index.UnionCompiler.optimizeUnionOrderByIfPossibleemitsUNION ORDER BY MERGE.SubselectRewriter.flattenincrements a counter slot onStatementContextper merge and emitsDERIVED TABLE FLATTENED <n>once with the final count, suppressed when the count is zero.Co-authored-by: Claude Opus 4.8[1m] noreply@anthropic.com