Skip to content

PHOENIX-7917 Expand the EXPLAIN WITH options list grammar - #2525

Merged
apurtell merged 2 commits into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7917
Jun 13, 2026
Merged

PHOENIX-7917 Expand the EXPLAIN WITH options list grammar#2525
apurtell merged 2 commits into
apache:PHOENIX-7876-featurefrom
apurtell:PHOENIX-7917

Conversation

@apurtell

@apurtellapurtell commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Replace the EXPLAIN [WITH REGIONS] grammar with a comma-separated option list EXPLAIN [(<opt> [, <opt>]*)] <stmt> accepting REGIONS, VERBOSE, FORMAT TEXT, and FORMAT JSON, preserving EXPLAIN WITH REGIONS as a backward compatible alias.

Update PhoenixSQL.gexplain_node rule to accept either LPAREN id (COMMA id)* RPAREN or WITH REGIONS between EXPLAIN and the inner oneStatement, with FORMAT TEXT|JSON parsed as FORMAT followed by an identifier. VERBOSE, FORMAT, TEXT, and JSON are matched as identifier inside explain_node and validated against a closed set in the action block.

ExplainStatement replaces ExplainType with ExplainOptions { boolean regions; boolean verbose; Format format; }. ParseNodeFactory gains a factory.explain(stmt, ExplainOptions) overload. PhoenixStatement#ExecutableExplainStatement takes ExplainOptions and propagates regions through to BaseResultIterators.explainUtil.

Region locator lookup still happens unconditionally.

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 expands Phoenix SQL’s EXPLAIN grammar from the legacy EXPLAIN [WITH REGIONS] <stmt> form to an option-list form EXPLAIN [(<opt> [, <opt>]*)] <stmt>, introducing a new ExplainOptions carrier object that is propagated through parsing/compilation and into StatementContext so explain rendering can be option-aware (while keeping EXPLAIN WITH REGIONS as a backward-compatible alias).

Changes:

  • Extend PhoenixSQL.g to parse EXPLAIN (...) option lists (plus EXPLAIN WITH REGIONS alias) and validate options into an ExplainOptions instance.
  • Replace the old ExplainType enum with ExplainOptions, propagate it through ParseNodeFactory, ExplainStatement, PhoenixStatement, and StatementContext.
  • Gate region-locations emission in ExplainTable on the REGIONS option and update tests/ITs to request region locations explicitly where needed.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
phoenix-core/src/test/java/org/apache/phoenix/query/explain/ExplainPlanTestUtil.javaAdds helpers to run optimization with explicit ExplainOptions and a convenience assertion entrypoint for REGIONS.
phoenix-core/src/test/java/org/apache/phoenix/parse/ExplainOptionsParserTest.javaAdds parser-level tests for the new EXPLAIN (...) option-list grammar and the legacy WITH REGIONS alias.
phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryLoggerIT.javaUpdates EXPLAIN usage to align explain output comparisons with logged plans.
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.javaSwitches region-location assertions to use the new “with regions” explain helper.
phoenix-core/src/it/java/org/apache/phoenix/end2end/FlappingLocalIndexIT.javaEnsures tests requesting region-location attributes enable REGIONS explicitly; adds test categorization annotation.
phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseAggregateIT.javaSwitches region-location assertions to use the new “with regions” explain helper.
phoenix-core-client/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.javaUpdates explain(...) factory method to accept ExplainOptions.
phoenix-core-client/src/main/java/org/apache/phoenix/parse/ExplainType.javaRemoves legacy ExplainType enum.
phoenix-core-client/src/main/java/org/apache/phoenix/parse/ExplainStatement.javaStores parsed ExplainOptions (defaulting to ExplainOptions.DEFAULT).
phoenix-core-client/src/main/java/org/apache/phoenix/parse/ExplainOptions.javaIntroduces ExplainOptions (regions/verbose/format) and a builder used by the parser.
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.javaPropagates ExplainOptions into compiled plan context so explain rendering can respect options.
phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ExplainTable.javaEmits region-location text/attributes only when REGIONS is requested via ExplainOptions.
phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.javaAdds ExplainOptions storage (defaulting to DEFAULT) with getters/setters.
phoenix-core-client/src/main/antlr3/PhoenixSQL.gExtends grammar to parse option lists and validates allowed options into an ExplainOptions.Builder.

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

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@apurtell

apurtell commented Jun 13, 2026

Copy link
Copy Markdown
ContributorAuthor

Test Results

Unit tests (*Test)

Test classTestsFailuresErrorsSkippedResult
ExplainOptionsParserTest (new)16000PASS
QueryParserTest93000PASS
ExplainPlanTest94000PASS
Total203000PASS

ExplainOptionsParserTest covers the new grammar: REGIONS, VERBOSE, FORMAT TEXT, FORMAT JSON, case-insensitivity, option ordering, the legacy WITH REGIONS alias, and the error paths (unknown option, unknown format kind, duplicate option, FORMAT without a value, REGIONS with a value, and mixing the legacy alias with the option list).

Integration tests (*IT)

Test classCategoryTestsFailuresErrorsSkippedResult
AggregateITParallelStatsDisabled25000PASS
GlobalImmutableNonTxIndexITParallelStatsDisabled46000PASS
LocalMutableNonTxIndexITParallelStatsDisabled46004PASS
QueryLoggerITNeedsOwnMiniCluster7000PASS
FlappingLocalIndexITNeedsOwnMiniCluster12000PASS
  • AggregateIT drives the three migrated sites in BaseAggregateIT (testGroupByOrderPreserving, testSumGroupByOrderPreserving, testAvgGroupByOrderPreserving).
  • GlobalImmutableNonTxIndexIT / LocalMutableNonTxIndexIT drive the three migrated sites in BaseIndexIT (testIndexWithNullableFixedWithCols, testIndexWithNullableDateCol, testSelectAllAndAliasWithIndex). The 4 skipped tests in LocalMutableNonTxIndexIT are pre-existing failing tests unrelated to this change tracked by PHOENIX-7893.
  • FlappingLocalIndexIT was previously uncategorized and therefore skipped by all group-filtered failsafe executions. It is now annotated @Category(NeedsOwnMiniClusterTest.class).

@apurtell
apurtell merged commit a4b24f1 into apache:PHOENIX-7876-featureJun 13, 2026
@apurtell
apurtell deleted the PHOENIX-7917 branch June 13, 2026 00:31
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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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