By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
6 rows affected
c1 | c2 | c3 |
---|---|---|
1 | 2 | 1 |
2 | 2 | 1 |
Microsoft SQL Server 2005 XML Showplan |
---|
<ShowPlanXML xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan" Version="1.481" Build="14.0.3045.24"><BatchSequence><Batch><Statements><StmtSimple StatementText="WITH
 SneakyNulls AS 
 (
 -- Introduce nulls the optimizer can't see
 SELECT
 D.c1,
 OA1.c2,
 OA2.c3
 FROM #Data AS D
 OUTER APPLY (SELECT D.c2 WHERE D.c2 <> 1) AS OA1
 OUTER APPLY (SELECT D.c3 WHERE D.c3 <> 2) AS OA2
 ),
 Numbered AS 
 (
 SELECT
 D.c1,
 D.c2,
 D.c3,
 rn = ROW_NUMBER() OVER (
 PARTITION BY D.c1
 ORDER BY D.c1) 
 FROM SneakyNulls AS D
 )
SELECT
 N.c1, 
 N.c2, 
 N.c3
FROM Numbered AS N
WHERE
 N.rn = 1" StatementId="1" StatementCompId="2" StatementType="SELECT" RetrievedFromCache="true" StatementSubTreeCost="0.00336203" StatementEstRows="2" SecurityPolicyApplied="false" StatementOptmLevel="FULL" QueryHash="0x420E88CB6B660EFE" QueryPlanHash="0xD737589C61C86C1E" 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" NonParallelPlanReason="NoParallelPlansInDesktopOrExpressEdition" CachedPlanSize="32" CompileTime="0" CompileCPU="0" CompileMemory="328"><MemoryGrantInfo SerialRequiredMemory="0" SerialDesiredMemory="0"></MemoryGrantInfo><OptimizerHardwareDependentProperties EstimatedAvailableMemoryGrant="419378" EstimatedPagesCached="26211" EstimatedAvailableDegreeOfParallelism="1" MaxCompileMemory="1121696"></OptimizerHardwareDependentProperties><OptimizerStatsUsage><StatisticsInfo LastUpdate="2019-06-24T15:02:00.98" ModificationCount="0" SamplingPercent="100" Statistics="[_WA_Sys_00000003_B7C2E8E9]" Table="[#Data_______________________________________________________________________________________________________________0000000000C2]" Schema="[dbo]" Database="[tempdb]"></StatisticsInfo><StatisticsInfo LastUpdate="2019-06-24T15:02:00.98" ModificationCount="0" SamplingPercent="100" Statistics="[c]" Table="[#Data_______________________________________________________________________________________________________________0000000000C2]" Schema="[dbo]" Database="[tempdb]"></StatisticsInfo><StatisticsInfo LastUpdate="2019-06-24T15:02:00.98" ModificationCount="0" SamplingPercent="100" Statistics="[_WA_Sys_00000002_B7C2E8E9]" Table="[#Data_______________________________________________________________________________________________________________0000000000C2]" Schema="[dbo]" Database="[tempdb]"></StatisticsInfo></OptimizerStatsUsage><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="Stream Aggregate" LogicalOp="Aggregate" EstimateRows="2" EstimateIO="0" EstimateCPU="4e-006" AvgRowSize="19" EstimatedTotalSubtreeCost="0.00336203" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c1"></ColumnReference><ColumnReference Column="Expr1002"></ColumnReference><ColumnReference Column="Expr1003"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="2" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><StreamAggregate><DefinedValues><DefinedValue><ColumnReference Column="Expr1002"></ColumnReference><ScalarOperator ScalarString="ANY([Expr1002])"><Aggregate Distinct="0" AggType="ANY"><ScalarOperator><Identifier><ColumnReference Column="Expr1002"></ColumnReference></Identifier></ScalarOperator></Aggregate></ScalarOperator></DefinedValue><DefinedValue><ColumnReference Column="Expr1003"></ColumnReference><ScalarOperator ScalarString="ANY([Expr1003])"><Aggregate Distinct="0" AggType="ANY"><ScalarOperator><Identifier><ColumnReference Column="Expr1003"></ColumnReference></Identifier></ScalarOperator></Aggregate></ScalarOperator></DefinedValue></DefinedValues><GroupBy><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c1"></ColumnReference></GroupBy><RelOp NodeId="1" PhysicalOp="Nested Loops" LogicalOp="Left Outer Join" EstimateRows="6" EstimateIO="0" EstimateCPU="2.508e-005" AvgRowSize="19" EstimatedTotalSubtreeCost="0.00335803" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c1"></ColumnReference><ColumnReference Column="Expr1002"></ColumnReference><ColumnReference Column="Expr1003"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="6" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><NestedLoops Optimized="0"><OuterReferences><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c3"></ColumnReference></OuterReferences><RelOp NodeId="2" PhysicalOp="Nested Loops" LogicalOp="Left Outer Join" EstimateRows="6" EstimateIO="0" EstimateCPU="2.508e-005" AvgRowSize="19" EstimatedTotalSubtreeCost="0.00332332" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c1"></ColumnReference><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c3"></ColumnReference><ColumnReference Column="Expr1002"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="6" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="1" ActualExecutions="1"></RunTimeCountersPerThread></RunTimeInformation><NestedLoops Optimized="0"><OuterReferences><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c2"></ColumnReference></OuterReferences><RelOp NodeId="3" PhysicalOp="Clustered Index Scan" LogicalOp="Clustered Index Scan" EstimateRows="6" EstimatedRowsRead="6" EstimateIO="0.003125" EstimateCPU="0.0001636" AvgRowSize="19" EstimatedTotalSubtreeCost="0.0032886" TableCardinality="6" Parallel="0" EstimateRebinds="0" EstimateRewinds="0" EstimatedExecutionMode="Row"><OutputList><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c1"></ColumnReference><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c2"></ColumnReference><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c3"></ColumnReference></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="6" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualScans="1" ActualLogicalReads="2" ActualPhysicalReads="0" ActualReadAheads="0" ActualLobLogicalReads="0" ActualLobPhysicalReads="0" ActualLobReadAheads="0" ActualRowsRead="6" 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="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c1"></ColumnReference></DefinedValue><DefinedValue><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c2"></ColumnReference></DefinedValue><DefinedValue><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c3"></ColumnReference></DefinedValue></DefinedValues><Object Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Index="[c]" Alias="[D]" IndexKind="Clustered" Storage="RowStore"></Object></IndexScan></RelOp><RelOp NodeId="4" PhysicalOp="Compute Scalar" LogicalOp="Compute Scalar" EstimateRows="1" EstimateIO="0" EstimateCPU="1e-007" AvgRowSize="11" EstimatedTotalSubtreeCost="9.637e-006" Parallel="0" EstimateRebinds="4" EstimateRewinds="1" EstimatedExecutionMode="Row"><OutputList><ColumnReference Column="Expr1002"></ColumnReference></OutputList><ComputeScalar><DefinedValues><DefinedValue><ColumnReference Column="Expr1002"></ColumnReference><ScalarOperator ScalarString="[tempdb].[dbo].[#Data].[c2] as [D].[c2]"><Identifier><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c2"></ColumnReference></Identifier></ScalarOperator></DefinedValue></DefinedValues><RelOp NodeId="5" PhysicalOp="Filter" LogicalOp="Filter" EstimateRows="1" EstimateIO="0" EstimateCPU="4.8e-007" AvgRowSize="9" EstimatedTotalSubtreeCost="9.037e-006" Parallel="0" EstimateRebinds="4" EstimateRewinds="1" EstimatedExecutionMode="Row"><OutputList></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="4" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualRebinds="6" ActualRewinds="0" ActualEndOfScans="2" ActualExecutions="6"></RunTimeCountersPerThread></RunTimeInformation><Filter StartupExpression="1"><RelOp NodeId="6" PhysicalOp="Constant Scan" LogicalOp="Constant Scan" EstimateRows="1" EstimateIO="0" EstimateCPU="1.157e-006" AvgRowSize="9" EstimatedTotalSubtreeCost="6.157e-006" Parallel="0" EstimateRebinds="0" EstimateRewinds="5" EstimatedExecutionMode="Row"><OutputList></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="4" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="0" ActualExecutions="4"></RunTimeCountersPerThread></RunTimeInformation><ConstantScan></ConstantScan></RelOp><Predicate><ScalarOperator ScalarString="[tempdb].[dbo].[#Data].[c2] as [D].[c2]<>(1)"><Compare CompareOp="NE"><ScalarOperator><Identifier><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c2"></ColumnReference></Identifier></ScalarOperator><ScalarOperator><Const ConstValue="(1)"></Const></ScalarOperator></Compare></ScalarOperator></Predicate></Filter></RelOp></ComputeScalar></RelOp></NestedLoops></RelOp><RelOp NodeId="7" PhysicalOp="Compute Scalar" LogicalOp="Compute Scalar" EstimateRows="1" EstimateIO="0" EstimateCPU="1e-007" AvgRowSize="11" EstimatedTotalSubtreeCost="9.637e-006" Parallel="0" EstimateRebinds="4" EstimateRewinds="1" EstimatedExecutionMode="Row"><OutputList><ColumnReference Column="Expr1003"></ColumnReference></OutputList><ComputeScalar><DefinedValues><DefinedValue><ColumnReference Column="Expr1003"></ColumnReference><ScalarOperator ScalarString="[tempdb].[dbo].[#Data].[c3] as [D].[c3]"><Identifier><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c3"></ColumnReference></Identifier></ScalarOperator></DefinedValue></DefinedValues><RelOp NodeId="8" PhysicalOp="Filter" LogicalOp="Filter" EstimateRows="1" EstimateIO="0" EstimateCPU="4.8e-007" AvgRowSize="9" EstimatedTotalSubtreeCost="9.037e-006" Parallel="0" EstimateRebinds="4" EstimateRewinds="1" EstimatedExecutionMode="Row"><OutputList></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="4" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualRebinds="6" ActualRewinds="0" ActualEndOfScans="2" ActualExecutions="6"></RunTimeCountersPerThread></RunTimeInformation><Filter StartupExpression="1"><RelOp NodeId="9" PhysicalOp="Constant Scan" LogicalOp="Constant Scan" EstimateRows="1" EstimateIO="0" EstimateCPU="1.157e-006" AvgRowSize="9" EstimatedTotalSubtreeCost="6.157e-006" Parallel="0" EstimateRebinds="0" EstimateRewinds="5" EstimatedExecutionMode="Row"><OutputList></OutputList><RunTimeInformation><RunTimeCountersPerThread Thread="0" ActualRows="4" Batches="0" ActualExecutionMode="Row" ActualElapsedms="0" ActualCPUms="0" ActualEndOfScans="0" ActualExecutions="4"></RunTimeCountersPerThread></RunTimeInformation><ConstantScan></ConstantScan></RelOp><Predicate><ScalarOperator ScalarString="[tempdb].[dbo].[#Data].[c3] as [D].[c3]<>(2)"><Compare CompareOp="NE"><ScalarOperator><Identifier><ColumnReference Database="[tempdb]" Schema="[dbo]" Table="[#Data]" Alias="[D]" Column="c3"></ColumnReference></Identifier></ScalarOperator><ScalarOperator><Const ConstValue="(2)"></Const></ScalarOperator></Compare></ScalarOperator></Predicate></Filter></RelOp></ComputeScalar></RelOp></NestedLoops></RelOp></StreamAggregate></RelOp></QueryPlan></StmtSimple></Statements></Batch></BatchSequence></ShowPlanXML> |