Skip to content

PHOENIX-7896 EXPLAIN top-of-plan disclosures - #2517

Merged
apurtell merged 3 commits into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7896
Jun 11, 2026
Merged

PHOENIX-7896 EXPLAIN top-of-plan disclosures#2517
apurtell merged 3 commits into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7896

Conversation

@apurtell

@apurtellapurtell commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Top-of-plan disclosures rendered as clause style lines before the first operator.

A new ExplainTable.explainTopOfPlan(planSteps, ...) static helper is invoked from ExecutableExplainStatement.compilePlan after plan.getExplainPlan(). The block emits TENANT '<id>' when getTenantId() is non-null, VIEW <viewName> OVER <baseTableName> when tableRef.getTable().getType() == PTableType.VIEW, with the user visible view name resolved from plan.getStatement().getFrom() and the base from PTable.getParentName() or getBaseTableLogicalName(), a CDC scope line when the table type is CDC or StatementContext.getCDCIncludeScopes() is not null, and TXN OMID when isTransactional().

Parse tree and optimizer rewrites are surfaced as REWRITE <description> lines in the same block, fed by a new appliedRewrites list in StatementContext. BaseQueryPlan.getExplainPlan walks the query planning context, dedupes, preserving first occurrence order, and prepends one REWRITE line per breadcrumb. ExplainPlanAttributes gains a rewrites attribute. SubqueryRewriter emits one of IN SUBQUERY AS SEMI JOIN / EXISTS SUBQUERY AS SEMI JOIN / NOT EXISTS SUBQUERY AS ANTI JOIN / SCALAR SUBQUERY AS INNER JOIN / CORRELATED SUBQUERY AS LEFT JOIN per decorrelation. JoinCompiler.JoinTable.getStarJoinVector() emits STAR JOIN ON <n> RIGHT LEGS when there are at least two right legs. HavingCompiler emits HAVING PREDICATE AS WHERE. RVCOffsetCompiler emits RVC OFFSET 0x<hex>. OrderByCompiler.compile emits REVERSE SCAN SUBSTITUTION. QueryCompiler.compileJoinQuery and SortMergeJoinPlan emit RIGHT JOIN AS LEFT JOIN when the swap fires. IndexExpressionParseNodeRewriter emits INDEX EXPRESSION <expr> AS <indexcol>. QueryOptimizer.isPartialIndexUsable emits PARTIAL INDEX APPLICABLE or PARTIAL INDEX NOT APPLICABLE -- <reason>, deduped per table and per index. UnionCompiler.optimizeUnionOrderByIfPossible emits UNION ORDER BY MERGE. SubselectRewriter.flatten increments a counter slot on StatementContext per merge and emits DERIVED 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

Co-authored-by: Claude Opus 4.8[1m] <noreply@anthropic.com>

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 ExplainPlanAttributes and populate them for root plans across plan types.
  • Record optimizer/parser rewrite “breadcrumbs” in StatementContext and render them as REWRITE ... lines at the top of JDBC EXPLAIN output.
  • 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
FileDescription
phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainPlanTestUtil.javaAdds fluent assertions for new disclosure + rewrite attributes.
phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainPlanTest.javaUpdates expected explain attributes and adds tests for rewrite/disclosure rendering.
phoenix-core/src/test/java/org/apache/phoenix/compile/TenantSpecificViewIndexCompileTest.javaMinor formatting-only change.
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexIT.javaUpdates EXPLAIN assertions to use ExplainPlanTestUtil.getPlanSteps.
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ChildViewsUseParentViewIndexIT.javaRemoves a stray blank line.
phoenix-core-client/src/main/java/org/apache/phoenix/util/ParseNodeUtil.javaChanges rewrite API to accept StatementContext so rewrite breadcrumbs can be recorded.
phoenix-core-client/src/main/java/org/apache/phoenix/parse/IndexExpressionParseNodeRewriter.javaOptionally records index-expression substitution breadcrumbs into the provided context.
phoenix-core-client/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.javaCarries rewrite state across recompile and adds partial-index applicability breadcrumbs.
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.javaPrepends disclosure text to JDBC EXPLAIN rows and threads rewrite context into compilation.
phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ExplainTable.javaPopulates top-of-plan attributes and renders disclosure text lines.
phoenix-core-client/src/main/java/org/apache/phoenix/execute/UnionPlan.javaPopulates top-of-plan attributes for root union plans.
phoenix-core-client/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.javaPopulates top-of-plan attributes for root SMJ plans.
phoenix-core-client/src/main/java/org/apache/phoenix/execute/HashJoinPlan.javaPopulates top-of-plan attributes for root hash join plans.
phoenix-core-client/src/main/java/org/apache/phoenix/execute/ClientScanPlan.javaPopulates top-of-plan attributes for root scan plans.
phoenix-core-client/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.javaPopulates top-of-plan attributes for root aggregate plans.
phoenix-core-client/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.javaPopulates top-of-plan attributes for root V2 explain-plan assembly.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/UpsertCompiler.javaThreads 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.javaRecords a breadcrumb when UNION ORDER BY merge optimization is preserved.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/SubselectRewriter.javaAdds optional context parameter to increment derived-table flatten counter.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/SubqueryRewriter.javaAdds optional context parameter and records subquery-to-join rewrite breadcrumbs.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.javaAdds breadcrumb storage, derived-table flatten counter, and partial-index dedupe tracking.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/RVCOffsetCompiler.javaRecords an RVC offset breadcrumb.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/QueryCompiler.javaAdopts 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.javaRecords reverse-scan substitution breadcrumb.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/JoinCompiler.javaThreads 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.javaRecords HAVING→WHERE rewrite breadcrumb.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/ExplainPlanAttributes.javaAdds disclosure + rewrites fields to structured explain attributes and builder.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/DeleteCompiler.javaThreads 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.

@apurtell

Copy link
Copy Markdown
ContributorAuthor

Test Results

SuiteScopeTestsFailuresErrorsResult
ExplainPlanTestDisclosure attributes + renderTopOfPlanText + compat baselines8300PASS
Connectionless UT sweepphoenix-core (all *Test)253700PASS
PartialIndexITDisclosure affected IT (migrated)6000PASS
PartialIndexIT#testPartialIndexBreadcrumbsAreDistinctPerIndexPer-index partial-index breadcrumb (×4 params)400PASS
HashJoinNoIndexITEXPLAIN relevant IT batch3300PASS
SortMergeJoinNoIndexITEXPLAIN relevant IT batch3500PASS
UnionAllITEXPLAIN relevant IT batch1900PASS
IndexUsageITEXPLAIN relevant IT batch3900PASS

@apurtell
apurtell merged commit 31e7f60 into apache:PHOENIX-7876-featureJun 11, 2026
@apurtell
apurtell deleted the PHOENIX-7896 branch June 11, 2026 17:38
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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@apurtell