SQLSaturday Sioux Falls, SD Hosted by (605) SQL

Similar documents
Eternal Story on Temporary Objects

MILOŠ RADIVOJEVIĆ, PRINCIPAL DATABASE CONSULTANT, BWIN GVC, VIENNA, AUSTRIA

SQL Saturday #662 Sioux Falls

Introduction to Statistics in SQL Server. Andy Warren

Triangle SQL Server User Group Adaptive Query Processing with Azure SQL DB and SQL Server 2017

Performance Troubleshooting Made Easier

7. Query Processing and Optimization

SELECT TOP (?) * FROM [50 Things All SQL Server Developers Need To Know] Aaron Bertrand, Senior Consultant

Identifying and Fixing Parameter Sniffing

Outline. Database Management and Tuning. Outline. Join Strategies Running Example. Index Tuning. Johann Gamper. Unit 6 April 12, 2012

DESIGNING FOR PERFORMANCE SERIES. Smokin Fast Queries Query Optimization

New Features in SQL That Will Change the Way You Tune

Get the Skinny on Minimally Logged Operations

Session id: The Self-Managing Database: Guided Application and SQL Tuning

Natural Born Killers, performance issues to avoid

Oracle Database 11g: SQL Tuning Workshop

Improve the Performance of Your T-SQL by Changing Your Habits. Mickey Stuewe Microsoft Junkie Sr Database Developer

TEN QUERY TUNING TECHNIQUES

Set Me Up. How to Think in Sets. Brian SQL Saturday #662 Sioux Falls, South Dakota 19 August 2017

TempDB how it works? Dubi Lebel Dubi Or Not To Be

Advanced Oracle SQL Tuning v3.0 by Tanel Poder

Course Outline. SQL Server Performance & Tuning For Developers. Course Description: Pre-requisites: Course Content: Performance & Tuning.

Get Your Optimizer to Give up All Its Secrets. Brian

Get Your Optimizer to Give up All Its Secrets

Troubleshooting With Extended Events

Query Performance Tuning: Start to Finish

Arrays are a very commonly used programming language construct, but have limited support within relational databases. Although an XML document or

PERFORMANCE TUNING SQL SERVER ON CRAPPY HARDWARE 3/1/2019 1

IT Best Practices Audit TCS offers a wide range of IT Best Practices Audit content covering 15 subjects and over 2200 topics, including:

Ms Sql Server 2008 R2 Check If Temp Table Exists

The dangerous Beauty of Bookmark Lookups

Indexing survival guide for SQL 2016 In-Memory OLTP. Ned Otter SQL Strategist

SQL Server technical e-book series. SQL Server performance: faster querying with SQL Server

Query Optimizer. Chapter 19. In This Chapter. c Tools for Editing the Optimizer Strategy. c Phases of Query Processing c How Query Optimization Works

Optimizer Challenges in a Multi-Tenant World

<Insert Picture Here> Inside the Oracle Database 11g Optimizer Removing the black magic

Copyright 2018, Oracle and/or its affiliates. All rights reserved.

This is the forth SAP MaxDB Expert Session and this session covers the topic database performance analysis.

6232B: Implementing a Microsoft SQL Server 2008 R2 Database

Parameter Sniffing Problem with Stored Procedures. Milos Radivojevic

Performance Tuning for the BI Professional. Jonathan Stewart

Top 7 Plan Stability Pitfalls & How to Avoid Them. Neil Chandler Chandler Systems Ltd UK

<Insert Picture Here> DBA Best Practices: A Primer on Managing Oracle Databases

Interpreting Explain Plan Output. John Mullins

Review -Chapter 4. Review -Chapter 5

20761 Querying Data with Transact SQL

What Developers must know about DB2 for z/os indexes

Oracle Database 11gR2 Optimizer Insights

DB2 9 for z/os Selected Query Performance Enhancements

Microsoft. Transition Your MCITP: Database Administrator 2008 or MCITP Database Developer 2008 to MCSE: Data Platform

Database Systems CSE 414

MTA Database Administrator Fundamentals Course

SQL Server 2014 Performance Tuning and Optimization

Independent consultant. Oracle ACE Director. Member of OakTable Network. Available for consulting In-house workshops. Performance Troubleshooting

SQL Server 2014 In-Memory OLTP: Prepare for Migration. George Li, Program Manager, Microsoft

Where Does R Fit Into Your SQL Server Stack? Stacia Varga blog.datainspirations.com

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

Multidimensional Clustering (MDC) Tables in DB2 LUW. DB2Night Show. January 14, 2011

Sql Server 2008 Query Table Schema Management Studio Create New

SQL Server DBA Course Content

1z0-062.exam.215q 1z0-062 Oracle Database 12c: Installation and Administration

Querying Data with Transact SQL

SQL Server 2016 Query Store

Synergetics-Standard-SQL Server 2012-DBA-7 day Contents

Index. B Batches comparing, bit or 64-bit architecture, 5 Blocking, 42 Buff er cache, 143 Bulk changed map (BCM), 85 87

55144-SQL Server 2014 Performance Tuning and Optimization

Independent consultant. Oracle ACE Director. Member of OakTable Network. Available for consulting In-house workshops. Performance Troubleshooting

Judge, Jury, and Executioner. What happens when you run a query and how to read all about it.

The DBA Survival Guide for In-Memory OLTP. Ned Otter SQL Strategist

Estimating Cardinality: Use of Jonathan Lewis CBO methodology

[MS10987A]: Performance Tuning and Optimizing SQL Databases

Introduction to Database Systems CSE 344

SQL Gone Wild: Taming Bad SQL the Easy Way (or the Hard Way) Sergey Koltakov Product Manager, Database Manageability

Exam Questions

Protecting Your Data With Encryption

Healthy SQL. Marlon Ramos Premiere Field Engineer - Development

Database Systems CSE 414

From development to production

T-SQL Performance Issues What you should know to avoid, find and resolve them. Claire Mora

EZY Intellect Pte. Ltd., #1 Changi North Street 1, Singapore

Comparing SQL and NOSQL databases

Benchmarking in the Cloud

SAP White Paper SAP Sybase Adaptive Server Enterprise. New Features in SAP Sybase Adaptive Server Enterprise 15.7 ESD2

IBM DB2 11 DBA for z/os Certification Review Guide Exam 312

Firebird in 2011/2012: Development Review

70-459: Transition Your MCITP: Database Administrator 2008 or MCITP: Database Developer 2008 to MCSE: Data Platform

DB2 11 for z/os Application Functionality (Check out these New Features) Randy Ebersole IBM

Oracle. Exam Questions 1Z Oracle Database 11g Release 2: SQL Tuning Exam. Version:Demo

Columnstore Technology Improvements in SQL Server 2016

Performance Tuning & Optimizing SQL Databases Microsoft Official Curriculum (MOC 10987)

Outline. Database Tuning. Join Strategies Running Example. Outline. Index Tuning. Nikolaus Augsten. Unit 6 WS 2014/2015

Tuning SQL without the Tuning Pack. John Larkin JP Morgan Chase

OMS Performance Tuning Guide

Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:

Datenbanksysteme II: Caching and File Structures. Ulf Leser

Querying Data with Transact-SQL

Create View With Schemabinding In Sql Server 2005

Update The Statistics On A Single Table+sql Server 2005

A Choice Performance Tuning

Into into Locking and Blocking. Dmitri Korotkevitch ( 1

Transcription:

SQLSaturday 2017 Sioux Falls, SD Hosted by (605) SQL

Please be sure to visit the sponsors during breaks and enter their end-of-day raffles! Remember to complete session surveys! You will be emailed a link after the event or you visit http://www.sqlsaturday.com/662/sessions/sessionevalu ation.aspx Event After Party At Will s Training Table (Formally Beef O Bradys) near the Pentagon starting at 5:45 PM Want More Networking and Training? (605) SQL meets the 2 nd Tuesday of every month. https://605sqlusergroup.sqlpass.org

Susantha Bathige Statistics And New Cardinality Estimator (CE)

Section Title

About me MCSA Database Administrator (SQL Server 2012/2014) MCITP SQL Server 2005 Sr. DBA Specialized in SQL Server Working as a Production DBA at Pearson Has more than 12+ years of experience in SQL Server starting with SQL Server 7.0 Writer: MSSQLTips.com, Personal blog (www.sqlservertorque.net) Active member in SQL Server User Groups in Denver and Sri Lanka Working on other database systems such as NoSQL DB systems like Cassandra and MongoDB Twitter: @sbathige Email: bathige@hotmail.com

In this section Part 1 Introduction Part 2 Statistics Part 3 New CE model Part 4 Statistics Maintenance Part 5 - Recap

Introduction

Issues with execution plans Query timeout Inconsistent performance of stored procedures High tempdb utilization High CPU utilization Over utilized memory

Execution plan Data Logic

Some concepts Predicate Condition which can evaluate to TRUE, FALSE or UNKNOWN. Density Uniqueness of a column. Density = 1 / No. of distinct values Ranges from 0 to 1. Estimates/Cardinality estimation Estimated no.of records return by predicates (WHERE, HAVING, JOIN) or GROUP BY operations. Selectivity Concept similar to cardinality estimation. Percentage of rows that satisfy by a predicate. Highly selective predicate returns small no.of records. #t 0.25 0.5

Understanding density 0 1 Low Density High Density High Selectivity Returns less no.of records More unique values Low Selectivity Returns high no.of records Less unique values

How SQL Server generates Exec. Plan Parse Check for language syntax Output: Query Tree Bind Series of validation steps Columns and tables in the tree are compared Output: Algebrizer tree Optimize Evaluate different possible plans Use statistics to evaluate different plans Output: Execution Plan Execute Executes the plan

Plan types Optimal Fast execution Less resource consumption Non optimal Slow execution High resource consumption

Statistics

Statistics Type of object exists in the database. Uses to generate execution plan. Can be associated with and index or they can exists with table column. Can create manually or query optimizer will create it for you. Has three main pieces; Header Density Vector Histogram

Inside stats object Density Vector Header Histogram

Estimates vs actuals What is actuals? Figures after the query execution. What is estimates? Pre-determined values. Why SQL Server uses estimates? To create best possible Execution plan. When it uses estimates? At query optimization stage. How SQL Server uses estimates? We will go through in detail.

Cardinality estimator Calculate estimated no. of row counts for each operator within a query Exec. Plan Statistics C.E Estimated row counts

CE and estimates How many rows will satisfy a single filter predicate? Or 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? Major factor in deciding which physical operator and plan shapes

DEMO 1: Calculate Estimated Rows

DB options for stats

Importance of accurate cardinality estimates Memory Access Method Table Scan Index Scan Clustered Index Scan Index Seek Clustered Index Seek RID Lookup Join Type (Nested Loop, Merge, Hash)

New CE model

New CE model Introduced in SQL Server 2014 (C.L 120) Major redesign of CE model after SQL Server 7.0 (C.L 70) There are some changes in SQL Server 2016 too. Affect Exec. Plan quality While many workloads will benefit from the new CE, in some cases, workload performance may degrade without a specific tuning effort.

How to activate new CE model ALTER DATABASE [AdventureWorks2016] SET COMPATIBILITY_LEVEL = 120; TF 2312 Server level - DBCC TRACEON(2312,-1) Session level - DBCC TRACEON(2312) Query level - QUERYTRACEON 2312 To revert TF 9481

CE precedence Query Level Trace Flag Server or Session Level Trace Flag Database Compatibility Level

DEMO 2: The impact of new CE model

Under and over estimates of row counts Under estimates Selection of serial plan when parallelism would have been an optimal method. Inappropriate join strategies. Inefficient index selection and navigation strategies. Over estimates Selection of parallel plan when serial plan would be an optimal method. Inappropriate join strategies. Inefficient index navigation strategies. Inflated memory grants.

How do you know which CE model is using In XML plan XE Plan property window

Stats maintenance

How to create stats Automatically by the Query Optimizer AUTO_CREATE_STATISTICS DB option Always single column statistics Explicit creation by using CREATE STATISTICS statement Single or multi column statistics When an index is created Single or multi column statistics

How to update stats AUTO_UPDATE_STATISTICS ON (DB option) Automatically updates when they are out of date. Synchronous (default). Happens before optimization. AUTO_UPDATE_STATISTICS OFF Asynchronous happens after optimization. Index rebuild operation UPDATE STATISTICS statement Note: Index Reorganization does not update statistics not even index statistics.

Stats maintenance UPDATE STATISTICS dbo.salesorderdetail UPDATE STATISTICS dbo.salesorderdetail WITH SAMPLE 50 PERCENT UPDATE STATISTICS dbo.salesorderdetail WITH FULLSCAN, COLUMNS UPDATE STATISTICS dbo.salesorderdetail WITH FULLSCAN, INDEX UPDATE STATISTICS dbo.salesorderdetail WITH FULLSCAN UPDATE STATISTICS dbo.salesorderdetail WITH FULLSCAN, ALL ALTER INDEX ix_productid ON dbo.salesorderdetail REBUILD

New feature in SQL Server 2016 SP1 CU4 Persisting statistics sampling rate UPDATE STATISTICS [Sales].[SalesOrderHeaderBulk] [IX_OrderDate] WITH FULLSCAN, PERSIST_SAMPLE_PERCENT = ON

Recap

Recap Up to date statistics are the main key factor for quality execution plan. Statistics needs be maintained. Multi-column statistics can be used to improve query performance when there is correlation between columns. Filtered statistics can be used to improve query performance in certain situations. Create many if needed. While many workloads will benefit from the new Cardinality Estimator changes, in some cases, workload performance may degrade without a specific tuning effort. Use parameters instead of variables in stored procedures.

Recap Auto Create Statistics should be ON. Consider asynchronous statistics update only if your facing delays in query execution. Explicitly created statistics should be maintained otherwise they will easily get outdated.

References SQL Server Technical Article: Optimizing Your Query Plans with the SQL Server 2014 Cardinality Estimator Research paper: A Black Box Approach to Query Cardinality Estimation Testing Cardinality Estimation Models in SQL Server https://blogs.msdn.microsoft.com/psssql/2014/04/01 /sql-server-2014s-new-cardinality-estimator-part-1/

THANK YOU SPONSORS

Thank You For Attending!