您好我有一个复杂的查询,可以快速运行现有数据,例如不到100毫秒
但是我插入了一些新记录并对它们运行完全相同的查询,返回需要4秒
我再次测试了一些随机挑选的其他旧记录,但仍然不到100毫秒。
我正在寻找一些问题清单,我应该检查这些问题以找到问题的根源,并在新记录上再次快速查询。
e.g。我期待像
这样的答案数据库是MSSQL2008R2
表'工作台'。扫描计数1,逻辑读取3,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_O'。扫描计数0,逻辑读取10,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_O_V'。扫描计数0,逻辑读取10,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A_O'。扫描计数0,逻辑读取10,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A_A'。扫描计数1,逻辑读取33,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表格'表格D'。扫描计数5,逻辑读取124,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_D'。扫描计数1,逻辑读取18,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A_S'。扫描计数1,逻辑读取4,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A'。扫描计数0,逻辑读取3,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
(1行受影响)
SQL Server执行时间: CPU时间= 16 ms,经过时间= 6 ms。 SQL Server解析和编译时间: CPU时间= 0 ms,经过时间= 0 ms。
表'表_O'。扫描计数0,逻辑读取2,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_O_V'。扫描计数0,逻辑读取2,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A_O'。扫描计数0,逻辑读取2,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'工作台'。扫描计数1,逻辑读取2603677,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A_A'。扫描计数1,逻辑读取30832,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表格'表格D'。扫描计数3,逻辑读取72,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_D'。扫描计数1,逻辑读取12,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A_S'。扫描计数1,逻辑读取4,物理读取0,预读读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
表'表_A'。扫描计数0,逻辑读取3,物理读取0,预读取读取0,lob逻辑读取0,lob物理读取0,lob预读读取0。
(1行受影响)
SQL Server执行时间: CPU时间= 2574 ms,经过时间= 2643 ms。 SQL Server解析和编译时间: CPU时间= 31 ms,经过时间= 55 ms。
<?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.4000.0" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementCompId="1" StatementEstRows="17652.3" StatementId="1" StatementOptmLevel="FULL" StatementSubTreeCost="4.05429" StatementText="SELECT *" StatementType="SELECT" QueryHash="0x66605DE9B339CF45" QueryPlanHash="0x3FFB07F2D475248D">
<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="2496" CachedPlanSize="176" CompileTime="54" CompileCPU="52" CompileMemory="3032">
<RelOp AvgRowSize="23" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Inner Join" NodeId="76" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.0403057">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="5" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<OuterReferences>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</OuterReferences>
<RelOp AvgRowSize="45" EstimateCPU="6.47743E-05" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="15.4963" LogicalOp="Inner Join" NodeId="77" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="0.0370109">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="5" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<OuterReferences>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="id" />
</OuterReferences>
<RelOp AvgRowSize="23" EstimateCPU="0.000174046" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="15.4963" LogicalOp="Index Seek" NodeId="78" Parallel="false" PhysicalOp="Index Seek" EstimatedTotalSubtreeCost="0.00329905" TableCardinality="861820">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="10" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="id" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Index="[I_A_A_a1_id]" Alias="[asso]" IndexKind="NonClustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a1_id" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A].[id] as [a].[id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A]" Alias="[a]" Column="id" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
<RelOp AvgRowSize="45" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="14.4963" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="80" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0336471" TableCardinality="861820">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="5" ActualEndOfScans="5" ActualExecutions="10" />
</RunTimeInformation>
<IndexScan Lookup="true" Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Index="[PK_A_A]" Alias="[asso]" TableReferenceId="-1" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="id" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A_A].[id] as [asso].[id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="id" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
<Predicate>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A_A].[a_a_type] as [asso].[a_a_type]='P'">
<Compare CompareOp="EQ">
<ScalarOperator>
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a_a_type" />
</Identifier>
</ScalarOperator>
<ScalarOperator>
<Const ConstValue="'P'" />
</ScalarOperator>
</Compare>
</ScalarOperator>
</Predicate>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
<RelOp AvgRowSize="23" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="84" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="215">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="5" ActualEndOfScans="0" ActualExecutions="5" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Index="[PK_A_O]" Alias="[ao]" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="ID" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A_A].[a2_id] as [asso].[a2_id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
<RelOp AvgRowSize="23" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="85" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="92">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Alias="[ov]" Column="o_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="5" ActualEndOfScans="0" ActualExecutions="5" />
</RunTimeInformation>
<IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" ForceSeek="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Alias="[ov]" Column="o_id" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Index="[PK_O_V]" Alias="[ov]" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Alias="[ov]" Column="id" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A_O].[o_v_id] as [ao].[o_v_id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
<Batch>
<Statements>
<StmtSimple StatementCompId="1" StatementEstRows="21366.7" StatementId="1" StatementOptmLevel="FULL" StatementSubTreeCost="23362.2" StatementText="SELECT *;" StatementType="SELECT" QueryHash="0x66605DE9B339CF45" QueryPlanHash="0xD286887E2ADC3D77">
<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="2496" CachedPlanSize="176" CompileTime="45" CompileCPU="45" CompileMemory="2896">
<RelOp AvgRowSize="23" EstimateCPU="4.18E-06" EstimateIO="0" EstimateRebinds="21365.7" EstimateRewinds="0" EstimateRows="1" LogicalOp="Inner Join" NodeId="75" Parallel="false" PhysicalOp="Nested Loops" EstimatedTotalSubtreeCost="105.672">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="false">
<OuterReferences>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</OuterReferences>
<RelOp AvgRowSize="23" EstimateCPU="0.862078" EstimateIO="50.2091" EstimateRebinds="21365.7" EstimateRewinds="0" EstimateRows="1" LogicalOp="Eager Spool" NodeId="76" Parallel="false" PhysicalOp="Index Spool" EstimatedTotalSubtreeCost="102.198">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRebinds="1" ActualRewinds="0" ActualRows="1" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<Spool>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a1_id" />
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a_a_type" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A].[id] as [a].[id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A]" Alias="[a]" Column="id" />
</Identifier>
</ScalarOperator>
<ScalarOperator ScalarString="'P'">
<Const ConstValue="'P'" />
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
<RelOp AvgRowSize="61" EstimateCPU="0.948159" EstimateIO="22.7579" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="861820" LogicalOp="Clustered Index Scan" NodeId="77" Parallel="false" PhysicalOp="Clustered Index Scan" EstimatedTotalSubtreeCost="23.7061" TableCardinality="861820">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a1_id" />
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a_a_type" />
</OutputList>
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="861820" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
<IndexScan Ordered="false" ForcedIndex="false" ForceScan="false" NoExpandHint="false">
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a1_id" />
</DefinedValue>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</DefinedValue>
<DefinedValue>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a_a_type" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Index="[PK_A_A]" Alias="[asso]" IndexKind="Clustered" />
</IndexScan>
</RelOp>
</Spool>
</RelOp>
<RelOp AvgRowSize="23" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="21365.7" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="78" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="3.38433" TableCardinality="215">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</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="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Index="[PK_A_O]" Alias="[ao]" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="ID" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A_A].[a2_id] as [asso].[a2_id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_A]" Alias="[asso]" Column="a2_id" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
</NestedLoops>
</RelOp>
<RelOp AvgRowSize="23" EstimateCPU="0.0001581" EstimateIO="0.003125" EstimateRebinds="21365.7" EstimateRewinds="0" EstimateRows="1" LogicalOp="Clustered Index Seek" NodeId="79" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="3.3937" TableCardinality="92">
<OutputList>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Alias="[ov]" Column="o_id" />
</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="[DB]" Schema="[DBO]" Table="[Table_O_V]" Alias="[ov]" Column="o_id" />
</DefinedValue>
</DefinedValues>
<Object Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Index="[PK_O_V]" Alias="[ov]" IndexKind="Clustered" />
<SeekPredicates>
<SeekPredicateNew>
<SeekKeys>
<Prefix ScanType="EQ">
<RangeColumns>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_O_V]" Alias="[ov]" Column="id" />
</RangeColumns>
<RangeExpressions>
<ScalarOperator ScalarString="[DB].[DBO].[Table_A_O].[o_v_id] as [ao].[o_v_id]">
<Identifier>
<ColumnReference Database="[DB]" Schema="[DBO]" Table="[Table_A_O]" Alias="[ao]" Column="o_v_id" />
</Identifier>
</ScalarOperator>
</RangeExpressions>
</Prefix>
</SeekKeys>
</SeekPredicateNew>
</SeekPredicates>
</IndexScan>
</RelOp>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
</BatchSequence>
</ShowPlanXML>