Skip to content

Drop redundant TRY_CONVERT wrapper that broke compat <110 databases#326

Merged
erikdarlingdata merged 1 commit into
devfrom
fix/try-convert-no-op-cast
May 10, 2026
Merged

Drop redundant TRY_CONVERT wrapper that broke compat <110 databases#326
erikdarlingdata merged 1 commit into
devfrom
fix/try-convert-no-op-cast

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Summary

  • sys.query_store_plan.query_plan is nvarchar(max) already — TRY_CONVERT(nvarchar(max), p.query_plan) is a no-op identity cast.
  • The wrapper also broke the query on databases at compatibility level <110: under compat 100 the parser doesn't recognize TRY_CONVERT as a keyword, tries to parse it as a user function call, and chokes on nvarchar(max) as the "argument" with 'nvarchar' is not a recognized built-in function name.
  • Removed three identical occurrences in QueryStoreService.cs (FetchTopPlansAsync, FetchGroupedByQueryHashAsync, FetchGroupedByModuleAsync) and updated the misleading "OUTER APPLY + TRY_CONVERT" comment.

Test plan

  • dotnet build — 0 warnings, 0 errors.
  • planview query-store against a compat-100 database (StackOverflow2010 on SQL 2019) returns plans successfully — same query previously failed with the parser error.

sys.query_store_plan.query_plan is already nvarchar(max), so the
TRY_CONVERT was a no-op identity cast. It also broke the query on
databases at compatibility level <110, where the parser doesn't
recognize TRY_CONVERT and reports 'nvarchar' is not a recognized
built-in function name. Three call sites in QueryStoreService.cs:
FetchTopPlansAsync, FetchGroupedByQueryHashAsync, and
FetchGroupedByModuleAsync. Verified against a compat-100 database.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 5d7105e into dev May 10, 2026
2 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/try-convert-no-op-cast branch May 10, 2026 19:56
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.

1 participant