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.
In SQL 2022 RTM when plan sensitive parameter optimization is in use, the query text for statements will be appended with (at least) one of two strings that contain the ObjectID of the parent stored procedure:
This PR strips out spaces around quotes and equals and checks the query text for "OPTION(PLAN PER VALUE(ObjectID=", then pulls the corresponding name from the plan cache if it contains the database id and object id.
You can test this on the StackOverflow2013 medium size database. The code below is a modified version of the test code from PSPO: How SQL Server 2022 Tries to Fix Parameter Sniffing
Then compare the output after applying the PR.