SlideShare a Scribd company logo
Table of Contents
Background.................................................................................................................................................... 2
Test Recipes ................................................................................................................................................... 3
Test Cases and Results .................................................................................................................................. 4
It’s Number Time ........................................................................................................................................... 5
Conclusion ..................................................................................................................................................... 6
References ..................................................................................................................................................... 7
Nested Loop Join Technique – Part
2(What’s the new thingin 11g?)
Background
Oracle introduces some improvements in 11g to optimize Nested Loop Join (NLJ).Apart from
that, new join technique also has been introduced (known as Table Batching). The impact of this
technique is as good as table prefetching (introduced in 9i) that we have seen in part1 of this series. To
be precise, this new technique will work more efficient in sorted non-unique index (in unique index, we
won’t see much different between all those 3 techniques). In most of the cases, we won’t see again the
classic NLJ (in the execution plan) in 11g until unless we specify it purposefully using SQL hint. In this
exercise, we will try to see the improvements which have been done by Oracle in 11g and also see what
is the different of batching and prefetching technique.
Before we move forward, let’s see the different of the execution plan diagram between those 3
techniques (classic, prefetching and batching) and how we instruct Oracle to use it (details are as below).
In batching technique, Oracle creates 2 NLJs. The first NLJ (the inner one) is for joining outer (driving)
table and available index of inner (or if I am allowed to call it: driven) table. The second NLJis for joining
above (previous) result with inner table. What make me confuse is that the second NLJ doesn’t have
information of cost, rows, etc. It looks like the second NLJ is created for clarity reason (to make it more
readable, compare to prefetching – even though the internal mechanism is different, we will see the
details in attached XLS file).
Classic Technique
Prefetching Technique

Batching Technique

Test Recipes
As a starting point, 5 tables will be created with 10,000 rows each and exactly10 rows per block,
using “MINIMIZE RECORDS_PER_BLOCK” command. The purpose is to get a good figure of the number.
In addition to those tables, 4 indexes will be created in the 4 inner tables (except DRIVER). The index
itself will be having BLEVEL=2 (I have to use PCTFREE=99 to force it), so the index height is 3 (ROOT 
BRANCH  LEAF). These steps are exactly the same steps that I had followed during 10g testing.
1. DRIVER, driving (outer) table.
2. T_UNIQ_SORTED, inner table with unique index on ID column and sorted data.
3. T_UNIQ_UNSORTED, inner table with unique index on ID column and scattered data/
random ordered.
4. T_NON_UNIQ_SORTED, inner table with non-unique index on ID column and sorted data.
5. T_NON_UNIQ_UNSORTED, inner table with non-unique index on ID column and scattered
data.

Create Tables and
Indexes.LST

Test Cases and Results
To be able to make “fair-enough” comparison, I am following these steps in this exercise. The
idea is to put as much as block in the buffer to minimize or remove physical IO completely.
1. Flush buffer_cache
2. Warm up the buffer by:
a. Select all data from outer table, DRIVER(full table scan)
b. Scan inner table using index access (full index scan)
3. Begin snapper process from separate session
4. Execute each test case and turn on event 10046 to trace SQL wait event and event 10200 to
dump consistent gets activity.

5. End snapper process

DBA series - Nested
Loop Join Technique - part2.xlsx
It’s Number Time
Below table give us enough information to see that there is only small different between 3
techniques in 11g. Oracle makes an optimization in the code level which impact in all 3 techniques. It is
not the same for 10g case, where we can see the different in few statistics. Let’s have a quick look on
below session statistics:
1. The result for all 3 techniques in 11g is equal or very close to the result of prefetching in 10g.
2. “consistent gets” is reduced from 42,000(10g classic method)to 34,000(10g prefetching and
all techniques in 11g). The same thing also happened for “cache buffers chains”.
3. Even though the result of “consistent gets” related statistics are similar each other, we can
see that “sql execute elapsed time” is varying for 11g. Batching technique is the fastest one
while classic NLJ is the slowest (it is slower compare to 10g as well)
4. In 11g, the result of “buffer is pinned count” is varying and prefetching technique is able to
pin more buffer compare to the other 2 techniques.
5. The new “consistent gets from cache (fastpath)” in 11g has relation with system parameter
“_fastpin_enable” (default to 1 in 11g). This parameter control how Oracle handles repeated
access to particular buffer for optimization.
I ran all these exercise once so I might miss something here. In this case, you always have a chance to
rerun all these exercises and share it with me 

Apart from that optimization, I am going to highlight one more statistic which is also impacting
total consistent get. That statistic is “SQL*Net roundtrips to/from client”. During 10g and 11g test, this
statistic always gives similar result. If we look further, we will see the same number for consistent get for
ROOT index. The number (668) is close to the result of “SQL*Net roundtrips to/from client”. Below are
the details.

So, from where the 668 is coming? It has relation with array size in sqlplus. During the test, I use default
array size, which is 15 in my test environment
Since I have 10,000 records in my table, and the size of array is 15, so Oracle has to send the result-set in:
ceil(10,000 / 15) = 667times
But have 1 extra in the result. Don’t worry, it is common in Oracle world that sometimes there is “plus
one, +1” in the calculation (for example, see “_table_scan_cost_plus_one”parameter), so 667 + 1 = 668.
When I reran the test with array size of 100, it gave me below result.

Simple calculation: ceil(10,000 / 100) + 1 = 100 + 1 = 101. So, we need to
consider also the size of array or fetch size (when we have bulk operation) since it has impact
on the number of consistent get.

Conclusion
1. Table prefetching brings a significant improvement for non-unique index in nested loop join.
2. Oracle has done some improvement in 11g and also has introduced new technique for NLJ,
this makes huge differences compare to 10g.
3. In 11g, Oracle introduces new statistic, “consistent gets from cache (fastpath)” which has
relation with system parameter “_fastpin_enable” (default to 1 in 11g). This parameter
control how Oracle handles repeated access to particular buffer for optimization. But the
impact of this optimization will be more efficient only for sorted data. For scattered data,
Oracle won’t be able to optimize much, because consecutive number might be stored in
different data block. So index with low clustering_factor will get benefit from this
optimization.
4. Consider array size or fetch size since it has impact on the consistent get.

References
http://hoopercharles.wordpress.com/2011/01/24/watching-consistent-gets-10200-tracefile-parser/
http://dioncho.wordpress.com/2010/08/16/batching-nlj-optimization-and-ordering/
http://blog.tanelpoder.com/2013/02/18/manual-before-and-after-snapshot-support-insnapper-v4/
-heri-

More Related Content

PDF
MySQL 8.0 EXPLAIN ANALYZE
DOCX
Ssis partitioning and best practices
PDF
An Introduction To PostgreSQL Triggers
PDF
PostgreSQL High_Performance_Cheatsheet
PDF
[PGDay.Seoul 2020] PostgreSQL 13 New Features
PDF
MySQL Document Store
PDF
Table partitioning in PostgreSQL + Rails
PDF
Configure the dbase using em in oracle 11g
MySQL 8.0 EXPLAIN ANALYZE
Ssis partitioning and best practices
An Introduction To PostgreSQL Triggers
PostgreSQL High_Performance_Cheatsheet
[PGDay.Seoul 2020] PostgreSQL 13 New Features
MySQL Document Store
Table partitioning in PostgreSQL + Rails
Configure the dbase using em in oracle 11g

What's hot (19)

PDF
Introduction to MySQL InnoDB Cluster
PPTX
Data Guard New Features
PDF
Good Tests Bad Tests
PDF
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
PDF
No SQL Unit - Devoxx 2012
PDF
你所不知道的Oracle后台进程Smon功能
PDF
PostgreSQL: Data analysis and analytics
PDF
Pl sql office hours data setup and teardown in database testing
PPT
Jdbc oracle
PDF
The Ring programming language version 1.7 book - Part 12 of 196
PDF
spring-tutorial
PDF
PostgreSQL query planner's internals
PDF
PostgreSQL 9.5 - Major Features
PPT
Refactoring Jdbc Programming
PPTX
Managing Unstructured Data: Lobs in the World of JSON
PDF
16 MySQL Optimization #burningkeyboards
DOCX
Custom faultpolicies
PPTX
SQL Server 2016 Query store
PDF
Introduction to MySQL InnoDB Cluster
Data Guard New Features
Good Tests Bad Tests
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
No SQL Unit - Devoxx 2012
你所不知道的Oracle后台进程Smon功能
PostgreSQL: Data analysis and analytics
Pl sql office hours data setup and teardown in database testing
Jdbc oracle
The Ring programming language version 1.7 book - Part 12 of 196
spring-tutorial
PostgreSQL query planner's internals
PostgreSQL 9.5 - Major Features
Refactoring Jdbc Programming
Managing Unstructured Data: Lobs in the World of JSON
16 MySQL Optimization #burningkeyboards
Custom faultpolicies
SQL Server 2016 Query store
Ad

Viewers also liked (16)

DOCX
Not in vs not exists
DOCX
Checking clustering factor to detect row migration
DOCX
Subquery factoring for FTS
DOCX
Correlated update vs merge
DOCX
PPT
Relaxing Join and Selection Queries - VLDB 2006 Slides
PPTX
Chapter 5.3
PPTX
An optimal and progressive algorithm for skyline queries slide
PPTX
Query Reranking As A Service
PDF
Nesting of for loops using C++
PDF
Skyline Query Processing using Filtering in Distributed Environment
PPSX
C lecture 4 nested loops and jumping statements slideshare
PPTX
Presentation on nesting of loops
PPTX
Few useful features
PPTX
Introduction to oracle optimizer
Not in vs not exists
Checking clustering factor to detect row migration
Subquery factoring for FTS
Correlated update vs merge
Relaxing Join and Selection Queries - VLDB 2006 Slides
Chapter 5.3
An optimal and progressive algorithm for skyline queries slide
Query Reranking As A Service
Nesting of for loops using C++
Skyline Query Processing using Filtering in Distributed Environment
C lecture 4 nested loops and jumping statements slideshare
Presentation on nesting of loops
Few useful features
Introduction to oracle optimizer
Ad

Similar to Nested loop join technique - part2 (20)

PPT
The life of a query (oracle edition)
PDF
Improving the Performance of PL/SQL function calls from SQL
PDF
Exploring plsql new features best practices september 2013
PDF
Oracle Join Methods and 12c Adaptive Plans
PPTX
The Amazing and Elegant PL/SQL Function Result Cache
PPTX
Top 10 tips for Oracle performance
PDF
Presentation indexing new features oracle 11g release 1 and release 2
PPT
11thingsabout11g 12659705398222 Phpapp01
PPT
11 Things About11g
PDF
In Memory Database In Action by Tanel Poder and Kerry Osborne
PDF
Oracle Database In-Memory Option in Action
PDF
A comprehensive study of non blocking joining techniques
PDF
A comprehensive study of non blocking joining technique
PPT
Myth busters - performance tuning 102 2008
PPTX
Sql server scalability fundamentals
PPTX
Oracle sql high performance tuning
PDF
Performance improvements in PostgreSQL 9.5 and beyond
PPT
Remote DBA Experts 11g Features
PDF
Lesson11 transactions
PPTX
How to tune a query - ODTUG 2012
The life of a query (oracle edition)
Improving the Performance of PL/SQL function calls from SQL
Exploring plsql new features best practices september 2013
Oracle Join Methods and 12c Adaptive Plans
The Amazing and Elegant PL/SQL Function Result Cache
Top 10 tips for Oracle performance
Presentation indexing new features oracle 11g release 1 and release 2
11thingsabout11g 12659705398222 Phpapp01
11 Things About11g
In Memory Database In Action by Tanel Poder and Kerry Osborne
Oracle Database In-Memory Option in Action
A comprehensive study of non blocking joining techniques
A comprehensive study of non blocking joining technique
Myth busters - performance tuning 102 2008
Sql server scalability fundamentals
Oracle sql high performance tuning
Performance improvements in PostgreSQL 9.5 and beyond
Remote DBA Experts 11g Features
Lesson11 transactions
How to tune a query - ODTUG 2012

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Machine Learning_overview_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine Learning_overview_presentation.pptx
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Nested loop join technique - part2

  • 1. Table of Contents Background.................................................................................................................................................... 2 Test Recipes ................................................................................................................................................... 3 Test Cases and Results .................................................................................................................................. 4 It’s Number Time ........................................................................................................................................... 5 Conclusion ..................................................................................................................................................... 6 References ..................................................................................................................................................... 7
  • 2. Nested Loop Join Technique – Part 2(What’s the new thingin 11g?) Background Oracle introduces some improvements in 11g to optimize Nested Loop Join (NLJ).Apart from that, new join technique also has been introduced (known as Table Batching). The impact of this technique is as good as table prefetching (introduced in 9i) that we have seen in part1 of this series. To be precise, this new technique will work more efficient in sorted non-unique index (in unique index, we won’t see much different between all those 3 techniques). In most of the cases, we won’t see again the classic NLJ (in the execution plan) in 11g until unless we specify it purposefully using SQL hint. In this exercise, we will try to see the improvements which have been done by Oracle in 11g and also see what is the different of batching and prefetching technique. Before we move forward, let’s see the different of the execution plan diagram between those 3 techniques (classic, prefetching and batching) and how we instruct Oracle to use it (details are as below). In batching technique, Oracle creates 2 NLJs. The first NLJ (the inner one) is for joining outer (driving) table and available index of inner (or if I am allowed to call it: driven) table. The second NLJis for joining above (previous) result with inner table. What make me confuse is that the second NLJ doesn’t have information of cost, rows, etc. It looks like the second NLJ is created for clarity reason (to make it more readable, compare to prefetching – even though the internal mechanism is different, we will see the details in attached XLS file). Classic Technique
  • 3. Prefetching Technique Batching Technique Test Recipes As a starting point, 5 tables will be created with 10,000 rows each and exactly10 rows per block, using “MINIMIZE RECORDS_PER_BLOCK” command. The purpose is to get a good figure of the number. In addition to those tables, 4 indexes will be created in the 4 inner tables (except DRIVER). The index itself will be having BLEVEL=2 (I have to use PCTFREE=99 to force it), so the index height is 3 (ROOT  BRANCH  LEAF). These steps are exactly the same steps that I had followed during 10g testing. 1. DRIVER, driving (outer) table.
  • 4. 2. T_UNIQ_SORTED, inner table with unique index on ID column and sorted data. 3. T_UNIQ_UNSORTED, inner table with unique index on ID column and scattered data/ random ordered. 4. T_NON_UNIQ_SORTED, inner table with non-unique index on ID column and sorted data. 5. T_NON_UNIQ_UNSORTED, inner table with non-unique index on ID column and scattered data. Create Tables and Indexes.LST Test Cases and Results To be able to make “fair-enough” comparison, I am following these steps in this exercise. The idea is to put as much as block in the buffer to minimize or remove physical IO completely. 1. Flush buffer_cache 2. Warm up the buffer by: a. Select all data from outer table, DRIVER(full table scan) b. Scan inner table using index access (full index scan) 3. Begin snapper process from separate session 4. Execute each test case and turn on event 10046 to trace SQL wait event and event 10200 to dump consistent gets activity. 5. End snapper process DBA series - Nested Loop Join Technique - part2.xlsx
  • 5. It’s Number Time Below table give us enough information to see that there is only small different between 3 techniques in 11g. Oracle makes an optimization in the code level which impact in all 3 techniques. It is not the same for 10g case, where we can see the different in few statistics. Let’s have a quick look on below session statistics: 1. The result for all 3 techniques in 11g is equal or very close to the result of prefetching in 10g. 2. “consistent gets” is reduced from 42,000(10g classic method)to 34,000(10g prefetching and all techniques in 11g). The same thing also happened for “cache buffers chains”. 3. Even though the result of “consistent gets” related statistics are similar each other, we can see that “sql execute elapsed time” is varying for 11g. Batching technique is the fastest one while classic NLJ is the slowest (it is slower compare to 10g as well) 4. In 11g, the result of “buffer is pinned count” is varying and prefetching technique is able to pin more buffer compare to the other 2 techniques. 5. The new “consistent gets from cache (fastpath)” in 11g has relation with system parameter “_fastpin_enable” (default to 1 in 11g). This parameter control how Oracle handles repeated access to particular buffer for optimization. I ran all these exercise once so I might miss something here. In this case, you always have a chance to rerun all these exercises and share it with me  Apart from that optimization, I am going to highlight one more statistic which is also impacting total consistent get. That statistic is “SQL*Net roundtrips to/from client”. During 10g and 11g test, this statistic always gives similar result. If we look further, we will see the same number for consistent get for
  • 6. ROOT index. The number (668) is close to the result of “SQL*Net roundtrips to/from client”. Below are the details. So, from where the 668 is coming? It has relation with array size in sqlplus. During the test, I use default array size, which is 15 in my test environment Since I have 10,000 records in my table, and the size of array is 15, so Oracle has to send the result-set in: ceil(10,000 / 15) = 667times But have 1 extra in the result. Don’t worry, it is common in Oracle world that sometimes there is “plus one, +1” in the calculation (for example, see “_table_scan_cost_plus_one”parameter), so 667 + 1 = 668. When I reran the test with array size of 100, it gave me below result. Simple calculation: ceil(10,000 / 100) + 1 = 100 + 1 = 101. So, we need to consider also the size of array or fetch size (when we have bulk operation) since it has impact on the number of consistent get. Conclusion 1. Table prefetching brings a significant improvement for non-unique index in nested loop join.
  • 7. 2. Oracle has done some improvement in 11g and also has introduced new technique for NLJ, this makes huge differences compare to 10g. 3. In 11g, Oracle introduces new statistic, “consistent gets from cache (fastpath)” which has relation with system parameter “_fastpin_enable” (default to 1 in 11g). This parameter control how Oracle handles repeated access to particular buffer for optimization. But the impact of this optimization will be more efficient only for sorted data. For scattered data, Oracle won’t be able to optimize much, because consecutive number might be stored in different data block. So index with low clustering_factor will get benefit from this optimization. 4. Consider array size or fetch size since it has impact on the consistent get. References http://hoopercharles.wordpress.com/2011/01/24/watching-consistent-gets-10200-tracefile-parser/ http://dioncho.wordpress.com/2010/08/16/batching-nlj-optimization-and-ordering/ http://blog.tanelpoder.com/2013/02/18/manual-before-and-after-snapshot-support-insnapper-v4/ -heri-