By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
-- Input numbers
DECLARE
@Executions float = 504,
@Density float = 0.002267574,
@IndexDataPages float = 201,
@Cardinality float = 113443;
-- SQL Server cost model constants
DECLARE
@SeqIO float = 0.000740740740741,
@RandomIO float = 0.003125,
@CPUbase float = 0.000157,
@CPUrow float = 0.0000011;
-- Computation
DECLARE
@IndexPages float = CEILING(@IndexDataPages * @Density),
@Rows float = @Cardinality * @Density,
@Rebinds float = @Executions - 1e0;
DECLARE
@CPU float = @CPUbase + (@Rows * @CPUrow),
@IO float = @RandomIO + (@SeqIO * (@IndexPages - 1e0)),
-- sample with replacement
@PSWR float = @IndexDataPages * (1e0 - POWER(1e0 - (1e0 / @IndexDataPages), @Rebinds));
-- Cost components (no rewinds)
DECLARE
@InitialCost float = @RandomIO + @CPUbase + @CPUrow,
@RebindCPU float = @Rebinds * (1e0 * @CPUbase + @CPUrow),
@RebindIO float = (1e0 / @Rows) * ((@PSWR - 1e0) * @IO);
-- Result
SELECT
OpCost = @InitialCost + @RebindCPU + @RebindIO;
OpCost |
---|
0.0850383431009574 |