SlideShare a Scribd company logo
4
Most read
6
Most read
17
Most read
QUERY PROCESSING AND
QUERY OPTIMIZATION
By NIRAJ GANDHA
What is Query Processing?
 It is a 3 step process that transforms a high level query
(sql) into an equivalent and more efficient lower-level
query (of relational algebra).
Query
Query
 Query is the statement written by the user in high language
using pl/sql.
Parser & Translator
Query
Parser
&
Translator
 Parser: Checks the syntax and verifies the relation.
 Translator: Translates the query into an equivalent
relational algebra.
Example:
SQL> select name from customer;
RA:=∏name(customer)
Relational Algebra
Query
Parser
&
Translator
Relational
Algebra
 It is the query converted in algebraic form from pl/ sql by
translator.
 Example:
SQL>SELECT ENAME FROM EMP,ASG WHERE
EMP.ENO=ASG.ENO AND DUR>37;
RA:1) ΠENAME(σDUR>37∧EMP.ENO=ASG.ENO(EMP × ASG))
2) ΠENAME(EMP ENO (σDUR>37(ASG)))
Optimizer
Query
Parser
&
Translator
Relational
Algebra
Optimizer
 It will select the query which has low cost.
Example:
1) ΠENAME(σDUR>37∧EMP.ENO=ASG.ENO(EMP × ASG))
2) ΠENAME(EMP ENO (σDUR>37(ASG)))
Optimizer will select Expression2 as it avoids
the expensive and large intermediate
Cartesian product, and therefore typically is
better.
Comparison of two relational queries
 ΠENAME(σDUR>37∧EMP.ENO=ASG.ENO
(EMP × ASG))
 ΠENAME(EMP ENO(σDUR>37(ASG)))
EMP x ASG
Temp as
EMP.ENO=ASG.ENO
ΠENAME
ENO(σDUR>37(ASG)
EMP ENO
ΠENAME
σDUR>37 ∧temp
Query
Parser
&
Translator
Relational
Algebra
Optimizer
Statistical
Data
Statistical Data
 A Statical Data is a
database used for
statistical analysis
purposes.
 It is an OLAP(Online
Analytical Processing),
instead of OLTP(Online
Transaction Processing)
system
Evaluation Plan
Query
Parser
&
Translator
Relational
Algebra
Optimizer
Statistical
Data
Evaluation
Plan
 Relational Algebra
annotated with instructions
on how to evaluate it is
called an evaluation
primitive.
 Sequence of primitive
operations that can be
used to evaluate a query is
a query evaluation plan.
EVALUATION & DATA
 The evaluation
engine takes
the evaluation
plan as
condition and
applies it on
the data.
Query
Parser
&
Translator
Relational
Algebra
Optimizer
Statistical
Data
Evaluation
Plan
Evaluation
 The information on
which the query has
to be performed is
called data.Data
OUTPUT
Query
Parser
&
Translator
Relational
Algebra
Optimizer
Statistical
Data
Evaluation
Plan
EvaluationOutput
Data
 After the evaluation of
plan on data,
processed information
is showed in output.
Diagram of Query Processing
Query
Parser
&
Translator
Relational
Algebra
Optimizer
Statistical
Data
Evaluation
Plan
EvaluationOutput
Data
Measures of Query Cost
 The cost of query evaluation can be measured in
terms of different resources, including
 disk accesses
 CPU time to execute a query in a distributed or
parallel database system
 the cost of communication.
Materialization
 In materialization approach, output of every single operation
is saved in temporary relation for the subsequent use.
 It starts from the lowest-level operations in the expression.
 Ex: Πcustomer(σbalance<2500(account) customer)
Πcustomer
σbalance<2500 customer
account
Pipelining
 In pipelining approach, output of every single operation is not
necessary to save in temporary relation for the subsequent
use.
 In this the operations take place simultaneously or in
background
 It starts from the lowest-level operations in the expression.
 Ex: Πcustomer(σbalance<2500(account) customer)
Πcustomer
σbalance<2500 customer
account
Query Optimization
 It is the process of selecting the most efficient query-
evaluation plan from among the many strategies usually
possible for processing a given query, especially if the query is
complex.
Example of Optimization
 ∏customer(σbranch_city=”Brooklyn”(branch
(account depositor)))
∏customer
σbranch_city=”Brooklyn”
branch
account depositor
 ∏customer((σbranch_city=”Brooklyn”(branc
h)) (account depositor))
∏customer
σbranch_city=”Brooklyn”
branch account depositor
The end

More Related Content

What's hot (20)

PPTX
Query optimization
Zunera Bukhari
 
PPTX
Query processing
Ravinder Kamboj
 
PPT
13. Query Processing in DBMS
koolkampus
 
PPT
Query optimization
dixitdavey
 
PPTX
Query Optimization
rohitsalunke
 
PPTX
Query-porcessing-& Query optimization
Saranya Natarajan
 
PPTX
joins in database
Sultan Arshad
 
PPTX
Storage Structure in OS
UniSoftCorner Pvt Ltd India.
 
PPTX
Concurrency Control in Database Management System
Janki Shah
 
PPTX
Functional dependency
Sakshi Jaiswal
 
PPTX
SQL Joins.pptx
Ankit Rai
 
PPTX
Normal forms
Samuel Igbanogu
 
PPTX
View of data DBMS
Rahul Narang
 
PPTX
Normalization in DBMS
Prateek Parimal
 
PPTX
DATABASE CONSTRAINTS
sunanditaAnand
 
PPTX
set operators.pptx
Anusha sivakumar
 
PDF
Dbms 14: Relational Calculus
Amiya9439793168
 
PDF
Query optimization in SQL
Abdul Rehman
 
PDF
Database design & Normalization (1NF, 2NF, 3NF)
Jargalsaikhan Alyeksandr
 
Query optimization
Zunera Bukhari
 
Query processing
Ravinder Kamboj
 
13. Query Processing in DBMS
koolkampus
 
Query optimization
dixitdavey
 
Query Optimization
rohitsalunke
 
Query-porcessing-& Query optimization
Saranya Natarajan
 
joins in database
Sultan Arshad
 
Storage Structure in OS
UniSoftCorner Pvt Ltd India.
 
Concurrency Control in Database Management System
Janki Shah
 
Functional dependency
Sakshi Jaiswal
 
SQL Joins.pptx
Ankit Rai
 
Normal forms
Samuel Igbanogu
 
View of data DBMS
Rahul Narang
 
Normalization in DBMS
Prateek Parimal
 
DATABASE CONSTRAINTS
sunanditaAnand
 
set operators.pptx
Anusha sivakumar
 
Dbms 14: Relational Calculus
Amiya9439793168
 
Query optimization in SQL
Abdul Rehman
 
Database design & Normalization (1NF, 2NF, 3NF)
Jargalsaikhan Alyeksandr
 

Viewers also liked (13)

PPT
Manual polybrene
Jhysheng Chang
 
PPTX
Региональные и муниципальные информационные системы
Раиса Шпакова
 
PPT
Artnet presentation2013
artnet1010
 
PPTX
Начальная(максимальная) цена контракта. Методы расчета и обоснования
Раиса Шпакова
 
PPTX
реестр договоров
Раиса Шпакова
 
PPTX
Benefits of biotin
Albert Green
 
PPTX
Msm for joints
Albert Green
 
PPTX
20151107 workshop HPA, HLA, HEA genotype
Jhysheng Chang
 
PPT
evaluation of thrombocytopenia
Jhysheng Chang
 
PPTX
Mp only 馬偕
Jhysheng Chang
 
PPT
All about platelet immunology
Jhysheng Chang
 
PPT
Hpa antibody
Jhysheng Chang
 
PPTX
20140430l北捐auto anibody
Jhysheng Chang
 
Manual polybrene
Jhysheng Chang
 
Региональные и муниципальные информационные системы
Раиса Шпакова
 
Artnet presentation2013
artnet1010
 
Начальная(максимальная) цена контракта. Методы расчета и обоснования
Раиса Шпакова
 
реестр договоров
Раиса Шпакова
 
Benefits of biotin
Albert Green
 
Msm for joints
Albert Green
 
20151107 workshop HPA, HLA, HEA genotype
Jhysheng Chang
 
evaluation of thrombocytopenia
Jhysheng Chang
 
Mp only 馬偕
Jhysheng Chang
 
All about platelet immunology
Jhysheng Chang
 
Hpa antibody
Jhysheng Chang
 
20140430l北捐auto anibody
Jhysheng Chang
 
Ad

Similar to Query processing and Query Optimization (20)

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
Query processing and optimization (updated)
Ravinder Kamboj
 
PPTX
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
AthosBeatus
 
PPT
Query optimization and processing for advanced database systems
meharikiros2
 
PPTX
Query processing and optimization on dbms
ar1289589
 
PPT
QPOfutyfurfugfuyttruft7rfu65rfuyt PPT - Copy.ppt
ahmed518927
 
PPT
ch02-240507064009-ac337bf1 .ppt
iamayesha2526
 
PPTX
1 query processing
Mr Patrick NIYISHAKA
 
PPTX
1 query processing
Mr Patrick NIYISHAKA
 
PDF
Chapter 2.pdf WND FWKJFW KSD;KFLWHFB ASNK
alemunuruhak9
 
PPTX
Mc seminar
Ankit Anand
 
PPTX
Advanced Database System Chapter Two Query processing and Optimization.pptx
mentesnotsibatuuu
 
PDF
dd presentation.pdf
AnSHiKa187943
 
PDF
Measures of query cost
Hitesh Mohapatra
 
PPTX
Distributed DBMS - Unit 6 - Query Processing
Gyanmanjari Institute Of Technology
 
PDF
CH5_Query Processing and Optimization.pdf
amariyarana
 
PPTX
Query optimization and performance
fika sweety
 
PPTX
Query optimization and performance
fika sweety
 
DB LECTURE 5 QUERY PROCESSING.pptx
grahamoyigo19
 
Ch-2-Query-Process.pptx advanced database
tasheebedane
 
700442110-advanced database Ch-2-Query-Process.pptx
tasheebedane
 
Query processing and optimization (updated)
Ravinder Kamboj
 
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
AthosBeatus
 
Query optimization and processing for advanced database systems
meharikiros2
 
Query processing and optimization on dbms
ar1289589
 
QPOfutyfurfugfuyttruft7rfu65rfuyt PPT - Copy.ppt
ahmed518927
 
ch02-240507064009-ac337bf1 .ppt
iamayesha2526
 
1 query processing
Mr Patrick NIYISHAKA
 
1 query processing
Mr Patrick NIYISHAKA
 
Chapter 2.pdf WND FWKJFW KSD;KFLWHFB ASNK
alemunuruhak9
 
Mc seminar
Ankit Anand
 
Advanced Database System Chapter Two Query processing and Optimization.pptx
mentesnotsibatuuu
 
dd presentation.pdf
AnSHiKa187943
 
Measures of query cost
Hitesh Mohapatra
 
Distributed DBMS - Unit 6 - Query Processing
Gyanmanjari Institute Of Technology
 
CH5_Query Processing and Optimization.pdf
amariyarana
 
Query optimization and performance
fika sweety
 
Query optimization and performance
fika sweety
 
Ad

Recently uploaded (20)

PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Difference between write and update in odoo 18
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
epi editorial commitee meeting presentation
MIPLM
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
infertility, types,causes, impact, and management
Ritu480198
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Council of Chalcedon Re-Examined
Smiling Lungs
 

Query processing and Query Optimization

  • 1. QUERY PROCESSING AND QUERY OPTIMIZATION By NIRAJ GANDHA
  • 2. What is Query Processing?  It is a 3 step process that transforms a high level query (sql) into an equivalent and more efficient lower-level query (of relational algebra).
  • 3. Query Query  Query is the statement written by the user in high language using pl/sql.
  • 4. Parser & Translator Query Parser & Translator  Parser: Checks the syntax and verifies the relation.  Translator: Translates the query into an equivalent relational algebra. Example: SQL> select name from customer; RA:=∏name(customer)
  • 5. Relational Algebra Query Parser & Translator Relational Algebra  It is the query converted in algebraic form from pl/ sql by translator.  Example: SQL>SELECT ENAME FROM EMP,ASG WHERE EMP.ENO=ASG.ENO AND DUR>37; RA:1) ΠENAME(σDUR>37∧EMP.ENO=ASG.ENO(EMP × ASG)) 2) ΠENAME(EMP ENO (σDUR>37(ASG)))
  • 6. Optimizer Query Parser & Translator Relational Algebra Optimizer  It will select the query which has low cost. Example: 1) ΠENAME(σDUR>37∧EMP.ENO=ASG.ENO(EMP × ASG)) 2) ΠENAME(EMP ENO (σDUR>37(ASG))) Optimizer will select Expression2 as it avoids the expensive and large intermediate Cartesian product, and therefore typically is better.
  • 7. Comparison of two relational queries  ΠENAME(σDUR>37∧EMP.ENO=ASG.ENO (EMP × ASG))  ΠENAME(EMP ENO(σDUR>37(ASG))) EMP x ASG Temp as EMP.ENO=ASG.ENO ΠENAME ENO(σDUR>37(ASG) EMP ENO ΠENAME σDUR>37 ∧temp
  • 8. Query Parser & Translator Relational Algebra Optimizer Statistical Data Statistical Data  A Statical Data is a database used for statistical analysis purposes.  It is an OLAP(Online Analytical Processing), instead of OLTP(Online Transaction Processing) system
  • 9. Evaluation Plan Query Parser & Translator Relational Algebra Optimizer Statistical Data Evaluation Plan  Relational Algebra annotated with instructions on how to evaluate it is called an evaluation primitive.  Sequence of primitive operations that can be used to evaluate a query is a query evaluation plan.
  • 10. EVALUATION & DATA  The evaluation engine takes the evaluation plan as condition and applies it on the data. Query Parser & Translator Relational Algebra Optimizer Statistical Data Evaluation Plan Evaluation  The information on which the query has to be performed is called data.Data
  • 12. Diagram of Query Processing Query Parser & Translator Relational Algebra Optimizer Statistical Data Evaluation Plan EvaluationOutput Data
  • 13. Measures of Query Cost  The cost of query evaluation can be measured in terms of different resources, including  disk accesses  CPU time to execute a query in a distributed or parallel database system  the cost of communication.
  • 14. Materialization  In materialization approach, output of every single operation is saved in temporary relation for the subsequent use.  It starts from the lowest-level operations in the expression.  Ex: Πcustomer(σbalance<2500(account) customer) Πcustomer σbalance<2500 customer account
  • 15. Pipelining  In pipelining approach, output of every single operation is not necessary to save in temporary relation for the subsequent use.  In this the operations take place simultaneously or in background  It starts from the lowest-level operations in the expression.  Ex: Πcustomer(σbalance<2500(account) customer) Πcustomer σbalance<2500 customer account
  • 16. Query Optimization  It is the process of selecting the most efficient query- evaluation plan from among the many strategies usually possible for processing a given query, especially if the query is complex.
  • 17. Example of Optimization  ∏customer(σbranch_city=”Brooklyn”(branch (account depositor))) ∏customer σbranch_city=”Brooklyn” branch account depositor  ∏customer((σbranch_city=”Brooklyn”(branc h)) (account depositor)) ∏customer σbranch_city=”Brooklyn” branch account depositor