David Konopnicki –1997, Rev. MS-2004 1 Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.

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

Presented By Akin S Walter-Johnson Ms Principal PeerLabs, Inc
1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems.
Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Algorithms for SELECT and JOIN Operations (8) Implementing the JOIN Operation: Join (EQUIJOIN, NATURAL.
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.
Join Processing in Databases Systems with Large Main Memories
CS CS4432: Database Systems II Operator Algorithms Chapter 15.
Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 14, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
DB performance tuning using indexes Section 8.5 and Chapters 20 (Raghu)
CSCI 5708: Query Processing II Pusheng Zhang University of Minnesota Feb 5, 2004.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
1 Query Optimization. 2 Why Optimize? Given a query of size n and a database of size m, how big can the output of applying the query to the database be?
1 The Optimizer How ORACLE optimizes SQL statements David Konopnicky 1997, Revised by Mordo Shalom 2004.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
CS186 Final Review Query Optimization.
Introduction to Database Systems 1 Join Algorithms Query Processing: Lecture 1.
1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
CS 4432query processing - lecture 171 CS4432: Database Systems II Lecture #17 Join Processing Algorithms (cont). Professor Elke A. Rundensteiner.
1 Optimization. 2 Why Optimize? Given a query of size n and a database of size m, how big can the output of applying the query to the database be? Example:
Query Evaluation and Optimization Main Steps 1.Translate into RA: select/project/join 2.Greedy optimization of RA: by pushing selection and projection.
Access Path Selection in a Relation Database Management System (summarized in section 2)
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.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
1 Implementation of Relational Operations: Joins.
Query Optimization, part 2 CS634 Lecture 13, Mar Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 14 – Join Processing.
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.
CPS216: Advanced Database Systems Notes 07:Query Execution Shivnath Babu.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Data Partitioning in VLDB Tal Olier
Status “Lifetime of a Query” –Query Rewrite –Query Optimization –Query Execution Optimization –Use cost-estimation to iterate over all possible plans,
Copyright © Curt Hill Query Evaluation Translating a query into action.
Review Jun 5th, HW#5.2 TableTupleTuple/pagePage R S R R.a = S.b S (52buffers)
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.
Module 4 Database SQL Tuning Section 3 Application Performance.
Indexes and Views Unit 7.
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
CS 440 Database Management Systems Lecture 5: Query Processing 1.
More Optimization Exercises. Block Nested Loops Join Suppose there are B buffer pages Cost: M + ceil (M/(B-2))*N where –M is the number of pages of R.
Sorting and Joining.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Query Execution Query compiler Execution engine Index/record mgr. Buffer manager Storage manager storage User/ Application Query update Query execution.
Query Processing and Query Optimization CS 157B Dennis Le Weishan Wang.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 8.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 6.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 5.
Execution Plans Detail From Zero to Hero İsmail Adar.
LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.
Choosing Access Path The basic methods.
Query Processing and Optimization
Teradata Join Processing
COST ESTIMATION FOR THE RELATIONAL ALGEBRA OPERATIONS MIT 813 GROUP 15 PRESENTATION.
Introduction to Execution Plans
Database Management Systems (CS 564)
CS222: Principles of Data Management Notes #13 Set operations, Aggregation Instructor: Chen Li.
Performance Join Operator Select * from R, S where R.a = S.a;
Introduction to Execution Plans
EXECUTION PLANS Quick Dive.
Introduction to Execution Plans
Introduction to Execution Plans
Presentation transcript:

David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access Paths ä Join Operation ä Join Order These Choices are related. Lets examine the different possible join operations.

David Konopnicki –1997, Rev. MS Nested Loops Join SELECT * FROM emp,dept WHERE emp.deptno=dept.deptno 1 - NESTED LOOPS 2 - TABLE ACCESS (FULL) emp 3 - TABLE ACCESS (BY ROWID) dept 4 - INDEX (UNIQUE SCAN) pk_dept The outer table or the driving table The inner Table

David Konopnicki –1997, Rev. MS Nested Loops Join ä The cost of nested loops operation is: ä Access(O) + Access(I) * Rows(O) ä Is good only when the outer table drives the inner table and the subsets accessed are small. ä In outer joins the outer table is dictated by the query.

David Konopnicki –1997, Rev. MS Hash Join 1 - HASH JOIN 3 - HASH (JOIN) 2- Table Access (FULL SCAN) emp 4 - Table Access (FULL SCAN) dept

David Konopnicki –1997, Rev. MS Hash Join ä The cost of a hash join is: ä Access (O) + Access(I) + Hash (min(I,O)) ä Can be used in equijoins only ä Best if Hash(min(I,O) ) can be stored in memory, otherwise it is partitioned. ä Not available with RBO. ä In outer joins the outer table is dictated by the query.

David Konopnicki –1997, Rev. MS Sort-merge Join 1 - MERGE JOIN 2 - SORT (JOIN)4 - SORT (JOIN) 3- Table Access (FULL SCAN) emp 5 - Table Access (FULL SCAN) dept

David Konopnicki –1997, Rev. MS Sort Merge Join ä The cost of a sort-merge join is: ä Access (O) + Access(I) + Sort (O) + Sort (I) ä Can not be used in non-equijoins only. ä No distinction between outer/inner tables except when dictated by the query. ä Preferred on hash when: It is not an equijoin, or It is not an equijoin, or Sorts are already required in other parts of the query, or Sorts are already required in other parts of the query, or SORT_AREA_SIZE >> HASH_AREA_SIZE SORT_AREA_SIZE >> HASH_AREA_SIZE

David Konopnicki –1997, Rev. MS Cluster Join 1 - NESTED LOOPS TABLE ACCESS (FULL) dept TABLE ACCESS (CLUSTER) emp

David Konopnicki –1997, Rev. MS Nested Loops ä The cost of nested loops operation is: ä Access(O) + Access(I) * Rows(O) ä Is good only when the outer table drives the inner table ä In outer joins the outer table is dictated by the query ä The cost of a sort-merge join is: ä Access (O) + Access(I) + Sort (O) + Sort (I) ä The cost of a hash join is: ä Access (O) + Access(I) + Hash (min(I,O)) ä Can be used in equijoins only ä Not available with RBO

David Konopnicki –1997, Rev. MS The Join Order ä The optimizer: ä begins with the joins that results in a single row (using keys & unique indexes). ä In outer joins the outer table must appear after the inner table in the join condition. ä The possible execution plans are generated and compared according to estimated costs.