Physical join operators
Download
1 / 20

Physical Join Operators - PowerPoint PPT Presentation


  • 60 Views
  • Uploaded on

Physical Join Operators. 2010. Ami Levin. Session Goals. SQL Server implements three different physical operators to perform joins. In this session we will see how each of these three operators work, its advantages and challenges.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Physical Join Operators' - emmy


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Physical join operators

Physical Join Operators

2010

Ami Levin


Session goals
Session Goals

  • SQL Server implements three different physical operators to perform joins. In this session we will see how each of these three operators work, its advantages and challenges.

  • We will try to understand the logic behind the optimizer’s decisions on which operator to use for various joins using (semi) real life examples and see examples about how to avoid common pitfalls.


Equi inner join
Equi-Inner-Join

SELECTX,Y,Z…

FROM[Table1] INNER JOIN [Table2]

ON [Table1].[C1] = [Table2].[C1]

AND [Table1].[C2] = [Table2].[C2]

WHERE…


Next time
Next Time

  • Outer Joins

  • Non Equi-Joins

  • Logical Processing Order

  • NULL Value Issues

  • Join Parallelism

  • Partitioned Joins



Nested loops
Nested Loops

Fetch next row from blue input

Start

No More Rows?

Quit

True

False

Find matching rows in red input


Considerations
Considerations

  • “Outer Loop” = The Number of Iterations

    • At Least One Small Input Preferable

  • “Inner Operation” = Work for Each Iteration

    • Index/Table Scan

    • Index Seek with Lookup

    • Covering Index Seek


Foreign key joins
Foreign Key Joins

  • Joins Parents and Childs

  • Most Common Relationship is One-to-Many

  • Parent ISIndexed Primary Key or Unique

  • Indexing Foreign Keys Enables Efficient Use of Nested Loops



Merge

Fetch next row from blue input

Start

Merge

No More Rows?

Quit

True

False

Fetch next row from red input

Rows Match?

True

False


Considerations1
Considerations

  • Input Must be Pre-Sorted

    • By All Join Expression(s)

    • Pre-Sorted in Plan, not necessarily in DB…

  • Immediate& Sorted Match Outputs

    • FASTFIRSTROW Hint

  • Very Efficient and Simple Operator


Merge1
Merge

DEMO


Physical join operators

Fetch next row from blue input

Fetch next row from red input

Start

No more rows?

No more rows?

True

True

False

Quit

False

Hash- Match

Apply “hash” function

Apply “hash” function

Place row in “hash” bucket

Probe bucket for matching rows


Considerations2
Considerations

  • Hash Function Selection

  • CPU, Memory and potential I/O Overhead

  • No Sorting Whatsoever

  • Probing Costs Not Revealed

  • May Indicate Sub-Optimal Indexing




For more information
For More Information

  • Books On Line

  • Microsoft White Papers

  • “SQL Server 2008 Internals”

    • Kalen Delaney, Kimberly L.Tripp and more…

  • Craig Freedman’s MSDN Blog

    • http://blogs.msdn.com/craigfr/about.aspx




Coming up

P/X001

Designing High Scale OLTP systems

Thomas Kejser

P/L001

TSQL Techniques – Why and how to tune a routine

Dave Ballantyne

P/L002

Implementing Common Business Calculations in DAX

Chris Webb

P/L005

Consolidating data collection with SQLDIAG and analysing it all with SQLNexusChristian Bolton

P/T007

Introduction to SQL Modelling Services

Robert Hogg

Coming up…

  • #SQLBITS