How to fix Error 12458 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 12458 – Query Store Cannot Force Plan Due to Query Hints

Why This Error Happens

This error occurs because Query Store identifies that the specified query_id has one or more USE HINT or OPTION-level Query Store hints already applied to it via sys.sp_query_store_set_hints. SQL Server’s query optimizer does not allow Query Store to force a specific execution plan on a query while manual query hints are simultaneously active, as this creates a conflict between two competing plan-shaping mechanisms. The engine prioritizes explicit hints over forced plans to avoid unpredictable or contradictory optimizer behavior.

Step-by-Step Resolution Guide

Step 1: Identify Existing Query Store Hints

  • Run the following query against your target database to check for existing hints:
  • SELECT * FROM sys.query_store_query_hints WHERE query_id = <your_query_id>;
  • Note the query_hint_id and the hint text returned for the affected query.

Step 2: Remove the Conflicting Query Hint

  • Execute the system stored procedure to clear hints for the specific query:
  • EXEC sys.sp_query_store_clear_hints @query_id = <your_query_id>;
  • Confirm no rows are returned when re-running the SELECT query from Step 1.

Step 3: Attempt to Force the Plan Again

  • Retry forcing the desired plan using Query Store once hints are cleared:
  • EXEC sys.sp_query_store_force_plan @query_id = <your_query_id>, @plan_id = <your_plan_id>;
  • Verify the command completes without raising Error 12458.

Step 4: Evaluate Hint vs. Forced Plan Strategy

  • Decide whether you actually need the hint or the forced plan, as SQL Server 2025 does not allow both simultaneously on the same query_id.
  • If the hint is required for correctness (e.g., OPTION (RECOMPILE) or MAXDOP), consider re-applying the hint instead of forcing a plan via sys.sp_query_store_set_hints.

Step 5: Validate Query Store Configuration

  • Open SQL Server Management Studio (SSMS) and navigate to Database Properties > Query Store.
  • Ensure “Query Store Capture Mode” and “Operation Mode” are set to READ_WRITE to allow plan forcing operations to persist correctly.

Alternative or Verification Steps

  • Run SELECT * FROM sys.query_store_plan WHERE query_id = <your_query_id> AND is_forced_plan = 1; to confirm the plan is now successfully forced.
  • If forcing still fails, use sys.sp_query_store_set_hints instead of plan forcing to achieve similar performance stability without triggering a conflict.