Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

Understanding SQL Server Query Execution Plans
CS 540 Database Management Systems
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Module 13: Optimizing Query Performance. Overview Introduction to the Query Optimizer Obtaining Execution Plan Information Using an Index to Cover a Query.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
8-1 Outline  Overview of Physical Database Design  File Structures  Query Optimization  Index Selection  Additional Choices in Physical Database Design.
CS 4432query processing - lecture 171 CS4432: Database Systems II Lecture #17 Join Processing Algorithms (cont). Professor Elke A. Rundensteiner.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
Database System Architecture and Performance CSCI 6442 ©Copyright 2015, David C. Roberts, all rights reserved.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
Module 12: Optimizing Query Performance. Overview Introducing the Query Optimizer Tuning Performance Using SQL Utilities Using an Index to Cover a Query.
Denny Cherry Manager of Information Systems MVP, MCSA, MCDBA, MCTS, MCITP.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Database Management 9. course. Execution of queries.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Data Partitioning in VLDB Tal Olier
Primary Key, Cluster Key & Identity Loop, Hash & Merge Joins Joe Chang
Copyright © Curt Hill Query Evaluation Translating a query into action.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Connect with life Nauzad Kapadia Quartz Systems
2010 Ami Levin. SQL Server implements three different physical operators to perform joins. In this session we will see how each of these three operators.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Sorting and Joining.
File Processing : Query Processing 2008, Spring Pusan National University Ki-Joune Li.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Eugene Meidinger Execution Plans
Dave LinkedIn
How to kill SQL Server Performance Håkan Winther.
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.
Tuning Transact-SQL Queries
CS 440 Database Management Systems
Query Tuning without Production Data
Query Tuning without Production Data
Database Performance Tuning and Query Optimization
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE
Introduction to Execution Plans
The Key to the Database Engine
Physical Join Operators
File Processing : Query Processing
Physical Database Design
Execution Plans Demystified
SQL Server 2016 Execution Plan Analysis Liviu Ieran
Selected Topics: External Sorting, Join Algorithms, …
SQL Server Query Plans Journeyman and Beyond
Dave Bland LinkedIn SQL Server Execution Plans: How to use them to find performance bottlenecks Dave Bland LinkedIn
Introduction to Execution Plans
Implementation of Relational Operations
Chapter 11 Database Performance Tuning and Query Optimization
EXECUTION PLANS Quick Dive.
Evaluation of Relational Operations: Other Techniques
Diving into Query Execution Plans
Introduction to Execution Plans
Introduction to Execution Plans
All about Indexes Gail Shaw.
Presentation transcript:

virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft Regional Director, Bangalore │ MVP, ASP.NET

Query Architecture

Query optimizer and statistics SQL Server always used a statistic based query optimizer Statistical information is used to chose the optimal index for a particular query The most important information for the optimizer is: – Selectivity or density: How many different values exist in this column of the table? – Histogram over the values of a column: How often does one particular value exist?

Analyzing Factors Application Database Design Microsoft SQL Server Operating System Hardware

SQL Coding Issues Excessive Scanning Poor use of indexes/missing Indexes Out of Date Table Statistics Non-selective Triggers ‘Where’ clause not limiting record set enough Excessive Recompiles Long blocking durations (multi-connections)

Where Limit number of Columns Avoid <>, OR, and not Indexed fields Avoid calculated columns Avoid functions Avoid redundant criteria

Search Arguments Equality Predicate SELECT * FROMCUSTOMER WHERE CUSTOMER_NAME = 'CUSTOMER# ' Range Predicate SELECT * FROMCUSTOMER WHERE CUSTOMER_ID BETWEEN 100 AND 200 Conjunctions SELECT * FROMORDER_ITEM WHERE SHIP_DATE = ' ' AND SUPPLIER_ID = 350 ANDPRODUCT_ID > Search arguments useful in driving index seeks

Non-Search Arguments Not Predicates SELECT * FROMCUSTOMER WHERE CUSTOMER_ID <> 100 Like pattern on left of column SELECT * FROMCUSTOMER WHERE CUSTOMER_NAME LIKE ‘%47‘ Function on column SELECT * FROMORDER_ITEM WHERE YEAR(SHIP_DATE) = 1998 Non-search arguments may still be evaluated in an index In Where clause of Index Scan or Index Seek Operator

Understanding Joins Outer Table Inner Table Join Method

Nested Loop Algorithm – Get Row From Outer Table (1st input to Join operator in showplan) Get Matching Row From Inner Table (2nd input to Join operator in showplan) Output Composite Result Loop Through Inner Table When Inner Table Exhausted,Loop on Outer Table Outer Table Inner Table

Merge Join Algorithm Get next row from outer table – Get next row from inner table with same key – If found output and loop on inner table – If not found loop on outer table Join Sequence Match and Merge Outer Table Inner Table

Hash Join Algorithm Scan Smaller (Build) Table – Hash Build Key Values; Store in Hash Table – 1st input to Join operator in SHOWPLAN Scan Larger (Probe) table – Hash Probe Key Value; Look Up in Hash Table – If Found, Output Result – 2nd input to Join operator in SHOWPLAN Build Table Hash Table Probe Table Lookup in Hash Table Lookup in Hash Table Hash Join Key Key Join Hash

Troubleshooting Join Performance Is join predicate missing? Indexes on join column(s)? Join columns exact data type match? Examine Statistics Profile for estimates versus actual – Hash Join: EstimateRows for child operator producing Build input – Nested Loop: EstimateExecute for inner table (2nd input) – Merge Scan: EstimateRows for Sort Operator (if present) Examine STATISTCS IO – SET STATISTICS IO ON – If Hash Join, are workfiles present Indicate Build tables have spilled to tempdb Last Resort: Join Hints

Stored Procedures Execution Plan Usage Keep them small Recompiles – Causes – Avoiding Analysis

Intelligent Indexing Minimizing result sets to columns needed (Covering index approach) instead of select * Avoid indexing fields that change frequently Compound Indexes – Unique >>>>Non-Unique

How do you do Partitioning? Before a table is partitioned two things have to be created, a partition Function and Schema Partition Function – Each row of an index/table is assigned to a partition (numbered 1, 2, 3,...) by using a “Partition Function” SQL Server 2005 supports Range partitioning only on a single column User defines the key column, the number of partitions, and the partition boundary points Partition Scheme – Each partition for a partition function is mapped to a physical storage location (Filegroup) through a “Partition Scheme”