SQL Performance for DBAs

Slides:



Advertisements
Similar presentations
1.
Advertisements

Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Introduction to SQL Tuning Brown Bag Three essential concepts.
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
Independent consultant Available for consulting In-house workshops Cost-Based Optimizer Performance By Design Performance Troubleshooting Oracle ACE Director.
Query Optimization Reserves Sailors sid=sid bid=100 rating > 5 sname (Simple Nested Loops) Imperative query execution plan: SELECT S.sname FROM Reserves.
Exadata Distinctives Brown Bag New features for tuning Oracle database applications.
Using the Optimizer to Generate an Effective Regression Suite: A First Step Murali M. Krishna Presented by Harumi Kuno HP.
Query Optimization CS634 Lecture 12, Mar 12, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
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 Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Access Path Selection in a Relational Database Management System Selinger et al.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Database Management 9. course. Execution of queries.
1 Chapter 7 Optimizing the Optimizer. 2 The Oracle Optimizer is… About query optimization Is a sophisticated set of algorithms Choosing the fastest approach.
Data Partitioning in VLDB Tal Olier
Oracle9i Performance Tuning Chapter 12 Tuning Tools.
SEMANTEC 1 Oracle Performance Tuning - Part I Krasen Paskalev Oracle 8i Certified DBA.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Module 4 Database SQL Tuning Section 3 Application Performance.
Chapter 5 Index and Clustering
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
Sorting and Joining.
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
How is data stored? ● Table and index Data are stored in blocks(aka Page). ● All IO is done at least one block at a time. ● Typical block size is 8Kb.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
CHAPTER 19 Query Optimization. CHAPTER 19 Query Optimization.
Top tips and techniques
SQL Server Statistics and its relationship with Query Optimizer
Practical Database Design and Tuning
AP CSP: Cleaning Data & Creating Summary Tables
Tuning Transact-SQL Queries
Cleveland SQL Saturday Catch-All or Sometimes Queries
EVOLUTION OF THE ORACLE OPTIMIZER THINKING
Using Stored Outlines & Profiles
Physical Database Design and Performance
Using Partitions and Fragments
Database Performance Tuning &
Query Tuning without Production Data
Query Tuning without Production Data
Optimizing SQL Queries
Software Architecture in Practice
Database Performance Tuning and Query Optimization
Overview of Query Optimization
Welcome!! While you are waiting…….. Have a look through your pack -
Chapter 15 QUERY EXECUTION.
Decoding the Cardinality Estimator to Speed Up Queries
From 4 Minutes to 8 Seconds in an Hour (or a bit less)
Examples of Physical Query Plan Alternatives
The Key to the Database Engine
Cardinality Estimates in SQL Server 2014
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Akshay Tomar Prateek Singh Lohchubh
Execution Plans Demystified
Statistics: What are they and How do I use them
Steve Hood SimpleSQLServer.com
Overview of Group Presentations & Counterarguments
Implementation of Relational Operations
Chapter 11 Database Performance Tuning and Query Optimization
EXECUTION PLANS Quick Dive.
Execution plans Eugene
Query Optimization.
Introduction to the Optimizer
Performance Tuning ETL Process
Query Transformations
All about Indexes Gail Shaw.
Presentation transcript:

SQL Performance for DBAs Steve Catmull UTOUG DBA SIG May 2012

A bit about Intermountain’s Data Warehouse We have an open environment. Any of our 200+ analysts can submit any query into production. We reserve the right to kill sessions. We publish high-resource users of our system. Just switched from single box to RAC last weekend.

A bit about me… I have worked for Intermountain Healthcare for 15 years (12 on the Data Warehousing Team). My fascination with databases started around 1982 when I started on Commodore 64 and helped write an invoicing application for my Mom’s business. I love a good challenge. A bit of obsessing goes a long way in solving difficult problems.

My SQL Performance Principles Know your data or know someone who does. Correct cardinality in explain plans is the heart of enduring performance. Right balance of simplicity and performance. Techniques have tradeoffs Don’t wait to look at waits.

Skills You Need Be able to read an explain plan Familiarity with the Oracle Concepts guide. Learn a few simple rules of how the optimizer works.

Know Your Data If you don’t know your data better than Oracle, this technique will not work. It’s okay to know someone who does.

What You Need to Know About Your Data Rough idea of how many rows are in tables. Rough idea of join cardinalities. For each parent, how many children rows? 1:1, 1:2, 1:3 … 1:n For popular columns that are filtered, know roughly how they are distributed. How much of a table are you going to select if you filter the table on that value?

What an Explain Plan Teaches Oracle thinks that about 4,000 male customers have spent more than 1775. With this explain plan what questions could you ask a subject matter expert? How many sales for more than 1775 have you made to male customers? How many customers for all time would you expect would have a sales bill for > 1775? How many customers are male? If they express in percentages… How many sales have you had over all time? (918000) so about .4% or 4 in a 1000 customers have sales amounts > 1775. How many customers do you have in the database? (55500) Do male and female customers tend to spend the same amount? Are you equally split on your highest bills?

Why is Cardinality Important? It is the key input to the optimizer. It’s why Oracle gathers these stats: Row counts for objects, segments, etc. Number of distinct values (NDV) Histograms

Beyond row cardinality Cardinality impacts cost. Cardinality is an input to cost calculations. Some other factors that affect plan choice & cost is: # of blocks (leaf/data) Clustering factor Density …

Cardinality Challenges Correlated columns Situational guesstimating Non-uniform distributions Non-uniform join cardinalities

Techniques Have Tradeoffs We are dealing with database SYSTEMS. Systems have lot of dependencies. If you add an index how might it effect… Overall processing time INSERT/UPDATE/DELETE performance Space used Contention Accept that sometimes the best thing may be no action at all.

Looking at Wait Events We call them wait events because something is always waiting. Waiting on IO Waiting on CPU Waiting for another session Waiting for the client to send a command. They give insight on what is going on right now and historically. “Database Performance Tuning Guide” for more details.

Looking at Waits (Instance)

Looking at Waits (session) This session has spent most of its time waiting on the client to send it something to do. The next most popular wait is to read data. Small little nuggets are found in the wait events like this one at the bottom showing that this session was waiting on the resource manager for a total of 4 seconds because some other users were given higher CPU priority over this user.

Applying These Principles “It Ran Fine Yesterday… and nothing changed”

“It Ran Fine Yesterday!” Common for DBA or Developer to say “Nothing changed.” Reality is that something changed. It can be costly to find the change vector / root cause. I often shift to making the most optimal query I can.

What Could Change? The common answer is “nothing changed” but… Everything could change. In reality it’s probably one of these: Underlying data Stats (object or system) Explain plan System load Cache hit on query Storage performance Query Execution method (binds versus literals) Oracle parameters

Applying the Principles Looking for Undesirable Patterns

Ascension of Doom Typical pattern Lots of work and the same cardinality for a long stretch. Often involving nested loops. Coupled with complains of poor execution time.

Are You Kidding Me? Resultant cardinality looks more like a Cartesian join. The cause is often Oracle gets confused on join cardinalities. Usually when someone is joining on data that has a function wrapped around it and especially analytical functions.

System HOGS

System Hogs Identify through “Top SQL” in OEM. Read explain plan through the lens of someone who knows the data. Do the cardinalities make sense? Any aggressive transformations being made by the optimizer?

Summary

Summary: Your Success It will depend on: Knowing your data or people who know your data Discovering how Oracle works. Example: Can you explain what these plan operations are doing? Determination

Summary – My Typical Checklist Does resultant cardinality look what I expect? Do I see odd patterns that I need to verify? Do I see nested loops where hash joins may be more appropriate. Do I see evidence of the optimizer doing some query transformations? Concatentation… Pushed predicates… Merge Cartesian…. Subquery unnesting Is the cardinality of the first few steps look right?

Let’s Explore