Skip to content

PHOENIX-7922 Consolidate the EXPLAIN rewrite pass entry points - #2529

Merged
apurtell merged 1 commit into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7922
Jun 14, 2026
Merged

PHOENIX-7922 Consolidate the EXPLAIN rewrite pass entry points#2529
apurtell merged 1 commit into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7922

Conversation

@apurtell

Copy link
Copy Markdown
Contributor

Consolidate the rewrite pass entry points.

Add forRewrite() on StatementContext, carrying rewrite breadcrumbs across the early rewrite pass at four call sites (PhoenixStatement.ExecutableSelectStatement.compilePlan, DeleteCompiler.compile, UpsertCompiler.compile, and QueryCompiler.compileSubquery). The bespoke BindManager and FromCompiler additions in PhoenixStatement and DeleteCompiler go away. Drops the legacy single argument rewriter overloads SubselectRewriter.flatten(SelectStatement, PhoenixConnection) and SubqueryRewriter.transform(SelectStatement, ColumnResolver, PhoenixConnection) plus the matching 3-arg new SubqueryRewriter(...) constructor. The four legacy overloads are deleted, and the trivial forwarding layer goes with them.

No behavior change. EXPLAIN text and JSON output are unchanged.

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 consolidates the early EXPLAIN rewrite-pass entry points by introducing StatementContext.forRewrite(...) and updating key compilation call sites to reuse a consistent rewrite context for breadcrumb accumulation, while removing now-redundant legacy overloads.

Changes:

  • Added StatementContext.forRewrite(...) factory methods to standardize creation of rewrite-pass contexts (including a variant that reuses an existing BindManager).
  • Updated rewrite-pass call sites in PhoenixStatement, QueryCompiler, UpsertCompiler, DeleteCompiler, and a test helper to pass an explicit rewrite context.
  • Removed legacy SubselectRewriter.flatten(...) and SubqueryRewriter.transform(...) overloads (and a forwarding constructor) that previously defaulted to null context.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.javaUpdates test helper to create and pass a rewrite StatementContext through flatten/transform.
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.javaSwitches to StatementContext.forRewrite(...) for top-level rewrite-pass context creation.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/UpsertCompiler.javaUses StatementContext.forRewrite(...) for UPSERT SELECT rewrite-pass context creation.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/SubselectRewriter.javaRemoves legacy 2-arg flatten(...) overload; callers must pass context (or null) explicitly.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/SubqueryRewriter.javaRemoves legacy 3-arg transform(...) overload and a forwarding constructor; explicit context required.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.javaIntroduces forRewrite(...) factory methods to standardize rewrite context construction.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/QueryCompiler.javaReplaces bespoke rewrite-context construction with StatementContext.forRewrite(statement, bindManager).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@apurtell

Copy link
Copy Markdown
ContributorAuthor

Test Results

Unit tests

Aggregate: tests run = 2640, skipped = 9.

Compile-pass tests directly exercising the patch

Test classTests run / passTime
org.apache.phoenix.query.explain.ExplainPlanTest105 / 1050.78 s
org.apache.phoenix.compile.QueryCompilerTest215 / 215 (2 sk)1.49 s
org.apache.phoenix.compile.JoinQueryCompilerTest2 / 20.09 s
org.apache.phoenix.compile.HavingCompilerTest11 / 110.22 s
org.apache.phoenix.compile.RVCOffsetCompilerTest7 / 70.03 s
org.apache.phoenix.compile.WhereOptimizerTest138 / 1384.95 s

Integration tests

The patch touches the four early rewrite-pass entry points (SELECT, DELETE, UPSERT SELECT, subquery in QueryCompiler) and the test-only getJoinTable utility. The IT classes below cover all of them and the EXPLAIN baseline.

IT classTests run / passTime
org.apache.phoenix.end2end.ExplainPlanWithStatsEnabledIT30 / 3045.9 s
org.apache.phoenix.end2end.ExplainPlanWithStatsDisabledIT17 / 1736.8 s
org.apache.phoenix.end2end.DerivedTableIT18 / 1850.0 s
org.apache.phoenix.end2end.join.SubqueryIT36 / 36204.7 s
org.apache.phoenix.end2end.RowValueConstructorOffsetIT33 / 3338.7 s
org.apache.phoenix.end2end.SortMergeJoinMoreIT10 / 1062.5 s
org.apache.phoenix.end2end.DeleteIT74 / 74201.7 s
org.apache.phoenix.end2end.UpsertSelectIT54 / 54204.3 s

@apurtell
apurtell merged commit be046f9 into apache:PHOENIX-7876-featureJun 14, 2026
@apurtell
apurtell deleted the PHOENIX-7922 branch June 14, 2026 04:59
apurtell added a commit to apurtell/phoenix that referenced this pull request Jun 17, 2026
…e#2529)
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
…e#2529)
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