SlideShare a Scribd company logo
1 of 20
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.  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 SELECTX,Y,Z… FROM[Table1] INNER JOIN [Table2] ON [Table1].[C1] = [Table2].[C1] AND [Table1].[C2] = [Table2].[C2] WHERE…
Next Time Outer Joins Non Equi-Joins Logical Processing Order NULL Value Issues Join Parallelism Partitioned Joins
What Is a Join
Nested Loops Fetch next row from blue input Start No More Rows? Quit True False Find matching rows in red input
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 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
Nested Loops DEMO
Fetch next row from blue input Start No More Rows? Quit True False Merge Fetch next row from red input Rows Match? True False
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
Merge DEMO
Fetch next row from blue input Fetch next row from red input Start No more rows? No more rows? True True False False Quit Hash- Match Apply “hash” function Apply “hash” function Place row in “hash” bucket Probe bucket for matching rows
Considerations Hash Function Selection CPU, Memory and potential I/O Overhead No Sorting Whatsoever Probing Costs Not Revealed May Indicate Sub-Optimal Indexing
Hash Match DEMO
Conclusion
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
Physical Join Operators Q&A?
Thank You
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 #SQLBITS

More Related Content

Viewers also liked

Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
DATAVERSITY
 

Viewers also liked (10)

Optimising Column stores with statistical analysis
Optimising Column stores with statistical analysisOptimising Column stores with statistical analysis
Optimising Column stores with statistical analysis
 
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
Practical Applications for Data Warehousing, Analytics, BI, and Meta-Integrat...
 
Master tuning
Master   tuningMaster   tuning
Master tuning
 
IO Dubi Lebel
IO Dubi LebelIO Dubi Lebel
IO Dubi Lebel
 
Microsoft SQL Server Analysis Services Multidimensional
Microsoft SQL Server Analysis Services MultidimensionalMicrosoft SQL Server Analysis Services Multidimensional
Microsoft SQL Server Analysis Services Multidimensional
 
Big Data vs Data Warehousing
Big Data vs Data WarehousingBig Data vs Data Warehousing
Big Data vs Data Warehousing
 
Random thoughts on sql server performance
Random thoughts on sql server performanceRandom thoughts on sql server performance
Random thoughts on sql server performance
 
SSAS Reference Architecture
SSAS Reference ArchitectureSSAS Reference Architecture
SSAS Reference Architecture
 
Yahoo! TAO Case Study Excerpt
Yahoo! TAO Case Study ExcerptYahoo! TAO Case Study Excerpt
Yahoo! TAO Case Study Excerpt
 
SQL Server Integration Services Best Practices
SQL Server Integration Services Best PracticesSQL Server Integration Services Best Practices
SQL Server Integration Services Best Practices
 

Similar to Physical join operators ISUG 105

Funwithsqlnopause 091010085359-phpapp01
Funwithsqlnopause 091010085359-phpapp01Funwithsqlnopause 091010085359-phpapp01
Funwithsqlnopause 091010085359-phpapp01
sagaroceanic11
 
Functional pogramming hl overview
Functional pogramming hl overviewFunctional pogramming hl overview
Functional pogramming hl overview
Elad Avneri
 
Speeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joinsSpeeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joins
Kaing Menglieng
 
Sql Patterns
Sql PatternsSql Patterns
Sql Patterns
phanleson
 

Similar to Physical join operators ISUG 105 (20)

Funwithsqlnopause 091010085359-phpapp01
Funwithsqlnopause 091010085359-phpapp01Funwithsqlnopause 091010085359-phpapp01
Funwithsqlnopause 091010085359-phpapp01
 
Automation Of Reporting And Alerting
Automation Of Reporting And AlertingAutomation Of Reporting And Alerting
Automation Of Reporting And Alerting
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and review
 
Python’s filter() function An Introduction to Iterable Filtering
Python’s filter() function An Introduction to Iterable FilteringPython’s filter() function An Introduction to Iterable Filtering
Python’s filter() function An Introduction to Iterable Filtering
 
Intro to t sql – 3rd session
Intro to t sql – 3rd sessionIntro to t sql – 3rd session
Intro to t sql – 3rd session
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Functional pogramming hl overview
Functional pogramming hl overviewFunctional pogramming hl overview
Functional pogramming hl overview
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
 
Automating With Excel An Object Oriented Approach
Automating  With  Excel    An  Object  Oriented  ApproachAutomating  With  Excel    An  Object  Oriented  Approach
Automating With Excel An Object Oriented Approach
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
 
Sub query_SQL
Sub query_SQLSub query_SQL
Sub query_SQL
 
Speeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joinsSpeeding up queries with semi joins and anti-joins
Speeding up queries with semi joins and anti-joins
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
 
Sql Patterns
Sql PatternsSql Patterns
Sql Patterns
 
Principles of the Play framework
Principles of the Play frameworkPrinciples of the Play framework
Principles of the Play framework
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Sww 2008 Automating Your Designs Excel, Vba And Beyond
Sww 2008   Automating Your Designs   Excel, Vba And BeyondSww 2008   Automating Your Designs   Excel, Vba And Beyond
Sww 2008 Automating Your Designs Excel, Vba And Beyond
 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
 

More from sqlserver.co.il

Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013
sqlserver.co.il
 
Things you can find in the plan cache
Things you can find in the plan cacheThings you can find in the plan cache
Things you can find in the plan cache
sqlserver.co.il
 
Sql server user group news january 2013
Sql server user group news   january 2013Sql server user group news   january 2013
Sql server user group news january 2013
sqlserver.co.il
 
SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3
sqlserver.co.il
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
sqlserver.co.il
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended EventsSQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
sqlserver.co.il
 
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoreSQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStore
sqlserver.co.il
 
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACSQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DAC
sqlserver.co.il
 
SQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: SpatialSQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: Spatial
sqlserver.co.il
 
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf FraenkelBi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
sqlserver.co.il
 

More from sqlserver.co.il (20)

Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013Windows azure sql_database_security_isug012013
Windows azure sql_database_security_isug012013
 
Things you can find in the plan cache
Things you can find in the plan cacheThings you can find in the plan cache
Things you can find in the plan cache
 
Sql server user group news january 2013
Sql server user group news   january 2013Sql server user group news   january 2013
Sql server user group news january 2013
 
DAC 2012
DAC 2012DAC 2012
DAC 2012
 
Query handlingbytheserver
Query handlingbytheserverQuery handlingbytheserver
Query handlingbytheserver
 
Adi Sapir ISUG 123 11/10/2012
Adi Sapir ISUG 123 11/10/2012Adi Sapir ISUG 123 11/10/2012
Adi Sapir ISUG 123 11/10/2012
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum version
 
SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended EventsSQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
 
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoreSQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStore
 
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACSQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DAC
 
SQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: SpatialSQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: Spatial
 
מיכאל
מיכאלמיכאל
מיכאל
 
נועם
נועםנועם
נועם
 
עדי
עדיעדי
עדי
 
מיכאל
מיכאלמיכאל
מיכאל
 
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf FraenkelBi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
 
DBCC - Dubi Lebel
DBCC - Dubi LebelDBCC - Dubi Lebel
DBCC - Dubi Lebel
 

Physical join operators ISUG 105

  • 1. Physical Join Operators 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 SELECTX,Y,Z… FROM[Table1] INNER JOIN [Table2] ON [Table1].[C1] = [Table2].[C1] AND [Table1].[C2] = [Table2].[C2] WHERE…
  • 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 ISIndexed Primary Key or Unique Indexing Foreign Keys Enables Efficient Use of Nested Loops
  • 10. Fetch next row from blue input Start No More Rows? Quit True False Merge 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
  • 13. Fetch next row from blue input Fetch next row from red input Start No more rows? No more rows? True True False False Quit Hash- Match 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
  • 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
  • 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 SQLNexusChristian Bolton P/T007 Introduction to SQL Modelling Services Robert Hogg #SQLBITS