Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, 2001 -- SQL Server 2000.

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
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Advanced Databases: Lecture 2 Query Optimization (I) 1 Query Optimization (introduction to query processing) Advanced Databases By Dr. Akhtar Ali.
Module 14: Analyzing Queries. Overview Queries That Use the AND Operator the OR Operator Join Operations.
Module 13: Optimizing Query Performance. Overview Introduction to the Query Optimizer Obtaining Execution Plan Information Using an Index to Cover a Query.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Indexes Rose-Hulman Institute of Technology Curt Clifton.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Module 7: Creating and Maintaining Indexes. Overview Creating Indexes Creating Index Options Maintaining Indexes Introduction to Statistics Querying the.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
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.
Query Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.
Advanced Databases: Lecture 6 Query Optimization (I) 1 Introduction to query processing + Implementing Relational Algebra Advanced Databases By Dr. Akhtar.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
DBA 328 Designing for Performance: Optimization with Indexes Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com
Indexes and Views Unit 7.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Chapter 4 Indexes. Index Architecture  By default data is inserted on a first-come, first-serve basis  Indexes bring order to this chaos  Once you.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
Pinal Dave Mentor | Solid Quality India |
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
Dave LinkedIn
Indexes Part 2 What type of Indexes are there? Make sure you have the pages 2 & 3 of the Lab for Indexes in front of you before playing this presentation.
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.
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.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Select Operation Strategies And Indexing (Chapter 8)
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Chris Index Feng Shui Chris
Microsoft SQL Server 2005 Advanced SQL Programming and Optimization
Indexes By Adrienne Watt.
CS522 Advanced database Systems
Advanced SQL Programming for SQL Server 2008
Database Performance Tuning &
Database Performance Tuning and Query Optimization
Chapter 15 QUERY EXECUTION.
The Key to the Database Engine
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Statistics: What are they and How do I use them
Chapter 4 Indexes.
CH 4 Indexes.
Reading Execution Plans Successfully
CH 4 Indexes.
Dave Bland LinkedIn SQL Server Execution Plans: How to use them to find performance bottlenecks Dave Bland LinkedIn
Query Processing CSD305 Advanced Databases.
Chapter 11 Database Performance Tuning and Query Optimization
Diving into Query Execution Plans
All about Indexes Gail Shaw.
Presentation transcript:

Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000

2 Agenda Introduction to Optimizing Queries Index Strategies Query Plan Analysis

3 Overview Introduction to the Query Optimizer Obtaining Query Plan Information Indexing Fundamentals Introduction to Statistics

4 Function of the Query Optimizer Determines the Most Efficient Query Plan Determining whether indexes exist and evaluating their usefulness Determining which indexes or columns can be used Determining how to process joins Using cost-based evaluation Creating column statistics Produces a Query Plan Uses Available Information

5 How the Query Optimizer Uses Cost-Based Optimization Limits the Number of Optimization Plans Cost is estimated in terms of I/O and CPU cost Determines Query Processing Time Use of physical operators and sequence of operations Use of parallel and serial processing

6 How the Query Optimizer Works Parsing Process Standardization Process Query Optimization Compilation Database Access Routines Transact-SQL Results Set Results Set

7 Query Optimization Phases Query Analysis Identifies the search and join criteria of the query Index Selection Determines whether an index or indexes exist Assesses the usefulness of the index or indexes Join Selection Evaluates which join strategy to use

8 Caching Query Plan Storing a Query Plan in Memory One copy for all serial executions Another copy for all parallel executions Using an Execution Context An existing query plan is reused, if one exists A new query plan is generated, if one does not exist Recompiling Query Plans Changes in database cause query plan to be inefficient or invalid

9 Obtaining Query Plan InformationObtaining Query Plan Information Querying the sysindexes Table Viewing STATISTIC Statements Output Viewing SHOWPLAN_ALL and SHOWPLAN_TEXT Output Viewing Graphical Showplan

10 Querying the sysindexes Table Stores Table and Index Information Type of index (indid) Space used (dpages, reserved, and used) Fill factor (OrigFillFactor) Stores Statistics for Each Index

11 Viewing SHOWPLAN_ALL and SHOWPLAN_TEXT Output Structure of the SHOWPLAN Statement Output Returns information as a set of rows Forms a hierarchical tree Represents steps taken by the query optimizer Shows estimated values of how a query was optimized, not the actual query plan Details of the Execution Steps Difference Between SHOWPLAN_TEXT and SHOWPLAN_ALL Output

12 Viewing Graphical Showplan Viewing Graphical Showplan Elements of Graphical Showplan Reading Graphical Query Plan Output

13 Elements of Graphical Showplan Steps Are Units of Work to Process a Query Sequence of Steps Is the Order in Which the Steps Are Processed Logical Operators Describe Relational Algebraic Operation Used to Process a Statement Physical Operators Describe Physical Implementation Algorithm Used to Process a Statement

14 Reading Graphical Query Plan Output Query Plan SELECT Cost: 0% Bookmark Lookup Cost: 8% Hash Match Root… Cost 28% Member.corp_no Cost 9% Member.fname Cost: 10% Filter Cost: 0% Sequence of Steps Index Seek Scanning a particular range of rows from a non-clustered index. Index Seek Scanning a particular range of rows from a non-clustered index. Physical operation: Logical operation: Row count: Estimated row sizes: I/O cost: CPU cost: Number of executes: Cost: Subtree cost: Index Seek (6%) Argument: OBJECT: ([credit].[dbo].[member].[fname]), SEEK: ([member],[firstname] >=‘Rb’ AND [member],[firstname] <‘T’) ORDERED

15 Indexing Fundamentals Indexing Fundamentals Understanding the Data Limiting a Search Determining Selectivity Determining Density Determining Distribution of Data

16 Determining Selectivity High selectivity member_nomember_no last_namelast_namefirst_namefirst_name Randall Flood Joshua Kathie Anderson Bill SELECT * FROM member WHERE member_no > = 10% Number of rows meeting criteria Total number of rows in table = Low selectivity member_nomember_no last_namelast_namefirst_namefirst_name Randall Flood Joshua Kathie Anderson Bill SELECT * FROM member WHERE member_no < = 90% Number of rows meeting criteria Total number of rows in table =

17 Determining Density last_namelast_namefirst_namefirst_name Randall Joshua Randall Cynthia Randall Tristan Ota Lani SELECT * FROM member WHERE last_name = ‘Ota’ Low Density SELECT * FROM member WHERE last_name = ‘Randall’ High Density

18 Determining Distribution of Data Standard Distribution of Values F - JA - EK - OP - UV - Z Last Name Number of Last Names Even Distribution of Values Last Name Number of Last Names C - FA - BG - K L - NO - Z

19 Updating Statistics Frequency of Updating Statistics Automatically Updating Statistics Manually Updating Statistics If you created an index before any data was put into the table If a table is truncated If you added many rows to a table that contained minimal or no data, and you plan to immediately query against that table

20 Viewing Statistics SQL Server Returns Information on: The Time When the Statistics Were Last Updated The Number of Rows Sampled to Produce the Histogram Density Information Average Key Length Contents of the statsblob Column DBCC SHOW_STATISTICS

21 Overview Accessing Data Using an Index to Cover a Query Using Index Tuning Tools to Improve Query Performance Indexing Strategies

22 Accessing Data Accessing Data Table Scans and Indexes Index Architecture and Navigation Using Row Identifiers to Access Data

23 Table Scans and Indexes Indexes Use Key Values to Locate Data Table Scans Access Every Page Data Pages … … … … Index Pages

24 Index Architecture and Navigation Clustered Index Nonclustered Index Index Pages Non-Leaf Level Leaf Level (Key Value) Data Pages Leaf Level Index Pages Non-Leaf Level Data Pages

25 Using Row Identifiers to Access Data Creation and Storage of a RID Consists of the file number, page number, and slot number, which identify the exact location of a row Is an internal value RID Is Used to Retrieve Rows Accessing the nonclustered index Performing a Bookmark Lookup operation

26 Using an Index to Cover a Query Using an Index to Cover a Query Introduction to Indexes That Cover a Query Locating Data by Using Indexes That Cover a Query Identifying Whether an Index Can Be Used to Cover a Query Determining Whether an Index Is Used to Cover a Query Guidelines to Creating Indexes That Can Cover a Query

27 Locating Data by Using Indexes That Cover a Query Example of Single Page Navigation Example of Partial Scan Navigation Example of Full Scan Navigation

28 Example of Single Page Navigation Index Pages Non-Leaf Level Non-Leaf Level Leaf Level (Key Value) SELECT lastname, firstname FROM member WHERE lastname = 'Hall' SELECT lastname, firstname FROM member WHERE lastname = 'Hall' Akhtar Barr Borm Buhl … … … … … … … … … … Ganio Hall Hart Jones … … … … … … … … … … Hall… Morgan Nash Nay Ota Rudd … … … … … … … … … … Martin Smith … … Akhtar Ganio … … Akhtar … … Martin Chai Con Cox Dale … … … … … … … … … … Dunn Fine Fort Funk … … … … … … … … … … Jordan Kim Koch … … … … … … … … … … Lang Martin Moris … … … … … … … … … … Smith … … … … … … … … … … … Data Pages

29 Example of Partial Scan Navigation Index Pages Non-Leaf Level Non-Leaf Level Leaf Level (Key Value) Akhtar Barr Borm Buhl … … … … … … … … … … Ganio Hall Hart Jones … … … … … … … … … … Morgan Nash Nay Ota Rudd … … … … … … … … … … Martin Smith … … Akhtar Ganio … … Akhtar … … Martin Chai Con Cox Dale … … … … … … … … … … Dunn Fine Fort Funk … … … … … … … … … … Jordan Kim Koch … … … … … … … … … … Lang Martin Moris … … … … … … … … … … Smith … … … … … … … … … … Data Pages USE credit SELECT lastname, firstname FROM member WHERE lastname BETWEEN 'Funk' AND 'Lang' USE credit SELECT lastname, firstname FROM member WHERE lastname BETWEEN 'Funk' AND 'Lang'

30 Example of Full Scan Navigation Index Pages Non-Leaf Level Non-Leaf Level Leaf Level (Key Value) Akhtar Barr Borm Buhl … … … … … … … … … … Ganio Hall Hart Jones … … … … … … … … … … Morgan Nash Nay Ota Rudd … … … … … … … … … … Martin Smith … … Akhtar Ganio … … Akhtar … … Martin Chai Con Cox Dale … … … … … … … … … … Dunn Fine Fort Funk … … … … … … … … … … Jordan Kim Koch … … … … … … … … … … Lang Martin Moris … … … … … … … … … … Smith … … … … … … … … … … … Data Pages USE credit SELECT lastname, firstname FROM member USE credit SELECT lastname, firstname FROM member

31 Identifying Whether an Index Can Be Used to Cover a Query All Data Can Be Found in the Index First Column of a Composite Index Is Not Referenced in the WHERE Clause A WHERE Clause Does Not Exist There Is a Clustered Index on a Column Referenced in the WHERE Clause, and Selectivity Requires More I/O to Use the Clustered Index Join Operations Exist

32 Determining Whether an Index Is Used to Cover a Query Observing the Query Plan Output Displays the phrase “Scanning a nonclustered index entirely or only a range” Comparing I/O Nonclustered index Total number of levels in the non–leaf level Total number of pages that make up the leaf level Total number of rows per leaf-level page Total number of rows per data page Total Number of pages that make up the table

33 Guidelines to Creating Indexes That Can Cover a Query Adding Columns to Indexes Limiting Index Key Size Maintaining Row-to-Key Size Ratio

34 Demo: Analyzing How Queries Are Covered By Different Types of Indexes

35 Using Index Tuning Tools to Improve Query Performance Using the Index Tuning Wizard Recommends or verifies optimal index configuration Provides cost analysis reports Recommends ways to tune the database Specifies criteria when a workload is evaluated Using the Index Analysis Tool Recommends optimal set of indexes to support a given query or batch

36 Access Method Page I/O Table scan 10,417 Clustered index on the charge_amt column 1042 Nonclustered index on the charge_amt column 100,273 Composite index on charge_amt, charge_no columns 273 Evaluating I/O for Queries That Access a Range of Data SELECT charge_no FROM charge WHERE charge_amt BETWEEN 20 AND 30

37 Demo : Analyzing Queries That Use the AND and OR Operators

Microsoft AREC TAM Internship go WHERE DO YOU WANT TO ? TODAY Microsoft