SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
QUERY OPTIMIZATION
What is Query Optimization?
• Query Processing: The process by which the query results are retrieved from a
high-level query such as SQL.
• Query Optimization: The process of choosing a suitable execution strategy for
retrieving results of query from database files for processing a query is known as
Query Optimization.
• Query optimization is a function of many relational database management
systems. The query optimizer attempts to determine the most efficient way to
execute a given query by considering the possible query plans.
Query Optimization Criteria
• Optimization criteria:
• Reduce total execution time of the query:
• Minimize the sum of the execution times of all individual operations
• Reduce the number of disk accesses
• Reduce response time of the query:
• Maximize parallel operations
Query Optimization Issues
• Query rewriting:
• transformations from one SQL query to another one using semantic properties.
• Selecting query execution plan:
• done on single query blocks
• Cost estimation:
• to compare between plans we need to estimate their cost using statistics on the
database.
Steps in Query Optimization
• Query optimization involves three steps:
1. Query Tree Generation:
A Query Tree is a tree data structure representing a relational algebra expression. The tables of
the query are represented as leaf nodes. The relational algebra operations are represented a
internal nodes. The root represents the query as a whole.
2. Query Plan Generation:
After the Query Tree is generated, a query plan is made. A query plan is an extended query tree
that includes access paths for all operation in the query tree. Access paths specify how the
relational operations in the tree should be performed.
3. Query Plan Code Generation:
Code Generation is the final step in the Query Optimization. It is the executable form of the
query. Once the query code is generated, the execution manager runs it and produces the results.
Two main Techniques for Query Optimization
 Heuristic Rules:
• Rules for ordering the operations in query optimization.
 Systematical estimation:
It estimates cost of different execution strategies and chooses the execution
plan with lowest execution cost.
Heuristic Approach
• Heuristic - problem-solving by experimental methods
• Applying general rules to choose the most appropriate internal query
representation
• Based on transformation rules for relational algebra operations
Transformation Rules
• Cascade of selection operations:
• Commutativity of selection operations
• Sequence of projection operations
where
)))((()( RR rqprqp  
))(())(( RR pqqp  
)...(
)(...
NML
R LNML


Heuristic Rules
• Perform selection as early as possible
• Combine Cross product with a subsequent selection
• Rearrange base relations so that the most restrictive selection is executed first.
• Perform projection as early as possible
• Compute common expressions once.
Systematical Estimation
• Cost Estimation Components:
• Cost of access to secondary storage
• Storage cost – cost of storing intermediate results
• Computation cost
• Memory usage cost – usage of RAM buffers
Systematical Estimation (Conti.)
• Cost Estimation for Relational Algebra Expressions:
• Formulae for cost estimation of each operation
• Estimation of relational algebra expression
• Choosing the expression with the lowest cost
Systematical Estimation (Conti.)
• Cost Estimation in Query Optimization:
• Based on relational algebra tree
• For each node in the tree the estimation is to be done for:
• the cost of performing the operation;
• the size of the result of the operation;
• whether the result is sorted.
Advantages of Query Optimization
1. Faster processing of Query.
2. Lesser cost per Query.
3. High performance of the system.
4. Lesser stress on the database.
5. Efficient usage of database engine.
6. Lesser memory is consumed.
Thank You!

More Related Content

What's hot (20)

PPTX
Query optimization
Zunera Bukhari
 
PPTX
Query-porcessing-& Query optimization
Saranya Natarajan
 
PPT
13. Query Processing in DBMS
koolkampus
 
PPTX
database language ppt.pptx
Anusha sivakumar
 
PPT
Query optimization
dixitdavey
 
PDF
PL/SQL TRIGGERS
Lakshman Basnet
 
PPT
Greedy Algorihm
Muhammad Amjad Rana
 
PPTX
SUBQUERIES.pptx
RenugadeviR5
 
PPTX
DBMS: Types of keys
Bharati Ugale
 
PPTX
Binary Tree in Data Structure
Meghaj Mallick
 
PPTX
Query processing and optimization (updated)
Ravinder Kamboj
 
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
PPTX
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
Saikiran Panjala
 
PDF
Serializability
Pyingkodi Maran
 
PPT
File organization 1
Rupali Rana
 
PPT
SQL : introduction
Shakila Mahjabin
 
PPTX
Query processing
Ravinder Kamboj
 
PPTX
Dynamic programming
Melaku Bayih Demessie
 
PPTX
Spatial Data Mining
Rashmi Bhat
 
Query optimization
Zunera Bukhari
 
Query-porcessing-& Query optimization
Saranya Natarajan
 
13. Query Processing in DBMS
koolkampus
 
database language ppt.pptx
Anusha sivakumar
 
Query optimization
dixitdavey
 
PL/SQL TRIGGERS
Lakshman Basnet
 
Greedy Algorihm
Muhammad Amjad Rana
 
SUBQUERIES.pptx
RenugadeviR5
 
DBMS: Types of keys
Bharati Ugale
 
Binary Tree in Data Structure
Meghaj Mallick
 
Query processing and optimization (updated)
Ravinder Kamboj
 
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
Saikiran Panjala
 
Serializability
Pyingkodi Maran
 
File organization 1
Rupali Rana
 
SQL : introduction
Shakila Mahjabin
 
Query processing
Ravinder Kamboj
 
Dynamic programming
Melaku Bayih Demessie
 
Spatial Data Mining
Rashmi Bhat
 

Similar to Query optimization (20)

PPTX
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
AthosBeatus
 
PPTX
DB LECTURE 5 QUERY PROCESSING.pptx
grahamoyigo19
 
PPTX
Ch-2-Query-Process.pptx advanced database
tasheebedane
 
PPTX
700442110-advanced database Ch-2-Query-Process.pptx
tasheebedane
 
PPTX
Heuristic approch monika sanghani
Monika Sanghani
 
PDF
Chapter 2.pdf WND FWKJFW KSD;KFLWHFB ASNK
alemunuruhak9
 
PDF
CH5_Query Processing and Optimization.pdf
amariyarana
 
PPTX
Adbms 40 heuristics in query optimization
Vaibhav Khanna
 
PPT
9-Query Processing-05-06-2023.PPT
venkatapranaykumarGa
 
PPTX
Advanced Database System Chapter Two Query processing and Optimization.pptx
mentesnotsibatuuu
 
PPTX
Query Execution Time and Query Optimization.
Radhe Krishna Rajan
 
PPTX
Concepts of Query Processing in ADBMS.pptx
AaradhyaDixit6
 
PPT
Query optimization and processing for advanced database systems
meharikiros2
 
PPT
QPOfutyfurfugfuyttruft7rfu65rfuyt PPT - Copy.ppt
ahmed518927
 
PPT
ch02-240507064009-ac337bf1 .ppt
iamayesha2526
 
PPTX
Query processing and Optimization in Database
Yordanos Zewge
 
PPT
Chapter15
gourab87
 
PDF
unit 3 DBMS.docx.pdf geometric transformer in query processing
FallenAngel35
 
PDF
unit 3 DBMS.docx.pdf geometry in query p
FallenAngel35
 
PDF
Issues in Query Processing and Optimization
Editor IJMTER
 
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
AthosBeatus
 
DB LECTURE 5 QUERY PROCESSING.pptx
grahamoyigo19
 
Ch-2-Query-Process.pptx advanced database
tasheebedane
 
700442110-advanced database Ch-2-Query-Process.pptx
tasheebedane
 
Heuristic approch monika sanghani
Monika Sanghani
 
Chapter 2.pdf WND FWKJFW KSD;KFLWHFB ASNK
alemunuruhak9
 
CH5_Query Processing and Optimization.pdf
amariyarana
 
Adbms 40 heuristics in query optimization
Vaibhav Khanna
 
9-Query Processing-05-06-2023.PPT
venkatapranaykumarGa
 
Advanced Database System Chapter Two Query processing and Optimization.pptx
mentesnotsibatuuu
 
Query Execution Time and Query Optimization.
Radhe Krishna Rajan
 
Concepts of Query Processing in ADBMS.pptx
AaradhyaDixit6
 
Query optimization and processing for advanced database systems
meharikiros2
 
QPOfutyfurfugfuyttruft7rfu65rfuyt PPT - Copy.ppt
ahmed518927
 
ch02-240507064009-ac337bf1 .ppt
iamayesha2526
 
Query processing and Optimization in Database
Yordanos Zewge
 
Chapter15
gourab87
 
unit 3 DBMS.docx.pdf geometric transformer in query processing
FallenAngel35
 
unit 3 DBMS.docx.pdf geometry in query p
FallenAngel35
 
Issues in Query Processing and Optimization
Editor IJMTER
 
Ad

Recently uploaded (20)

PDF
What companies do with Pharo (ESUG 2025)
ESUG
 
PPTX
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PDF
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
PDF
AI Image Enhancer: Revolutionizing Visual Quality”
docmasoom
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PDF
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
What companies do with Pharo (ESUG 2025)
ESUG
 
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
AI Image Enhancer: Revolutionizing Visual Quality”
docmasoom
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
Activate_Methodology_Summary presentatio
annapureddyn
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
Presentation about variables and constant.pptx
kr2589474
 
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
Ad

Query optimization

  • 2. What is Query Optimization? • Query Processing: The process by which the query results are retrieved from a high-level query such as SQL. • Query Optimization: The process of choosing a suitable execution strategy for retrieving results of query from database files for processing a query is known as Query Optimization. • Query optimization is a function of many relational database management systems. The query optimizer attempts to determine the most efficient way to execute a given query by considering the possible query plans.
  • 3. Query Optimization Criteria • Optimization criteria: • Reduce total execution time of the query: • Minimize the sum of the execution times of all individual operations • Reduce the number of disk accesses • Reduce response time of the query: • Maximize parallel operations
  • 4. Query Optimization Issues • Query rewriting: • transformations from one SQL query to another one using semantic properties. • Selecting query execution plan: • done on single query blocks • Cost estimation: • to compare between plans we need to estimate their cost using statistics on the database.
  • 5. Steps in Query Optimization • Query optimization involves three steps: 1. Query Tree Generation: A Query Tree is a tree data structure representing a relational algebra expression. The tables of the query are represented as leaf nodes. The relational algebra operations are represented a internal nodes. The root represents the query as a whole. 2. Query Plan Generation: After the Query Tree is generated, a query plan is made. A query plan is an extended query tree that includes access paths for all operation in the query tree. Access paths specify how the relational operations in the tree should be performed. 3. Query Plan Code Generation: Code Generation is the final step in the Query Optimization. It is the executable form of the query. Once the query code is generated, the execution manager runs it and produces the results.
  • 6. Two main Techniques for Query Optimization  Heuristic Rules: • Rules for ordering the operations in query optimization.  Systematical estimation: It estimates cost of different execution strategies and chooses the execution plan with lowest execution cost.
  • 7. Heuristic Approach • Heuristic - problem-solving by experimental methods • Applying general rules to choose the most appropriate internal query representation • Based on transformation rules for relational algebra operations
  • 8. Transformation Rules • Cascade of selection operations: • Commutativity of selection operations • Sequence of projection operations where )))((()( RR rqprqp   ))(())(( RR pqqp   )...( )(... NML R LNML  
  • 9. Heuristic Rules • Perform selection as early as possible • Combine Cross product with a subsequent selection • Rearrange base relations so that the most restrictive selection is executed first. • Perform projection as early as possible • Compute common expressions once.
  • 10. Systematical Estimation • Cost Estimation Components: • Cost of access to secondary storage • Storage cost – cost of storing intermediate results • Computation cost • Memory usage cost – usage of RAM buffers
  • 11. Systematical Estimation (Conti.) • Cost Estimation for Relational Algebra Expressions: • Formulae for cost estimation of each operation • Estimation of relational algebra expression • Choosing the expression with the lowest cost
  • 12. Systematical Estimation (Conti.) • Cost Estimation in Query Optimization: • Based on relational algebra tree • For each node in the tree the estimation is to be done for: • the cost of performing the operation; • the size of the result of the operation; • whether the result is sorted.
  • 13. Advantages of Query Optimization 1. Faster processing of Query. 2. Lesser cost per Query. 3. High performance of the system. 4. Lesser stress on the database. 5. Efficient usage of database engine. 6. Lesser memory is consumed.