Understanding SQL Server Join Operators

slide1 n.w
1 / 20
Embed
Share

Explore the implementation of three different physical operators in SQL Server for joining tables. Learn about their advantages, challenges, and how to optimize query performance. Dive into topics like outer joins, non-equi joins, and logical processing order. Gain insights into foreign key joins and nested loops to enhance efficiency.

  • SQL Server
  • Join Operators
  • Query Optimization
  • Foreign Keys
  • Nested Loops

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. 2010 Ami Levin

  2. 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.

  3. EQUI-INNER-JOIN SELECT X,Y,Z FROM WHERE [Table1] INNER JOIN [Table2] ON [Table1].[C1] = [Table2].[C1] AND [Table1].[C2] = [Table2].[C2]

  4. NEXT TIME Outer Joins Non Equi-Joins Logical Processing Order NULL Value Issues Join Parallelism Partitioned Joins

  5. WHAT IS A JOIN

  6. NESTED LOOPS Fetch next row from blue input Start No More Rows? Quit True False Find matching rows in red input

  7. 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

  8. FOREIGN KEY JOINS Joins Parents and Childs Most Common Relationship is One-to-Many Parent IS Indexed Primary Key or Unique Indexing Foreign Keys Enables Efficient Use of Nested Loops

  9. NESTED LOOPS

  10. Fetch next row from blue input Start M E R G E No More Rows? Quit True False Fetch next row from red input Rows Match? True False

  11. 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

  12. MERGE

  13. H A S H - M A T C H Fetch next row from blue input Fetch next row from red input Start True No more rows? No more rows? True False False Quit Apply hash function Apply hash function Place row in hash bucket Probe bucket for matching rows

  14. CONSIDERATIONS Hash Function Selection CPU, Memory and potential I/O Overhead No Sorting Whatsoever Probing Costs Not Revealed May Indicate Sub-Optimal Indexing

  15. HASH MATCH

  16. CONCLUSION Nested Loops Merge Hash Small outer input Inner input indexed Pre-sorted inputs Sorting required Very large inputs Not well indexed Good choice when Low *Unless requires sorting Low *Unless requires sorting CPU consumption Low High Memory usage Low High Low * Hidden cost of probes Logical reads High Low Output matches Fast Fast Slow

  17. 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

  18. PHYSICAL JOIN OPERATORS

  19. THANK YOU

  20. 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 SQLNexus Christian Bolton P/T007 Introduction to SQL Modelling Services Robert Hogg #SQLBITS

Related


More Related Content