Download presentation
Presentation is loading. Please wait.
Published byMilagros Villalba Vidal Modified over 6 years ago
1
Query Optimization Statistics: The Driving Force Behind Good Performance
G. Vern Rabe -
3
Vern Rabe Portland, OR independent consultant, trainer MCTA, MCDBA, MCSE, MCITP Oregon PASS Chapter Leader Working with/focusing on SQL Server since 1993, starting with SQL Server 4.21a My first PC had a 10MB hard drive G. Vern Rabe –
4
The Optimizer Determines how to execute a query
Simple 2 table JOIN example • 3 join operators Order of tables Filter/predicate … Cardinality major factor Cardinality determined from statistics Cardinality estimator rewritten in SQL Server 2014 4 G. Vern Rabe –
5
What are Statistics? Estimated summary information of distribution of values in one or more columns All indexes Any column used in predicate (by default) Any column(s) you define Header, density vector, histogram 5 G. Vern Rabe –
6
How Do I Read Statistics?
SSMS • sp_helpstats – deprecated DBCC SHOW_STATISTICS • WITH STAT_HEADER WITH DENSITY_VECTOR WITH HISTOGRAM sp_autostats • sys.stats sys.stats_columns sys.dm_db_stats_properties • 6 G. Vern Rabe –
7
How Should Statistics be Maintained?
AUTO_UPDATE_STATISTICS[_ASYNC] SQL Server < 2014 – for tables > 500 rows, 20% row changes SQL Server >= 2014 – “more aggressive” as table rows increase sp_autostats - turn off/on for table or statistic object AUTO_CREATE_STATISTICS • UPDATE STATISTICS • WITH FULLSCAN WITH <number> PERCENT | ROWS If you manually update stats, it’s recommended to disable auto stats for that statistics object, to avoid overwriting high sample size with lower “standard” sample size sp_createstats – creates column statistics where they don’t already exist sp_updatestats – executes UPDATE STATISTICS for entire database 7 G. Vern Rabe –
8
What Can Go Wrong? Bad Sample Ascending Key
Statistics are estimates – not exact By default, only reads SOME of the data • Ascending Key Statistics Outliers • <= 2012, cardinality estimate of 1 >= 2014, cardinality estimate of 30% of rows changed sp_FindStatisticsOutliers • 8 G. Vern Rabe –
9
Summary Statistics are über important for performance Multiple ways to view statistics Statistics are great but not perfect Ascending Key issues – override default updating of statistics 9 G. Vern Rabe –
11
Vern Rabe Thanks. Questions? 11 G. Vern Rabe – vern@rabedata.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.