Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 2010 Ami Levin

2 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 SELECTX,Y,Z… FROM[Table1] INNER JOIN [Table2] ON [Table1].[C1] = [Table2].[C1] AND [Table1].[C2] = [Table2].[C2] WHERE…

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

5

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

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

10 Fetch next row from blue input Fetch next row from red input True Start Rows Match? False Quit No More Rows? False True

11 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

13 Fetch next row from blue input No more rows? Fetch next row from red input False Start Apply “hash” function Place row in “hash” bucket No more rows? Apply “hash” function False True Probe bucket for matching rows Quit

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

15

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

17 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

19

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


Download ppt "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."

Similar presentations


Ads by Google