August 8, 2015 at 4:03 am
We are facing issues in our Coding application and database.Our coding application having front end asp.net 3.5 and back end SQL Server 2008 R2.Based on project requirement we doing fields setting for coding.We facing issues of coding application & database getting more time (hang) during the coding process. Below mentioned testing observation
TestBatchRecordsCoding CompletedQC CompletedUsersFieldsRecord Saving TimeRemarks
1Batch143743743715-2042 - 5 SecNo Issue
2Batch288288288215-2042 - 5 SecNo Issue
3Batch314261426142615-2052 - 5 SecNo Issue
4Batch45761125253115-2012 - 5 SecNo Issue
5Batch5167544835715-2052 - 5 SecNo Issue
6Batch624724724715-2042 - 5 SecNo Issue
7Batch766566566515-2042 - 5 SecNo Issue
8Batch822422422415-202First 2-5 Sec After 200 takes 5 - 10 SecNo Issue
9Batch979025025015-202First 2-5 Sec After 200 takes 5 - 10 SecHanging start
10Batch1057328227315-201First 2-5 Sec After 200 takes 5 - 10 SecHanging start after 250 records
We run the trace and found sp FetchDocumentID taking more time. We execute the sp in SQL Server by selecting Executing plan and not found any missing Indexes.
Below mention Sp structure
CREATE PROCEDURE [dbo].[FetchDocumentID]
(@i_UserId int,
@i_ProjectId int)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Error INT = 0
, @ErrorLine INT
, @ErrorDesc NVARCHAR(1000)
, @Message NVARCHAR(1000)
, @ProcName NVARCHAR(128) = N'Project.dbo.FetchDocumentID.procedure.sql'
, @VALUES VARCHAR(128)
, @UserDetailId BIGINT
, @RoleName VARCHAR(150)
BEGIN TRY
CREATE TAble #Document (Id INT IDENTITY(1,1) PRIMARY KEY
,FieldId INT
, DocumentID INT
, Rejected INT )
IF NOT EXISTS(SELECT UA.AccessId
FROM dbo.UserAccess UA
WHERE UA.ProjectMasterId = @i_ProjectId
AND UA.AccessId = 4
)
BEGIN
INSERT #Document (DocumentID,Rejected )
SELECT TOP 1 [DM].[DocumentId],1
FROM [dbo].[DataMaster] DM WITH(NOLOCK)
LEFT JOIN [dbo].[DocumentMaster] DC WITH(NOLOCK)
ON [DM].[DocumentId] = [DC].[DocumentMasterId]
WHERE [DM].[IsCoded] = 1
AND [DM].[IsRejected]=1
AND [DM].CoderId = @i_UserId
AND [DC].[ProjectId] = @i_ProjectId
AND (([DC].[IsLocked] = 1 and [DC].[Status] = @i_UserId)
OR ([DC].[IsLocked] = 0 AND [DC].[IsChecked] = 1 ))
GROUP BY [DM].[DocumentId]
ORDER BY [DM].[DocumentId]
END
IF NOT EXISTS(SELECT * FROM #Document)
BEGIN
INSERT #Document (FieldId
,DocumentID)
SELECT A.FieldId
, B.DocumentMasterId
FROM dbo.UserAccess A WITH(NOLOCK)
INNER JOIN dbo.DocumentMaster B WITH(NOLOCK)
ON A.ProjectMasterId = b.ProjectId
WHERE A.[UserMasterId] =@i_UserId
AND A.ProjectMasterId=@i_ProjectId
AND (B.IsLocked = 0 OR (B.IsLocked = 1 AND B.[STATUS] = @i_UserId) )
CREATE TABLE #temp1(DocID INT )
INSERT #temp1
SELECT TOP 1 A.DocumentID
FROM #Document A
LEFT JOIN DataMaster b
ON a.FieldId = b.FieldId
AND a.DocumentID = b.DocumentId
WHERE b.DocumentId IS NULL
GROUP BY A.DocumentID
ORDER BY a.DocumentID
if EXISTS(select * from #temp1)
Begin
UPDATE [dbo].[DocumentMaster]
SET [IsLocked] = 1
,[LockedTime] = SYSDATETIME()
,[Status] = @i_UserId
WHERE [DocumentMasterId] = (select DocID from #temp1)
End
SELECT TOP 1 A.DocumentID
, 0 AS Rejected
FROM #Document A
LEFT JOIN DataMaster b
ON a.FieldId = b.FieldId
AND a.DocumentID = b.DocumentId
WHERE b.DocumentId IS NULL
GROUP BY A.DocumentID
ORDER BY a.DocumentID
END
ELSE
BEGIN
UPDATE [dbo].[DocumentMaster]
SET [IsLocked] = 1
,[LockedTime] = SYSDATETIME()
,[Status] = @i_UserId
WHERE [DocumentMasterId] = (select DocumentID from #Document)
SELECT A.DocumentID,Rejected
FROM #Document A
ORDER BY A.DocumentID
END
END TRY
BEGIN CATCH
SELECT @Error = ERROR_NUMBER()
, @ErrorLine = ERROR_LINE()
, @ErrorDesc = ERROR_MESSAGE()
SET @Message = N'Application of the procedure, %s, failed at line, %d, due to error no. %d.: %s'
RAISERROR(@Message, 11, 1, @ProcName, @ErrorLine, @Error, @ErrorDesc) WITH NOWAIT
END CATCH
END_THIS:
RETURN (@Error)
END--FetchDocumentID
Can anyone help me to resolve hang issue.
Thank you in advance
August 10, 2015 at 5:04 am
Can you post the execution plan? On an initial read through the procedure I didn't spot any immediate issues, so it's a question of understanding how each of those actions is getting resolved within the procedure.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 10, 2015 at 6:27 am
Here is the Execution Plan
<?xml version="1.0" encoding="utf-16"?>
<ShowPlanXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.1" Build="10.50.6000.34" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementCompId="7" StatementEstRows="1" StatementId="1" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.00328854" StatementText="IF NOT EXISTS(SELECT UA.AccessId FROM dbo.UserAccess UA WHERE UA.ProjectMasterId = @i_ProjectId AND UA.AccessId = 4 ) " StatementType="COND WITH QUERY" QueryHash="0xA74AB84D9722F10E" QueryPlanHash="0xA7021E71AEE11389">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" CachedPlanSize="16" CompileTime="3" CompileCPU="3" CompileMemory="152">
<RelOp AvgRowSize="11" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="0" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00328854">
<OutputList>
<ColumnReference Column="Expr1002" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1002" />
<ScalarOperator ScalarString="CASE WHEN [Expr1003] IS NULL THEN (1) ELSE (0) END">
<IF>
<Condition>
<ScalarOperator>
<Compare CompareOp="IS">
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1003" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="9" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Left Semi Join" NodeId="1" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.00328844">
<OutputList>
<ColumnReference Column="Expr1003" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1003" />
</DefinedValue>
</DefinedValues>
<ProbeColumn>
<ColumnReference Column="Expr1003" />
</ProbeColumn>
<RelOp AvgRowSize="9" EstimateCPU="1.157E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Constant Scan" NodeId="2" Parallel="false" PhysicalOp="Constant Scan" EstimatedTotalSubtreeCost="1.157E-06">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<ConstantScan />
</RelOp>
<RelOp AvgRowSize="9" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Index Seek" NodeId="3" Parallel="false" PhysicalOp="Index Seek" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="352">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues />
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Index="[INX00001]" Alias="[UA]" IndexKind="NonClustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[UA]" Column="ProjectMasterId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[UA]" Column="AccessId" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="CONVERT_IMPLICIT(bigint,[@i_ProjectId],0)">
<Convert DataType="bigint" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_ProjectId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
<ScalarOperator ScalarString="(4)">
<Const ConstValue="(4)" />
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
</ComputeScalar>
</RelOp>
<ParameterList>
<ColumnReference Column="@i_ProjectId" ParameterCompiledValue="(158)" ParameterRuntimeValue="(158)" />
</ParameterList>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="8" StatementEstRows="1" StatementId="2" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.0279351" StatementText="INSERT #Document (DocumentID,Rejected ) SELECT TOP 1 [DM].[DocumentId],1 FROM [dbo].[DataMaster] DM WITH(NOLOCK) LEFT JOIN [dbo].[DocumentMaster] DC WITH(NOLOCK) ON [DM].[DocumentId] = [DC].[DocumentMasterId] WHERE [DM].[IsCoded] = 1 AND [DM].[IsRejected]=1 AND [DM].CoderId = @i_UserId AND [DC].[ProjectId] = @i_ProjectId AND (([DC].[IsLocked] = 1 and [DC].[Status] = @i_UserId) OR ([DC].[IsLocked] = 0 AND [DC].[IsChecked] = 1 )) GROUP BY [DM].[DocumentId] ORDER BY [DM].[DocumentId] " StatementType="INSERT" QueryHash="0x66355D87178B8DA3" QueryPlanHash="0x0BA6CF19C429EC4A">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" MemoryGrant="1024" CachedPlanSize="40" CompileTime="13" CompileCPU="13" CompileMemory="648">
<RelOp AvgRowSize="9" EstimateCPU="1E-06" EstimateIO="0.01" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Insert" NodeId="0" Parallel="false" PhysicalOp="Clustered Index Insert" EstimatedTotalSubtreeCost="0.0279351">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Update DMLRequestSort="false">
<Object Database="[tempdb]" Schema="[dbo]" Table="[#Document]" Index="[PK__#Documen__3214EC070FE2393C]" />
<SetPredicate>
<ScalarOperator ScalarString="[#Document].[DocumentID] = [Expr1009],[#Document].[Rejected] = [Expr1007],[#Document].[Id] = [Expr1008],[#Document].[FieldId] = NULL">
<ScalarExpressionList>
<ScalarOperator>
<MultipleAssign>
<Assign>
<ColumnReference Table="[#Document]" Column="DocumentID" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1009" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Table="[#Document]" Column="Rejected" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1007" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Table="[#Document]" Column="Id" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1008" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Table="[#Document]" Column="FieldId" />
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Assign>
</MultipleAssign>
</ScalarOperator>
</ScalarExpressionList>
</ScalarOperator>
</SetPredicate>
<RelOp AvgRowSize="19" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="1" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0179341">
<OutputList>
<ColumnReference Column="Expr1007" />
<ColumnReference Column="Expr1008" />
<ColumnReference Column="Expr1009" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1009" />
<ScalarOperator ScalarString="CONVERT_IMPLICIT(int,[SH_Semper].[dbo].[DataMaster].[DocumentId] as [DM].[DocumentId],0)">
<Convert DataType="int" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="23" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="2" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.017934">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
<ColumnReference Column="Expr1007" />
<ColumnReference Column="Expr1008" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1008" />
<ScalarOperator ScalarString="getidentity((234483914),(2),N'#Document')">
<Intrinsic FunctionName="getidentity">
<ScalarOperator>
<Const ConstValue="(234483914)" />
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(2)" />
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="N'#Document'" />
</ScalarOperator>
</Intrinsic>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="19" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="3" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0179339">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
<ColumnReference Column="Expr1007" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1007" />
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="15" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Top" NodeId="4" Parallel="false" PhysicalOp="Top" EstimatedTotalSubtreeCost="0.0179338">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Top RowCount="false" IsPercent="false" WithTies="false">
<TopExpression>
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
</TopExpression>
<RelOp AvgRowSize="15" EstimateCPU="0.000100015" EstimateIO="0.0112613" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Distinct Sort" NodeId="5" Parallel="false" PhysicalOp="Sort" EstimatedTotalSubtreeCost="0.0179337">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</OutputList>
<MemoryFractions Input="1" Output="1" />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRebinds="1" ActualRewinds="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Sort Distinct="true">
<OrderBy>
<OrderByColumn Ascending="true">
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</OrderByColumn>
</OrderBy>
<RelOp AvgRowSize="15" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Inner Join" NodeId="6" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.00657246">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<OuterReferences>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</OuterReferences>
<RelOp AvgRowSize="15" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Index Seek" NodeId="7" Parallel="false" PhysicalOp="Index Seek" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="1094">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</DefinedValue>
</DefinedValues>
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Index="[INX00002]" Alias="[DM]" IndexKind="NonClustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="IsCoded" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="IsRejected" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="CoderId" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
<ScalarOperator ScalarString="[@i_UserId]">
<Identifier>
<ColumnReference Column="@i_UserId" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
<RelOp AvgRowSize="20" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="8" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="2717">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="0" ActualExecutions="0" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues />
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Index="[PK_DocumentInfo]" Alias="[DC]" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="[DC]" Column="DocumentMasterId" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[DataMaster].[DocumentId] as [DM].[DocumentId]">
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="[DM]" Column="DocumentId" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
<Predicate>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[DocumentMaster].[ProjectId] as [DC].[ProjectId]=CONVERT_IMPLICIT(bigint,[@i_ProjectId],0) AND ([SH_Semper].[dbo].[DocumentMaster].[IsLocked] as [DC].[IsLocked]=(1) AND [SH_Semper].[dbo].[DocumentMaster].[Status] as [DC].[Status]=[@i_UserId] OR [SH_Semper].[dbo].[DocumentMaster].[IsLocked] as [DC].[IsLocked]=(0) AND [SH_Semper].[dbo].[DocumentMaster].[IsChecked] as [DC].[IsChecked]=(1))">
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="[DC]" Column="ProjectId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="ConstExpr1010">
<ScalarOperator>
<Convert DataType="bigint" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_ProjectId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
</ColumnReference>
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Logical Operation="OR">
<ScalarOperator>
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="[DC]" Column="IsLocked" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="[DC]" Column="Status" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_UserId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
</Logical>
</ScalarOperator>
<ScalarOperator>
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="[DC]" Column="IsLocked" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="[DC]" Column="IsChecked" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Predicate>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
</Sort>
</RelOp>
</Top>
</RelOp>
</ComputeScalar>
</RelOp>
</ComputeScalar>
</RelOp>
</ComputeScalar>
</RelOp>
</Update>
</RelOp>
<ParameterList>
<ColumnReference Column="@i_ProjectId" ParameterCompiledValue="(158)" ParameterRuntimeValue="(158)" />
<ColumnReference Column="@i_UserId" ParameterCompiledValue="(294)" ParameterRuntimeValue="(294)" />
</ParameterList>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="10" StatementEstRows="1" StatementId="3" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.00328854" StatementText="IF NOT EXISTS(SELECT * FROM #Document) " StatementType="COND WITH QUERY" QueryHash="0xAF0B76B73C0A6A78" QueryPlanHash="0xBCB0B4CCB60404A4">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" CachedPlanSize="16" CompileTime="0" CompileCPU="0" CompileMemory="112">
<RelOp AvgRowSize="11" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="0" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00328854">
<OutputList>
<ColumnReference Column="Expr1004" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1004" />
<ScalarOperator ScalarString="CASE WHEN [Expr1005] IS NULL THEN (1) ELSE (0) END">
<IF>
<Condition>
<ScalarOperator>
<Compare CompareOp="IS">
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1005" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="9" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Left Semi Join" NodeId="1" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.00328844">
<OutputList>
<ColumnReference Column="Expr1005" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1005" />
</DefinedValue>
</DefinedValues>
<ProbeColumn>
<ColumnReference Column="Expr1005" />
</ProbeColumn>
<RelOp AvgRowSize="9" EstimateCPU="1.157E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Constant Scan" NodeId="2" Parallel="false" PhysicalOp="Constant Scan" EstimatedTotalSubtreeCost="1.157E-06">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<ConstantScan />
</RelOp>
<RelOp AvgRowSize="9" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Scan" NodeId="3" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues />
<Object Database="[tempdb]" Schema="[dbo]" Table="[#Document]" Index="[PK__#Documen__3214EC070FE2393C]" />
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
</ComputeScalar>
</RelOp>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="11" StatementEstRows="1100" StatementId="4" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.0383449" StatementText="INSERT #Document (FieldId ,DocumentID) SELECT A.FieldId , B.DocumentMasterId FROM dbo.UserAccess A WITH(NOLOCK) INNER JOIN dbo.DocumentMaster B WITH(NOLOCK) ON A.ProjectMasterId = b.ProjectId WHERE A.[UserMasterId] =@i_UserId AND A.ProjectMasterId=@i_ProjectId AND (B.IsLocked = 0 OR (B.IsLocked = 1 AND B.[STATUS] = @i_UserId) ) " StatementType="INSERT" QueryHash="0x07D8ED14A91048BA" QueryPlanHash="0xBA8AA0F4B3AEC552">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" CachedPlanSize="32" CompileTime="4" CompileCPU="4" CompileMemory="392">
<RelOp AvgRowSize="9" EstimateCPU="0.0011" EstimateIO="0.0204816" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1100" LogicalOp="Insert" NodeId="0" Parallel="false" PhysicalOp="Clustered Index Insert" EstimatedTotalSubtreeCost="0.0383449">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Update DMLRequestSort="true">
<Object Database="[tempdb]" Schema="[dbo]" Table="[#Document]" Index="[PK__#Documen__3214EC070FE2393C]" />
<SetPredicate>
<ScalarOperator ScalarString="[#Document].[FieldId] = [Expr1008],[#Document].[DocumentID] = [Expr1009],[#Document].[Id] = [Expr1007],[#Document].[Rejected] = NULL">
<ScalarExpressionList>
<ScalarOperator>
<MultipleAssign>
<Assign>
<ColumnReference Table="[#Document]" Column="FieldId" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1008" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Table="[#Document]" Column="DocumentID" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1009" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Table="[#Document]" Column="Id" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1007" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Table="[#Document]" Column="Rejected" />
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Assign>
</MultipleAssign>
</ScalarOperator>
</ScalarExpressionList>
</ScalarOperator>
</SetPredicate>
<RelOp AvgRowSize="19" EstimateCPU="0.00011" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1100" LogicalOp="Compute Scalar" NodeId="1" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0167633">
<OutputList>
<ColumnReference Column="Expr1007" />
<ColumnReference Column="Expr1008" />
<ColumnReference Column="Expr1009" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1008" />
<ScalarOperator ScalarString="CONVERT_IMPLICIT(int,[SH_Semper].[dbo].[UserAccess].[FieldId] as [A].[FieldId],0)">
<Convert DataType="int" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="FieldId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
</DefinedValue>
<DefinedValue>
<ColumnReference Column="Expr1009" />
<ScalarOperator ScalarString="CONVERT_IMPLICIT(int,[SH_Semper].[dbo].[DocumentMaster].[DocumentMasterId] as .[DocumentMasterId],0)">
<Convert DataType="int" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="DocumentMasterId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="27" EstimateCPU="0.00011" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1100" LogicalOp="Compute Scalar" NodeId="2" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0166533">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="FieldId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="DocumentMasterId" />
<ColumnReference Column="Expr1007" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1007" />
<ScalarOperator ScalarString="getidentity((234483914),(2),N'#Document')">
<Intrinsic FunctionName="getidentity">
<ScalarOperator>
<Const ConstValue="(234483914)" />
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(2)" />
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="N'#Document'" />
</ScalarOperator>
</Intrinsic>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="23" EstimateCPU="0.00011" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1100" LogicalOp="Top" NodeId="3" Parallel="false" PhysicalOp="Top" EstimatedTotalSubtreeCost="0.0165433">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="FieldId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="DocumentMasterId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Top RowCount="true" IsPercent="false" WithTies="false">
<TopExpression>
<ScalarOperator ScalarString="(0)">
<Const ConstValue="(0)" />
</ScalarOperator>
</TopExpression>
<RelOp AvgRowSize="23" EstimateCPU="0.004598" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1100" LogicalOp="Inner Join" NodeId="4" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.0164333">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="FieldId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="DocumentMasterId" />
</OutputList>
<Warnings NoJoinPredicate="true" />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<RelOp AvgRowSize="27" EstimateCPU="0.0005442" EstimateIO="0.00386574" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="2" LogicalOp="Clustered Index Scan" NodeId="5" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.00440994" TableCardinality="352">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="FieldId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="2" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="FieldId" />
</DefinedValue>
</DefinedValues>
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Index="[PK_UserAccess]" Alias="[A]" IndexKind="Clustered" />
<Predicate>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[UserAccess].[ProjectMasterId] as [A].[ProjectMasterId]=CONVERT_IMPLICIT(bigint,[@i_ProjectId],0) AND [SH_Semper].[dbo].[UserAccess].[UserMasterId] as [A].[UserMasterId]=[@i_UserId]">
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="ProjectMasterId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="ConstExpr1010">
<ScalarOperator>
<Convert DataType="bigint" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_ProjectId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
</ColumnReference>
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[UserAccess]" Alias="[A]" Column="UserMasterId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_UserId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Predicate>
</IndexScan>
</RelOp>
<RelOp AvgRowSize="20" EstimateCPU="0.000762" EstimateIO="0.00418363" EstimateRebinds="0" EstimateRewinds="1" EstimateRows="550" LogicalOp="Index Seek" NodeId="6" Parallel="false" PhysicalOp="Index Seek" EstimatedTotalSubtreeCost="0.00570763" TableCardinality="2717">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="DocumentMasterId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="2" ActualExecutions="2" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="DocumentMasterId" />
</DefinedValue>
</DefinedValues>
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Index="[INX00003]" Alias="" IndexKind="NonClustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="ProjectId" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="CONVERT_IMPLICIT(bigint,[@i_ProjectId],0)">
<Identifier>
<ColumnReference Column="ConstExpr1010">
<ScalarOperator>
<Convert DataType="bigint" Style="0" Implicit="true">
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_ProjectId" />
</Identifier>
</ScalarOperator>
</Convert>
</ScalarOperator>
</ColumnReference>
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
<Predicate>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[DocumentMaster].[IsLocked] as .[IsLocked]=(0) OR [SH_Semper].[dbo].[DocumentMaster].[IsLocked] as .[IsLocked]=(1) AND [SH_Semper].[dbo].[DocumentMaster].[Status] as .[Status]=[@i_UserId]">
<Logical Operation="OR">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="IsLocked" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="IsLocked" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Alias="" Column="Status" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_UserId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Predicate>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
</Top>
</RelOp>
</ComputeScalar>
</RelOp>
</ComputeScalar>
</RelOp>
</Update>
</RelOp>
<ParameterList>
<ColumnReference Column="@i_ProjectId" ParameterCompiledValue="(158)" ParameterRuntimeValue="(158)" />
<ColumnReference Column="@i_UserId" ParameterCompiledValue="(294)" ParameterRuntimeValue="(294)" />
</ParameterList>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="13" StatementEstRows="1" StatementId="5" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.0698195" StatementText="INSERT #temp1 SELECT TOP 1 A.DocumentID FROM #Document A LEFT JOIN DataMaster b ON a.FieldId = b.FieldId AND a.DocumentID = b.DocumentId WHERE b.DocumentId IS NULL GROUP BY A.DocumentID ORDER BY a.DocumentID " StatementType="INSERT" QueryHash="0xC773D13C6EFEF02F" QueryPlanHash="0xD70B59EC1B3C87B4">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" MemoryGrant="1024" CachedPlanSize="24" CompileTime="18" CompileCPU="18" CompileMemory="408">
<RelOp AvgRowSize="9" EstimateCPU="1E-06" EstimateIO="0.01" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Insert" NodeId="0" Parallel="false" PhysicalOp="Table Insert" EstimatedTotalSubtreeCost="0.0698195">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Update DMLRequestSort="false">
<Object Database="[tempdb]" Schema="[dbo]" Table="[#temp1]" />
<SetPredicate>
<ScalarOperator ScalarString="[#temp1].[DocID] = #document.[DocumentID] as [A].[DocumentID]">
<ScalarExpressionList>
<ScalarOperator>
<MultipleAssign>
<Assign>
<ColumnReference Table="[#temp1]" Column="DocID" />
<ScalarOperator>
<Identifier>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</Identifier>
</ScalarOperator>
</Assign>
</MultipleAssign>
</ScalarOperator>
</ScalarExpressionList>
</ScalarOperator>
</SetPredicate>
<RelOp AvgRowSize="11" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Top" NodeId="1" Parallel="false" PhysicalOp="Top" EstimatedTotalSubtreeCost="0.0598185">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Top RowCount="false" IsPercent="false" WithTies="false">
<TopExpression>
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
</TopExpression>
<RelOp AvgRowSize="11" EstimateCPU="0.000502934" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Aggregate" NodeId="2" Parallel="false" PhysicalOp="Stream Aggregate" EstimatedTotalSubtreeCost="0.0598184">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="0" ActualExecutions="1" />
</RunTimeInformation>
<StreamAggregate>
<DefinedValues />
<GroupBy>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</GroupBy>
<RelOp AvgRowSize="11" EstimateCPU="0.000609525" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1.28484" LogicalOp="Filter" NodeId="3" Parallel="false" PhysicalOp="Filter" EstimatedTotalSubtreeCost="0.0598173">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="2" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Filter StartupExpression="false">
<RelOp AvgRowSize="19" EstimateCPU="4.98448" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="2.88447" LogicalOp="Left Outer Join" NodeId="4" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.0598159">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<Predicate>
<ScalarOperator ScalarString="#document.[FieldId] as [A].[FieldId]=[SH_Semper].[dbo].[DataMaster].[FieldId] as .[FieldId] AND #document.[DocumentID] as [A].[DocumentID]=[SH_Semper].[dbo].[DataMaster].[DocumentId] as .[DocumentId]">
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="FieldId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Predicate>
<RelOp AvgRowSize="15" EstimateCPU="0.0172572" EstimateIO="0.0112613" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="2.47595" LogicalOp="Sort" NodeId="5" Parallel="false" PhysicalOp="Sort" EstimatedTotalSubtreeCost="0.0352217">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<MemoryFractions Input="1" Output="1" />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRebinds="1" ActualRewinds="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Sort Distinct="false">
<OrderBy>
<OrderByColumn Ascending="true">
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OrderByColumn>
</OrderBy>
<RelOp AvgRowSize="15" EstimateCPU="0.001356" EstimateIO="0.00534722" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1090" LogicalOp="Clustered Index Scan" NodeId="6" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.00670322" TableCardinality="1090">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
</DefinedValue>
<DefinedValue>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</DefinedValue>
</DefinedValues>
<Object Database="[tempdb]" Schema="[dbo]" Table="[#Document]" Index="[PK__#Documen__3214EC070FE2393C]" Alias="[A]" />
</IndexScan>
</RelOp>
</Sort>
</RelOp>
<RelOp AvgRowSize="23" EstimateCPU="0.0012819" EstimateIO="0.0135739" EstimateRebinds="0" EstimateRewinds="2.47368" EstimateRows="1094" LogicalOp="Clustered Index Scan" NodeId="7" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.0180268" TableCardinality="1094">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="FieldId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1192460" ActualEndOfScans="1090" ActualExecutions="1090" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="FieldId" />
</DefinedValue>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</DefinedValue>
</DefinedValues>
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Index="[PK_DataMaster]" Alias="" IndexKind="Clustered" />
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
<Predicate>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[DataMaster].[DocumentId] as .[DocumentId] IS NULL">
<Compare CompareOp="IS">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Predicate>
</Filter>
</RelOp>
</StreamAggregate>
</RelOp>
</Top>
</RelOp>
</Update>
</RelOp>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="14" StatementEstRows="1" StatementId="6" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.00328854" StatementText="if EXISTS(select * from #temp1) " StatementType="COND WITH QUERY" QueryHash="0x1A42CB848023B8D5" QueryPlanHash="0xD64ABA727B7D8D4F">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" CachedPlanSize="16" CompileTime="0" CompileCPU="0" CompileMemory="104">
<RelOp AvgRowSize="11" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="0" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00328854">
<OutputList>
<ColumnReference Column="Expr1005" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1005" />
<ScalarOperator ScalarString="CASE WHEN [Expr1006] THEN (1) ELSE (0) END">
<IF>
<Condition>
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1006" />
</Identifier>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="9" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Left Semi Join" NodeId="1" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.00328844">
<OutputList>
<ColumnReference Column="Expr1006" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1006" />
</DefinedValue>
</DefinedValues>
<ProbeColumn>
<ColumnReference Column="Expr1006" />
</ProbeColumn>
<RelOp AvgRowSize="9" EstimateCPU="1.157E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Constant Scan" NodeId="2" Parallel="false" PhysicalOp="Constant Scan" EstimatedTotalSubtreeCost="1.157E-06">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<ConstantScan />
</RelOp>
<RelOp AvgRowSize="9" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Table Scan" NodeId="3" Parallel="false" PhysicalOp="Table Scan" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="1">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="0" ActualExecutions="1" />
</RunTimeInformation>
<TableScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues />
<Object Database="[tempdb]" Schema="[dbo]" Table="[#temp1]" />
</TableScan>
</RelOp>
</NestedLoops>
</RelOp>
</ComputeScalar>
</RelOp>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="15" StatementEstRows="1" StatementId="7" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.0265743" StatementText="UPDATE [dbo].[DocumentMaster] SET [IsLocked] = 1 ,[LockedTime] = SYSDATETIME() ,[Status] = @i_UserId WHERE [DocumentMasterId] = (select DocID from #temp1) " StatementType="UPDATE" QueryHash="0x2254A6C248573DBF" QueryPlanHash="0x608DE4A7E6988DF7">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" CachedPlanSize="40" CompileTime="5" CompileCPU="5" CompileMemory="416">
<RelOp AvgRowSize="9" EstimateCPU="2E-06" EstimateIO="0.02" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Update" NodeId="1" Parallel="false" PhysicalOp="Clustered Index Update" EstimatedTotalSubtreeCost="0.0265743">
<OutputList />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Update DMLRequestSort="false">
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Index="[PK_DocumentInfo]" IndexKind="Clustered" />
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Index="[INX00003]" IndexKind="NonClustered" />
<SetPredicate>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[DocumentMaster].[IsLocked] = [Expr1008],[SH_Semper].[dbo].[DocumentMaster].[LockedTime] = [Expr1009],[SH_Semper].[dbo].[DocumentMaster].[Status] = [@i_UserId]">
<ScalarExpressionList>
<ScalarOperator>
<MultipleAssign>
<Assign>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="IsLocked" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1008" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="LockedTime" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1009" />
</Identifier>
</ScalarOperator>
</Assign>
<Assign>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="Status" />
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_UserId" />
</Identifier>
</ScalarOperator>
</Assign>
</MultipleAssign>
</ScalarOperator>
</ScalarExpressionList>
</ScalarOperator>
</SetPredicate>
<RelOp AvgRowSize="28" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="2" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00657226">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
<ColumnReference Column="Expr1008" />
<ColumnReference Column="Expr1009" />
<ColumnReference Column="Expr1025" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1025" />
<ScalarOperator ScalarString="[Expr1025]">
<Identifier>
<ColumnReference Column="Expr1025" />
</Identifier>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="28" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="3" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00657226">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
<ColumnReference Column="Expr1008" />
<ColumnReference Column="Expr1009" />
<ColumnReference Column="Expr1025" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1025" />
<ScalarOperator ScalarString="CASE WHEN [Expr1013] AND [Expr1015] THEN (0) ELSE (1) END">
<IF>
<Condition>
<ScalarOperator>
<Logical Operation="AND">
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1013" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1015" />
</Identifier>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="24" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="4" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00657216">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
<ColumnReference Column="Expr1008" />
<ColumnReference Column="Expr1009" />
<ColumnReference Column="Expr1013" />
<ColumnReference Column="Expr1015" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1008" />
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
</DefinedValue>
<DefinedValue>
<ColumnReference Column="Expr1009" />
<ScalarOperator ScalarString="CONVERT_IMPLICIT(datetime,sysdatetime(),0)">
<Identifier>
<ColumnReference Column="ConstExpr1016">
<ScalarOperator>
<Convert DataType="datetime" Style="0" Implicit="true">
<ScalarOperator>
<Intrinsic FunctionName="sysdatetime" />
</ScalarOperator>
</Convert>
</ScalarOperator>
</ColumnReference>
</Identifier>
</ScalarOperator>
</DefinedValue>
<DefinedValue>
<ColumnReference Column="Expr1015" />
<ScalarOperator ScalarString="CASE WHEN [SH_Semper].[dbo].[DocumentMaster].[Status] = [@i_UserId] THEN (1) ELSE (0) END">
<IF>
<Condition>
<ScalarOperator>
<Compare CompareOp="BINARY IS">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="Status" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Column="@i_UserId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="20" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="5" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.00657206">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="Status" />
<ColumnReference Column="Expr1013" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1013" />
<ScalarOperator ScalarString="CASE WHEN [SH_Semper].[dbo].[DocumentMaster].[IsLocked] = (1) THEN (1) ELSE (0) END">
<IF>
<Condition>
<ScalarOperator>
<Compare CompareOp="BINARY IS">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="IsLocked" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="20" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Inner Join" NodeId="6" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.00657196">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="IsLocked" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="Status" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<OuterReferences>
<ColumnReference Column="Expr1018" />
</OuterReferences>
<RelOp AvgRowSize="11" EstimateCPU="4.8E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Assert" NodeId="7" Parallel="false" PhysicalOp="Assert" EstimatedTotalSubtreeCost="0.00328468">
<OutputList>
<ColumnReference Column="Expr1018" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Assert StartupExpression="false">
<RelOp AvgRowSize="19" EstimateCPU="1.1E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Aggregate" NodeId="8" Parallel="false" PhysicalOp="Stream Aggregate" EstimatedTotalSubtreeCost="0.0032842">
<OutputList>
<ColumnReference Column="Expr1017" />
<ColumnReference Column="Expr1018" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<StreamAggregate>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1017" />
<ScalarOperator ScalarString="Count(*)">
<Aggregate AggType="countstar" Distinct="false" />
</ScalarOperator>
</DefinedValue>
<DefinedValue>
<ColumnReference Column="Expr1018" />
<ScalarOperator ScalarString="ANY([#temp1].[DocID])">
<Aggregate AggType="ANY" Distinct="false">
<ScalarOperator>
<Identifier>
<ColumnReference Table="[#temp1]" Column="DocID" />
</Identifier>
</ScalarOperator>
</Aggregate>
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="11" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Table Scan" NodeId="9" Parallel="false" PhysicalOp="Table Scan" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="1">
<OutputList>
<ColumnReference Table="[#temp1]" Column="DocID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<TableScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Table="[#temp1]" Column="DocID" />
</DefinedValue>
</DefinedValues>
<Object Database="[tempdb]" Schema="[dbo]" Table="[#temp1]" />
</TableScan>
</RelOp>
</StreamAggregate>
</RelOp>
<Predicate>
<ScalarOperator ScalarString="CASE WHEN [Expr1017]>(1) THEN (0) ELSE NULL END">
<IF>
<Condition>
<ScalarOperator>
<Compare CompareOp="GT">
<ScalarOperator>
<Identifier>
<ColumnReference Column="Expr1017" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="(1)" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Condition>
<Then>
<ScalarOperator>
<Const ConstValue="(0)" />
</ScalarOperator>
</Then>
<Else>
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Else>
</IF>
</ScalarOperator>
</Predicate>
</Assert>
</RelOp>
<RelOp AvgRowSize="20" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="14" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="2717">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="IsLocked" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="Status" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="0" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
</DefinedValue>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="IsLocked" />
</DefinedValue>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="Status" />
</DefinedValue>
</DefinedValues>
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Index="[PK_DocumentInfo]" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DocumentMaster]" Column="DocumentMasterId" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[Expr1018]">
<Identifier>
<ColumnReference Column="Expr1018" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
</ComputeScalar>
</RelOp>
</ComputeScalar>
</RelOp>
</ComputeScalar>
</RelOp>
</ComputeScalar>
</RelOp>
</Update>
</RelOp>
<ParameterList>
<ColumnReference Column="@i_UserId" ParameterCompiledValue="(294)" ParameterRuntimeValue="(294)" />
</ParameterList>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="17" StatementEstRows="1" StatementId="8" StatementOptmLevel="FULL" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" StatementSubTreeCost="0.0598186" StatementText="SELECT TOP 1 A.DocumentID , 0 AS Rejected FROM #Document A LEFT JOIN DataMaster b ON a.FieldId = b.FieldId AND a.DocumentID = b.DocumentId WHERE b.DocumentId IS NULL GROUP BY A.DocumentID ORDER BY a.DocumentID " StatementType="SELECT" QueryHash="0x55DFB58FC45265FA" QueryPlanHash="0xA0A3FEF33F72D1FB">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="1" MemoryGrant="1024" CachedPlanSize="24" CompileTime="9" CompileCPU="9" CompileMemory="392">
<RelOp AvgRowSize="15" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Compute Scalar" NodeId="0" Parallel="false" PhysicalOp="Compute Scalar" EstimatedTotalSubtreeCost="0.0598186">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
<ColumnReference Column="Expr1004" />
</OutputList>
<ComputeScalar>
<DefinedValues>
<DefinedValue>
<ColumnReference Column="Expr1004" />
<ScalarOperator ScalarString="(0)">
<Const ConstValue="(0)" />
</ScalarOperator>
</DefinedValue>
</DefinedValues>
<RelOp AvgRowSize="11" EstimateCPU="1E-07" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Top" NodeId="1" Parallel="false" PhysicalOp="Top" EstimatedTotalSubtreeCost="0.0598185">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Top RowCount="false" IsPercent="false" WithTies="false">
<TopExpression>
<ScalarOperator ScalarString="(1)">
<Const ConstValue="(1)" />
</ScalarOperator>
</TopExpression>
<RelOp AvgRowSize="11" EstimateCPU="0.000502934" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Aggregate" NodeId="2" Parallel="false" PhysicalOp="Stream Aggregate" EstimatedTotalSubtreeCost="0.0598184">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="0" ActualExecutions="1" />
</RunTimeInformation>
<StreamAggregate>
<DefinedValues />
<GroupBy>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</GroupBy>
<RelOp AvgRowSize="11" EstimateCPU="0.000609525" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1.28484" LogicalOp="Filter" NodeId="3" Parallel="false" PhysicalOp="Filter" EstimatedTotalSubtreeCost="0.0598173">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="2" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Filter StartupExpression="false">
<RelOp AvgRowSize="19" EstimateCPU="4.98448" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="2.88447" LogicalOp="Left Outer Join" NodeId="4" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.0598159">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<Predicate>
<ScalarOperator ScalarString="#document.[FieldId] as [A].[FieldId]=[SH_Semper].[dbo].[DataMaster].[FieldId] as .[FieldId] AND #document.[DocumentID] as [A].[DocumentID]=[SH_Semper].[dbo].[DataMaster].[DocumentId] as .[DocumentId]">
<Logical Operation="AND">
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="FieldId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
<ScalarOperator>
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</Identifier>
</ScalarOperator>
</Compare>
</ScalarOperator>
</Logical>
</ScalarOperator>
</Predicate>
<RelOp AvgRowSize="15" EstimateCPU="0.0172572" EstimateIO="0.0112613" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="2.47595" LogicalOp="Sort" NodeId="5" Parallel="false" PhysicalOp="Sort" EstimatedTotalSubtreeCost="0.0352217">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<MemoryFractions Input="1" Output="1" />
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRebinds="1" ActualRewinds="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Sort Distinct="false">
<OrderBy>
<OrderByColumn Ascending="true">
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OrderByColumn>
</OrderBy>
<RelOp AvgRowSize="15" EstimateCPU="0.001356" EstimateIO="0.00534722" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1090" LogicalOp="Clustered Index Scan" NodeId="6" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.00670322" TableCardinality="1090">
<OutputList>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1090" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Table="#Document" Alias="[A]" Column="FieldId" />
</DefinedValue>
<DefinedValue>
<ColumnReference Table="#Document" Alias="[A]" Column="DocumentID" />
</DefinedValue>
</DefinedValues>
<Object Database="[tempdb]" Schema="[dbo]" Table="[#Document]" Index="[PK__#Documen__3214EC070FE2393C]" Alias="[A]" />
</IndexScan>
</RelOp>
</Sort>
</RelOp>
<RelOp AvgRowSize="23" EstimateCPU="0.0012819" EstimateIO="0.0135739" EstimateRebinds="0" EstimateRewinds="2.47368" EstimateRows="1094" LogicalOp="Clustered Index Scan" NodeId="7" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="0.0180268" TableCardinality="1094">
<OutputList>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="FieldId" />
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1192460" ActualEndOfScans="1090" ActualExecutions="1090" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="FieldId" />
</DefinedValue>
<DefinedValue>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</DefinedValue>
</DefinedValues>
<Object Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Index="[PK_DataMaster]" Alias="" IndexKind="Clustered" />
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
<Predicate>
<ScalarOperator ScalarString="[SH_Semper].[dbo].[DataMaster].[DocumentId] as .[DocumentId] IS NULL">
<Compare CompareOp="IS">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[SH_Semper]" Schema="[dbo]" Table="[DataMaster]" Alias="" Column="DocumentId" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="NULL" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Predicate>
</Filter>
</RelOp>
</StreamAggregate>
</RelOp>
</Top>
</RelOp>
</ComputeScalar>
</RelOp>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
</BatchSequence>
</ShowPlanXML>
August 10, 2015 at 7:02 am
mohan_padekal (8/10/2015)
Here is the Execution Plan
How about as an attachment instead? I doubt anybody is going to waste their time piecing that back together into something usable.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 10, 2015 at 7:45 am
Sean Lange (8/10/2015)
mohan_padekal (8/10/2015)
Here is the Execution PlanHow about as an attachment instead? I doubt anybody is going to waste their time piecing that back together into something usable.
+100
Please, attach the .SQLPLAN file.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 10, 2015 at 8:23 am
I copied and pasted into Notepad, then saved it as TEST.SQLPLAN. It's attached, and it did successfully open in SSMS for SQL 2008 R2.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
August 10, 2015 at 8:44 am
Might be a good idea to put an index on your temporary table and ensure that the statistics are up to date. This query is the most costly:
SELECT TOP 1
A.DocumentID
FROM #Document A
LEFT JOIN DataMaster b
ON A.FieldId = b.FieldId
AND A.DocumentID = b.DocumentId
WHERE b.DocumentId IS NULL
GROUP BY A.DocumentID
ORDER BY A.DocumentID;
It's estimating 2 rows, but actually returning over 1000. Then, the nested loop join that is being used to run the scans against the DataMaster table gets executed 1000 times. Also, the query there is somewhat problematic. You're trying to do a JOIN on DocumentID, but, you have a WHERE clause that finds where DocumentID IS NULL. The JOIN is going to be returning some odd data. You have the same problem again i the last query.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 10, 2015 at 8:52 am
Grant Fritchey (8/10/2015)
Might be a good idea to put an index on your temporary table and ensure that the statistics are up to date. This query is the most costly:
SELECT TOP 1
A.DocumentID
FROM #Document A
LEFT JOIN DataMaster b
ON A.FieldId = b.FieldId
AND A.DocumentID = b.DocumentId
WHERE b.DocumentId IS NULL
GROUP BY A.DocumentID
ORDER BY A.DocumentID;
It's estimating 2 rows, but actually returning over 1000. Then, the nested loop join that is being used to run the scans against the DataMaster table gets executed 1000 times. Also, the query there is somewhat problematic. You're trying to do a JOIN on DocumentID, but, you have a WHERE clause that finds where DocumentID IS NULL. The JOIN is going to be returning some odd data. You have the same problem again i the last query.
Grant,
Would using NOT EXISTS be better than the IS NULL and LEFT JOIN, or would an index, or lack thereof, be the larger factor? Also, given the TOP 1, is GROUP BY serving any purpose at all?
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
August 10, 2015 at 8:53 am
When is the last time you updated your statistics? The stats on DataMaster seem to be very stale. The plan estimated 1094 rows but found 1.1 Million when it executed.
Try running this (you do have a copy of this on a test server right?).
update statistics DataMaster
I am curious why you seem to just randomly throw the NOLOCK hint in. You seem to have it in some queries but no others even when the queries are looking at the same tables. This is a clear indication that there is a lack of understanding what that hint does. http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/%5B/url%5D
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 10, 2015 at 9:01 am
sgmunson (8/10/2015)
Grant Fritchey (8/10/2015)
Might be a good idea to put an index on your temporary table and ensure that the statistics are up to date. This query is the most costly:
SELECT TOP 1
A.DocumentID
FROM #Document A
LEFT JOIN DataMaster b
ON A.FieldId = b.FieldId
AND A.DocumentID = b.DocumentId
WHERE b.DocumentId IS NULL
GROUP BY A.DocumentID
ORDER BY A.DocumentID;
It's estimating 2 rows, but actually returning over 1000. Then, the nested loop join that is being used to run the scans against the DataMaster table gets executed 1000 times. Also, the query there is somewhat problematic. You're trying to do a JOIN on DocumentID, but, you have a WHERE clause that finds where DocumentID IS NULL. The JOIN is going to be returning some odd data. You have the same problem again i the last query.
Grant,
Would using NOT EXISTS be better than the IS NULL and LEFT JOIN, or would an index, or lack thereof, be the larger factor? Also, given the TOP 1, is GROUP BY serving any purpose at all?
Chances are good that the GROUP BY isn't doing anything in terms of data, but you can see in the plan that it's causing work. Test using NOT EXISTS. It can be better, depending. Stats seem to be way off though. That's causing poor choices in the optimizer.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 10, 2015 at 9:20 am
The following script will return, for each statement in the specified stored procedure:
sql text, last_elapsed_time, last_worker_time (CPU), last_blocked_time (waiting on lock), last_reads, last_writes, last_rows returned, and plan text, ... etc.
For procedures with a large number of statements, you can order by max_elapsed_time easily see which are the bottleneck. For situations where a procedure runs faster on some occasions or circumstances than others, you can order by statement_text, take two samples (one fast and one slow), and then determine the difference between two results by comparing side by side using a text difference tool like WinMerge or Beyond Compare.
SELECT
db_name(qt.dbid)database_name
,OBJECT_NAME(qt.objectid, qt.dbid) object_name
,case when qs.statement_start_offset is not null
then
substring(char(13)+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) + 1),1,8000)
else qt.text
end as statement_text
,creation_time
,last_execution_time
,execution_count
,convert(varchar,dateadd(ms,(last_elapsed_time / 1000),getdate())-getdate(),108)last_elapsed_time
,convert(varchar,dateadd(ms,(last_worker_time / 1000),getdate())-getdate(),108)last_worker_time
,convert(varchar,dateadd(ms,(last_elapsed_time / 1000) - (last_worker_time / 1000),getdate())-getdate(),108)last_blocked_time
,last_logical_reads
,last_physical_reads
,last_logical_writes
,last_rows
,query_plan
from sys.dm_exec_query_stats qs
cross apply sys.dm_exec_sql_text(qs.sql_handle) qt
cross apply sys.dm_exec_query_plan(qs.plan_handle) qp
-- where qt.text like '%insert%MyTable%'
where OBJECT_NAME(qt.objectid) = 'FetchDocumentID'
--order by (qs.max_elapsed_time) desc;
order by statement_text;
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
August 11, 2015 at 3:00 am
Getting this error while execute the script
Msg 207, Level 16, State 1, Line 24
Invalid column name 'last_rows'.
August 11, 2015 at 3:16 am
August 11, 2015 at 3:30 am
First i updated Statistics of DataMaster table then try to execute the script that time getting error
August 11, 2015 at 3:34 am
mohan_padekal (8/11/2015)
First i updated Statistics of DataMaster table then try to execute the script that time getting error
Updating statistics won't change the names of columns. Have you made other changes to the script or your tables?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply