Skip to content

Instantly share code, notes, and snippets.

@JosiahSiegel
Created October 17, 2024 20:58
Show Gist options
  • Save JosiahSiegel/9a760130e722c153c01819124518887a to your computer and use it in GitHub Desktop.
Save JosiahSiegel/9a760130e722c153c01819124518887a to your computer and use it in GitHub Desktop.
Force hint on query in query store
-- get query id
SELECT
q.query_id,
qt.query_sql_text
FROM sys.query_store_query_text qt
INNER JOIN sys.query_store_query q ON
qt.query_text_id = q.query_text_id
WHERE query_sql_text like N'%select column from table%'
GO
-- set query hint
EXEC sys.sp_query_store_set_hints @query_id= 888, @query_hints = N'OPTION(USE HINT(''ENABLE_PARALLEL_PLAN_PREFERENCE''))';
-- view query hints
SELECT *
FROM sys.query_store_query_hints
-- remove query hints
EXEC sys.sp_query_store_clear_hints @query_id = 888;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment