15. Januar 2010 17:21
16. Januar 2010 14:32
-- MS Dynamics NAV Sustained Engineering Team
-- http://blogs.msdn.com/microsoft_dynamics_nav_sustained_engineering/archive/2008/10/14/simple-query-to-check-the-recent-performance-history-ii-now-including-query-plan-information.aspx
-- PLEASE READ THE BLOG BEFORE USING THE FEATURE!
SELECT TOP 100
SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset END
- qs.statement_start_offset)/2) + 1) as statement_text,
execution_count,
case
when execution_count = 0 then null
else total_logical_reads/execution_count
end as avg_logical_reads,
last_logical_reads,
min_logical_reads,
max_logical_reads,
plan_handle,
ph.query_plan,
-- Query Plan Information
case when
ph.query_plan.exist('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtCursor/ns:CursorPlan/@CursorRequestedType)[1]') = 0
then '' else
ph.query_plan.value('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtCursor/ns:CursorPlan/@CursorRequestedType)[1]','nvarchar (max)')
end as cursor_type
-- Missing Indexes
,case when ph.query_plan.exist('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtSimple/ns:QueryPlan/ns:MissingIndexes/ns:MissingIndexGroup)[1]') = 0
then ''
else ph.query_plan.value('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtSimple/ns:QueryPlan/ns:MissingIndexes/ns:MissingIndexGroup/@Impact)[1]','nvarchar (max)')
end as missing_index_impact,
case when ph.query_plan.exist('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtSimple/ns:QueryPlan/ns:MissingIndexes/ns:MissingIndexGroup/ns:MissingIndex/@Table)[1]') = 0
then ''
else ph.query_plan.value('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtSimple/ns:QueryPlan/ns:MissingIndexes/ns:MissingIndexGroup/ns:MissingIndex/@Table)[1]','nvarchar(max)')
end as missing_index_table,
case when ph.query_plan.exist('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtSimple/ns:QueryPlan/ns:MissingIndexes/ns:MissingIndexGroup/ns:MissingIndex/ns:ColumnGroup/ns:Column/@Name)[1]') = 0
then ''
else ph.query_plan.value('declare namespace ns="http://schemas.microsoft.com/sqlserver/2004/07/showplan";(/ns:ShowPlanXML/ns:BatchSequence/ns:Batch/ns:Statements/ns:StmtSimple/ns:QueryPlan/ns:MissingIndexes/ns:MissingIndexGroup/ns:MissingIndex/ns:ColumnGroup/ns:Column/@Name)[1]','nvarchar(max)')
end as missing_index_field
FROM sys.dm_exec_query_stats as qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) as ph
ORDER BY max_logical_reads DESC
declare @p1 int
set @p1=1073741837
declare @p5 int
set @p5=12290 -- >> Dynamic Cursor
declare @p6 int
set @p6=8193
exec sp_cursorprepare @p1 output,N'@P1 tinyint,@P2 varchar(20)',N'SELECT *,DATALENGTH("Outlook Calendar StoreID") FROM "Navision"."dbo"."CRONUS 403$Salesperson_Purchaser" WITH (READUNCOMMITTED) WHERE (("Enable Synchronization"=@P1)) AND (("Navision User ID"=@P2)) ORDER BY "Code" ',1,@p5 output,@p6 output
select @p1, @p5, @p6
19. Februar 2010 23:54
20. Februar 2010 11:23
SELECT qs.[session_id], si.[login_name], si.[host_name], si.[program_name], [cursor_id], [properties], [creation_time], [is_open], qs.[reads],
SUBSTRING(qt.[text],qs.[statement_start_offset]/2+1, (case when qs.[statement_end_offset] = -1
then len(convert(nvarchar(max), qt.[text])) * 2
else qs.[statement_end_offset] end -qs.[statement_start_offset])/2)
as [statement]
FROM sys.dm_exec_cursors(0) qs -- 0 = all sessions; or use specific SPID
CROSS APPLY sys.dm_exec_sql_text(qs.[sql_handle]) as qt
LEFT JOIN sys.dm_exec_sessions si on si.[session_id] = qs.[session_id]
ORDER BY [reads] DESC
20. Februar 2010 11:51
20. Februar 2010 12:22
walterotto hat geschrieben:...
Was hat MS eigentlich gesagt zu diesem thema, wenn es an die schon herangetragen wurde?
20. Februar 2010 18:29
20. Februar 2010 18:41
walterotto hat geschrieben:danke. Und wie löst du solche Probleme? Es kann doch nicht die Lösung sein, Indizes zu hauf anzulegen (die wollen ja bei Schreibtransaktionen auch gepflegt werden)
20. Februar 2010 19:53
20. Februar 2010 21:54
walterotto hat geschrieben:mhm ok, und wenn du queries wie diesen: Select timestamp, No-, usw from Database$Item WHERE (("DecimalField">0)) AND (("Search Description" LIKE '%WAT%' AND "Search Description" LIKE '%28%')) AND "No_"<'23456789012345' ORDER BY "No_" DESC OPTION (RECOMPILE)
liest, der so oder so ähnlich permanent losgelassen wird legst du dann einen Index an mit: Search Description,DecimalFeld und included coloumns No_ an?
CREATE INDEX myidx01 ON [dbo].[Company$Item]
("Search Description", "No_")
INCLUDE
("DecimalField")
20. Februar 2010 22:30
21. Februar 2010 09:38
21. Februar 2010 20:04
23. Februar 2010 14:09
23. Februar 2010 15:12
25. Februar 2010 22:27