By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE [dbo].[Settings](
[id] [int] IDENTITY(1,1) NOT NULL,
[resourceId] [int] NULL,
[typeID] [int] NULL,
[remark] [varchar](max) NULL,
CONSTRAINT [PK_Settings] PRIMARY KEY CLUSTERED ([id] ASC)
)
CREATE TABLE [dbo].[Resources](
[id] [int] IDENTITY(1,1) NOT NULL,
[resourceUID] [int] NULL,
CONSTRAINT [PK_Resources] PRIMARY KEY CLUSTERED ([id] ASC)
)
CREATE NONCLUSTERED INDEX [IX_UID] ON [dbo].[Resources]
(
[resourceUID] ASC
)
CREATE NONCLUSTERED INDEX [IX_Test] ON [dbo].[Settings]
(
[resourceId] ASC,
[typeID] ASC
)
set statistics xml on;
select r.id,remark
FROM Resources r
inner join Settings on resourceid=r.id
where resourceUID=1
ORDER BY typeID
id | remark |
---|
Microsoft SQL Server 2005 XML Showplan |
---|
<ShowPlanXML xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan" Version="1.481" Build="14.0.3451.2"><BatchSequence><Batch><Statements><StmtSimple StatementText="select r.id,remark
FROM Resources r
inner join Settings on resourceid=r.id
where resourceUID=1
ORDER BY typeID" StatementId="1" StatementCompId="2" StatementType="SELECT" RetrievedFromCache="true" StatementSubTreeCost="0.0179357" StatementEstRows="1" SecurityPolicyApplied="false" StatementOptmLevel="FULL" QueryHash="0xE9D48EC414698A5F" QueryPlanHash="0x4C865077C1493A23" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" CardinalityEstimationModelVersion="140"><StatementSetOptions QUOTED_IDENTIFIER="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" NUMERIC_ROUNDABORT="false"></StatementSetOptions><QueryPlan DegreeOfParallelism="0" MemoryGrant="1024" NonParallelPlanReason="NoParallelPlansInDesktopOrExpressEdition" CachedPlanSize="24" CompileTime="0" CompileCPU="0" CompileMemory="232"><MemoryGrantInfo SerialRequiredMemory="512" SerialDesiredMemory="544" RequiredMemory="512" DesiredMemory="544" RequestedMemory="1024" GrantWaitTime="0" GrantedMemory="1024" MaxUsedMemory="0" MaxQueryMemory="384632"></MemoryGrantInfo><OptimizerHardwareDependentProperties EstimatedAvailableMemoryGrant="1258238" EstimatedPagesCached="78639" EstimatedAvailableDegreeOfParallelism="1" MaxCompileMemory="674056"></OptimizerHardwareDependentProperties><TraceFlags IsCompileTime="1"><TraceFlag Value="460" Scope="Global"></TraceFlag><TraceFlag Value="8017" Scope="Global"></TraceFlag></TraceFlags><TraceFlags IsCompileTime="0"><TraceFlag Value="460" Scope="Global"></TraceFlag><TraceFlag Value="8017" Scope="Global"></TraceFlag></TraceFlags><QueryTimeStats ElapsedTime="0" CpuTime="0"></QueryTimeStats><RelOp NodeId="0" PhysicalOp="Sort" LogicalOp="Sort" EstimateRows="1" EstimateIO="0.0112613" EstimateCPU="0.000104043" AvgRowSize="4043" EstimatedTotalSubtreeCost="0.0179357" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="typeID"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="remark"></ColumnReference></OutputList><MemoryFractions Input="1" Output="1"></MemoryFractions><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="0" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualRebinds="1" ActualRewinds="0" ActualEndOfScans="1" ActualExecutions="1" InputMemoryGrant="1024" OutputMemoryGrant="640" UsedMemoryGrant="0"></RunTimeCountersPerThread></RunTimeInformation><Sort Distinct="0"><OrderBy><OrderByColumn Ascending="1"><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="typeID"></ColumnReference></OrderByColumn></OrderBy><RelOp NodeId="1" PhysicalOp="Nested Loops" LogicalOp="Inner Join" EstimateRows="1" EstimateIO="0" EstimateCPU="4.18e-006" AvgRowSize="4043" EstimatedTotalSubtreeCost="0.00657038" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="typeID"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="remark"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><NestedLoops Optimized="0"><OuterReferences><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="resourceId"></ColumnReference></OuterReferences><RelOp NodeId="2" PhysicalOp="Clustered Index Scan" LogicalOp="Clustered Index Scan" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="4043" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="resourceId"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="typeID"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="remark"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="1" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="0" ForcedIndex="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="resourceId"></ColumnReference></DefinedValue><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="typeID"></ColumnReference></DefinedValue><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="remark"></ColumnReference></DefinedValue></DefinedValues><Object Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Index="[PK_Settings]" IndexKind="Clustered" Storage="RowStore"></Object></IndexScan></RelOp><RelOp NodeId="3" PhysicalOp="Index Seek" LogicalOp="Index Seek" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="11" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="0" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualEndOfScans="0" ActualExecutions="0"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="1" ScanDirection="FORWARD" ForcedIndex="0" ForceSeek="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></DefinedValue></DefinedValues><Object Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Index="[IX_UID]" Alias="[r]" IndexKind="NonClustered" Storage="RowStore"></Object><SeekPredicates><SeekPredicateNew><SeekKeys><Prefix ScanType="EQ"><RangeColumns><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="resourceUID"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></RangeColumns><RangeExpressions><ScalarOperator ScalarString="(1)"><Const ConstValue="(1)"></Const></ScalarOperator><ScalarOperator ScalarString="[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[resourceId]"><Identifier><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Column="resourceId"></ColumnReference></Identifier></ScalarOperator></RangeExpressions></Prefix></SeekKeys></SeekPredicateNew></SeekPredicates></IndexScan></RelOp></NestedLoops></RelOp></Sort></RelOp></QueryPlan></StmtSimple></Statements></Batch></BatchSequence></ShowPlanXML> |
select r.id,remark
FROM Resources r
inner join Settings on resourceid=r.id
where resourceUID=1
ORDER BY typeID
SELECT
SELECT
Cached plan size | 24 KB |
---|---|
Estimated Operator Cost | 0 (0%) |
Estimated Subtree Cost | 0.0179357 |
Degree of Parallelism | 0 |
Memory Grant | 1024 |
Estimated Number of Rows | 1 |
Statement
select r.id,remark
FROM Resources r
inner join Settings on resourceid=r.id
where resourceUID=1
ORDER BY typeID
Sort
Cost: 63%
Sort
Sort the input.
Physical Operation | Sort |
---|---|
Logical Operation | Sort |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0113653 (63%) |
Estimated I/O Cost | 0.0112613 |
Estimated CPU Cost | 0.000104 |
Estimated Subtree Cost | 0.0179357 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 4043 B |
Actual Rebinds | 1 |
Actual Rewinds | 0 |
Node ID | 0 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].typeID
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].remark
Order By
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].typeID Ascending
Nested Loops
(Inner Join)
Cost: 0%
Nested Loops
For each row in the top (outer) input, scan the bottom (inner) input, and output matching rows.
Physical Operation | Nested Loops |
---|---|
Logical Operation | Inner Join |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0000042 (0%) |
Estimated I/O Cost | 0 |
Estimated CPU Cost | 0.0000042 |
Estimated Subtree Cost | 0.0065704 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 4043 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Node ID | 1 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].typeID
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].remark
Outer References
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].resourceId
Clustered Index Scan (Clustered)
[Settings].[PK_Settings]
Cost: 18%
Clustered Index Scan (Clustered)
Scanning a clustered index, entirely or only a range.
Physical Operation | Clustered Index Scan |
---|---|
Logical Operation | Clustered Index Scan |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Storage | RowStore |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0032831 (18%) |
Estimated I/O Cost | 0.003125 |
Estimated CPU Cost | 0.0001581 |
Estimated Subtree Cost | 0.0032831 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows to be Read | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 4043 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Ordered | False |
Node ID | 2 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].resourceId
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].typeID
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].remark
Object
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[PK_Settings]
Index Seek (NonClustered)
[Resources].[IX_UID].[r]
Cost: 18%
Index Seek (NonClustered)
Scan a particular range of rows from a nonclustered index.
Physical Operation | Index Seek |
---|---|
Logical Operation | Index Seek |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Storage | RowStore |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0032831 (18%) |
Estimated I/O Cost | 0.003125 |
Estimated CPU Cost | 0.0001581 |
Estimated Subtree Cost | 0.0032831 |
Estimated Number of Executions | 1 |
Estimated Number of Rows to be Read | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 11 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Ordered | True |
Node ID | 3 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
Object
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[IX_UID].[r]
Seek Predicates
Seek Keys[1]: Prefix: [fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].resourceUID, [fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].id = Scalar Operator((1)), Scalar Operator([fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[resourceId])
set statistics xml on;
WITH CTE AS (
SELECT TOP 1000000000 r.ID, s.ID AS ID2, s.typeID
FROM Resources r
inner join Settings s on resourceid=r.id
where resourceUID=1
ORDER BY s.typeID
)
SELECT c.ID, ca.remark
FROM CTE c
CROSS APPLY (SELECT remark FROM dbo.Settings s WHERE s.id = c.ID2) ca(remark)
ORDER BY c.typeID
ID | remark |
---|
Microsoft SQL Server 2005 XML Showplan |
---|
<ShowPlanXML xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan" Version="1.481" Build="14.0.3451.2"><BatchSequence><Batch><Statements><StmtSimple StatementText="WITH CTE AS (
SELECT TOP 1000000000 r.ID, s.ID AS ID2, s.typeID
FROM Resources r
inner join Settings s on resourceid=r.id
where resourceUID=1
ORDER BY s.typeID
)
SELECT c.ID, ca.remark
FROM CTE c
CROSS APPLY (SELECT remark FROM dbo.Settings s WHERE s.id = c.ID2) ca(remark)
ORDER BY c.typeID" StatementId="1" StatementCompId="2" StatementType="SELECT" RetrievedFromCache="true" StatementSubTreeCost="0.021219" StatementEstRows="1" SecurityPolicyApplied="false" StatementOptmLevel="FULL" QueryHash="0x131B107125343532" QueryPlanHash="0x6044B817EE53A7B5" StatementOptmEarlyAbortReason="GoodEnoughPlanFound" CardinalityEstimationModelVersion="140"><StatementSetOptions QUOTED_IDENTIFIER="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" NUMERIC_ROUNDABORT="false"></StatementSetOptions><QueryPlan DegreeOfParallelism="0" MemoryGrant="1024" NonParallelPlanReason="NoParallelPlansInDesktopOrExpressEdition" CachedPlanSize="32" CompileTime="0" CompileCPU="0" CompileMemory="312"><MemoryGrantInfo SerialRequiredMemory="512" SerialDesiredMemory="544" RequiredMemory="512" DesiredMemory="544" RequestedMemory="1024" GrantWaitTime="0" GrantedMemory="1024" MaxUsedMemory="0" MaxQueryMemory="384632"></MemoryGrantInfo><OptimizerHardwareDependentProperties EstimatedAvailableMemoryGrant="1258238" EstimatedPagesCached="78639" EstimatedAvailableDegreeOfParallelism="1" MaxCompileMemory="674056"></OptimizerHardwareDependentProperties><TraceFlags IsCompileTime="1"><TraceFlag Value="460" Scope="Global"></TraceFlag><TraceFlag Value="8017" Scope="Global"></TraceFlag></TraceFlags><TraceFlags IsCompileTime="0"><TraceFlag Value="460" Scope="Global"></TraceFlag><TraceFlag Value="8017" Scope="Global"></TraceFlag></TraceFlags><QueryTimeStats ElapsedTime="0" CpuTime="0"></QueryTimeStats><RelOp NodeId="0" PhysicalOp="Nested Loops" LogicalOp="Inner Join" EstimateRows="1" EstimateIO="0" EstimateCPU="4.18e-006" AvgRowSize="4043" EstimatedTotalSubtreeCost="0.021219" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="typeID"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="remark"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><NestedLoops Optimized="0"><OuterReferences><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference></OuterReferences><RelOp NodeId="1" PhysicalOp="Sort" LogicalOp="TopN Sort" EstimateRows="1" EstimateIO="0.0112613" EstimateCPU="0.000100019" AvgRowSize="19" EstimatedTotalSubtreeCost="0.0179317" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="typeID"></ColumnReference></OutputList><MemoryFractions Input="1" Output="1"></MemoryFractions><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="0" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualRebinds="1" ActualRewinds="0" ActualEndOfScans="1" ActualExecutions="1" InputMemoryGrant="1024" OutputMemoryGrant="640" UsedMemoryGrant="0"></RunTimeCountersPerThread></RunTimeInformation><TopSort Distinct="0" Rows="1000000000"><OrderBy><OrderByColumn Ascending="1"><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="typeID"></ColumnReference></OrderByColumn></OrderBy><RelOp NodeId="2" PhysicalOp="Nested Loops" LogicalOp="Inner Join" EstimateRows="1" EstimateIO="0" EstimateCPU="4.18e-006" AvgRowSize="19" EstimatedTotalSubtreeCost="0.00657038" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="typeID"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><NestedLoops Optimized="0"><OuterReferences><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></OuterReferences><RelOp NodeId="3" PhysicalOp="Index Seek" LogicalOp="Index Seek" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="11" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="1" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="1" ScanDirection="FORWARD" ForcedIndex="0" ForceSeek="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></DefinedValue></DefinedValues><Object Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Index="[IX_UID]" Alias="[r]" IndexKind="NonClustered" Storage="RowStore"></Object><SeekPredicates><SeekPredicateNew><SeekKeys><Prefix ScanType="EQ"><RangeColumns><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="resourceUID"></ColumnReference></RangeColumns><RangeExpressions><ScalarOperator ScalarString="(1)"><Const ConstValue="(1)"></Const></ScalarOperator></RangeExpressions></Prefix></SeekKeys></SeekPredicateNew></SeekPredicates></IndexScan></RelOp><RelOp NodeId="4" PhysicalOp="Index Seek" LogicalOp="Index Seek" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="15" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="typeID"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="0" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualEndOfScans="0" ActualExecutions="0"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="1" ScanDirection="FORWARD" ForcedIndex="0" ForceSeek="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference></DefinedValue><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="typeID"></ColumnReference></DefinedValue></DefinedValues><Object Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Index="[IX_Test]" Alias="[s]" TableReferenceId="1" IndexKind="NonClustered" Storage="RowStore"></Object><SeekPredicates><SeekPredicateNew><SeekKeys><Prefix ScanType="EQ"><RangeColumns><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="resourceId"></ColumnReference></RangeColumns><RangeExpressions><ScalarOperator ScalarString="[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[id] as [r].[id]"><Identifier><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Resources]" Alias="[r]" Column="id"></ColumnReference></Identifier></ScalarOperator></RangeExpressions></Prefix></SeekKeys></SeekPredicateNew></SeekPredicates></IndexScan></RelOp></NestedLoops></RelOp></TopSort></RelOp><RelOp NodeId="5" PhysicalOp="Clustered Index Seek" LogicalOp="Clustered Index Seek" EstimateRows="1" EstimatedRowsRead="1" EstimateIO="0.003125" EstimateCPU="0.0001581" AvgRowSize="4035" EstimatedTotalSubtreeCost="0.0032831" TableCardinality="0" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="remark"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="0" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="0" ActualLogicalReads="0" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualEndOfScans="0" ActualExecutions="0"></RunTimeCountersPerThread></RunTimeInformation><IndexScan Ordered="1" ScanDirection="FORWARD" ForcedIndex="0" ForceSeek="0" ForceScan="0" NoExpandHint="0" Storage="RowStore"><DefinedValues><DefinedValue><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="remark"></ColumnReference></DefinedValue></DefinedValues><Object Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Index="[PK_Settings]" Alias="[s]" TableReferenceId="2" IndexKind="Clustered" Storage="RowStore"></Object><SeekPredicates><SeekPredicateNew><SeekKeys><Prefix ScanType="EQ"><RangeColumns><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference></RangeColumns><RangeExpressions><ScalarOperator ScalarString="[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[id] as [s].[id]"><Identifier><ColumnReference Database="[fiddle_4598f7f85545439e8b8dc8373568f851]" Schema="[dbo]" Table="[Settings]" Alias="[s]" Column="id"></ColumnReference></Identifier></ScalarOperator></RangeExpressions></Prefix></SeekKeys></SeekPredicateNew></SeekPredicates></IndexScan></RelOp></NestedLoops></RelOp></QueryPlan></StmtSimple></Statements></Batch></BatchSequence></ShowPlanXML> |
WITH CTE AS (
SELECT TOP 1000000000 r.ID, s.ID AS ID2, s.typeID
FROM Resources r
inner join Settings s on resourceid=r.id
where resourceUID=1
ORDER BY s.typeID
)
SELECT c.ID, ca.remark
FROM CTE c
CROSS APPLY (SELECT remark FROM dbo.Settings s WHERE s.id = c.ID2) ca(remark)
ORDER BY c.typeID
SELECT
SELECT
Cached plan size | 32 KB |
---|---|
Estimated Operator Cost | 0 (0%) |
Estimated Subtree Cost | 0.021219 |
Degree of Parallelism | 0 |
Memory Grant | 1024 |
Estimated Number of Rows | 1 |
Statement
WITH CTE AS (
SELECT TOP 1000000000 r.ID, s.ID AS ID2, s.typeID
FROM Resources r
inner join Settings s on resourceid=r.id
where resourceUID=1
ORDER BY s.typeID
)
SELECT c.ID, ca.remark
FROM CTE c
CROSS APPLY (SELECT remark FROM dbo.Settings s WHERE s.id = c.ID2) ca(remark)
ORDER BY c.typeID
Nested Loops
(Inner Join)
Cost: 0%
Nested Loops
For each row in the top (outer) input, scan the bottom (inner) input, and output matching rows.
Physical Operation | Nested Loops |
---|---|
Logical Operation | Inner Join |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0000042 (0%) |
Estimated I/O Cost | 0 |
Estimated CPU Cost | 0.0000042 |
Estimated Subtree Cost | 0.021219 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 4043 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Node ID | 0 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].typeID
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].remark
Outer References
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].id
Sort
(TopN Sort)
Cost: 54%
Sort
Sort the input.
Physical Operation | Sort |
---|---|
Logical Operation | TopN Sort |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0113613 (54%) |
Estimated I/O Cost | 0.0112613 |
Estimated CPU Cost | 0.0001 |
Estimated Subtree Cost | 0.0179317 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 19 B |
Actual Rebinds | 1 |
Actual Rewinds | 0 |
Node ID | 1 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].typeID
Nested Loops
(Inner Join)
Cost: 0%
Nested Loops
For each row in the top (outer) input, scan the bottom (inner) input, and output matching rows.
Physical Operation | Nested Loops |
---|---|
Logical Operation | Inner Join |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0000042 (0%) |
Estimated I/O Cost | 0 |
Estimated CPU Cost | 0.0000042 |
Estimated Subtree Cost | 0.0065704 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 19 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Node ID | 2 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].typeID
Outer References
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
Index Seek (NonClustered)
[Resources].[IX_UID].[r]
Cost: 15%
Index Seek (NonClustered)
Scan a particular range of rows from a nonclustered index.
Physical Operation | Index Seek |
---|---|
Logical Operation | Index Seek |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Storage | RowStore |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0032831 (15%) |
Estimated I/O Cost | 0.003125 |
Estimated CPU Cost | 0.0001581 |
Estimated Subtree Cost | 0.0032831 |
Estimated Number of Executions | 1 |
Number of Executions | 1 |
Estimated Number of Rows to be Read | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 11 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Ordered | True |
Node ID | 3 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[r].id
Object
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[IX_UID].[r]
Seek Predicates
Seek Keys[1]: Prefix: [fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].resourceUID = Scalar Operator((1))
Index Seek (NonClustered)
[Settings].[IX_Test].[s]
Cost: 15%
Index Seek (NonClustered)
Scan a particular range of rows from a nonclustered index.
Physical Operation | Index Seek |
---|---|
Logical Operation | Index Seek |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Storage | RowStore |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0032831 (15%) |
Estimated I/O Cost | 0.003125 |
Estimated CPU Cost | 0.0001581 |
Estimated Subtree Cost | 0.0032831 |
Estimated Number of Executions | 1 |
Estimated Number of Rows to be Read | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 15 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Ordered | True |
Node ID | 4 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].id
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].typeID
Object
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[IX_Test].[s]
Seek Predicates
Seek Keys[1]: Prefix: [fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].resourceId = Scalar Operator([fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Resources].[id] as [r].[id])
Clustered Index Seek (Clustered)
[Settings].[PK_Settings].[s]
Cost: 15%
Clustered Index Seek (Clustered)
Scanning a particular range of rows from a clustered index.
Physical Operation | Clustered Index Seek |
---|---|
Logical Operation | Clustered Index Seek |
Actual Execution Mode | Row |
Estimated Execution Mode | Row |
Storage | RowStore |
Actual Number of Rows | 0 |
Actual Number of Batches | 0 |
Estimated Operator Cost | 0.0032831 (15%) |
Estimated I/O Cost | 0.003125 |
Estimated CPU Cost | 0.0001581 |
Estimated Subtree Cost | 0.0032831 |
Estimated Number of Executions | 1 |
Estimated Number of Rows to be Read | 1 |
Estimated Number of Rows | 1 |
Estimated Row Size | 4035 B |
Actual Rebinds | 0 |
Actual Rewinds | 0 |
Ordered | True |
Node ID | 5 |
Output List
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[s].remark
Object
[fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[PK_Settings].[s]
Seek Predicates
Seek Keys[1]: Prefix: [fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].id = Scalar Operator([fiddle_4598f7f85545439e8b8dc8373568f851].[dbo].[Settings].[id] as [s].[id])