I force plan in query store. Plan is connected to procedure in a job which run once a day. One of step of this job is just:
EXEC [schema].[LoadData]
Procedure [schema].[LoadData] looks like
TRUNCATE TABLE [schema].[Data];
INSERT INTO [schema].[Data]
([A1],
[A2],
.
.
.,
[A49]
)
SELECT *
,CURRENT_TIMESTAMP AS [Insert TimeStamp]
FROM [schema].[View]
where view is a view which contains some CTEs and use synonyms (connect to tables from different databases).
In query store execution looks like :
To test If forcing plan is working I follow below steps:
- Run query in SSMS ->
EXEC [schema].[LoadData]
- Above execution was treated as different query so did not see anything new in Query Store for query = 7
- DBA create a new job just with step which is running query ->
EXEC [schema].[LoadData]
- Run of above newly created job cause Plan Id = 29800
Question why execution plan was not forced ? In column "forced plan failure count" is 0.