Skip to content

Restore OPTION(RECOMPILE) to plan_correction's payload: #2760 removed it on an unverified compile-cost claim #2766

Closed

Description

@erikdarlingdata

PR #2762 (issue #2760) removed OPTION(RECOMPILE) from both statements in PlanCorrectionCollector.PayloadBodyText. The justification was that ~4,237ms of avg CPU observed on multi-45/Demo was compile cost being paid per database, per server, every cycle.

That attribution was never verified

It was inferred from a telemetry signature (high CPU against 381 logical reads and 18 rows), not measured. Nothing ever isolated compile time from execution time.

The actual cost was the live Query Store catalog-view joins in the final SELECT — which PR #2765 then replaced with staged temps, completing the sp_QuickieStore pattern. Staging fixed it. Removing RECOMPILE never addressed it.

Measured compile cost, post-#2765

SET STATISTICS TIME ON against SQL Server 2025, current dev payload text:

statement compile CPU
1 50 ms
2 13 ms
3 6 ms
4 4 ms
5 11 ms
total 84 ms

Clean, no errors. Measured on a Rosetta-emulated container, so 84ms is a ceiling — real hardware compiles faster.

Why RECOMPILE belongs here

Plan cache hygiene, not performance. This body runs once per database, per server, every cycle. Caching a plan for each of those accumulates cache bulk across the fleet for plans nobody reuses. RECOMPILE keeps them out of cache entirely, and at ~84ms total that costs effectively nothing.

Fix

Restore OPTION(RECOMPILE) to the two statements #2762 removed it from, in the post-#2765 query shape. Everything #2765 introduced (the four #pm_plan_correction_* staging temps, the EXISTS-gated SELECT INTOs, the final SELECT joining temps rather than catalog views) stays exactly as-is. Rewrite the doc comment to state the plan-cache-hygiene reason and correct the record, and replace the PayloadBody_DoesNotCarryRecompile test with one pinning that RECOMPILE is present, so this does not get removed again to "save" compile time.

Activity

  1. erikdarlingdata commented on Sep 3, 2026

    @erikdarlingdata
    OwnerAuthor

    Resolved by #2767, merged to dev. Closing manually: Fixes #N only fires on the dev->main release merge, so completed work otherwise sits open until release.

  2. added a commit that references this issue on Sep 10, 2026
    7b1eef0
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions