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 .
Ad

More Related Content

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
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
辛鹤 李
 
Week2 excel
Week2 excelWeek2 excel
Week2 excel
Jumari Mercullo
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
vuhaininh88
 
AVL Tree
AVL Tree  AVL Tree
AVL Tree
Ali_Jaan474
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
Wings Interactive
 
Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2
Dalia 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_1
Dalia 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
 
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
 
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
 
Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2Triad 2010 excel_chapter_2
Triad 2010 excel_chapter_2
Dalia 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
 
Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1
Dalia Saeed
 
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
 

Viewers also liked (20)

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
 
certificate
certificatecertificate
certificate
Hitesh Gondalia (ITIL®,OCE®,OCP®)
 
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
 
TarunSharma_CV
TarunSharma_CVTarunSharma_CV
TarunSharma_CV
Tarun Sharma
 
statement_sql
statement_sqlstatement_sql
statement_sql
Shubham Gupta
 
akanksha bakul foundation
akanksha  bakul foundationakanksha  bakul foundation
akanksha bakul foundation
Amitabh Yadav
 
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
 
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
 
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 foundation
Amitabh Yadav
 
Ad

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

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
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
Hitesh Kumar Markam
 
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 Course
rspaike
 
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
 
More Complex SQL and Concurrency ControlModule 4.pptx
More Complex SQL and Concurrency ControlModule 4.pptxMore Complex SQL and Concurrency ControlModule 4.pptx
More Complex SQL and Concurrency ControlModule 4.pptx
bgscseise
 
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 optimization
Baohua Cai
 
Sql
SqlSql
Sql
RittikaBaksi
 
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 Course
rspaike
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
More Complex SQL and Concurrency ControlModule 4.pptx
More Complex SQL and Concurrency ControlModule 4.pptxMore Complex SQL and Concurrency ControlModule 4.pptx
More Complex SQL and Concurrency ControlModule 4.pptx
bgscseise
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
Rajesh Gunasundaram
 
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
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
Riteshkiit
 
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 optimization
Baohua Cai
 
Ad

Recently uploaded (20)

Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 

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 .
  翻译: