SlideShare una empresa de Scribd logo
1 de 13
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 .

Más contenido relacionado

La actualidad más candente

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 TutorialIlgar Zarbaliyev
 
The Microsoft Excel Program
The Microsoft Excel ProgramThe Microsoft Excel Program
The Microsoft Excel ProgramRolly 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 queryvuhaininh88
 
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 StrategyHamid 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 hsMarkFreudBolima
 
"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 indexRiteshkiit
 
Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Dalia Saeed
 
Introduction to data analysis using excel
Introduction to data analysis using excelIntroduction to data analysis using excel
Introduction to data analysis using excelAhmed 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 TutorialIlgar Zarbaliyev
 
Spreadsheet advanced functions ppt (2)
Spreadsheet advanced functions ppt (2)Spreadsheet advanced functions ppt (2)
Spreadsheet advanced functions ppt (2)Tammy Carter
 

La actualidad más candente (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)
 

Destacado

Ayane - Projector Phone
Ayane - Projector PhoneAyane - Projector Phone
Ayane - Projector PhoneVansh Kapil
 
Managing troubleshooting cluster_360dgrees
Managing troubleshooting cluster_360dgreesManaging troubleshooting cluster_360dgrees
Managing troubleshooting cluster_360dgreesSyed Hussain
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit 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 EnvironmentNeeraj Bhatia
 
Consumer Behavior of Bihar and Bengal
Consumer Behavior of Bihar and BengalConsumer Behavior of Bihar and Bengal
Consumer Behavior of Bihar and BengalArgha 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 lifeKarsten 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 PresentationRick van Ek
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introductionadryanbub
 
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 IstanbulMahir 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 OptimizerChristian Antognini
 
akanksha bakul foundation
akanksha  bakul foundationakanksha  bakul foundation
akanksha bakul foundationAmitabh Yadav
 

Destacado (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 a How oracle query works (The SQL Optimizers)

Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai1
 
Tech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingTech Jam 01 - Database Querying
Tech Jam 01 - Database QueryingRodger 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-dbuncleRhyme
 
Oracle Course
Oracle CourseOracle Course
Oracle Courserspaike
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
Pl sql best practices document
Pl sql best practices documentPl sql best practices document
Pl sql best practices documentAshwani 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 analysisRiteshkiit
 
ADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsADBMS - Joins , Sorting , Distributed Database Systems
ADBMS - Joins , Sorting , Distributed Database SystemsJoshua Costa
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSwapnilSaurav7
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimizationBaohua Cai
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 

Similar a 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
 

Último

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Último (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

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 .