Repository navigation
Clarify the separate compilation when SET options change - #10499
Open
Rudi Bruchez (rudi-bruchez) wants to merge 1 commit into
Open
Rudi Bruchez (rudi-bruchez) wants to merge 1 commit into
Rudi Bruchez (rudi-bruchez) wants to merge 1 commit into
Conversation
prmerger-automator
Bot
requested review from
Van To (VanMSFT),
William Assaf MSFT (WilliamDAssafMSFT) and
Derek Wilson (thesqlsith)
November 14, 2026 20:01
Contributor
|
Rudi Bruchez (@rudi-bruchez) : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change. |
Contributor
|
Rudi Bruchez (@rudi-bruchez) : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change. |
Contributor
|
Learn Build status updates of commit a4b84d7: ✅ Validation status: passed
For more details, please refer to the build report. |
Contributor
|
Can you review the proposed changes? Due to the upcoming conference, all merging and publishing is on hold until the morning of November 17. Important: When the changes are ready for publication, adding a #label:"aq-pr-triaged" |
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.
What's wrong
In "Cache multiple plans for the same query", the
SET ANSI_DEFAULTSexample explains the secondplan_handleas an execution-context reinitialization and says that both entries refer to the same plan.The existing plan remains cached, and SQL Server compiles and caches a separate plan for the other SET options. Matching
query_hashandquery_plan_hashvalues describe the same query and plan shape across these separate cached plans. The absence of a statement-level recompilation event doesn't mean that no new compilation occurred.The wording was already present before 9a6541d9de2 (February 2020); that edit expanded the explanation without changing this distinction.
Evidence
Fresh Linux containers, Developer editions. The reproduction follows the documented stored-procedure example: execute
usp_SalesByCustomertwice withANSI_DEFAULTS ON, then once withOFF. It uses a smallSales.Customerstable in a fresh database instead of requiring the WideWorldImporters sample.AUTO_CLOSE OFF, Query Store off; compatibility levels 150, 160 and 170 respectively. Diagnostic queries restore ANSI options after the three procedure calls so XML methods can read the event target.On each version, the plans have different
plan_handleandmemory_object_addressvalues,set_options251 and 266, and matchingquery_hashandquery_plan_hash. Bothsql_statement_post_compileevents haveis_recompile = falseandrecompile_cause = 19(Not a recompile). Events are selected by the procedure's object ID or collected object name; recompilations of the diagnostic batches aren't counted.Reproduction (run with sqlcmd, with permissions to create the test database and event session):
The assertions verify two cached entries, matching fingerprints, three executions in total, two compilation events, two cache insertions, and no statement-recompilation event for the procedure. The script drops the event session and database when the checks pass.
Change
Replaces only the nested bullet explaining the new plan handle: separate compilation, the original plan remaining cached, and the meaning of the matching fingerprints. No changes to the example or its output.
Not tested on Windows, Azure SQL Database, Azure SQL Managed Instance or Fabric.