Skip to content

Avoid rerunning logical optimizer rules on unchanged plans #22411

Open

Description

@Dandandan

Describe the problem

The logical optimizer reruns every rule on each optimizer pass, even when a rule already returned Transformed::no for the current logical plan and no later rule has changed that plan before the next invocation of the same rule.

This adds avoidable planning cost on queries that need multiple optimizer passes. ClickBench queries are a good example: many converge only after a second pass, but most rules in that pass see the exact same input they already reported as unchanged.

Proposed improvement

Track a cheap logical plan version during optimization. Increment the version whenever a rule reports transformed = true. If a rule previously returned Transformed::no at the current plan version, skip rerunning it until some rule changes the plan.

This keeps the existing optimizer fixed-point behavior while avoiding repeated no-op work for unchanged rule inputs.

Local measurement

Using a temporary local ClickBench logical planning probe over all 51 ClickBench queries, 30 iterations:

  • Baseline optimizer-only: 607.259 us/query
  • Patched optimizer-only: 409.473 us/query and 423.034 us/query
  • Baseline parse/analyze/optimize: 1001.498 us/query
  • Patched parse/analyze/optimize: 822.877 us/query and 844.032 us/query

The patch preserves optimizer behavior and only skips rules after a prior Transformed::no for the same unchanged plan version.

Activity

  1. saadtajwar commented on Jun 30, 2026

    @saadtajwar
    Contributor

    Hey @Dandandan , saw you had a PR for this earlier - is this still open/needing to be worked on? Happy to help if so :)

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions