DBA 328 Designing for Performance: Optimization with Indexes Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com

Slides:



Advertisements
Similar presentations
Dos and don’ts of Columnstore indexes The basis of xVelocity in-memory technology What’s it all about The compression methods (RLE / Dictionary encoding)
Advertisements

Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Architecting a Large-Scale Data Warehouse with SQL Server 2005 Mark Morton Senior Technical Consultant IT Training Solutions DAT313.
OFC324 Microsoft Project Server: Putting Enterprise Project Management (EPM) To Work Sam Brooks
DBA 322 Optimizing Stored Procedure Performance Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
DAT308 SQL Server 2000 Profiler: The Database Programmer's Best Friend Fernando G. Guerrero S olid Q uality L earning
Maintaining a Microsoft SQL Server 2008 Database SQLServer-Training.com.
Monday, 13 October 2003 The Anatomy of a Data Modification Subset of: What everyone should know about Performance, Recovery & Logging Monday, 13 October.
Designing for Performance General Database Optimizations Presentation Highlight: The Anatomy of a Data Modification Wednesday, 12 November 2003 – 16:30-18:00.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
OFC304 Excel 2003 Overview: XML Support Joseph Chirilov Program Manager.
OFC 200 Microsoft Solution Accelerator for Intranets Scott Fynn Microsoft Consulting Services National Practices.
DAT335 SQL Server 2000 Tips and Tricks: DBAs and Developers Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com
SEC303 Assessing and Managing Privacy in the Enterprise JC Cannon Privacy Strategist.
Module 12: Optimizing Query Performance. Overview Introducing the Query Optimizer Tuning Performance Using SQL Utilities Using an Index to Cover a Query.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
OFC 303 Advanced Word XML: Customer-Defined Schemas Brian Jones Program Manager Authoring Services.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design
Understanding Logging & Recovery What Programmers Always Avoid Until it’s too Late! Kimberly L. Tripp Principal Mentor, Solid Quality Learning at
By Shanna Epstein IS 257 September 16, Cnet.com Provides information, tools, and advice to help customers decide what to buy and how to get the.
Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000.
DEV303 ASP.NET: Leveraging Visual Studio.NET For Web Projects Tony Goodhew Product Manager Microsoft Corp.
DAT 332 SQL Server 2000 Data Transformation Services (DTS) Best Practices Euan Garden Product Unit Manager SQL Server Development Microsoft Corporation.
DEP331 Migrating to Windows XP Mike Coleman Lead Product Manager, Windows XP Microsoft Corporation.
Indexes and Views Unit 7.
SQL School is strongly committed to provide COMPLETE PRACTICAL REALTIME Trainings on SQL Server Technologies – Dev, SQL DBA, MSBI (SSIS, SSAS, SSRS) and.
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.
Connect with life Nauzad Kapadia Quartz Systems
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.
OFC311 Developing Microsoft Office InfoPath 2003 Solutions: Technical Drilldown Part 1 Tudor Toma Group Program Manager Office Microsoft Corporation.
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Patrick Ortiz Global SQL Solution Architect Dell Inc. BIN209.
Introducing Application and Multi-Server Management.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
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.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Chris Index Feng Shui Chris
Indexes By Adrienne Watt.
Parameter Sniffing in SQL Server Stored Procedures
Introduction to SQL Server Management for the Non-DBA
Database Performance Tuning and Query Optimization
SQL 2014 In-Memory OLTP What, Why, and How
Query Optimization Techniques
Azure SQL DWH: Tips and Tricks for developers
Indexing Fundamentals
Steve Hood SimpleSQLServer.com
Reading Execution Plans Successfully
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Please thank our sponsors!
Query Processing CSD305 Advanced Databases.
Azure SQL DWH: Tips and Tricks for developers
Chapter 11 Database Performance Tuning and Query Optimization
Diving into Query Execution Plans
Query Optimization Techniques
Reading execution plans successfully
All about Indexes Gail Shaw.
Presentation transcript:

DBA 328 Designing for Performance: Optimization with Indexes Kimberly L. Tripp Solid Quality Learning – SolidQualityLearning.com SYSolutions, Inc. – SQLSkills.com

Introduction Kimberly L. Tripp, SQL Server MVP Principal Mentor, Solid Quality Learning * In-depth, high quality training around the world! Content Manager for Writer/Editor for TSQL Solutions/SQL Mag and Consultant/Trainer/Speaker Coauthor for MSPress title: SQL Server 2000 High Availability Presenter/Technical Manager for SQL Server 2000 High Availability Overview DVD Very approachable. Please ask me questions!

Overview Selectivity How to Improve Queries with Varying Search Arguments (SARGs) Indexing for AND Indexing for OR How to Improve Joins How to Improve Aggregations Indexes on Base Tables Indexed Views

Selectivity Not just based on the Number of Rows Returned Always Relative to the Number of Rows in the Table (usually expressed as a percentage) Low Number = High Selectivity Any Index is Useful if even ONE condition is highly selective! High Number = Low Selectivity This is harder!

How to Improve Search ARGs Don’t use * in your queries! Limit Column List Returned to Client (views!) Make Sure You Limit Rows – ALWAYS Use a WHERE Clause Isolate Columns MonthlySalary > /12 -- CAN Seek MonthlySalary * 12 > MUST Scan Minimize Wildcards – Avoid Leading Wildcards Always supply a join condition for every table

Low Selectivity Queries Limited Select List Index On Columns Requested SELECT LastName, FirstName, PhoneNo FROM dbo.Member WHERE LastName LIKE ‘[S-Z]%’ Rows, 3072 in S-Z Range Covering! A Mini Clustered Table of Just the Data You Need!

Options to Access Data Table Scan Nonclustered on LastName Bookmark Lookups for Every Row Nonclustered on LastName, FirstName and PhoneNo Nonclustered on FirstName, LastName, PhoneNo

Actual Costs Table Scan = 184 Reads NC LastName = 6354 Reads NC Covering Seek = 19 Reads NC Covering SCAN = 59 Reads

Indexing for AND AND Progressively Limits the SET All Conditions MUST be true Find the SMALLEST Set and work from there. Evaluate Columns in WHERE A Single Highly Selective Condition Any combination of Highly Selective Criteria If NOTHING Yields a Selective Set Consider Covering

Indexing for OR OR Is Similar to UNION ANY Condition must be true Optimally find each set or scan for the whole thing – requires useful indexes for EACH AND EVERY condition Consider re-writing as UNION Include a Row Identifier – such as the Primary Key – to get same results (OR only equals UNION if the SELECT list has a UNIQUE row identifier) Test!

Indexing for Joins Tables are Joined Two Tables at a Time Each Table has a Join Condition Optionally Each Table has a SARG Usually the Join is Between the Primary and Foreign Key Always Try to Give SQL Server as Many Options to Choose From…

Best Options for Joins Table1 Table2 SARG1 Join Col PK SARG2 Join Col FK One Join Strategy Might use Table1 SARG1 to Table2 Join Another could use Table2 SARG2 to Table1 Join Another could use the Join Indexes on Both Tables BUT if ALL 4 Indexes are there then the Join has the best Options to choose from! Do you already have individual indexes on each and all of these columns? Foreign Key???

Cover the Combination SARG1 Join Col PK SARG2 Join Col FK Not Using Any of These Indexes? Performance Still Awful? Cover the Combo – Create 4 Indexes (2 Per Table) Table1 (SARG, Join) – Priority to the Search Condition Table1 (Join, SARG) – Priority to the Join Condition Test! Still not working? Table1 Table2

Cover One/Both of the Tables SARG1 Join Col PK SARG2 Join Col FK Not Using Any of These Indexes? Performance Still Awful? Try Covering – Create Indexes to Cover the Individual Tables requested… Trying them in both orders – Priority for the Join and Priority for the SARG. Still not working? Table1 Table2

Indexing for Aggregations Two types of Aggregates Stream and Hash Try to Achieve Stream to Minimize Overhead in temp table creation Computation of the Aggregate Still Required Lots of Users, Contention and/or Minimal Cache can Aggravate the problem!

Aggregate Query Member has 10,000 Rows Charge has 800,000 Rows SELECT member_no AS MemberNo, sum(charge_amt) AS TotalSales FROM dbo.charge GROUP BY member_no

Aggregate Query No Indexes Table 'charge'. Scan count 1, logical reads 4858

Aggregate Query Hash Match Table 'charge'. Scan count 1, logical reads 2275

Aggregate Query Stream Table 'charge'. Scan count 1, logical reads 2275

Aggregate Query Indexed View Requirements: Enterprise Edition Only (or Developer – for testing) View Must Be SCHEMABOUND to the Base Table View Must include COUNT_BIG if Aggregate in View Concern: Test Performance of INSERT/DELETE/UPDATE to Base Table Benefits: Data is Pre-aggregated, no hash or stream Minimized Contention, Minimized Cache Utilization Check out the Resources Listed at the End of this Session for more info and reading about Indexed Views!

Aggregate Query Indexed View Table 'charge'. Scan count 1, logical reads 34

What’s the Diff?

Index Strategies Determine Primary Usage of Table – OLTP vs. OLAP vs. Combo? This determines Clustered Index Create Constraints – Primary Key and Alternate/Candidate Keys Manually Add Indexes to Foreign Key Constraints Capture a Workload and Run through Index Tuning Wizard Continue to test, tune and troubleshoot and Add Additional Indexes using these strategies

Summary Limit the Search Limit Columns Requested Prioritize OLTP/OLAP choose Clustered Index Strategy Add Nonclustered for PK/UK/FK Add Nonclustered for SARGs Consider Covering for Low Selectivity Test, Test, Test!

Review Selectivity How to Improve Queries with Varying Search Arguments (SARGs) Indexing for AND Indexing for OR How to Improve Joins How to Improve Aggregations Indexes on Base Tables Indexed Views

DAT 335 – SQL Server Tips and Tricks for DBAs and Developers Tuesday, 1 July 2003, 15:15-16:30 DBA 324 – Designing for Performance: Structures, Partitioning, Views and Constraints Wednesday, 2 July 2003, 08:30-09:45 DBA 328 – Designing for Performance: Optimization with Indexes Wednesday, 2 July 2003, 16:45-18:00 DBA 322 – Optimizing Stored Procedure Performance in SQL Server 2000 Thursday, 3 July 2003, 08:30-09:45 Other Sessions…

Articles in TSQLSolutions at (FREE, just register) All About Raiserror, InstantDoc ID#22980 Saving Production Data from Production DBAs, InstantDoc ID#22073 Articles in SQL Server Magazine, Sept 2002: Before Disaster Strikes, InstantDoc ID#25915 Log Backups Paused for Good Reason, InstantDoc ID#26032 Restoring After Isolated Disk Failure, InstantDoc #26067 Filegroup Usage for VLDBs, InstantDoc ID#26031 Search and for additional articleswww.sqlmag.comwww.tsqlsolutions.com Articles…

Check out for scripts, demos, links and new resources! Inside Microsoft SQL Server 2000, Kalen Delaney, MS Press, ISBN: Whitepaper: Database Architecture: The Storage Engine, us/dnsql2k/html/thestorageengine.asp? us/dnsql2k/html/thestorageengine.asp Register on to get free access to technical TSQL articles from SQL Server Magazine. Check out Instant Doc ID#23733 for the “n-Table Joins” article for more information on adding redundant keys. Resources…

Whitepaper: Statistics Used by the Query Optimizer in Microsoft SQL Server 2000, Whitepaper: Microsoft SQL Server 2000 Index Defragmentation Best Practices chnet/prodtechnol/sql/maintain/Optimize/SS2KIDBP.asp chnet/prodtechnol/sql/maintain/Optimize/SS2KIDBP.asp Support WebCast: SQL Server 2000 Profiler: What's New and How to Effectively Use It sks%2Fwebcasts%2Fwc111400%2Fwcblurb111400%2Easp sks%2Fwebcasts%2Fwc111400%2Fwcblurb111400%2EaspResources…

Community Resources Most Valuable Professional (MVP) Newsgroups Converse online with Microsoft Newsgroups, including Worldwide User Groups Meet and learn with your peers

Ask The Experts Get Your Questions Answered I will be available in the ATE area after most of my sessions!

Kimberly L. Tripp Principal Mentor, Solid Quality Learning Website: President, SYSolutions, Inc. Website: Thank You! Thank You!

Suggested Reading And Resources The tools you need to put technology to work! TITLE Available Microsoft® SQL Server™ 2000 High Availability: /9/03 Today Microsoft® SQL Server™ 2000 Administrator's Companion: Microsoft Press books are 20% off at the TechEd Bookstore Also buy any TWO Microsoft Press books and get a FREE T-Shirt

evaluations evaluations

© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.