Drop redundant TRY_CONVERT wrapper that broke compat <110 databases#326
Merged
Conversation
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>
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.
Summary
sys.query_store_plan.query_planisnvarchar(max)already —TRY_CONVERT(nvarchar(max), p.query_plan)is a no-op identity cast.TRY_CONVERTas a keyword, tries to parse it as a user function call, and chokes onnvarchar(max)as the "argument" with'nvarchar' is not a recognized built-in function name.QueryStoreService.cs(FetchTopPlansAsync, FetchGroupedByQueryHashAsync, FetchGroupedByModuleAsync) and updated the misleading "OUTER APPLY + TRY_CONVERT" comment.Test plan
dotnet build— 0 warnings, 0 errors.planview query-storeagainst a compat-100 database (StackOverflow2010 on SQL 2019) returns plans successfully — same query previously failed with the parser error.