AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides.

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,
Understanding SQL Server Query Execution Plans
Introduction to SQL Tuning Brown Bag Three essential concepts.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems.
What Happens when a SQL statement is issued?
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
1 Use EXPLAIN PLAN and TKPROF To Tune Your Applications Roger Schrag Database Specialists, Inc.
1 King Saud University College of Computer & Information Sciences IS 335 Database Management System Lecture 6 Query Processing and Optimization (Practice)
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
Query Processing & Optimization
Optimization Exercises. Question 1 How do you think the following query should be computed? What indexes would you suggest to use? SELECT E.ename, D.mgr.
Top tips for Oracle SQL tuning Guy Harrison Senior Software Architect, Quest Software BUY QUEST PRODUCTS BUY GUY’S BOOK BUY QUEST PRODUCTS.
Obtaining and Interpreting Execution Plans using DBMS_XPLAN David Kurtz Go-Faster Consultancy Ltd.
Dale Roberts 8/20/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
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.
Lecture 8 Index Organized Tables Clusters Index compression
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Csci 5708 : Execution Plan -Bhavtosh Rath. Syntax: SELECT * FROM TABLE (DBMS_XPLAN. DISPLAY(‘PLAN_TABLE',‘ ')); DISPLAY function: Displays result/content.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Data Warehouse and the Star Schema CSCI 242 ©Copyright 2015, David C. Roberts, all rights reserved.
Data Partitioning in VLDB Tal Olier
11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Star Transformations Tony Hasler, UKOUG Birmingham 2012 Tony Hasler, Anvil Computer Services Ltd.
SQL Performance and Optimization l SQL Overview l Performance Tuning Process l SQL-Tuning –EXPLAIN PLANs –Tuning Tools –Optimizing Table Scans –Optimizing.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
Module 4 Database SQL Tuning Section 3 Application Performance.
SQL Tuning 101 excerpt: Explain Plan A Logical Approach Michael Ruckdaschel Affinion Group International.
Indexes and Views Unit 7.
© IBM Corporation 2005 Informix User Forum 2005 John F. Miller III Explaining SQLEXPLAIN ®
PowerBuilder Online Courses - by Prasad Bodepudi Database Painter Primary & Foreign Keys Extended Attributes PowerBuilder System Tables Database Profiles.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Optimization and Administartion of a Database Management Systems Krystian Zieja.
Query Processing and Query Optimization CS 157B Dennis Le Weishan Wang.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 5.
LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
IT 5433 LM4 Physical Design. Learning Objectives: Describe the physical database design process Explain how attributes transpose from the logical to physical.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
CHAPTER 19 Query Optimization. CHAPTER 19 Query Optimization.
EXPLAIN and AUTOTRACE.
Prepared by : Ankit Patel (226)
Choosing Access Path The basic methods.
Interpreting Execution Plans
Chapter 15 QUERY EXECUTION.
Advance Database Systems
A – Pre Join Indexes.
Introduction to Execution Plans
Introduction to the Optimizer
Introduction to Execution Plans
Presentation transcript:

AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides are available at :

WHAT IS AN EXECUTION PLAN? Detailed steps necessary to execute a SQL statement Steps expressed as a set of database operators that consumes and produces rows Optimizer decides The order of the operators and their implementation using query transformations and physical optimization techniques The display is commonly shown in a tabular format, but a plan is in fact tree-shaped

TABULAR AND TREE REPRESENTATIONS Query SELECT prod_category, avg(amount_sold) FROM sales s, products p WHERE p.prod_id = s.prod_id GROUP BY prod_category; Tabular representation of plan Id Operation Name SELECT STATEMENT 1 HASH GROUP BY 2 HASH JOIN 3 TABLE ACCESS FULL PRODUCTS 4 PARTITION RANGE ALL 5 TABLE ACCESS FULL SALES Tree-shaped representation of plan GROUP BY | JOIN ______|_______ | | TABLE ACCESS TABLE ACCESS PRODUCTS SALES

HOW TO GET AN EXECUTION PLAN ? EXPLAIN PLAN command Displays an execution plan for a SQL statement without actually executing the statement EXPLAIN PLAN SET STATEMENT_ID = ' ' FOR ; Plan stored in PLAN_TABLE

SELECT LPAD(' ', 2*LEVEL)||OPERATION||' '||OPTIONS||' '||OBJECT_NAME Query_Plan FROM PLAN_TABLE CONNECT BY PRIOR ID = PARENT_ID and STATEMENT_ID = ' ' START WITH ID=0 and STATEMENT_ID = ' ' ORDER BY ID; QUERY THE PLAN_TABLE

USE CASE Use Case: Plan review allows review of access paths and join types Access paths Is the data being accessed in the best way? Scan? Index lookup? Join type Are the right join algorithm types being used?

ACCESS PATHS Access Path describes method to get data out of the table The access path can be: Full table scan Table access by Rowid Index unique scan Index range scan (descending) Index skip scan Full index scan Fast full index scan Index joins Bitmap indexes

Look in Operation session to see how obj is being accessed EXAMPLE OF ACCESS PATHS What access method should be use for this Query? SELECT e.name, e.salary, d.dept_name FROM hr.employees e, hr.departments d WHERE d.dept_name IN ('Marketing‘,'Sales') AND e.department_id=d.department_id; Employees has 107 rows Departments has 27 rows Foreign key relationship between Employees and Departments on dept_id

JOIN ALGORITHM TYPE A Join retrieve data from more than one table Possible join algorithm types are Nested Loops joins Hash Joins Partition Wise Joins Sort Merge joins Cartesian Joins Outer Joins

JOIN ALGORITHM TYPE EXAMPLE What Join type should be use for this Query? SELECT e.name, e.salary, d.dept_name FROM hr.employees e, hr.departments d WHERE d.dept_name IN ('Marketing‘,'Sales') AND e.department_id=d.department_id; Employees has 107 rows Departments has 27 rows Foreign key relationship between Employees and Departments on dept_id Look in Operation session to see Join strategy