Query Optimization Statistics: The Driving Force Behind Good Performance G. Vern Rabe - vern@rabedata.com.

Slides:



Advertisements
Similar presentations
Cardinality How many rows? Distribution How many distinct values? density How many rows for each distinct value? Used by optimizer A histogram 200 steps.
Advertisements

© IBM Corporation Informix Chat with the Labs John F. Miller III Unlocking the Mysteries Behind Update Statistics STSM.
CS4432: Database Systems II
CSE544 Database Statistics Tuesday, February 15 th, 2011 Dan Suciu , Winter
Query Optimization CS634 Lecture 12, Mar 12, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
SQL Performance 2011/12 Joe Chang, SolidQ
Dave Ballantyne Clear Sky SQL. ›Freelance Database Developer/Designer –Specializing in SQL Server for 15+ years ›SQLLunch –Lunchtime usergroup –London.
Shu J Scott Program Manager for Query Processing SQL Server Relational Engine, Microsoft DAT318.
Indexes Rose-Hulman Institute of Technology Curt Clifton.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Indexes and Views Unit 7.
Maciej Pilecki | Project Botticelli Ltd.. SELECT Bio FROM Speakers WHERE FullName=‘Maciej Pilecki’;  Microsoft Certified Trainer since 2001  SQL Server.
Pinal Dave Mentor | Solid Quality India |
Virtual techdays INDIA │ august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI.
SQL SERVER MAINTENANCE PLANS Kat
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
High Performance Functions SQLBits VI. Going backwards is faster than going forwards.
You Inherited a Database Now What? What you should immediately check and start monitoring for. Tim Radney, Senior DBA for a top 40 US Bank President of.
SQL Server Magic Buttons! What are Trace Flags and why should I care? Steinar Andersen, SQL Service Nordic AB Thanks to Thomas Kejser for peer-reviewing.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Chiu Luk CS257 Database Systems Principles Spring 2009
SQL Server Statistics and its relationship with Query Optimizer
You Inherited a Database Now What?
Microsoft SQL Server 2005 Advanced SQL Programming and Optimization
Execution Planning for Success
SQL Server Statistics 101 Travis Whitley Senior Consultant, Oakwood Systems whitleysql.wordpress.com.
T-SQL Coding Techniques Are you playing with fire?
Finding more space for your tight environment
Parameter Sniffing in SQL Server Stored Procedures
Query Tuning without Production Data
Reading execution plans successfully
Ouch! Our Data Type Choices Did THAT?
Reading Execution Plans Successfully
Statistics for beginners
Introduction to Execution Plans
Query Execution Expectation-Reality Denis Reznik
It’s About Time : Temporal Table Support in SQL Server 2016/2017
Statistics And New Cardinality Estimator (CE)
Marcos Freccia Stop everything! Top T-SQL tricks to a developer
Statistics for beginners
Proper DataType Usage = Guaranteed Better Performance and Accuracy
The Key to the Database Engine
Now where does THAT estimate come from?
Cardinality Estimator 2014/2016
It’s About Time : Temporal Table Support in SQL Server 2016/2017
Statistics What are the chances
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Execution Plans Demystified
Statistics: What are they and How do I use them
Hidden gems of SQL Server 2016
Reading Execution Plans Successfully
Hugo Kornelis Now where does THAT estimate come from? The nuts and bolts of cardinality estimation.
SQL Server Query Plans Journeyman and Beyond
The 5 Hidden Performance Gems
Database systems Lecture 6 – Indexes
Transact SQL Performance Tips
Ascending Key Problem in SQL Server Large Tables
Please Support our Sponsors
You Inherited a Database Now What?
Introduction to Execution Plans
Score a (row) goal and beat a query optimizer
Query Tuning Fundamentals
Introduction to Execution Plans
Reading execution plans successfully
T-SQL Basics: Coding for performance
Introduction to Execution Plans
The Ins and Outs of Indexes
Presentation transcript:

Query Optimization Statistics: The Driving Force Behind Good Performance G. Vern Rabe - vern@rabedata.com

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 – vern@rabedata.com

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 – vern@rabedata.com

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 – vern@rabedata.com

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 – vern@rabedata.com

How Should Statistics be Maintained? https://ola.hallengren.com/ AUTO_UPDATE_STATISTICS[_ASYNC] SQL Server < 2014 – for tables > 500 rows, 20% + 500 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 – vern@rabedata.com

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 – vern@rabedata.com

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 – vern@rabedata.com

Vern Rabe Thanks. Questions? 11 G. Vern Rabe – vern@rabedata.com