Skip to content

Conversation

@LLDay
Copy link

@LLDay LLDay commented Jan 26, 2026

Rationale for this change

This PR covers a part of #14342.

Currently, DataFusion's support for placeholders is handled at the logical plan level. This requires re-planning every time parameter values change.

This PR introduces physical-level support for placeholders, allowing a physical plan to be created once and then executed multiple times with different parameter values. This should improve performance for repeated executions of the same query with different parameters by avoiding the overhead of physical planning.

What changes are included in this PR?

This PR introduces several key components to support physical placeholders:

  1. Expression Rewriting Interface: Added physical_expressions and with_physical_expressions to the ExecutionPlan trait to allow inspection and replacement of expressions within plan nodes.
  2. PlaceholderExpr: A new physical expression that represents a placeholder in the physical plan. It stores the placeholder ID and its data type.
  3. ResolvePlaceholdersExec: A new execution plan node that acts as a wrapper. It identifies placeholders within its subtree and resolves them using parameter values provided at execution time.
  4. PhysicalExprResolver Optimizer Rule: Wraps the final optimized plan in a ResolvePlaceholdersExec if any unresolved placeholders are detected.
  5. TaskContext Update: Updated to carry ParamValues.

Are these changes tested?

  • The new physical_expressions and with_physical_expressions methods are verified using the check_physical_expressions invariant.
  • ResolvePlaceholdersExec is tested with unit tests and SLT tests.

Are there any user-facing changes?

Yes, a user can now build physical plan from a logical plan with placeholders.

Denis Semenov added 2 commits January 26, 2026 11:57
Introduces `physical_expressions` and `with_physical_expressions`
methods to the `ExecutionPlan` trait. These methods provide an interface
to inspect and replace physical expressions within execution plan nodes.

The commit also implements these methods for various ExecutionPlans and
introduces a new physical expression invariant check to ensure
consistency between expression retrieval and replacement.
This commit introduces physical-level support for placeholders, allowing physical plans
to be prepared once and executed multiple times with different parameter values.

Key changes:
- Added `PlaceholderExpr` physical expression.
- Added `ResolvePlaceholdersExec` to handle placeholder resolution at execution time.
- Updated `TaskContext` to carry `ParamValues` for resolution during `execute`.
- Added `PhysicalExprResolver` optimizer rule to manage `ResolvePlaceholdersExec` nodes.
- Updated `FilterPushdown` to correctly handle expressions containing placeholders.
@github-actions github-actions bot added physical-expr Changes to the physical-expr crates optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) execution Related to the execution crate proto Related to proto crate datasource Changes to the datasource crate physical-plan Changes to the physical-plan crate labels Jan 26, 2026
@LLDay LLDay marked this pull request as ready for review January 26, 2026 13:18
@LLDay
Copy link
Author

LLDay commented Jan 26, 2026

@askalt, could you review the PR as well?

@askalt
Copy link
Contributor

askalt commented Jan 26, 2026

cc @Omega359 (I remember you were also interested in placeholders within physical plans).

@Omega359
Copy link
Contributor

cc @Omega359 (I remember you were also interested in placeholders within physical plans).

Yes, I would like to be able to reuse plans - I'll try and find time in the next day or so to review this though I'm not particularly familiar with this area of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate datasource Changes to the datasource crate execution Related to the execution crate optimizer Optimizer rules physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate proto Related to proto crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants