Last active
August 29, 2015 14:06
-
-
Save peschkaj/101e6656da840447ad85 to your computer and use it in GitHub Desktop.
Find the cost and memory grant of queries in the plan cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT qs.query_plan_hash , | |
query_plan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan"; | |
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryHash, 3)) = xs:hexBinary(sql:column("qs.query_hash"))]/@StatementSubTreeCost)', | |
'float') AS cost , | |
query_plan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan"; | |
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryHash, 3)) = xs:hexBinary(sql:column("qs.query_hash"))]/p:QueryPlan/p:MemoryGrantInfo/@SerialDesiredMemory)', 'float') AS serial_desired_memory, | |
query_plan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004 | |
/07/showplan"; | |
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryHash, 3)) = xs:hexBinary(sql:column("qs.query_hash"))]/p:QueryPlan/p:MemoryGrantInfo/@SerialRequiredMemory)', 'float') AS serial_required_memory, | |
* | |
FROM sys.dm_exec_query_stats qs | |
OUTER APPLY sys.dm_exec_query_plan(qs.plan_handle) qp | |
ORDER BY 3 DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated the formatting and stuff.