perf(planner): Skip unnecessary processing for leaf expressions and trivial predicates in wide projections#27544
Closed
feilong-liu wants to merge 1 commit intoprestodb:masterfrom
Closed
Conversation
Contributor
Reviewer's GuideIntroduces targeted fast-path optimizations in the query planner for wide-column project nodes by short‑circuiting common cases in symbol mapping, pruning unreferenced outputs, and predicate pushdown without changing semantics. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The fast path in
PredicatePushDown.visitProjectshould likely checkcontext.get() == TRUE_CONSTANTrather than.equals(TRUE_CONSTANT), since an arbitrary expression that evaluates to true but still contains conjuncts would now bypass predicate pushdown, changing behavior rather than just optimizing. - In the same fast path, consider early-returning using the existing
context.get()instead of hardcodingTRUE_CONSTANTintodefaultRewriteto avoid subtly changing behavior if a non-literal true predicate ever reaches this code path.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The fast path in `PredicatePushDown.visitProject` should likely check `context.get() == TRUE_CONSTANT` rather than `.equals(TRUE_CONSTANT)`, since an arbitrary expression that evaluates to true but still contains conjuncts would now bypass predicate pushdown, changing behavior rather than just optimizing.
- In the same fast path, consider early-returning using the existing `context.get()` instead of hardcoding `TRUE_CONSTANT` into `defaultRewrite` to avoid subtly changing behavior if a non-literal true predicate ever reaches this code path.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
kaikalur
approved these changes
Apr 8, 2026
kaikalur
approved these changes
Apr 8, 2026
Three targeted fast paths for wide-column queries: 1. SymbolMapper.map(RowExpression): Skip TreeRewriter instantiation for leaf expressions (VariableReferenceExpression and ConstantExpression). 2. PruneUnreferencedOutputs.visitProject: Short-circuit VariablesExtractor.extractUnique() for VariableReferenceExpression assignments by directly adding the variable. 3. PredicatePushDown.visitProject: Early return when inherited predicate is TRUE_CONSTANT, skipping isDeterministic evaluation on all assignments.
ca0c364 to
69aa6f7
Compare
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.
Description
Three targeted fast-path optimizations for wide-column queries (e.g., FAB BA capping query with ~2225 column assignments):
SymbolMapper.map(RowExpression): Skip TreeRewriter instantiation for leaf expressions (VariableReferenceExpression and ConstantExpression). For identity assignments, call
map(VariableReferenceExpression)directly instead of creating an anonymousRowExpressionRewriter+TreeRewriter.PruneUnreferencedOutputs.visitProject: Short-circuit
VariablesExtractor.extractUnique()for VariableReferenceExpression assignments by directly adding the variable, avoidingImmutableList.Builder, visitor traversal, andImmutableSetallocation.PredicatePushDown.visitProject: Early return when inherited predicate is
TRUE_CONSTANT(no conjuncts to push), skippingisDeterministicevaluation on all assignments.Motivation and Context
For wide projections with ~2225 assignments, the majority are passthrough identity variables (
col := col). Each of these was going through expensive processing paths that produce no useful work:SymbolMapperinstantiated a fullRowExpressionTreeRewriter+ anonymousRowExpressionRewriterfor every leaf expressionPruneUnreferencedOutputsran fullVariablesExtractor.extractUnique()with visitor traversal for simple variable referencesPredicatePushDownevaluatedisDeterministicon all assignments even when the inherited predicate is trivially TRUEImpact
Reduces optimizer overhead for queries with wide projections. No functional behavior changes — all optimizations are pure fast paths that produce identical results.
Test Plan
testMapRowExpressionVariable,testMapRowExpressionConstant,testMapRowExpressionUnmappedVariableinTestSymbolMappertestProjectWithVariableReferenceAssignmentsinTestPruneUnreferencedOutputstestNoPredicateOverProjectioninTestPredicatePushdownContributor checklist
Release Notes