Guides

Query Store forced plan not used: find plan forcing failures (NO_INDEX)

By Scott Coffey, Senior Database Developer. Updated 2026-11-24.

You forced a good plan in Query Store to stop a regression. Weeks later the query is slow again, Query Store still shows the plan as forced, and nobody got an error. The query ran fine; it just ran with a different plan.

That is how plan forcing fails. When SQL Server compiles a query that has a forced plan and cannot reproduce that plan, it records the failure and compiles a normal plan instead. The application sees no error. The most common cause is that an index the forced plan uses was dropped or renamed. In our test on SQL Server 2022, renaming the index with sp_rename broke forcing exactly as dropping it did.

Step 1: check that Query Store is on and read-write

Query Store is per database, so run these queries in the database that owns the query:

SELECT actual_state_desc, desired_state_desc, readonly_reason,
       current_storage_size_mb, max_storage_size_mb
FROM sys.database_query_store_options;

If actual_state_desc differs from desired_state_desc, Query Store changed state on its own, and readonly_reason says why. A store that has gone READ_ONLY because it is full stops capturing new runtime data, which makes the next steps harder to read.

Step 2: list forced plans with their failure count and reason

SELECT p.plan_id, q.query_id,
       OBJECT_NAME(q.object_id) AS object_name,
       p.plan_forcing_type_desc,
       p.force_failure_count,
       p.last_force_failure_reason_desc,
       p.last_execution_time,
       LEFT(qt.query_sql_text, 80) AS query_text
FROM sys.query_store_plan AS p
JOIN sys.query_store_query AS q       ON q.query_id = p.query_id
JOIN sys.query_store_query_text AS qt ON qt.query_text_id = q.query_text_id
WHERE p.is_forced_plan = 1
ORDER BY p.force_failure_count DESC;

Any row with force_failure_count above zero has failed at least once. last_force_failure_reason_desc gives the reason. NO_INDEX means an index in the plan no longer exists under that name. NO_PLAN means the optimizer could not produce the forced plan shape at all, often after a schema change. plan_forcing_type_desc shows MANUAL for plans a person forced and AUTO for plans forced by automatic tuning (FORCE_LAST_GOOD_PLAN).

Two details from testing. The counter goes up once per compilation, not per execution, so a count of 1 can mean every call since the last recompile ran the wrong plan. And the counter and reason do not reset when you fix the cause. They cleared only when the plan was unforced and forced again. So a nonzero count tells you forcing failed at some point, not that it is failing now. Step 3 tells you that.

Step 3: confirm which plan actually ran

DECLARE @query_id bigint = 4;  -- from Step 2

SELECT p.plan_id, p.is_forced_plan,
       SUM(rs.count_executions) AS executions,
       MAX(rs.last_execution_time) AS last_run,
       CAST(AVG(rs.avg_logical_io_reads) AS bigint) AS avg_reads
FROM sys.query_store_plan AS p
LEFT JOIN sys.query_store_runtime_stats AS rs ON rs.plan_id = p.plan_id
WHERE p.query_id = @query_id
GROUP BY p.plan_id, p.is_forced_plan
ORDER BY p.plan_id;

If a plan with is_forced_plan = 0 has the most recent last_run, forcing is failing now. In our test, after the index was dropped, the replacement plan scanned the table and averaged several thousand logical reads per call, against about 140 for the forced seek plan. Times in Query Store are stored with a UTC offset, so compare them in the same zone.

Step 4: find the index the forced plan needs

The forced plan's XML lists every index it touches. Compare those names against sys.indexes:

WITH XMLNAMESPACES (DEFAULT 'http://schemas.microsoft.com/sqlserver/2004/07/showplan'),
plan_indexes AS (
    SELECT DISTINCT p.plan_id,
           ix.n.value('@Schema', 'sysname') AS schema_name,
           ix.n.value('@Table', 'sysname')  AS table_name,
           ix.n.value('@Index', 'sysname')  AS index_name
    FROM sys.query_store_plan AS p
    CROSS APPLY (SELECT TRY_CAST(p.query_plan AS xml)) AS x(plan_xml)
    CROSS APPLY x.plan_xml.nodes('//Object[@Index]') AS ix(n)
    WHERE p.is_forced_plan = 1
)
SELECT pi.plan_id, pi.schema_name, pi.table_name, pi.index_name,
       CASE WHEN i.index_id IS NULL THEN 'MISSING' ELSE 'ok' END AS index_status
FROM plan_indexes AS pi
LEFT JOIN sys.indexes AS i
       ON i.object_id = OBJECT_ID(pi.schema_name + N'.' + pi.table_name)
      AND i.name = PARSENAME(pi.index_name, 1)
ORDER BY index_status, pi.plan_id;

A MISSING row is your cause. Look at system-generated names too, such as PK__Orders__C3905BAF.... If a constraint is dropped and recreated without an explicit name, it gets a new generated name, and any forced plan that used the old one fails with NO_INDEX.

Step 5: restore the index or unforce and re-force a current plan

If the index was renamed or dropped by mistake, put it back under the original name. Then recompile so the next call picks up the forced plan:

CREATE INDEX IX_Orders_CustomerID ON dbo.Orders (CustomerID);
EXEC sys.sp_recompile N'dbo.GetCustomerOrders';

Re-run Step 3 after the next call. In our test the forced plan was used again immediately. If the index change was intentional, the old forced plan cannot come back. Unforce it, let the query compile, check the new plans' runtime stats, and force a current plan only if one is clearly better:

EXEC sys.sp_query_store_unforce_plan @query_id = 4, @plan_id = 4;
-- later, after reviewing runtime stats:
-- EXEC sys.sp_query_store_force_plan @query_id = 4, @plan_id = 28;

Treat both as production changes: note the query_id and plan_id, and keep the unforce statement as your rollback.

Step 6: catch the next failure

Forcing failures do not reach the application or the error log, so watch for them on purpose. The query_store_plan_forcing_failed Extended Event fires on each failure and includes the underlying error. In our test it reported error 8712: Index 'QsTest.dbo.Orders.IX_Orders_CustomerID', specified in the USE PLAN hint, does not exist.

CREATE EVENT SESSION QS_ForcingFailed ON SERVER
ADD EVENT qds.query_store_plan_forcing_failed
    (ACTION (sqlserver.database_name, sqlserver.sql_text))
ADD TARGET package0.ring_buffer;
ALTER EVENT SESSION QS_ForcingFailed ON SERVER STATE = START;

SELECT x.e.value('@timestamp', 'datetime2') AS event_time_utc,
       x.e.value('(data[@name="error_number"]/value)[1]', 'int') AS error_number,
       x.e.value('(data[@name="message"]/value)[1]', 'nvarchar(400)') AS message,
       x.e.value('(data[@name="plan_id"]/value)[1]', 'bigint') AS plan_id,
       x.e.value('(data[@name="query_id"]/value)[1]', 'bigint') AS query_id,
       x.e.value('(action[@name="database_name"]/value)[1]', 'sysname') AS database_name
FROM sys.dm_xe_session_targets AS t
JOIN sys.dm_xe_sessions AS s ON s.address = t.event_session_address
CROSS APPLY (SELECT CAST(t.target_data AS xml)) AS d(x)
CROSS APPLY d.x.nodes('RingBufferTarget/event') AS x(e)
WHERE s.name = N'QS_ForcingFailed';

A ring buffer is lost on restart. For a lasting record, use an event_file target. Or schedule a check as a T-SQL step in a SQL Server Agent job, in each database that forces plans, that fails when a non-forced plan of the same query ran more recently than the forced one:

IF EXISTS (SELECT 1
           FROM sys.query_store_plan AS fp
           JOIN sys.query_store_plan AS op
             ON op.query_id = fp.query_id AND op.is_forced_plan = 0
           WHERE fp.is_forced_plan = 1
             AND op.last_execution_time > fp.last_execution_time)
    THROW 50001, N'A forced Query Store plan is not being used. Run the Step 2 and Step 3 queries.', 1;

The job fails, and its failure notification reaches a person. The SQL Rig agent-job-create-template.sql builds that job disabled and in dry-run mode first, and the Agent job failure guide covers reading its history.

The best prevention is to run the Step 4 query before any index is dropped or renamed. The pack's unused-indexes.sql and task-index-review.md already refuse to drop indexes automatically and output commented DROP statements for review; add "not referenced by a forced plan" to that review. For the query side, expensive-queries.sql Section B reads the same Query Store views to rank the top queries by CPU, duration, or reads, which is usually how a regressed query is found in the first place. If you need to read Query Store as a non-sysadmin, the least-privilege diagnostics guide covers the permissions.