Skip to content

[SPARK-55654][SQL] Enable TreePattern pruning for EliminateSubqueryAliases and ResolveInlineTables#54440

Closed
yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn:tree-pattern-pruning-inline-tables
Closed

[SPARK-55654][SQL] Enable TreePattern pruning for EliminateSubqueryAliases and ResolveInlineTables#54440
yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn:tree-pattern-pruning-inline-tables

Conversation

@yaooqinn
Copy link
Member

@yaooqinn yaooqinn commented Feb 24, 2026

What changes were proposed in this pull request?

Replace AlwaysProcess.fn with pattern-based pruning in two Analyzer rules:

  1. EliminateSubqueryAliases: Use _.containsPattern(SUBQUERY_ALIAS)

    • Skips entire plan traversal when no SubqueryAlias nodes exist
    • Common in resolved plans after initial resolution passes
  2. ResolveInlineTables: Use _.containsPattern(INLINE_TABLE_EVAL)

    • Skips traversal when no UnresolvedInlineTable nodes exist
    • Inline tables are rare; most queries never contain them

Also adds INLINE_TABLE_EVAL to UnresolvedInlineTable.nodePatterns, which was previously only defined on ResolvedInlineTable. Without this, the pruning condition for ResolveInlineTables could never be satisfied for unresolved inline tables.

Both rules previously used AlwaysProcess.fn, forcing full tree traversal on every fixedPoint iteration even when no matching nodes existed. TreePatternBits propagation enables O(1) root-level short-circuit.

Why are the changes needed?

Performance optimization: avoids unnecessary full-plan traversals during analysis when the relevant node types are absent.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing tests: AnalysisSuite, EliminateSubqueryAliasesSuite, and inline table related tests all pass.

Was this patch authored or co-authored using generative AI tooling?

Yes, GitHub Copilot.

…iases and ResolveInlineTables

Replace AlwaysProcess.fn with pattern-based pruning in two Analyzer rules:

1. EliminateSubqueryAliases: Use _.containsPattern(SUBQUERY_ALIAS)
   - Skips entire plan traversal when no SubqueryAlias nodes exist
   - Common in resolved plans after initial resolution passes

2. ResolveInlineTables: Use _.containsPattern(INLINE_TABLE_EVAL)
   - Skips traversal when no UnresolvedInlineTable nodes exist
   - Inline tables are rare; most queries never contain them

Also adds INLINE_TABLE_EVAL to UnresolvedInlineTable.nodePatterns,
which was previously only on ResolvedInlineTable. Without this fix,
the pruning condition could never be satisfied for unresolved inline
tables, causing analysis failures for queries using VALUES clauses.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yaooqinn yaooqinn force-pushed the tree-pattern-pruning-inline-tables branch from b828d55 to 1cfb1c2 Compare February 24, 2026 09:15
@yaooqinn yaooqinn changed the title [WIP][SPARK-XXXXX][SQL] Enable TreePattern pruning for EliminateSubqueryAliases and ResolveInlineTables [SPARK-55654][SQL] Enable TreePattern pruning for EliminateSubqueryAliases and ResolveInlineTables Feb 24, 2026
@yaooqinn yaooqinn marked this pull request as ready for review February 24, 2026 09:16
@yaooqinn yaooqinn closed this in 7d67ff3 Feb 24, 2026
@yaooqinn yaooqinn deleted the tree-pattern-pruning-inline-tables branch February 24, 2026 09:59
@yaooqinn
Copy link
Member Author

Merged to master, thank you @peter-toth

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, late LGTM.

@yaooqinn
Copy link
Member Author

Thank you @dongjoon-hyun

Sign up for free to 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.

3 participants