Carrying Baggage Through Query Plans: Why Wide Queries Get Heavy
I see this pattern repeatedly: a “wide” query that returns many columns and less than 100k rows runs slowly. SQL Server gets slow when it …
Read MoreNope.
At least, not right now.
I started thinking about this when I noticed that the sys.sp_query_store_unforce_plan requires you to specify both a @query_id and a @plan_id.
If there’s only ever one plan that can be forced for a query, why would I need to specify the @plan_id?
I’ve got no insider knowledge on this, I just started thinking about it.
It will only force the plan for the most recent statement you ran.
If I have a query with id=4 which has two plans with plan ids 3, and 5, and I run this TSQL all at once:
EXEC sys.sp_query_store_force_plan @query_id = 4, @plan_id= 3;
GO
EXEC sys.sp_query_store_force_plan @query_id = 4, @plan_id= 5;
GOFor a brief moment after the first statement runs, @plan_id 3 will be forced.
After both statements complete, only @plan_id 5 will be forced.
There can only be one!
We might have a parameterized query that we want multiple plans for, depending on how it’s executed.
The query is executed with @parameter_x = null, I want Plan A.
Otherwise I want Plan B.
Could be nifty!
Perhaps it’s required to specify the @plan_id in case I make a mistake, and specify the wrong query id for a plan id, and it wants to make sure I really have it right?
It’s possible, but doesn’t seem super likely to me. I’d rather optimistically hope that some day plan forcing will become even more flexible.
Will it ever happen? I have no idea :smile:
Copyright (c) 2025, Catalyze SQL, LLC; all rights reserved. Opinions expressed on this site are solely those of Kendra Little of Catalyze SQL, LLC. Content policy: Short excerpts of blog posts (3 sentences) may be republished, but longer excerpts and artwork cannot be shared without explicit permission.