Independent consultant Available for consulting In-house workshops Cost-Based Optimizer Performance By Design Performance Troubleshooting Oracle ACE Director.

Slides:



Advertisements
Similar presentations
Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Advertisements

The Basics of Efficient SQL Written for myself –Writing doesnt make you rich Proof of what works –and what doesnt Three parts: –Data Model Tuning –SQL.
Chapter 13: Query Processing
Query Processing Reading: CB, Chaps 5 & 23. Dept of Computing Science, University of Aberdeen2 In this lecture you will learn the basic concepts of Query.
Independent consultant Available for consulting In-house workshops Cost-Based Optimizer Performance By Design Performance Troubleshooting Oracle ACE Director.
Examples of Physical Query Plan Alternatives
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.
Overview of Query Evaluation (contd.) Chapter 12 Ramakrishnan and Gehrke (Sections )
Query Optimization Reserves Sailors sid=sid bid=100 rating > 5 sname (Simple Nested Loops) Imperative query execution plan: SELECT S.sname FROM Reserves.
Natural Data Clustering: Why Nested Loops Win So Often May, 2008 ©2008 Dan Tow, All rights reserved SingingSQL.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
CSE544 Database Statistics Tuesday, February 15 th, 2011 Dan Suciu , Winter
Query Optimization May 31st, Today A few last transformations Size estimation Join ordering Summary of optimization.
Query Optimization CS634 Lecture 12, Mar 12, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
SQL Performance 2011/12 Joe Chang, SolidQ
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Query Execution, Concluded Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 18, 2003 Some slide content may.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 8.
Query Optimization Goal: Declarative SQL query
A Fast Growing Market. Interesting New Players Lyzasoft.
Efficient Query Evaluation on Probabilistic Databases
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
1 The Optimizer How ORACLE optimizes SQL statements David Konopnicky 1997, Revised by Mordo Shalom 2004.
The query processor does what the query plan tells it to do A “good” query plan is essential for a well- performing.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
CS 345: Topics in Data Warehousing Tuesday, October 19, 2004.
Course Title Database Technologies Instructor: Dr ALI DAUD Course Credits: 3 with Lab Total Hours: 45 approximately.
Access Path Selection in a Relational Database Management System Selinger et al.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
From Zero to Hero : Using an assortment of caching techniques to improve performance of SQL containing PL/SQL calls. Tim Hall.
Views Lesson 7.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Indexes and Views Unit 7.
CS453: Databases and State in Web Applications (Part 2) Prof. Tom Horton.
Chap 5. Disk IO Distribution Chap 6. Index Architecture Written by Yong-soon Kwon Summerized By Sungchan IDS Lab
DB Tuning : Chapter 10. Optimizer Center for E-Business Technology Seoul National University Seoul, Korea 이상근 Intelligent Database Systems Lab School of.
Query Processing – Implementing Set Operations and Joins Chap. 19.
REED : Robust, Efficient Filtering and Event Detection in Sensor Network Daniel J. Abadi, Samuel Madden, Wolfgang Lindner Proceedings of the 31st VLDB.
IMinMax B.C. Ooi, K.-L Tan, C. Yu, S. Stephen. Indexing the Edges -- A Simple and Yet Efficient Approach to High dimensional Indexing. ACM SIGMOD-SIGACT-
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
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 Tuning Scripts Bobby Durrett US Foodservice
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
 Independent consultant  Performance Troubleshooting  In-house workshops  Cost-Based Optimizer  Performance By Design  Oracle ACE Director  Member.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Tuning Transact-SQL Queries
Relational Algebra Chapter 4 1.
A Black-Box Approach to Query Cardinality Estimation
Choosing Access Path The basic methods.
Interpreting Execution Plans
Database Performance Tuning and Query Optimization
Blazing-Fast Performance:
Chapter 15 QUERY EXECUTION.
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
From 4 Minutes to 8 Seconds in an Hour (or a bit less)
Examples of Physical Query Plan Alternatives
Cardinality Estimator 2014/2016
Relational Algebra 1.
Relational Algebra Chapter 4 1.
Akshay Tomar Prateek Singh Lohchubh
Query Processing CSD305 Advanced Databases.
Chapter 11 Database Performance Tuning and Query Optimization
Query Optimization.
SQL Performance for DBAs
Presentation transcript:

Independent consultant Available for consulting In-house workshops Cost-Based Optimizer Performance By Design Performance Troubleshooting Oracle ACE Director Member of OakTable Network

Optimizer Basics – Key Concepts Proactive: Performance by design Reactive: Troubleshooting

Three main questions you should ask when looking for an efficient execution plan: How much data? How many rows / volume? How scattered / clustered is the data? Caching? => Know your data!

Why are these questions so important? Two main strategies: One Big Job => How much data, volume? Few/many Small Jobs => How many times / rows? => Effort per iteration? Clustering / Caching

Optimizers cost estimate is based on: How much data? How many rows / volume? How scattered / clustered? (partially) (Caching?) Not at all

Single table cardinality Join cardinality Filter subquery / Aggregation cardinality

Selectivity of predicates applying to a single table

Base CardinalityFiltered Cardinality / Filter Ratio

Optimizer challenges Skewed column value distribution Gaps / clustered values Correlated column values Complex predicates and expressions Bind variables

Demo! optimizer_basics_single_table_cardinality_testcase.sql

Tree shape of execution plan

T1T2 T1, T2 1,000 rows 0 rows 1,000,000 rows

T1T2 T1, T2 Join cardinality = Cardinality T1 * Cardinality T2 * Join selectivity

Challenges Semi Joins (EXISTS (), = ANY()) Anti Joins (NOT EXISTS (), <> ALL()) Non-Equi Joins (Range, Unequal etc.)

Demo! optimizer_basics_join_cardinality_testcase.sql

1,000 rows => visit 1,000 table blocks: 1,000 * 5ms = 5 s

1,000 rows => visit 10 table blocks: 10 * 5ms = 50 ms

No table access => only index blocks are visited!

Re-visiting the same recent table blocks

Demo! optimizer_basics_inter_table_clustering_testcase.sql

How to apply these concepts, where to go from here? Read Jonathan Lewis article Designing Efficient SQL at Red Gates Simple Talk Probably the best coverage of the concepts outlined here including clustering and caching

How to apply these concepts, where to go from here? Read one of Tom Kytes books to learn more about the pros and cons of clusters and index organized tables

How to apply these concepts, where to go from here? Learn how to read, interpret and understand Oracle execution plans => Chapter 6 of Troubleshooting Oracle Performance by Christian Antognini This knowledge is required in order to compare your understanding of the query to the optimizers understanding

How to apply these concepts, where to go from here? Be aware of Query Transformations: The optimizer might rewrite your query to something that is semantically equivalent but potentially more efficient This might take you by surprise when trying to understand the execution plan favored by the optimizer Query transformation examples by courtesy of Joze Senegacnik (OOW 2010)

If you want a more formal approach Read SQL Tuning by Dan Tow Teaches a formal approach how to design and visualize an execution plan Focuses on robust execution plans in an OLTP environment The formal approach doesnt take into account clustering and caching, however it is mentioned in the book at some places

If you want a more formal approach Read Relational Database Index Design and the Optimizers by Tapio Lahdenmäki and Michael Leach Focuses on index design Provides simple and more advanced formulas allowing to predict the efficiency of queries and indexes Covers clustering and caching

For application developers Read Use the Index, Luke by Markus Winand Focuses on index design Provides a lot of examples how to design efficient database access using different front-end languages (Java, Perl, PHP, etc.) Also available as free eBook Cross database (Oracle DB2, MySQL…)

If you want dive into the details of the Cost- Based Optimizer Read Cost-Based Oracle: Fundamentals by Jonathan Lewis Almost six years old Still the best book about the Oracle optimizer Covers the key concepts mentioned here in great detail