Blocking a query with ABORT_QUERY_EXECUTION (SQL Server 2025)

In one line: SQL Server 2025’s ABORT_QUERY_EXECUTION Query Store hint makes one query fail every time it runs, without changing the application. It blocks one Query Store query_id, dooms the caller’s transaction, and stops working if Query Store is turned off.

Run it yourself: the scripts that reproduce everything on this page are in sqlserver-demos/abort-query-execution on GitHub.

What you’ll see

  • Error 8778: “Query execution has been aborted because the ABORT_QUERY_EXECUTION hint was specified.”
  • The “blocked” query still running when it’s sent from somewhere else: the same text outside the procedure ran.
  • A rolled-back transaction around the blocked query. XACT_STATE() was -1 with XACT_ABORT on or off.
  • A block that disappears after Query Store is turned off.

Why it happens

The hint is stored in Query Store against one query_id. Query Store identifies a query by its text and its context, so the same text in a procedure and in an ad hoc batch are two queries.

The abort is an error raised when the query starts. Inside a transaction it dooms the transaction, so everything before it in the transaction is rolled back.

Query Store hints are applied by Query Store. In READ_ONLY mode the block held; with Query Store OFF the query ran.

What to do

  • Use it as an emergency brake for one known query, such as the report that takes the server down, while the real fix is made.
  • Find every query_id the application uses for that query (procedure, ad hoc, different SET options) and block each one.
  • Check what calls it. If it runs inside a business transaction, that whole transaction will fail.
  • Remove it with sp_query_store_clear_hints once the query is fixed: the block lifts at once.
  • Test the block again after any Query Store maintenance, especially after turning it off and on.

What doesn’t help

  • Expecting it to block similar queries. It blocks one query_id.
  • Turning Query Store off to reduce overhead while relying on the block.

Check your server

-- SQL Server 2025+: queries blocked with ABORT_QUERY_EXECUTION in this
-- database, and the state of Query Store.
SELECT h.query_id, h.query_hint_text, t.query_sql_text,
       OBJECT_NAME(q.object_id) AS module_name
FROM sys.query_store_query_hints AS h
JOIN sys.query_store_query AS q ON q.query_id = h.query_id
JOIN sys.query_store_query_text AS t ON t.query_text_id = q.query_text_id
WHERE h.query_hint_text LIKE '%ABORT_QUERY_EXECUTION%';

SELECT actual_state_desc, readonly_reason
FROM sys.database_query_store_options;

See it happen

The abort-query-execution demo blocks one query in a procedure and shows:

  • the same text outside the procedure, which still runs
  • what the abort does to a transaction, with XACT_ABORT off and on
  • clearing the hint and setting it again
  • what happens with Query Store READ_ONLY and OFF

On 2022 and earlier it reports SKIPPED.

Related: Query Store plan regressions · blocking chains · wait stats triage

Measured on SQL Server 2025 RTM-CU9-GDR (17.0.5015.4), Linux container. Your numbers will differ; the behaviour shouldn’t.

Part of SQL Server Demos: short explanations of SQL Server problems, each backed by a runnable demo in MarlonRibunal/sqlserver-demos on GitHub. Written with the help of AI; every number comes from running the demo on SQL Server. How this was made.

Verified by MonsterInsights