SlideShare a Scribd company logo
7
Most read
12
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)

PPT
14. Query Optimization in DBMS
koolkampus
 
PPTX
Lec 7 query processing
Md. Mashiur Rahman
 
PPT
Query optimization
Neha Behl
 
PDF
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
PPTX
Query-porcessing-& Query optimization
Saranya Natarajan
 
PPTX
Query processing and Query Optimization
Niraj Gandha
 
PPTX
Query Optimization
rohitsalunke
 
PPTX
Unification and Lifting
Megha Sharma
 
PPTX
Distributed database
ReachLocal Services India
 
PDF
Query trees
Shefa Idrees
 
PPTX
Lock based protocols
ChethanMp7
 
PPTX
Distributed DBMS - Unit 6 - Query Processing
Gyanmanjari Institute Of Technology
 
PPTX
ADBMS Object and Object Relational Databases
Jayanthi Kannan MK
 
PPTX
anatomy of a jsp page & jsp syntax.pptx
Sameenafathima4
 
PPTX
Structure of dbms
Megha yadav
 
PPTX
Artificial Intelligence Searching Techniques
Dr. C.V. Suresh Babu
 
PPTX
serializability in dbms
Saranya Natarajan
 
PPTX
Query processing in Distributed Database System
Meghaj Mallick
 
PPTX
Knowledge representation in AI
Vishal Singh
 
PPTX
Active database system
Adeolu Olaniyan
 
14. Query Optimization in DBMS
koolkampus
 
Lec 7 query processing
Md. Mashiur Rahman
 
Query optimization
Neha Behl
 
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
Query-porcessing-& Query optimization
Saranya Natarajan
 
Query processing and Query Optimization
Niraj Gandha
 
Query Optimization
rohitsalunke
 
Unification and Lifting
Megha Sharma
 
Distributed database
ReachLocal Services India
 
Query trees
Shefa Idrees
 
Lock based protocols
ChethanMp7
 
Distributed DBMS - Unit 6 - Query Processing
Gyanmanjari Institute Of Technology
 
ADBMS Object and Object Relational Databases
Jayanthi Kannan MK
 
anatomy of a jsp page & jsp syntax.pptx
Sameenafathima4
 
Structure of dbms
Megha yadav
 
Artificial Intelligence Searching Techniques
Dr. C.V. Suresh Babu
 
serializability in dbms
Saranya Natarajan
 
Query processing in Distributed Database System
Meghaj Mallick
 
Knowledge representation in AI
Vishal Singh
 
Active database system
Adeolu Olaniyan
 

Viewers also liked (20)

PPTX
Query processing and optimization (updated)
Ravinder Kamboj
 
PPT
13. Query Processing in DBMS
koolkampus
 
PDF
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Beat Signer
 
PPTX
Optimizing distributed queries
Pokhara University, Nobel College
 
PDF
An Analysis on Query Optimization in Distributed Database
Editor IJMTER
 
PDF
Database Review and Challenges (2016)
Mayuree Srikulwong
 
ODP
BIS05 Introduction to SQL
Prithwis Mukerjee
 
PPTX
Event Driven Automation Meetup May 14/2015
Dmitri Zimine
 
PPTX
2 ddb architecture
Mr Patrick NIYISHAKA
 
PDF
Distributed Database
Mayuree Srikulwong
 
PPTX
Query processing
Deepak Singh
 
PPTX
Distributed Query Processing
Mythili Kannan
 
PDF
8 query processing and optimization
Kumar
 
PDF
Introduction to Data Warehousing
Edureka!
 
PPT
Query processing-and-optimization
WBUTTUTORIALS
 
PPTX
Types of Database Models
Murassa Gillani
 
PDF
Responsive Design Workflow: Mobilism 2012
Stephen Hay
 
PPTX
Top 5 Computer Crime's
Mar Soriano
 
PPT
Data mining & data warehousing
Shubha Brota Raha
 
Query processing and optimization (updated)
Ravinder Kamboj
 
13. Query Processing in DBMS
koolkampus
 
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Beat Signer
 
Optimizing distributed queries
Pokhara University, Nobel College
 
An Analysis on Query Optimization in Distributed Database
Editor IJMTER
 
Database Review and Challenges (2016)
Mayuree Srikulwong
 
BIS05 Introduction to SQL
Prithwis Mukerjee
 
Event Driven Automation Meetup May 14/2015
Dmitri Zimine
 
2 ddb architecture
Mr Patrick NIYISHAKA
 
Distributed Database
Mayuree Srikulwong
 
Query processing
Deepak Singh
 
Distributed Query Processing
Mythili Kannan
 
8 query processing and optimization
Kumar
 
Introduction to Data Warehousing
Edureka!
 
Query processing-and-optimization
WBUTTUTORIALS
 
Types of Database Models
Murassa Gillani
 
Responsive Design Workflow: Mobilism 2012
Stephen Hay
 
Top 5 Computer Crime's
Mar Soriano
 
Data mining & data warehousing
Shubha Brota Raha
 
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
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
 
PDF
CH5_Query Processing and Optimization.pdf
amariyarana
 
PPTX
Query optimization and performance
fika sweety
 
PPTX
Query optimization and performance
fika sweety
 
PPTX
Query optimization
Zunera Bukhari
 
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
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
 
CH5_Query Processing and Optimization.pdf
amariyarana
 
Query optimization and performance
fika sweety
 
Query optimization and performance
fika sweety
 
Query optimization
Zunera Bukhari
 
Ad

Recently uploaded (20)

PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PDF
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 

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