Presentation on theme: "Cardinality How many rows? Distribution How many distinct values? density How many rows for each distinct value? Used by optimizer A histogram 200 steps."— Presentation transcript:
Cardinality How many rows? Distribution How many distinct values? density How many rows for each distinct value? Used by optimizer A histogram 200 steps max DBCC SHOWSTATISTICS
Index statistics User defined statistics Optimizer created statistics AKA column statistics Filtered FULLSCAN vs SAMPLE Default sampling rate
DBCC SHOW_STATISTICS sys.stats view DMF sys.dm_db_stats_properties (object_id, stats_id) modification_counter sys.sysrscols (DAC) sys.system_internals_partition_columns Which stats were actually used by optimizer?
UPDATE STATISTICS A single one or all stats on a table WITH FULLSCAN | SAMPLE | STATS_STREAM, ROWCOUNT, PAGECOUNT ALL | COLUMN | INDEX NORECOMPUTE Index rebuild (but not reorganize!) Doesn’t update column statistics FULLSCAN is what you get sp_updatestats Updates all stats in the database where rowmodctr > 0 SAMPLE by default
ALTER DATABASE SET AUTO_CREATE_STATISTICS ON SET AUTO_UPDATE_STATISTICS ON SET AUTO_UPDATE_STATISTICS_ASYNC ON Stale statistics during optimization
Your consent to our cookies if you continue to use this website.