SlideShare a Scribd company logo
I want to share a small comparison between NOT EXISTS and NOT IN operator. We see these 2 operators
mostly in the sub-query and in reporting query. Few points that we should understand regarding these
operations:
1. Not In and Not Exists will produces exactly the same result if there is no NULL value in the sub-query. If
we have NULL value in the sub-query, we can add one more condition to eliminate that value (for
example: … AND (column_name IS NOT NULL …). The other approach is to define the column as
NOT NULL.
2. Not Exists is more efficient because when Oracle found 1 record in the sub-query that satisfies the
condition, Oracle will move to the next record of main query. If there is efficient index access to that
sub-query, Oracle will be able to use that index.
3. In case of Not In, Oracle has to scan the whole population (full table scan) of sub-query before Oracle
can move to the next record of main query,it requires more IO. If there is an efficient index access to
the sub-query, Oracle will not be able to use that index because of implicit LNNVL function in the
predicate.
4. Not In will be translated as ((column_name != VALUE_1) AND (column_name != VALUE_2)
AND (column_name != VALUE_3) … AND (column_name != VALUE_N)).
Let’s the party started! This is the test data.

We have 2 exactly the same tables (structure and data). BULK_ACT will be the main table, while BULK_ACT will
be the sub-query table. There is an index on each table. Later we update 2 records in the main table to
simulate NULL value and 1 different value between main and sub-query table.
This is the session statistics comparison (XLS) of those 2 operations and also the output of trace file of event
10053.
exist_vs_in.xlsx

In Predicate Information section of Not In version, we can see 1 bind variable, :B1, which can be translated as
Oracle executes the sub-query over and over again. We have 100,000 rows in BULK_ACT, so we will have
100,000 times Table Full Scan against BULK_GRP. Let’s check the session statistics for the confirmation.

There should be only 2 table scans in the Not Exists version, but we got 7 in above table, so the other 5 table
scans are belong to another tables/ processes. Looking forward to the Not In version, we got 100,006 table
scans, if 5 of its are belong to another tables, then we have only 100,001 table scans for the Not In version. 1
table scan for BULK_ACT and 100,000 table scans for BULK_GRP. The next 2 statistics (table scan blocks gotten
and table scan rows gotten) also confirmed that more operation were done in the Not In version.
Due to this huge table scans execution, the execution time and number of consistent gets for Not In version
also increase significantly.
Not In version with
dynamic sampling is on

Not Exists versionwith
dynamic sampling is on
So, what will be happened if we remove the “IS NOT NULL” part? The null value will be reported in the query as
below. There 2 rows in the output: 100,001 and NULL.

As mentioned earlier, we can also define the column as NOT NULL to have the same result.
What’s the Improvement in 11g?
There is new method which introduced in 11g to handle the inefficient Not In version (without re-writing the
query). I rerun the Not In version in 11g and here is the result.
As seen below, the new “HASH JOIN ANTI NA” has been introduced. The NA is stand for Null-Aware (please
read: http://structureddata.org/2008/05/22/null-aware-anti-join/). So we don’t need to rewrite the query 
since Oracle can take the benefit of Hash Join, instead of using Filter (as we have seen in previous 10g version).
The new
HASH JOIN ANTI NA

In above link, you will see also another new Hash Join method, “HASH JOIN ANTI SNA”. So please go through
that site, read and get your hand dirt with trial and error 
-heri-

More Related Content

What's hot

Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
linked list
linked list linked list
linked list
Narendra Chauhan
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
Ahmed Farag
 
Technical
TechnicalTechnical
Technical
ved prakash
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Circular linked list
Circular linked listCircular linked list
Circular linked listdchuynh
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniques
kumar gaurav
 
Linklist
LinklistLinklist
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
linked list
linked listlinked list
linked list
Shaista Qadir
 
Sql Queries
Sql QueriesSql Queries
Sql Querieswebicon
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
Ajay Gupte
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
Ajay Gupte
 

What's hot (20)

Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
 
linked list
linked list linked list
linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
Linked list
Linked listLinked list
Linked list
 
Technical
TechnicalTechnical
Technical
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniques
 
Linklist
LinklistLinklist
Linklist
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
linked list
linked listlinked list
linked list
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
 

Similar to Not in vs not exists

Nested loop join technique - part2
Nested loop join technique - part2Nested loop join technique - part2
Nested loop join technique - part2
Heribertus Bramundito
 
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-joinsKaing Menglieng
 
Hash join
Hash joinHash join
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
Gurpreet singh
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
Anil Pandey
 
Interview Preparation
Interview PreparationInterview Preparation
Interview Preparation
Ravi Kanudawala
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008paulguerin
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution Plan
Optimiz DBA
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
nagesh Rao
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
Vikas Gupta
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
Edgar Alejandro Villegas
 
Autonumber
AutonumberAutonumber
Autonumber
oracle documents
 
How to Use VLOOKUP in Excel
How to Use VLOOKUP in ExcelHow to Use VLOOKUP in Excel
How to Use VLOOKUP in Excel
Milorad Krstevski
 
Migration
MigrationMigration
Migration
oracle documents
 
Oracle interview questions
Oracle interview questionsOracle interview questions
Oracle interview questions
barbie0909
 
Oracle SQL Part 2
Oracle SQL Part 2Oracle SQL Part 2
Oracle SQL Part 2
Gurpreet singh
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
LakshmiSarvani6
 
Oracle foreign key missing index - a single index can boost performance
Oracle foreign key missing index - a single index can boost performanceOracle foreign key missing index - a single index can boost performance
Oracle foreign key missing index - a single index can boost performance
Carlos Oliveira
 
Ijetr012023
Ijetr012023Ijetr012023
Ijetr012023
ER Publication.org
 

Similar to Not in vs not exists (20)

Nested loop join technique - part2
Nested loop join technique - part2Nested loop join technique - part2
Nested loop join technique - part2
 
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
 
Hash join
Hash joinHash join
Hash join
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
Interview Preparation
Interview PreparationInterview Preparation
Interview Preparation
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution Plan
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
 
Autonumber
AutonumberAutonumber
Autonumber
 
How to Use VLOOKUP in Excel
How to Use VLOOKUP in ExcelHow to Use VLOOKUP in Excel
How to Use VLOOKUP in Excel
 
UPD_OP_SQL
UPD_OP_SQLUPD_OP_SQL
UPD_OP_SQL
 
Migration
MigrationMigration
Migration
 
Oracle interview questions
Oracle interview questionsOracle interview questions
Oracle interview questions
 
Oracle SQL Part 2
Oracle SQL Part 2Oracle SQL Part 2
Oracle SQL Part 2
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Oracle foreign key missing index - a single index can boost performance
Oracle foreign key missing index - a single index can boost performanceOracle foreign key missing index - a single index can boost performance
Oracle foreign key missing index - a single index can boost performance
 
Ijetr012023
Ijetr012023Ijetr012023
Ijetr012023
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 

Not in vs not exists

  • 1. I want to share a small comparison between NOT EXISTS and NOT IN operator. We see these 2 operators mostly in the sub-query and in reporting query. Few points that we should understand regarding these operations: 1. Not In and Not Exists will produces exactly the same result if there is no NULL value in the sub-query. If we have NULL value in the sub-query, we can add one more condition to eliminate that value (for example: … AND (column_name IS NOT NULL …). The other approach is to define the column as NOT NULL. 2. Not Exists is more efficient because when Oracle found 1 record in the sub-query that satisfies the condition, Oracle will move to the next record of main query. If there is efficient index access to that sub-query, Oracle will be able to use that index. 3. In case of Not In, Oracle has to scan the whole population (full table scan) of sub-query before Oracle can move to the next record of main query,it requires more IO. If there is an efficient index access to the sub-query, Oracle will not be able to use that index because of implicit LNNVL function in the predicate. 4. Not In will be translated as ((column_name != VALUE_1) AND (column_name != VALUE_2) AND (column_name != VALUE_3) … AND (column_name != VALUE_N)). Let’s the party started! This is the test data. We have 2 exactly the same tables (structure and data). BULK_ACT will be the main table, while BULK_ACT will be the sub-query table. There is an index on each table. Later we update 2 records in the main table to simulate NULL value and 1 different value between main and sub-query table. This is the session statistics comparison (XLS) of those 2 operations and also the output of trace file of event 10053.
  • 2. exist_vs_in.xlsx In Predicate Information section of Not In version, we can see 1 bind variable, :B1, which can be translated as Oracle executes the sub-query over and over again. We have 100,000 rows in BULK_ACT, so we will have 100,000 times Table Full Scan against BULK_GRP. Let’s check the session statistics for the confirmation. There should be only 2 table scans in the Not Exists version, but we got 7 in above table, so the other 5 table scans are belong to another tables/ processes. Looking forward to the Not In version, we got 100,006 table scans, if 5 of its are belong to another tables, then we have only 100,001 table scans for the Not In version. 1 table scan for BULK_ACT and 100,000 table scans for BULK_GRP. The next 2 statistics (table scan blocks gotten and table scan rows gotten) also confirmed that more operation were done in the Not In version. Due to this huge table scans execution, the execution time and number of consistent gets for Not In version also increase significantly.
  • 3. Not In version with dynamic sampling is on Not Exists versionwith dynamic sampling is on
  • 4. So, what will be happened if we remove the “IS NOT NULL” part? The null value will be reported in the query as below. There 2 rows in the output: 100,001 and NULL. As mentioned earlier, we can also define the column as NOT NULL to have the same result.
  • 5. What’s the Improvement in 11g? There is new method which introduced in 11g to handle the inefficient Not In version (without re-writing the query). I rerun the Not In version in 11g and here is the result. As seen below, the new “HASH JOIN ANTI NA” has been introduced. The NA is stand for Null-Aware (please read: http://structureddata.org/2008/05/22/null-aware-anti-join/). So we don’t need to rewrite the query  since Oracle can take the benefit of Hash Join, instead of using Filter (as we have seen in previous 10g version).
  • 6. The new HASH JOIN ANTI NA In above link, you will see also another new Hash Join method, “HASH JOIN ANTI SNA”. So please go through that site, read and get your hand dirt with trial and error  -heri-