Skip to content

Type plan_force_flat ids as bigint in @expert_mode parser#772

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/quickiestore-tuning-rec-ltrim
Apr 29, 2026
Merged

Type plan_force_flat ids as bigint in @expert_mode parser#772
erikdarlingdata merged 1 commit intodevfrom
fix/quickiestore-tuning-rec-ltrim

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Refs #767, follow-up to #771.

Summary

  • The string-split path that parses sys.dm_db_tuning_recommendations.details (the pre-2017-compat fallback) returns regressed_plan_id / recommended_plan_id with a leading space — the REPLACE chain inserts ': ' after every colon, and the SUBSTRING math doesn't account for it.
  • The original code relied on the implicit cast on insert into #tuning_recommendations (defined as bigint NULL) to silently strip the space. PR Fix: error while inserting #tuning_recommendations #771 added TRY_CAST(... AS bigint) in the WHERE clause to survive the same surface in another spot.
  • This change moves the type intent to the projection: TRY_CAST(LTRIM(SUBSTRING(...)) AS bigint) so the derived-table columns leave the parser already typed.
  • Drops the now-redundant TRY_CAST from the WHERE clause that Fix: error while inserting #tuning_recommendations #771 added.
  • Does not touch the SUBSTRING/CHARINDEX/IIF math — that lattice is fragile and the leading-space symptom isn't actually a math bug, it's a REPLACE side-effect.

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

  • Installed updated proc on SQL2022.
  • EXEC dbo.sp_QuickieStore @expert_mode = 1, @top = 1 against StackOverflow2013 — no conversion error, no 8114/8145.
  • Repro tenant on Azure SQL DB Hyperscale (per @ravirajch / @ClaudioESSilva) — would appreciate a confirmation run.

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.
@erikdarlingdata erikdarlingdata merged commit 6d902ee into dev Apr 29, 2026
5 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/quickiestore-tuning-rec-ltrim branch April 29, 2026 18:49
@ClaudioESSilva
Copy link
Copy Markdown
Contributor

@erikdarlingdata compiled and executed without error!

@erikdarlingdata
Copy link
Copy Markdown
Owner Author

@ClaudioESSilva first time for everything 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants