Skip to content

Support reusing the physical plan in prepared statements #26706

Description

@nuno-faria

Is your feature request related to a problem or challenge?

Building and optimizing the physical plan can be relatively expensive when we execute small queries. Currently, DataFusion's prepared statements only reuse the logical plan.
Image

In a proof of concept, I found that we can improve the performance of small queries in >3x if we just reuse the physical plan.
Image

This was done in a hacky way that first created the physical plan using placeholder arguments and at runtime replaced nodes like DataSourceExec and FilterExec with the passed arguments.

Describe the solution you'd like

For a clean implementation, I think we need the following:

  • Build ExecutionPlan from queries with placeholder values.
  • Add a ExecutionPlan::set_placeholder (or similar) method that is implemented by every operator that uses placeholder values, changing only what is necessary and returning a new plan that can be consumed.

This would certainly be a breaking change.

Describe alternatives you've considered

Hacky downstream implementation.

Additional context

Related:

Willingness to contribute

None

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions