If a stored procedure is erratic, see if it recompiles, look into parameter sniffing, others have already talked about it (with good links), I will provide links later What to do if a specific query is slow, do the steps below. If your specific query is not slow on another system, do these steps on both slow and not slow systems 1. Duration, CPU & IO info it is essential to provide CPU as well duration if you complain only about duration, we cannot tell whether it is an expensive execution plan or blocking, which has completely different resolution paths. Do the following from Query Analyzer or SQL Management Studio SET STATISTICS IO ON GO SET STATISTICS TIME ON GO Your SQL query or stored procedure call GO SET STATISTICS TIME OFF GO SET STATISTICS IO OFF GO the output should look like: SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 0 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 0 ms. (1104 row(s) affected) Table 'M1'. Scan count 2, logical reads 12, physical reads 0, read-ahead reads 1. SQL Server Execution Times: CPU time = 0 ms, elapsed time = 5 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 0 ms. 2a. Execution Plan, if on SQL Server 2000 do the following to generate the estimated execution plan any temp tables used must be created first in order to generate the estimated plan CREATE TABLE #xx (if there are any temp tables) GO SET SHOWPLAN_ALL ON GO Your SQL query or stored procedure call GO SET SHOWPLAN_ALL OFF GO DROP TABLE #xx (if required above) copy the results into a MS Excel spreadsheet then save the file as XML open the XML with notepad, paste the contents in its own reply box example in next reply box it might also help to compare estimated plans with empty and populated temp tables get the actual plan, ie, actual row counts SET STATISTICS PROFILE ON GO Your SQL query or stored procedure call GO SET STATISTICS PROFILE OFF GO 2b. Execution Plan, if on SQL Server 2005 generate the Displayed Estimated Execution Plan (ctrl-L) from SQL Server Management Studio -> Query -> Display .. save the execution plan as XML (*.sqlplan extension) right click on the graphical plan, 1st option (Save Execution Plan as) open the XML plan (*.sqlplan file) with Notepad paste the contents in its own reply box generate the actual execution plan, Include Actual Execution Plan (Ctrl-M ?) save as XML open with notepad paste SQL 2000 - Excel XML and SQL 2005 XML plans below is a simple SQL 2000 SHOWPLAN_ALL copied first to Excel, then saved as XML file it can be copied back into a XML file, that we can open in Excel and examine it without difficulty that a direct copy to here involves next, after Luis, is a SQL 2005 plan saved as .sqlplan then opened with notepad, and pasted here we can put the contents back into a .sqlplan and actually examine the graphical plan if you want us to help you help us see what your problem is special handling for large Excel plan files as I just found out in the SQL 2000 forum section if the Excel XML or sqlplan file is very large it is not practical to post it here so email the person helping you, and send it compressed (for Excel, keep it in native .xls format, not need for XML) 3. SQL Clone and statistics-only database for more extensive remote performance troubleshooting work my site www.qdpma.com has a utility to create a statistics-only database for SQL Server 2000 for SQL Server 2005 right click the database from Management Studio -> Tasks -> Generate Scripts after selecting the database -> Choose Script Options -> General -> Script Statistics i think the option is statistics with histogram you could just provide the DDL for the tables involved, with indexes look into the following command example DBCC SHOW_STATISTICS(N'[AdventureWorks].[Sales].[Store]', N'AK_Store_rowguid') WITH STATS_STREAM the Option: STATS_STREAM sends the raw binary of the statistics the command below applies the statistics to a newly generated table UPDATE STATISTICS [HumanResources].[Employee]([AK_Employee_LoginID]) WITH STATS_STREAM = long binary value, ROWCOUNT = 290, PAGECOUNT = 3
<?xml version="1.0"?><br /><?mso-application progid="Excel.Sheet"?><br /><Workbook xmlns="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt='' />ffice<img src='/community/emoticons/emotion-7.gif' alt=':s' />preadsheet"<br /> xmlns<img src='/community/emoticons/emotion-3.gif' alt='' />="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt='' />ffice<img src='/community/emoticons/emotion-3.gif' alt='' />ffice"<br /> xmlns<img src='/community/emoticons/emotion-12.gif' alt=':x' />="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt='' />ffice:excel"<br /> xmlns<img src='/community/emoticons/emotion-7.gif' alt=':s' />s="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt='' />ffice<img src='/community/emoticons/emotion-7.gif' alt=':s' />preadsheet"<br /> xmlns:html="http://www.w3.org/TR/REC-html40"><br /> <DocumentProperties xmlns="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt='' />ffice<img src='/community/emoticons/emotion-3.gif' alt='' />ffice"><br /> <Author>Joe Chang</Author><br /> <LastAuthor>Joe Chang</LastAuthor><br /> <Created>2007-02-17T03:08:50Z</Created><br /> <Company>QDPMA</Company><br /> <Version>11.8122</Version><br /> </DocumentProperties><br /> <ExcelWorkbook xmlns="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt='' />ffice:excel"><br /> <WindowHeight>9720</WindowHeight><br /> <WindowWidth>5595</WindowWidth><br /> <WindowTopX>480</WindowTopX><br /> <WindowTopY>15</WindowTopY><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectStructure>False</ProtectStructure><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectWindows>False</ProtectWindows><br /> </ExcelWorkbook><br /> <Styles><br /> <Style ss:ID="Default" ss:Name="Normal"><br /> <Alignment ss:Vertical="Bottom"/><br /> <Borders/><br /> <Font/><br /> <Interior/><br /> <NumberFormat/><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotection/><br /> </Style><br /> <Style ss:ID="s21"><br /> <NumberFormat ss:Format="Scientific"/><br /> </Style><br /> </Styles><br /> <Worksheet ss:Name="Sheet1"><br /> <Table ss:ExpandedColumnCount="18" ss:ExpandedRowCount="2" x:FullColumns="1"<br /> x:FullRows="1"><br /> <Row><br /> <Cell><Data ss:Type="String">SELECT * FROM M1</Data></Cell><br /> <Cell><Data ss:Type="Number">1</Data></Cell><br /> <Cell><Data ss:Type="Number">1</Data></Cell><br /> <Cell><Data ss:Type="Number">0</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="Number">1</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="Number">1104</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell ss<img src='/community/emoticons/emotion-7.gif' alt=':S' />tyleID="s21"><Data ss:Type="Number">4.2575101999999997E-2</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="String">SELECT</Data></Cell><br /> <Cell><Data ss:Type="Number">0</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> </Row><br /> <Row><br /> <Cell><Data ss:Type="String"> |#45;-Table Scan(OBJECT<img src='/community/emoticons/emotion-6.gif' alt='' />[MetArt].[dbo].[M1]))</Data></Cell><br /> <Cell><Data ss:Type="Number">1</Data></Cell><br /> <Cell><Data ss:Type="Number">3</Data></Cell><br /> <Cell><Data ss:Type="Number">1</Data></Cell><br /> <Cell><Data ss:Type="String">Table Scan</Data></Cell><br /> <Cell><Data ss:Type="String">Table Scan</Data></Cell><br /> <Cell><Data ss:Type="String">OBJECT<img src='/community/emoticons/emotion-6.gif' alt='' />[MetArt].[dbo].[M1])</Data></Cell><br /> <Cell><Data ss:Type="String">[M1]. Code: </Data></Cell><br /> <Cell><Data ss:Type="Number">1104</Data></Cell><br /> <Cell ss<img src='/community/emoticons/emotion-7.gif' alt=':S' />tyleID="s21"><Data ss:Type="Number">4.1282203000000003E-2</Data></Cell><br /> <Cell ss<img src='/community/emoticons/emotion-7.gif' alt=':S' />tyleID="s21"><Data ss:Type="Number">1.2928999E-3</Data></Cell><br /> <Cell><Data ss:Type="Number">266</Data></Cell><br /> <Cell ss<img src='/community/emoticons/emotion-7.gif' alt=':S' />tyleID="s21"><Data ss:Type="Number">4.2575101999999997E-2</Data></Cell><br /> <Cell><Data ss:Type="String">[M1].[Code]</Data></Cell><br /> <Cell><Data ss:Type="String">NULL</Data></Cell><br /> <Cell><Data ss:Type="String"><img src='/community/emoticons/emotion-4.gif' alt=';P' />LAN_ROW</Data></Cell><br /> <Cell><Data ss:Type="Number">0</Data></Cell><br /> <Cell><Data ss:Type="Number">1</Data></Cell><br /> </Row><br /> </Table><br /> <WorksheetOptions xmlns="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt=':o' />ffice:excel"><br /> <Selected/><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />anes><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />ane><br /> <Number>3</Number><br /> <ActiveRow>8</ActiveRow><br /> <ActiveCol>13</ActiveCol><br /> </Pane><br /> </Panes><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectObjects>False</ProtectObjects><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectScenarios>False</ProtectScenarios><br /> </WorksheetOptions><br /> </Worksheet><br /> <Worksheet ss:Name="Sheet2"><br /> <WorksheetOptions xmlns="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt=':o' />ffice:excel"><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectObjects>False</ProtectObjects><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectScenarios>False</ProtectScenarios><br /> </WorksheetOptions><br /> </Worksheet><br /> <Worksheet ss:Name="Sheet3"><br /> <WorksheetOptions xmlns="urn<img src='/community/emoticons/emotion-7.gif' alt=':s' />chemas-microsoft-com<img src='/community/emoticons/emotion-3.gif' alt=':o' />ffice:excel"><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectObjects>False</ProtectObjects><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />rotectScenarios>False</ProtectScenarios><br /> </WorksheetOptions><br /> </Worksheet><br /></Workbook><br />
I changed this to Sticky. If moderators don't think so, let me know. Luis Martin Moderator SQL-Server-Performance.com All in Love is Fair Stevie Wonder All postings are provided “AS IS†with no warranties for accuracy.
<?xml version="1.0" encoding="utf-16"?><br /><ShowPlanXML xmlns<img src='/community/emoticons/emotion-12.gif' alt=':x' />si="http://www.w3.org/2001/XMLSchema-instance" xmlns<img src='/community/emoticons/emotion-12.gif' alt=':x' />sd="http://www.w3.org/2001/XMLSchema" Version="1.0" Build="9.00.2153.00" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan"><br /> <BatchSequence><br /> <Batch><br /> <Statements><br /> <StmtSimple StatementCompId="1" StatementEstRows="1" StatementId="1" StatementOptmLevel="TRIVIAL" StatementSubTreeCost="0.0032831" StatementText="SELECT ID2 FROM C2 WHERE ID1 = 1#xD;#xA;#xD;#xA;" StatementType="SELECT"><br /> <StatementSetOptions ANSI_NULLS="false" ANSI_PADDING="false" ANSI_WARNINGS="false" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="false" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="false" /><br /> <QueryPlan CachedPlanSize="9"><br /> <RelOp AvgRowSize="11" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="0" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0032831"><br /> <OutputList><br /> <ColumnReference Database="[Test2]" Schema="[dbo]" Table="[C2]" Column="ID2" /><br /> </OutputList><br /> <IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" NoExpandHint="false"><br /> <DefinedValues><br /> <DefinedValue><br /> <ColumnReference Database="[Test2]" Schema="[dbo]" Table="[C2]" Column="ID2" /><br /> </DefinedValue><br /> </DefinedValues><br /> <Object Database="[Test2]" Schema="[dbo]" Table="[C2]" Index="[PK_C2]" /><br /> <SeekPredicates><br /> <SeekPredicate><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />refix ScanType="EQ"><br /> <RangeColumns><br /> <ColumnReference Database="[Test2]" Schema="[dbo]" Table="[C2]" Column="ID1" /><br /> </RangeColumns><br /> <RangeExpressions><br /> <ScalarOperator ScalarString="CONVERT_IMPLICIT(int,[@1],0)"><br /> <Convert DataType="int" Style="0" Implicit="true"><br /> <ScalarOperator><br /> <Identifier><br /> <ColumnReference Column="@1" /><br /> </Identifier><br /> </ScalarOperator><br /> </Convert><br /> </ScalarOperator><br /> </RangeExpressions><br /> </Prefix><br /> </SeekPredicate><br /> </SeekPredicates><br /> </IndexScan><br /> </RelOp><br /> <<img src='/community/emoticons/emotion-4.gif' alt=';P' />arameterList><br /> <ColumnReference Column="@1" ParameterCompiledValue="(1)" /><br /> </ParameterList><br /> </QueryPlan><br /> </StmtSimple><br /> </Statements><br /> </Batch><br /> </BatchSequence><br /></ShowPlanXML>