Skip to content

Instantly share code, notes, and snippets.

@mjswart
Created March 22, 2018 16:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mjswart/109a641f35adb7ffcbe46a5f8d4bc259 to your computer and use it in GitHub Desktop.
Save mjswart/109a641f35adb7ffcbe46a5f8d4bc259 to your computer and use it in GitHub Desktop.
Multiple query plans for one query
with cte as
(
select
count(*) as [count],
query_hash,
min(sql_handle) as sql_handle_example
from sys.dm_exec_query_stats
group by query_hash
)
select cte.*, t.text as query_text_example
from cte
cross apply sys.dm_exec_sql_text(sql_handle_example) t
where [count] > 100
order by [count] desc
@hardik23197
Copy link

This is wonderful may i know as i get my query text from here there are 3 queries whose count is like 516,512,420 what steps should i take further now so that query doesn't make plans again and again but reuse the plans
Basically i want to know about what steps should be taken now to optimize there queries whose counts are this much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment