Cardinality Estimator 2014/2016

Slides:



Advertisements
Similar presentations
Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Advertisements

Cardinality How many rows? Distribution How many distinct values? density How many rows for each distinct value? Used by optimizer A histogram 200 steps.
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.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Access Path Selection in a Relational Database Management System Selinger et al.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
1 Chapter 7 Optimizing the Optimizer. 2 The Oracle Optimizer is… About query optimization Is a sophisticated set of algorithms Choosing the fastest approach.
T-SQL: Simple Changes That Go a Long Way DAVE ingeniousSQL.com linkedin.com/in/ingenioussql.
Query Optimizer Execution Plan Cost Model Joe Chang
Meta Data Cardinality Explored CSSQLUG User Group - June 2009.
Pinal Dave Mentor | Solid Quality India |
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
8 Copyright © 2005, Oracle. All rights reserved. Gathering Statistics.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Session Name Pelin ATICI SQL Premier Field Engineer.
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.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
SQL Server Statistics and its relationship with Query Optimizer
Joe Sack, Principal Program Manager, Microsoft
Tuning Transact-SQL Queries
Execution Planning for Success
SQL Server Statistics 101 Travis Whitley Senior Consultant, Oakwood Systems whitleysql.wordpress.com.
Stored Procedures – Facts and Myths
Query Tuning without Production Data
T-SQL: Simple Changes That Go a Long Way
Query Tuning without Production Data
Query Tuning without Production Data
Reading execution plans successfully
Reading Execution Plans Successfully
Four Rules For Columnstore Query Performance
SQL Server Optimizing Query Plans
Introduction to Execution Plans
Statistics And New Cardinality Estimator (CE)
Using Indexed Views & Computed Columns for Performance !
Decoding the Cardinality Estimator to Speed Up Queries
Statistics for beginners
SQL Server 2017 has more cool features than just running on Linux
Now where does THAT estimate come from?
Statistics What are the chances
Query Optimization Techniques
Cardinality Estimates in SQL Server 2014
Akshay Tomar Prateek Singh Lohchubh
Execution Plans Demystified
Statistics: What are they and How do I use them
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
Ascending Key Problem in SQL Server Large Tables
Four Rules For Columnstore Query Performance
Introduction to Execution Plans
Parameter Sniffing on SQL Server
Score a (row) goal and beat a query optimizer
Execution plans Eugene
Diving into Query Execution Plans
Query Profiling Options in SQL Server
Introduction to Execution Plans
From adaptive to intelligent: query processing in SQL Server 2019
Query Optimization Techniques
Reading execution plans successfully
T-SQL Basics: Coding for performance
Introduction to Execution Plans
All about Indexes Gail Shaw.
Automagic Tuning - SQL Server 2019 and Beyond
From adaptive to intelligent:
Presentation transcript:

Cardinality Estimator 2014/2016 Dean Savović Cardinality Estimator 2014/2016

Our Partners If you think, that a SQL Saturday is a nice possibility to learn from and network with fellow SQL Server enthusiasts FOR FREE, I just ask you one thing: Visit the sponsor booths and chat with the sponsors! They are covering the expenses for each and every of you, with is around EUR 60 …

Overview CE Intro CE Model Assumptions CE Calculation Direction CE Model Version Improvements (SQL 2014) Improvements (SQL 2016) Improvements (SQL 2017) Troubleshooting Conclusion

CE Intro How many rows will satisfy a single filter predicate? Multiple filter predicates? How many rows will satisfy a join predicate between two tables? How many distinct values do we expect from a specific column? A set of columns? Under estimating rows The selection of serial plan when parallelism would have been more optimal. Inappropriate join strategies. Inefficient index selection and navigation strategies. Over estimating rows Selection of a parallel plan when a serial plan might be more optimal. Inappropriate join strategy selection. Inefficient index navigation strategies (scan versus seek). Inflated memory grants. Wasted memory and unnecessarily throttled concurrency.

CE Model Assumptions Independence Uniformity Containment Inclusion Data distributions on different columns are independent unless correlation information is available. Uniformity Within each statistics object histogram step, distinct values are evenly spread and each value has the same frequency. Containment If something is being searched for, it is assumed that it actually exists. Inclusion For filter predicates involving a column-equal-constant expression, the constant is assumed to actually exist for the associated column.

CE Calculation Direction

CE Model Version Database compatibility level >=120 – 120 <= 110 - 70 Trace Flags 9481 – legacy CE (CE 70) 2312 – new CE (CE 120) SQL Server 2016 SP1+ USE HINT FORCE_LEGACY_CARDINALITY_ESTIMATION Database Scoped Configuration LEGACY_CARDINALITY_ESTIMATION

Improvements (SQL 2014) Increased Correlation Assumption for Multiple Predicates (demo) CE 70 – data contained across different columns as uncorrelated with one another CE 120 – correlation between data; exponential back-off Modified Ascending Key and Out-Of-Range Value Estimation (demo) the “ascending key problem” arises when query predicates reference newly inserted data that fall out of the range of a statistic object histogram CE 70 – estimates 1 row CE 120 – assumes that data exists (average frequency = table cardinality * density)

Improvements (SQL 2014) (2) Distinct Value Count Estimation Changes (demo) No many-to-many join operations - difference is small Advanced Diagnostic Output XE Event - query_optimizer_estimate_cardinality

Improvements (SQL 2016) Compatibility Level Guarantess No plan changes if we stick with older compatibility level QO Improvements under flag 4199 Parallel Update of Sampled Statistics Auto update stats Sublinear Threshold for Update of Statistics Previous 20% of the table TF 2371 in previous releases Misc Batch query processing in serial queries Sort operators in batch mode Window aggregates in batch mode Distinct aggregates in batch mode Parallel INSERT SELECT into heaps and CCI Heap scans for memory-optimized tables Parallel scans for memory-optimized tables Sampled and auto-update stats for memory-optimized tables

Improvements (SQL 2017)

Interleaved Execution

Batch Mode Memory Grant Feedback

Batch Mode Adaptive Joins

Troubleshooting (1) Changing DB compatibility level Trace Flags Missing Statistics Stale Statistics Statistic Object Sampling Issues Filtered Statistics Filtered statistics may help address statistics quality issues for very large tables that contain uneven data distributions Multi-column Statistics Parameter Sensitivity Trace flag 4136 – disable parameter sniffing Table Variables Multi-statement User-defined Table Functions Fixed cardinality = 100 (previous 1)

Troubleshooting (2) Recursive CTE Predicate Complexity if non-unique parent/child keys are used for recursion Predicate Complexity Query Complexity XML Reader Table-Valued Function Operations XML index Data Type Conversions Intra-table Column Comparison Computed columns Query Hints Use with caution Distributed Queries User rights (db_ddladmin) SQL Server 2012 SP1 reduces user rights to SELECT permission

Conclusion CE 120 brings improvements Also can bring problems  Trace flags and hints for control Various troubleshooting methods

Thank You  email: dean.savovic@comminus.hr web: www.comminus.hr blog: www.savovic.com.hr