Physical Join Operators

Slides:



Advertisements
Similar presentations
Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
Advertisements

CS 245Notes 71 CS 245: Database System Principles Notes 7: Query Optimization Hector Garcia-Molina.
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.
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
CS 4432query processing - lecture 171 CS4432: Database Systems II Lecture #17 Join Processing Algorithms (cont). Professor Elke A. Rundensteiner.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Data Partitioning in VLDB Tal Olier
Primary Key, Cluster Key & Identity Loop, Hash & Merge Joins Joe Chang
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Exploiting Asynchronous IO using the Asynchronous Iterator Model Suresh Iyengar * S. Sudarshan Santosh Kumar # Raja Agrawal & IIT Bombay Current affiliations:
Query Optimizer Execution Plan Cost Model Joe Chang
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
2010 Ami Levin. SQL Server implements three different physical operators to perform joins. In this session we will see how each of these three operators.
Computing & Information Sciences Kansas State University Wednesday, 08 Nov 2006CIS 560: Database System Concepts Lecture 32 of 42 Monday, 06 November 2006.
Sorting and Joining.
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.
Thinking in Sets and SQL Query Logical Processing.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
The PostgreSQL Query Planner Robert Haas PostgreSQL East 2010.
CS 540 Database Management Systems
Database Management System
Query Tuning without Production Data
Database Applications (15-415) DBMS Internals- Part VII Lecture 16, October 25, 2016 Mohammad Hammoud.
Query Tuning without Production Data
Query Tuning without Production Data
Chapter 13: Query Processing
Chapter 12: Query Processing
Query Processing.
Database Performance Tuning and Query Optimization
Chapter 13: Query Processing
Introduction to Execution Plans
Database Management Systems (CS 564)
Database Applications (15-415) DBMS Internals- Part VII Lecture 19, March 27, 2018 Mohammad Hammoud.
Physical Database Design
Yan Huang - CSCI5330 Database Implementation – Access Methods
Query Processing.
Chapter 13: Query Processing
Chapter 13: Query Processing
CS143:Evaluation and Optimization
External Joins Query Optimization 10/4/2017
Example R1 R2 over common attribute C
Chapter 12: Query Processing
Chapter 13: Query Processing
Module 13: Query Processing
Chapters 15 and 16b: Query Optimization
Chapter 12: Query Processing
Lecture 2- Query Processing (continued)
Dave Bland LinkedIn SQL Server Execution Plans: How to use them to find performance bottlenecks Dave Bland LinkedIn
Introduction to Execution Plans
Implementation of Relational Operations
Chapter 11 Database Performance Tuning and Query Optimization
EXECUTION PLANS Quick Dive.
Evaluation of Relational Operations: Other Techniques
Overview of Query Evaluation: JOINS
Diving into Query Execution Plans
Sorting We may build an index on the relation, and then use the index to read the relation in sorted order. May lead to one disk block access for each.
Chapter 13: Query Processing
A – Pre Join Indexes.
Chapter 13: Query Processing
Introduction to Execution Plans
Chapter 12: Query Processing
Introduction to Execution Plans
Presentation transcript:

Physical Join Operators Nesting Merged Hash Loops Ami Levin Think Big. Move Fast.

Session Goals SQL Server uses three physical join operators: Nested loops, Merge, and Hash Match. In this session we will: See how each of these operators work Review their advantages and drawbacks Understand some of the logic behind the optimizer’s decisions on which operator to use Learn to identify common join-related pitfalls AD-400|Physical Join Operators

Not This Time Outer joins Non equi-joins Logical processing order NULL issues Join parallelism Partitioned joins … AD-400|Physical Join Operators

Equi-Inner-Join SELECT Foo, Bar, ... FROM T1 INNER JOIN T2 ON T1.C1 = T2.C1 AND T1.C2 = T2.C2 AND ... WHERE ... AD-400|Physical Join Operators

Visual Join Simulator AD-400|Physical Join Operators

Nested Loops ? Fetch next row from blue input Start Row exists Quit False True Find matching rows in red input AD-400|Physical Join Operators

Nested Loops I Outer loop determines number of iterations At least one input should be (relatively) small Inner operation is performed for every iteration of the outer loop Index or table scan (naïve) Index seek + lookup Covering index seek Index spool AD-400|Physical Join Operators

Nested Loops II Data pages may be accessed repeatedly Risky a-sequential page access path Output of matching row sets is fast Unordered, but typically grouped Physical resources CPU Very low Physical IO low to very high Memory low AD-400|Physical Join Operators

Nested Loops with Foreign Key Joins Foreign keys join parent and child Most common relationship is one-to-many Often parent input is significantly smaller Parent must already be indexed Either primary key or unique constraint Therefore, indexing foreign keys often enables efficient use of nested loops AD-400|Physical Join Operators

Nested Loops DEMO AD-400|Physical Join Operators

Merge ? ? Fetch next row from blue input Start False Row exists Rows match Quit ? ? False True True Fetch next row from red input AD-400|Physical Join Operators

Merge I Inputs must be sorted prior to merge Sorted by (all?) join expression(s) Pre-sorted in plan, but not necessarily in DB Preferred when sorting supports additional plan operations Merge join types One to many Many to many - requires temporary worktable AD-400|Physical Join Operators

Merge II Residual predicates Fast, ordered and grouped output Physical resources CPU Very low Physical IO Very low Memory Very low * Excluding sorting costs AD-400|Physical Join Operators

Merge DEMO AD-400|Physical Join Operators

Hash Match - Phase I (Build) Start Fetch next row from blue input ♥ ♦ Row exists Phase II ? False ♣ True Apply hash function ♠ AD-400|Physical Join Operators

Hash Match - Phase II (Probe) Fetch next row from red input ♥ Row exists ♦ Quit ? False ♣ True Apply hash function ♠ AD-400|Physical Join Operators

Hash Match I Hash function selection Build and probe costs are hidden Extremely complex CPU intensive Build and probe costs are hidden Do not constitute logical reads Output of matching row sets is slow Unordered and typically ungrouped AD-400|Physical Join Operators

Hash Match II In memory hash join Grace hash join Recursive hash join Hash bailout Hash warnings event class Update Statistics Add more RAM Role reversal AD-400|Physical Join Operators

Hash Match III May indicate sub-optimal indexing Best for very large, non covered joins Physical resources CPU Very high Physical IO Low to very high Memory Very high AD-400|Physical Join Operators

Hash Match DEMO AD-400|Physical Join Operators

Summary Nested Loops Merge Hash Good when CPU Memory Physical IO   Nested Loops Merge Hash Good when Small outer input Inner input indexed Pre-sorted inputs Sorting needed Very large inputs Not well indexed CPU Low * Excluding sorting High Memory Physical IO Low / High Logical reads * Misleading Output Fast, unordered, grouped* Fast, ordered, grouped Slow, unordered, ungrouped* AD-400|Physical Join Operators

For More Information Books on line White papers “Inside Microsoft SQL server” books Craig Freedman’s blog http://blogs.msdn.com/craigfr/about.aspx AD-400|Physical Join Operators

Physical Join Operators Q&A AD-400|Physical Join Operators

Session Code | Session Title

Thank you