SlideShare a Scribd company logo
How Oracle Query
Works ?!
Or how write most optimized query !
MohamadReza NamaziZade
Content
• The SQL Optimizers
• Rule-Based & Cost-Based Optimizer Problems and Solutions
• SQL Tuning Tips
• How good is the index?
• SQL Hint
• Execution plans
• Different types of index scan
• How write nice queries
• How optimized my high inefficient queries
• Conclusion
The SQL Optimizers
• There are 2 primary optimizer
• 1 - Rule Based Optimizer
• The rule-based optimizer (RBO) uses a predefined set of precedence
rules to figure out which path it will use to access the database.
• 2 - Cost Based Optimizer
• The cost-based optimizer uses database information such as table
size, number of rows, key spread, and so forth, rather than rigid
rules.
• Which one used on my query ?!
• OPTIMIZER_MODE = RULE - > init.ora
• OPTIMIZER_MODE = CHOOSE - > init.ora
• ALTER SESSION SET OPTIMIZER_MODE = RULE
• SELECT /*+ RULE */
One or more I/Os to find or
store the key value in the
index
Another I/O to read or
write the row in the table
or cluster
Golden Rules of Rule Based :
Rank Condition
1 ROWID = constant
2 Cluster join with unique or primary key = constant
3 Hash cluster key with unique or primary key = constant
4 Entire Unique concatenated index = constant
5 Unique indexed column = constant
6 Entire cluster key = corresponding cluster key of another table in the
same cluster
7 Hash cluster key = constant
8 Entire cluster key = constant
9 Entire non-UNIQUE CONCATENATED index = constant
10 Non-UNIQUE index merge
11 Entire concatenated index = lower bound
12 Most leading column(s) of concatenated index = constant
Golden Rules of Rule Based 2 :
RANK Condition
13 Indexed column between low value and high value or indexed column
LIKE "ABC%"
(bounded range)
14 Non-UNIQUE indexed column between low value and high value or
indexed column like
`ABC%' (bounded range)
15 UNIQUE indexed column or constant (unbounded range)
16 Non-UNIQUE indexed column or constant (unbounded range)
17 Equality on non-indexed = column or constant (sort/merge join)
18 MAX or MIN of single indexed columns
19 ORDER BY entire index
20 Full table scans
Why CBO over RBO ?
• RBO :
• When using the Rule Based Optimizer -- the placement of
tables in the FROM clause is relevant. We process the from
clause from the RIGHT to the LEFT -- we would tend to pick a
driving table from the end of the FROM list. There is a hint in
the Cost Based Optimizer to have this happen as well.
• CBO :
• When using CBO -- the order of tables is not relevant (unless
you hint it to be). We use the statistics and data dictionary to
determine which table is best to be used as the driving table.
• Ask TOM
Why CBO over RBO 2…
What’s wrong with RBO ?
Incorrect driving table (example above)
Incorrect index
Incorrect driving index
Using the ORDER BY index and not the WHERE index
CBO problems !?
• The skewness problem
• SELECT * FROM at_tri_payment_way t where t.paymnt_status
= 'PAID'
• (1 – PAID = 5,000,000, 2 - UNPAID = 100)
• unaware of how many rows exist for each of 1 & 2
• assumes a 50/50 spread of data for each
• Solution :
• ANALYZE TABLE TRANS COMPUTE STATISTICS FOR ALL
INDEXED COLUMNS
Common Problems …
• 1. Statement not written for indexes
• 2. Indexes are missing or inappropriate
• 3. Use of single-column index merge
• 4. Misuse of nested loop, sort merge, or hash join
• 5. Misuse of IN, EXISTS, NOT IN, NOT EXISTS, or table joins
• 6. Unnecessary Sorts
• 7. Too many indexes on a table
• 8. Use of OR instead of UNION
• 9. Tables and indexes with many deletes
Statement not written for indexes
• Use function : substr , trunc, NVL…
• User != <> NOT : indexes can tell you what is in a table but not
what is not in a table !!!
• String concentration ||
• Arithmetic
Leading Column
• On Partitioned tables
• Column on which partition created must be on where clause
• Must be first on Multi-Column Index
• On Composite Index
• Must be specified in condition
How good is the index?
• unique index values
• selectivity = ----------------------------
• total number records
• low cardinality fields make bad indexes
• Gender(male, female)
• primary key is highly selective(100% selective)
• If there are 1000 rows, there will be 1000 unique keys
Conclusion
• B-tree indexes are created to decrease the amount of I/O
required to find and load a set of data. A highly selective index
uses least amount of I/O necessary, poorly selective indices
are not much better than a table scan.
• Always decide on real data and don’t stick with execution plan
numbers .

More Related Content

What's hot

Row, Column, Index, Match, Offset Functions. Excel Tutorial
Row, Column, Index, Match, Offset Functions. Excel TutorialRow, Column, Index, Match, Offset Functions. Excel Tutorial
Row, Column, Index, Match, Offset Functions. Excel Tutorial
Ilgar Zarbaliyev
 
The Microsoft Excel Program
The Microsoft Excel ProgramThe Microsoft Excel Program
The Microsoft Excel Program
Rolly Franco
 
Excel11
Excel11Excel11
Excel11
acharyaa
 
How mysql choose the execution plan
How mysql choose the execution planHow mysql choose the execution plan
How mysql choose the execution plan
辛鹤 李
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
vuhaininh88
 
AVL Tree
AVL Tree  AVL Tree
AVL Tree
Ali_Jaan474
 
Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2Dalia Saeed
 
SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition Strategy
Hamid J. Fard
 
Intermediate ms excel for business elective course for dlsu-d hs
Intermediate ms excel for business   elective course for dlsu-d hsIntermediate ms excel for business   elective course for dlsu-d hs
Intermediate ms excel for business elective course for dlsu-d hs
MarkFreudBolima
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Andriy Krayniy
 
Database index
Database indexDatabase index
Database index
Riteshkiit
 
Advance excel
Advance excelAdvance excel
Advance excel
SiddheshHadge
 
Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Dalia Saeed
 
Join sql
Join sqlJoin sql
Join sql
Vikas Gupta
 
Introduction to data analysis using excel
Introduction to data analysis using excelIntroduction to data analysis using excel
Introduction to data analysis using excel
Ahmed Essam
 
Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)
Tammy Carter
 
New Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel TutorialNew Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel Tutorial
Ilgar Zarbaliyev
 
Spreadsheet advanced functions ppt (2)
Spreadsheet advanced functions ppt (2)Spreadsheet advanced functions ppt (2)
Spreadsheet advanced functions ppt (2)
Tammy Carter
 

What's hot (20)

Row, Column, Index, Match, Offset Functions. Excel Tutorial
Row, Column, Index, Match, Offset Functions. Excel TutorialRow, Column, Index, Match, Offset Functions. Excel Tutorial
Row, Column, Index, Match, Offset Functions. Excel Tutorial
 
The Microsoft Excel Program
The Microsoft Excel ProgramThe Microsoft Excel Program
The Microsoft Excel Program
 
Excel11
Excel11Excel11
Excel11
 
How mysql choose the execution plan
How mysql choose the execution planHow mysql choose the execution plan
How mysql choose the execution plan
 
Week2 excel
Week2 excelWeek2 excel
Week2 excel
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
 
AVL Tree
AVL Tree  AVL Tree
AVL Tree
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2
 
SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition Strategy
 
Intermediate ms excel for business elective course for dlsu-d hs
Intermediate ms excel for business   elective course for dlsu-d hsIntermediate ms excel for business   elective course for dlsu-d hs
Intermediate ms excel for business elective course for dlsu-d hs
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
 
Database index
Database indexDatabase index
Database index
 
Advance excel
Advance excelAdvance excel
Advance excel
 
Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1
 
Join sql
Join sqlJoin sql
Join sql
 
Introduction to data analysis using excel
Introduction to data analysis using excelIntroduction to data analysis using excel
Introduction to data analysis using excel
 
Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)Spreadsheet formulas ppt (1)
Spreadsheet formulas ppt (1)
 
New Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel TutorialNew Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel Tutorial
 
Spreadsheet advanced functions ppt (2)
Spreadsheet advanced functions ppt (2)Spreadsheet advanced functions ppt (2)
Spreadsheet advanced functions ppt (2)
 

Viewers also liked

Ash and awr performance data2
Ash and awr performance data2Ash and awr performance data2
Ash and awr performance data2
Kellyn Pot'Vin-Gorman
 
Ayane - Projector Phone
Ayane - Projector PhoneAyane - Projector Phone
Ayane - Projector Phone
Vansh Kapil
 
Managing troubleshooting cluster_360dgrees
Managing troubleshooting cluster_360dgreesManaging troubleshooting cluster_360dgrees
Managing troubleshooting cluster_360dgrees
Syed Hussain
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
Amrit Kaur
 
Capacity & Performance Management in Solaris Virtualized Environment
Capacity & Performance Management in Solaris Virtualized EnvironmentCapacity & Performance Management in Solaris Virtualized Environment
Capacity & Performance Management in Solaris Virtualized Environment
Neeraj Bhatia
 
Cost Based Oracle
Cost Based OracleCost Based Oracle
Cost Based Oracle
Santosh Kangane
 
Consumer Behavior of Bihar and Bengal
Consumer Behavior of Bihar and BengalConsumer Behavior of Bihar and Bengal
Consumer Behavior of Bihar and Bengal
Argha Ray
 
It Works! Presenting DBAL use in real life
It Works! Presenting DBAL use in real lifeIt Works! Presenting DBAL use in real life
It Works! Presenting DBAL use in real life
Karsten Dambekalns
 
Exadata Smart Scan - What is so smart about it?
Exadata Smart Scan  - What is so smart about it?Exadata Smart Scan  - What is so smart about it?
Exadata Smart Scan - What is so smart about it?
Uwe Hesse
 
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
N/A
 
Rman Presentation
Rman PresentationRman Presentation
Rman Presentation
Rick van Ek
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
adryanbub
 
Oracle on linux
Oracle on linuxOracle on linux
Oracle on linux
VINAY PANDEY
 
Real-Time Query for Data Guard
Real-Time Query for Data Guard Real-Time Query for Data Guard
Real-Time Query for Data Guard
Uwe Hesse
 
Oracle Database In-Memory & Multitenant - TROUG Days'16 Istanbul
Oracle Database In-Memory & Multitenant - TROUG Days'16 IstanbulOracle Database In-Memory & Multitenant - TROUG Days'16 Istanbul
Oracle Database In-Memory & Multitenant - TROUG Days'16 Istanbul
Mahir M. Quluzade
 
Oracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerOracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query Optimizer
Christian Antognini
 
akanksha bakul foundation
akanksha  bakul foundationakanksha  bakul foundation
akanksha bakul foundationAmitabh Yadav
 

Viewers also liked (20)

Ash and awr performance data2
Ash and awr performance data2Ash and awr performance data2
Ash and awr performance data2
 
Ayane - Projector Phone
Ayane - Projector PhoneAyane - Projector Phone
Ayane - Projector Phone
 
Managing troubleshooting cluster_360dgrees
Managing troubleshooting cluster_360dgreesManaging troubleshooting cluster_360dgrees
Managing troubleshooting cluster_360dgrees
 
certificate
certificatecertificate
certificate
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Capacity & Performance Management in Solaris Virtualized Environment
Capacity & Performance Management in Solaris Virtualized EnvironmentCapacity & Performance Management in Solaris Virtualized Environment
Capacity & Performance Management in Solaris Virtualized Environment
 
Cost Based Oracle
Cost Based OracleCost Based Oracle
Cost Based Oracle
 
Consumer Behavior of Bihar and Bengal
Consumer Behavior of Bihar and BengalConsumer Behavior of Bihar and Bengal
Consumer Behavior of Bihar and Bengal
 
It Works! Presenting DBAL use in real life
It Works! Presenting DBAL use in real lifeIt Works! Presenting DBAL use in real life
It Works! Presenting DBAL use in real life
 
Exadata Smart Scan - What is so smart about it?
Exadata Smart Scan  - What is so smart about it?Exadata Smart Scan  - What is so smart about it?
Exadata Smart Scan - What is so smart about it?
 
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
 
Rman Presentation
Rman PresentationRman Presentation
Rman Presentation
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
 
Oracle on linux
Oracle on linuxOracle on linux
Oracle on linux
 
Real-Time Query for Data Guard
Real-Time Query for Data Guard Real-Time Query for Data Guard
Real-Time Query for Data Guard
 
Oracle Database In-Memory & Multitenant - TROUG Days'16 Istanbul
Oracle Database In-Memory & Multitenant - TROUG Days'16 IstanbulOracle Database In-Memory & Multitenant - TROUG Days'16 Istanbul
Oracle Database In-Memory & Multitenant - TROUG Days'16 Istanbul
 
Oracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query OptimizerOracle Database In-Memory and the Query Optimizer
Oracle Database In-Memory and the Query Optimizer
 
TarunSharma_CV
TarunSharma_CVTarunSharma_CV
TarunSharma_CV
 
statement_sql
statement_sqlstatement_sql
statement_sql
 
akanksha bakul foundation
akanksha  bakul foundationakanksha  bakul foundation
akanksha bakul foundation
 

Similar to How oracle query works (The SQL Optimizers)

Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
GMO-Z.com Vietnam Lab Center
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
Tech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingTech Jam 01 - Database Querying
Tech Jam 01 - Database Querying
Rodger Oates
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Oracle Course
Oracle CourseOracle Course
Oracle Courserspaike
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
Leo Mark Villar
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
Rajesh Gunasundaram
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
Priyabrat Kar
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices document
Ashwani Pandey
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager
Krishan Singh
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
MalaikaRahatQurashi
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
Riteshkiit
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
Antonios Chatzipavlis
 
ADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database Systems
Joshua Costa
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdf
SwapnilSaurav7
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimizationBaohua Cai
 
Sql
SqlSql
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
Riteshkiit
 

Similar to How oracle query works (The SQL Optimizers) (20)

Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Tech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingTech Jam 01 - Database Querying
Tech Jam 01 - Database Querying
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices document
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
 
ADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database Systems
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdf
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimization
 
Sql
SqlSql
Sql
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 

Recently uploaded

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 

Recently uploaded (20)

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 

How oracle query works (The SQL Optimizers)

  • 1. How Oracle Query Works ?! Or how write most optimized query ! MohamadReza NamaziZade
  • 2. Content • The SQL Optimizers • Rule-Based & Cost-Based Optimizer Problems and Solutions • SQL Tuning Tips • How good is the index? • SQL Hint • Execution plans • Different types of index scan • How write nice queries • How optimized my high inefficient queries • Conclusion
  • 3. The SQL Optimizers • There are 2 primary optimizer • 1 - Rule Based Optimizer • The rule-based optimizer (RBO) uses a predefined set of precedence rules to figure out which path it will use to access the database. • 2 - Cost Based Optimizer • The cost-based optimizer uses database information such as table size, number of rows, key spread, and so forth, rather than rigid rules. • Which one used on my query ?! • OPTIMIZER_MODE = RULE - > init.ora • OPTIMIZER_MODE = CHOOSE - > init.ora • ALTER SESSION SET OPTIMIZER_MODE = RULE • SELECT /*+ RULE */
  • 4. One or more I/Os to find or store the key value in the index Another I/O to read or write the row in the table or cluster Golden Rules of Rule Based : Rank Condition 1 ROWID = constant 2 Cluster join with unique or primary key = constant 3 Hash cluster key with unique or primary key = constant 4 Entire Unique concatenated index = constant 5 Unique indexed column = constant 6 Entire cluster key = corresponding cluster key of another table in the same cluster 7 Hash cluster key = constant 8 Entire cluster key = constant 9 Entire non-UNIQUE CONCATENATED index = constant 10 Non-UNIQUE index merge 11 Entire concatenated index = lower bound 12 Most leading column(s) of concatenated index = constant
  • 5. Golden Rules of Rule Based 2 : RANK Condition 13 Indexed column between low value and high value or indexed column LIKE "ABC%" (bounded range) 14 Non-UNIQUE indexed column between low value and high value or indexed column like `ABC%' (bounded range) 15 UNIQUE indexed column or constant (unbounded range) 16 Non-UNIQUE indexed column or constant (unbounded range) 17 Equality on non-indexed = column or constant (sort/merge join) 18 MAX or MIN of single indexed columns 19 ORDER BY entire index 20 Full table scans
  • 6. Why CBO over RBO ? • RBO : • When using the Rule Based Optimizer -- the placement of tables in the FROM clause is relevant. We process the from clause from the RIGHT to the LEFT -- we would tend to pick a driving table from the end of the FROM list. There is a hint in the Cost Based Optimizer to have this happen as well. • CBO : • When using CBO -- the order of tables is not relevant (unless you hint it to be). We use the statistics and data dictionary to determine which table is best to be used as the driving table. • Ask TOM
  • 7. Why CBO over RBO 2… What’s wrong with RBO ? Incorrect driving table (example above) Incorrect index Incorrect driving index Using the ORDER BY index and not the WHERE index
  • 8. CBO problems !? • The skewness problem • SELECT * FROM at_tri_payment_way t where t.paymnt_status = 'PAID' • (1 – PAID = 5,000,000, 2 - UNPAID = 100) • unaware of how many rows exist for each of 1 & 2 • assumes a 50/50 spread of data for each • Solution : • ANALYZE TABLE TRANS COMPUTE STATISTICS FOR ALL INDEXED COLUMNS
  • 9. Common Problems … • 1. Statement not written for indexes • 2. Indexes are missing or inappropriate • 3. Use of single-column index merge • 4. Misuse of nested loop, sort merge, or hash join • 5. Misuse of IN, EXISTS, NOT IN, NOT EXISTS, or table joins • 6. Unnecessary Sorts • 7. Too many indexes on a table • 8. Use of OR instead of UNION • 9. Tables and indexes with many deletes
  • 10. Statement not written for indexes • Use function : substr , trunc, NVL… • User != <> NOT : indexes can tell you what is in a table but not what is not in a table !!! • String concentration || • Arithmetic
  • 11. Leading Column • On Partitioned tables • Column on which partition created must be on where clause • Must be first on Multi-Column Index • On Composite Index • Must be specified in condition
  • 12. How good is the index? • unique index values • selectivity = ---------------------------- • total number records • low cardinality fields make bad indexes • Gender(male, female) • primary key is highly selective(100% selective) • If there are 1000 rows, there will be 1000 unique keys
  • 13. Conclusion • B-tree indexes are created to decrease the amount of I/O required to find and load a set of data. A highly selective index uses least amount of I/O necessary, poorly selective indices are not much better than a table scan. • Always decide on real data and don’t stick with execution plan numbers .