Join Algorithms. Join Algorithms - 1 There are 6 join Algorithms These are the 6 ways that the optimiser can choose to use to solve a join They all have.

Slides:



Advertisements
Similar presentations
Dana Shapira Hash Tables
Advertisements

Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
CS 245Notes 71 CS 245: Database System Principles Notes 7: Query Optimization Hector Garcia-Molina.
Selinger Optimizer Lecture 10 October 15, 2009 Sam Madden.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Algorithms for SELECT and JOIN Operations (8) Implementing the JOIN Operation: Join (EQUIJOIN, NATURAL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
1 40T1 60T2 30T3 10T4 20T5 10T6 60T7 40T8 20T9 R S C C R JOIN S?
CS 4432query processing - lecture 161 CS4432: Database Systems II Lecture #16 Join Processing Algorithms Professor Elke A. Rundensteiner.
6.830 Lecture 9 10/1/2014 Join Algorithms. Database Internals Outline Front End Admission Control Connection Management (sql) Parser (parse tree) Rewriter.
Lecture 8 Join Algorithms. Intro Until now, we have used nested loops for joining data – This is slow, n^2 comparisons How can we do better? – Sorting.
CS 540 Database Management Systems
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.
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.
Lecture 24: Query Execution Monday, November 20, 2000.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257.
Introduction to Database Systems 1 Join Algorithms Query Processing: Lecture 1.
Chapter 5 Parallel Join 5.1Join Operations 5.2Serial Join Algorithms 5.3Parallel Join Algorithms 5.4Cost Models 5.5Parallel Join Optimization 5.6Summary.
Evaluation of Relational Operations. Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation.
Query Evaluation and Optimization Main Steps 1.Translate into RA: select/project/join 2.Greedy optimization of RA: by pushing selection and projection.
Addition and Subtraction Investigation Algorithm for the investigation 1. Choose two or three numbers. 2. Arrange them in order, biggest first. 3. Reverse.
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.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Querying Large Databases Rukmini Kaushik. Purpose Research for efficient algorithms and software architectures of query engines.
Status “Lifetime of a Query” –Query Rewrite –Query Optimization –Query Execution Optimization –Use cost-estimation to iterate over all possible plans,
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Query Optimizer Execution Plan Cost Model Joe Chang
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
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.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
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.
1 Lecture 23: Query Execution Monday, November 26, 2001.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 5.
Eugene Meidinger Execution Plans
Execution Plans Detail From Zero to Hero İsmail Adar.
IFS180 Intro. to Data Management Chapter 10 - Unions.
CS 540 Database Management Systems
CS 440 Database Management Systems
Putting tables together
Database Applications (15-415) DBMS Internals- Part VII Lecture 16, October 25, 2016 Mohammad Hammoud.
Choosing Access Path The basic methods.
Teradata Join Processing
Introduction to Execution Plans
Physical Join Operators
Physical Database Design
Example R1 R2 over common attribute C
Performance Join Operator Select * from R, S where R.a = S.a;
Chapters 15 and 16b: Query Optimization
Advance Database Systems
Product of Powers Property
Introduction to Execution Plans
Slides adapted from Donghui Zhang, UC Riverside
Execution plans Eugene
Lecture 22: Query Execution
Print the following triangle, using nested loops
A – Pre Join Indexes.
Introduction to Execution Plans
Introduction to Execution Plans
Lecture 22: Friday, November 22, 2002.
Welcome!.
Project report cs331.
Presentation transcript:

Join Algorithms

Join Algorithms - 1 There are 6 join Algorithms These are the 6 ways that the optimiser can choose to use to solve a join They all have differing advantages Some may be better for larger or smaller tables Some may work better for complex (more than 2 table) joins

Join Algorithms - 2 You have some limited ability to affect the join algorithms used This is probably not that useful Knowledge of the joins and there strengths and weaknesses can help in the decoding of the query plans This can then allow you to see where the query may be running slowly – and change this

The Big 6 The 6 Join Algorithms are : –Nested Loop JoinNLJ –Nested Loop PushdownNLPD –Hash JoinHJ –Hash Join PushdownHPDJ –Sort Merge JoinSMJ –Sort Merge PushdownSMPDJ

Nested Loop Join Take Small Table (or result set) Store it For each row in the Big Table, compare with each row in the Small Table Store

Nested Loop Pushdown Reverse of the Nested Loop For each Row in the Small Table Probe a fast index(LF or HG) on the Big Table

Hash Join (Classic Hash) Create a hash table for the Small Side For each row in the Big Table probe the Hash Table for Join Conditions Used when small side < 1,250,000 rows in a two table join Used when the ratio between the large side and small side <600:1 in a more than two table join “Classic Hash” - needs to be kept in memory

Hash Join Pushdown If the Distinct Count of T3.X is small –i.e.T3 is a small table or T4 predicate can filter T3xT4 to small size Then I.2 has a hash table keyed on T3.X and I.2 is complete Create an Artificial IN Clause on T1 to filter out rows that do not satisfy T1.X=T3.X T1T2T3T4 I.1 I.2 R1T1.X=T3.X

Sort Merge Join Sort on both sides then merge result sets Used in all other cases Optimised now (12.4) for 1:M (Primary or UNIQUE Join Key) There is an exception in the case of M:M join, when there is a Loop against the small side

Sort Merge Pushdown - 1 Similar to the Hash Pushdown But in this case there are too many rows from I2 to store in a Classic Hash Instead we compute a hash table (as a bit vector) to report that 1 or more rows in I2 have the hash value Also there is more than 1 key matching the hash number New T1T2T3T4 I.1 I.2 R1

Sort Merge Pushdown - 2 We have a “Probably IN” Hash table Push Down the Bit Vector to T1 Now we know that if the hash # is NOT in the hash table then we know that the key value is NOT going to match at R1 If the Key # IS in the hash table then it MAY match and should go up to I.1 and R1 New T1T2T3T4 I.1 I.2 R1

Join Optimisation Join_Optimization Def ON –Switching this off will set the optimiser to parse the join tree left to right – as the table were specified in the from clause –This may help an individual query – but generally this should only be used if you have drawn out the query tree and you are certain that the optimiser has misjudged the query

Join Preference Join_Algorithm_Preference –0Let the optimiser choose - default –1/-1Prefer/Avoid Sort/Merge –2/-2Prefer/Avoid Nested Loop –3/-3Prefer/Avoid Nested Loop Pushdown –4/-4Prefer/Avoid Hash Join –5/-5Prefer/Avoid Hash Join Pushdown –6/-6Prefer/Avoid Pre-join Indexes –7/-7Prefer/Avoid Sort/Merge Pushdown

Extended_Join This option controls the allowing of ambiguous syntax joins shouldWith the ANSI join syntax there should be no ambiguity With the “old fashioned” method of joining there could be ambiguity If this option is ON (default) then the query will be thrown out with a syntax error If not the query will be run using the plan that has the lowest cost

Join Algorithms - End