Type plan_force_flat ids as bigint in @expert_mode parser#772
Merged
erikdarlingdata merged 1 commit intodevfrom Apr 29, 2026
Merged
Type plan_force_flat ids as bigint in @expert_mode parser#772erikdarlingdata merged 1 commit intodevfrom
erikdarlingdata merged 1 commit intodevfrom
Conversation
The string-split path that parses sys.dm_db_tuning_recommendations.details returns regressed_plan_id / recommended_plan_id with a leading space because the upstream REPLACE chain inserts ': ' after every colon. The implicit cast on insert into #tuning_recommendations was silently swallowing the space; #771 added a TRY_CAST in the WHERE clause to survive the same surface. Move the type intent to the projection: TRY_CAST(LTRIM(SUBSTRING(...)) AS bigint) so the columns leave the derived table already typed. Drops the redundant TRY_CAST from the WHERE clause. Doesn't touch the splitting math.
Contributor
|
@erikdarlingdata compiled and executed without error! |
Owner
Author
|
@ClaudioESSilva first time for everything 😛 |
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.
Refs #767, follow-up to #771.
Summary
sys.dm_db_tuning_recommendations.details(the pre-2017-compat fallback) returnsregressed_plan_id/recommended_plan_idwith a leading space — the REPLACE chain inserts': 'after every colon, and the SUBSTRING math doesn't account for it.#tuning_recommendations(defined asbigint NULL) to silently strip the space. PR Fix: error while inserting #tuning_recommendations #771 addedTRY_CAST(... AS bigint)in the WHERE clause to survive the same surface in another spot.TRY_CAST(LTRIM(SUBSTRING(...)) AS bigint)so the derived-table columns leave the parser already typed.TRY_CASTfrom the WHERE clause that Fix: error while inserting #tuning_recommendations #771 added.Credit: @ClaudioESSilva confirmed via repro on Hyperscale that no truncation is happening, just the leading space, and the implicit cast was the silent rescuer.
Test plan
EXEC dbo.sp_QuickieStore @expert_mode = 1, @top = 1against StackOverflow2013 — no conversion error, no 8114/8145.