Can anyone explain why despite having inaccurate table statistics, the actual query plan "estimated number of rows" is correct? E.g table has 30 rows but all table statistics show 50 rows. However a query on the table produces a plan that apparently correctly estimates 30 rows. How did it know there are actually 30 rows?
CREATE TABLE dbo.TestPerf
(
ID INT IDENTITY(1, 1),
Col1 VARCHAR(100)
)
GO
INSERT TestPerf
SELECT 'badger'
GO 1000
CREATE STATISTICS stat_TestPerf_Col1 ON dbo.TestPerf (Col1) WITH FULLSCAN;
--lose some rows
DELETE dbo.TestPerf
WHERE ID > 750 --Check the stat not updated - still shows 1000 rows
DBCC SHOW_STATISTICS (N'dbo.TestPerf', stat_TestPerf_Col1) --now run a query and see the estimatedRows
SET statistics profile ON
SELECT *
FROM dbo.TestPerf
SET statistics profile OFF --estimatedRows = 750