Microsoft SQL Server Forcing plan for query


Example

SQL Query optimizer will choose the baes possible plan that he can find for some query. If you can find some plan that works optimally for some query, you can force QO to always use that plan using the following stored procedure:

EXEC sp_query_store_unforce_plan @query_id, @plan_id

From this point, QO will always use plan provided for the query.

If you want to remove this binding, you can use the following stored procedure:

EXEC sp_query_store_force_plan @query_id, @plan_id

From this point, QO will again try to find the best plan.