How was a plan forced?

If you use Automatic Plan Correction, and thus also Query Store, you may wonder how was a plan forced: manually or automatically with APC?  The type of forced plan is tracked in sys.query_store_plan, and you can use this simple query to determine how a plan was forced:

SELECT p.is_forced_plan, p.plan_forcing_type, p.plan_forcing_type_desc FROM sys.query_store_plan p WHERE p.is_forced_plan = 1; GO

Manual vs. Automatically Forced


Now, this information is a good start, but we can do better if we join to sys.dm_db_tuning_recommendations and the other Query Store view.  The query below is not pretty I know 🙂 but it does the job: