SlideShare a Scribd company logo
Query processing and optimisation
Query processing: The steps
Translating SQL queries into RA
Query execution
Query optimisation
Examples
Translation rules
Cost estimations
Semantic optimisation
Query in a high-level language
Scanning
Parsing
Validating
Intermediate form of query
Execution plan
Code to execute the query
Runtime database processor
Result of query
Query code generator
Query optimiser
Query Processing: activities involved
in retrieving from the database
typical steps when processing
a high-level query (e.g SQL
query)
Query tree: internal representation
of the query
Execution strategy: how to retrieve
results of query
project( member.name )
select( book.title = "Dracula" and .... )
product BOOK with LOANBOOK
BOOK
product LOAN with BOOK
LOAN
MEMBER
book (access#, title)
member (ticket#, name)
loan(loanedBook,loanedTo)
select member.name
from book, loan, member
where book.title = "Dracula"
and member.ticket# = loan.loanedTo
and loan.loanedBook = book.access#
Translating SQL queries into RA
Initial canonical query tree
Translating SQL queries into RA
Query blocks
Select Lname, Fname
from Employee
where Salary > (select Max (Salary)
from Employee
where Dno = 5)
 Query optimisation
 Execution plan for each block
 Uncorrelated vs. correlated nested queries (later harder to optimise)
 Query execution
 For each operation (join, select, project, aggregation, …)
 Typical algorithms (e.g. binary search for simple selection)
 Specific or not to storage structure and access paths
project( member.name )
select( book.title = "Dracula" and .... )
product BOOK with LOANBOOK
BOOK
product LOAN with BOOK
LOAN
MEMBER
(1 record)
(30,000,000 records)
(300,000 records)
(1,000 records)
(300 records)
(100 records)
project( member.name )
product MEMBER with LOANDRACULA
product LOAN with DRACULA
LOAN
(300 records)
(300 records)
BOOK (1,000 records)
MEMBER
(100 records)
select( book.title = "Dracula" )
(1 record)
(1 record)
select( member.ticket# = loan.loanedTo)
(100 records)
select( book.access# = loan.loanedBook)
(1 record)
book (access#, title)
member (ticket#, name)
select member.name loan(loanedBook,loanedTo)
from book, loan, member
where book.title = "Dracula"
and member.ticket# = loan.loanedTo
and loan.loanedBook = book.access#
Query optimisation
 Enumerating alternative execution plans based on heuristic rules for
evaluating the query; typically, only a subset is considered because
number of alternative may be very large
 Order operations using translation rules
 Work well in most cases but are not guaranteed to work well in all cases
 Estimate cost of each enumerated execution plan:
 Cost of different strategies
 Chose execution plan with lower cost
Heuristic rules
initial query tree final query tree
rules of equivalence among
RA expressions
optimise into equivalent best query
query tree (reasonably efficient strategy)
Example
Select Lname
from Employee, Works_on, Project
where Pname = ‘Aquarius’ and
Pnumber = Pno and
ESSN=SSN and
Bdate > ‘31-12-1957’;
Initial (canonical) query tree
Employee Works_on
Project


select(Pname=‘Aquarius’ and Pnumber=Pno and ESSN=SSN and Bdate > ‘31-12-1957’)
project(Lname)
Moving select operations down the tree
Employee
Works_on
Project
select(Bdate>’31-12-1957’)

select (ESSN=SSN) select(Pname = ‘Aquarius’)
select(Pnumber=Pno)
project(Lname)

Applying the more restrictive select operation first
Project
Works_on
Employee
select(Bdate>’31-12-1957’)

select (ESSN=SSN)
select(Pname = ‘Aquarius’)
select(Pnumber=Pno)
project(Lname)

Replacing Cartesian product by join
Project
Works_on Employee
select(Bdate>’31-12-1957’)
join (ESSN=SSN)
select(Pname = ‘Aquarius’)
join(Pnumber=Pno)
project(Lname)
Moving project down the tree
Project
Works_on
Employee
select(Bdate>’31-12-1957’)
project(ESSN,Pno)
select(Pname = ‘Aquarius’)
join(Pnumber=Pno)
project(Pnumber)
project(SSN,Lname)
project(ESSN)
join(ESSN=SSN)
project(Lname)
Translation rules (Examples)
 Cascade of select
select (R, c1 and c2 and c3)  select (select (select (R,c1), c2), c3)
 Commutativity of select
select (select (R, c1), c2)  select (select (R, c2), c1)
 Cascade of project
project (project (project (R, A3), A2), A1)  project (R, A1)
where A3  A2  A1
Translation rules (Examples)
 Commuting select with join
 select (join (R,S), c)  join (select (R,c), S)
when c applies to R only
 select (join (R,S), c1 and c2)  join (select (R,c1), select (S,c2))
when c1 applies to R
when c2 applies to S
 Commuting select with , , and -
select (R  S, c)  select (R,c)  select (S,c)
Rules
Apply first operations that reduce size of intermediary results
1. perform as early as possible select and project
(move down the tree the select and project)
2. execute first most restrictive join and select
reorder leaf nodes
avoid Cartesian product
adjust rest of tree accordingly
Cost estimations
 Estimate and compare costs of executing query using different execution
strategies
 Choose strategy with lower cost
 Cost estimates
 Limit number of strategies
 Compiled vs interpreted queries (eventually no full scale optimisation for
the latter)
 Traditional optimisation techniques
 Search solution space to a problem for a solution
 Minimise cost function
 Selection of a strategy (not always optimal)
Cost components for query execution
 Access to secondary storage (searching, reading, writing blocks)
 Storage cost (intermediate files)
 Computational cost (searching, sorting, merging in main memory)
 Memory usage cost (memory buffers)
 Communication cost (distributed DBs)
Components are not the same for all cases:
 Large DB
 Minimise access cost to secondary storage
(number of blocks transferred between disks and main memory)
 Small DB
 Data file in main memory
 Minimise computation cost
 Distributed DB
 Minimise the communication cost between sites
Semantic Query Optimisation
 Use constraints to guide the query processing:
 e.g. given the constraint “No employee earns more than their supervisor”
select E.name
from employee E M
where E.salary > M.salary
and M.NI# = E.supervisor
The above query is obviously empty.
Ad

More Related Content

Similar to 9-Query Processing-05-06-2023.PPT (20)

Chapter15
Chapter15Chapter15
Chapter15
gourab87
 
Query-porcessing-& Query optimization
Query-porcessing-& Query optimizationQuery-porcessing-& Query optimization
Query-porcessing-& Query optimization
Saranya Natarajan
 
Data Mining Presentation on Science Day 2023
Data Mining Presentation on Science Day 2023Data Mining Presentation on Science Day 2023
Data Mining Presentation on Science Day 2023
SakshiTiwari490123
 
Sedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing RewriterSedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing Rewriter
Ivan Shcheklein
 
Heuristic approch monika sanghani
Heuristic approch  monika sanghaniHeuristic approch  monika sanghani
Heuristic approch monika sanghani
Monika Sanghani
 
unit 3 DBMS.docx.pdf geometric transformer in query processing
unit 3 DBMS.docx.pdf geometric transformer in query processingunit 3 DBMS.docx.pdf geometric transformer in query processing
unit 3 DBMS.docx.pdf geometric transformer in query processing
FallenAngel35
 
unit 3 DBMS.docx.pdf geometry in query p
unit 3 DBMS.docx.pdf geometry in query punit 3 DBMS.docx.pdf geometry in query p
unit 3 DBMS.docx.pdf geometry in query p
FallenAngel35
 
dd presentation.pdf
dd presentation.pdfdd presentation.pdf
dd presentation.pdf
AnSHiKa187943
 
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Databricks
 
Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2 Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2
Databricks
 
Ch-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced databaseCh-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced database
tasheebedane
 
700442110-advanced database Ch-2-Query-Process.pptx
700442110-advanced database Ch-2-Query-Process.pptx700442110-advanced database Ch-2-Query-Process.pptx
700442110-advanced database Ch-2-Query-Process.pptx
tasheebedane
 
IRJET- Review of Existing Methods in K-Means Clustering Algorithm
IRJET- Review of Existing Methods in K-Means Clustering AlgorithmIRJET- Review of Existing Methods in K-Means Clustering Algorithm
IRJET- Review of Existing Methods in K-Means Clustering Algorithm
IRJET Journal
 
Query processing and Optimization in Database
Query processing and Optimization in DatabaseQuery processing and Optimization in Database
Query processing and Optimization in Database
Yordanos Zewge
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
B2 2006 sizing_benchmarking
B2 2006 sizing_benchmarkingB2 2006 sizing_benchmarking
B2 2006 sizing_benchmarking
Steve Feldman
 
B2 2006 sizing_benchmarking (1)
B2 2006 sizing_benchmarking (1)B2 2006 sizing_benchmarking (1)
B2 2006 sizing_benchmarking (1)
Steve Feldman
 
Hands on Mahout!
Hands on Mahout!Hands on Mahout!
Hands on Mahout!
OSCON Byrum
 
Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...
Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...
Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...
Gruter
 
Query optimization to improve performance of the code execution
Query optimization to improve performance of the code executionQuery optimization to improve performance of the code execution
Query optimization to improve performance of the code execution
Alexander Decker
 
Query-porcessing-& Query optimization
Query-porcessing-& Query optimizationQuery-porcessing-& Query optimization
Query-porcessing-& Query optimization
Saranya Natarajan
 
Data Mining Presentation on Science Day 2023
Data Mining Presentation on Science Day 2023Data Mining Presentation on Science Day 2023
Data Mining Presentation on Science Day 2023
SakshiTiwari490123
 
Sedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing RewriterSedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing Rewriter
Ivan Shcheklein
 
Heuristic approch monika sanghani
Heuristic approch  monika sanghaniHeuristic approch  monika sanghani
Heuristic approch monika sanghani
Monika Sanghani
 
unit 3 DBMS.docx.pdf geometric transformer in query processing
unit 3 DBMS.docx.pdf geometric transformer in query processingunit 3 DBMS.docx.pdf geometric transformer in query processing
unit 3 DBMS.docx.pdf geometric transformer in query processing
FallenAngel35
 
unit 3 DBMS.docx.pdf geometry in query p
unit 3 DBMS.docx.pdf geometry in query punit 3 DBMS.docx.pdf geometry in query p
unit 3 DBMS.docx.pdf geometry in query p
FallenAngel35
 
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Databricks
 
Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2 Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2
Databricks
 
Ch-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced databaseCh-2-Query-Process.pptx advanced database
Ch-2-Query-Process.pptx advanced database
tasheebedane
 
700442110-advanced database Ch-2-Query-Process.pptx
700442110-advanced database Ch-2-Query-Process.pptx700442110-advanced database Ch-2-Query-Process.pptx
700442110-advanced database Ch-2-Query-Process.pptx
tasheebedane
 
IRJET- Review of Existing Methods in K-Means Clustering Algorithm
IRJET- Review of Existing Methods in K-Means Clustering AlgorithmIRJET- Review of Existing Methods in K-Means Clustering Algorithm
IRJET- Review of Existing Methods in K-Means Clustering Algorithm
IRJET Journal
 
Query processing and Optimization in Database
Query processing and Optimization in DatabaseQuery processing and Optimization in Database
Query processing and Optimization in Database
Yordanos Zewge
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
B2 2006 sizing_benchmarking
B2 2006 sizing_benchmarkingB2 2006 sizing_benchmarking
B2 2006 sizing_benchmarking
Steve Feldman
 
B2 2006 sizing_benchmarking (1)
B2 2006 sizing_benchmarking (1)B2 2006 sizing_benchmarking (1)
B2 2006 sizing_benchmarking (1)
Steve Feldman
 
Hands on Mahout!
Hands on Mahout!Hands on Mahout!
Hands on Mahout!
OSCON Byrum
 
Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...
Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...
Hadoop Summit 2014: Query Optimization and JIT-based Vectorized Execution in ...
Gruter
 
Query optimization to improve performance of the code execution
Query optimization to improve performance of the code executionQuery optimization to improve performance of the code execution
Query optimization to improve performance of the code execution
Alexander Decker
 

More from venkatapranaykumarGa (14)

5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
venkatapranaykumarGa
 
10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx
venkatapranaykumarGa
 
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
venkatapranaykumarGa
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
venkatapranaykumarGa
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
venkatapranaykumarGa
 
11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx
venkatapranaykumarGa
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
venkatapranaykumarGa
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
venkatapranaykumarGa
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
venkatapranaykumarGa
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
venkatapranaykumarGa
 
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
venkatapranaykumarGa
 
7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx
venkatapranaykumarGa
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
venkatapranaykumarGa
 
10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx
venkatapranaykumarGa
 
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
venkatapranaykumarGa
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
venkatapranaykumarGa
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
venkatapranaykumarGa
 
11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx
venkatapranaykumarGa
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
venkatapranaykumarGa
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
venkatapranaykumarGa
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
venkatapranaykumarGa
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
venkatapranaykumarGa
 
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
venkatapranaykumarGa
 
7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx
venkatapranaykumarGa
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 
Ad

Recently uploaded (20)

Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Ad

9-Query Processing-05-06-2023.PPT

  • 1. Query processing and optimisation Query processing: The steps Translating SQL queries into RA Query execution Query optimisation Examples Translation rules Cost estimations Semantic optimisation
  • 2. Query in a high-level language Scanning Parsing Validating Intermediate form of query Execution plan Code to execute the query Runtime database processor Result of query Query code generator Query optimiser Query Processing: activities involved in retrieving from the database typical steps when processing a high-level query (e.g SQL query) Query tree: internal representation of the query Execution strategy: how to retrieve results of query
  • 3. project( member.name ) select( book.title = "Dracula" and .... ) product BOOK with LOANBOOK BOOK product LOAN with BOOK LOAN MEMBER book (access#, title) member (ticket#, name) loan(loanedBook,loanedTo) select member.name from book, loan, member where book.title = "Dracula" and member.ticket# = loan.loanedTo and loan.loanedBook = book.access# Translating SQL queries into RA Initial canonical query tree
  • 4. Translating SQL queries into RA Query blocks Select Lname, Fname from Employee where Salary > (select Max (Salary) from Employee where Dno = 5)  Query optimisation  Execution plan for each block  Uncorrelated vs. correlated nested queries (later harder to optimise)  Query execution  For each operation (join, select, project, aggregation, …)  Typical algorithms (e.g. binary search for simple selection)  Specific or not to storage structure and access paths
  • 5. project( member.name ) select( book.title = "Dracula" and .... ) product BOOK with LOANBOOK BOOK product LOAN with BOOK LOAN MEMBER (1 record) (30,000,000 records) (300,000 records) (1,000 records) (300 records) (100 records) project( member.name ) product MEMBER with LOANDRACULA product LOAN with DRACULA LOAN (300 records) (300 records) BOOK (1,000 records) MEMBER (100 records) select( book.title = "Dracula" ) (1 record) (1 record) select( member.ticket# = loan.loanedTo) (100 records) select( book.access# = loan.loanedBook) (1 record) book (access#, title) member (ticket#, name) select member.name loan(loanedBook,loanedTo) from book, loan, member where book.title = "Dracula" and member.ticket# = loan.loanedTo and loan.loanedBook = book.access#
  • 6. Query optimisation  Enumerating alternative execution plans based on heuristic rules for evaluating the query; typically, only a subset is considered because number of alternative may be very large  Order operations using translation rules  Work well in most cases but are not guaranteed to work well in all cases  Estimate cost of each enumerated execution plan:  Cost of different strategies  Chose execution plan with lower cost
  • 7. Heuristic rules initial query tree final query tree rules of equivalence among RA expressions optimise into equivalent best query query tree (reasonably efficient strategy)
  • 8. Example Select Lname from Employee, Works_on, Project where Pname = ‘Aquarius’ and Pnumber = Pno and ESSN=SSN and Bdate > ‘31-12-1957’;
  • 9. Initial (canonical) query tree Employee Works_on Project   select(Pname=‘Aquarius’ and Pnumber=Pno and ESSN=SSN and Bdate > ‘31-12-1957’) project(Lname)
  • 10. Moving select operations down the tree Employee Works_on Project select(Bdate>’31-12-1957’)  select (ESSN=SSN) select(Pname = ‘Aquarius’) select(Pnumber=Pno) project(Lname) 
  • 11. Applying the more restrictive select operation first Project Works_on Employee select(Bdate>’31-12-1957’)  select (ESSN=SSN) select(Pname = ‘Aquarius’) select(Pnumber=Pno) project(Lname) 
  • 12. Replacing Cartesian product by join Project Works_on Employee select(Bdate>’31-12-1957’) join (ESSN=SSN) select(Pname = ‘Aquarius’) join(Pnumber=Pno) project(Lname)
  • 13. Moving project down the tree Project Works_on Employee select(Bdate>’31-12-1957’) project(ESSN,Pno) select(Pname = ‘Aquarius’) join(Pnumber=Pno) project(Pnumber) project(SSN,Lname) project(ESSN) join(ESSN=SSN) project(Lname)
  • 14. Translation rules (Examples)  Cascade of select select (R, c1 and c2 and c3)  select (select (select (R,c1), c2), c3)  Commutativity of select select (select (R, c1), c2)  select (select (R, c2), c1)  Cascade of project project (project (project (R, A3), A2), A1)  project (R, A1) where A3  A2  A1
  • 15. Translation rules (Examples)  Commuting select with join  select (join (R,S), c)  join (select (R,c), S) when c applies to R only  select (join (R,S), c1 and c2)  join (select (R,c1), select (S,c2)) when c1 applies to R when c2 applies to S  Commuting select with , , and - select (R  S, c)  select (R,c)  select (S,c)
  • 16. Rules Apply first operations that reduce size of intermediary results 1. perform as early as possible select and project (move down the tree the select and project) 2. execute first most restrictive join and select reorder leaf nodes avoid Cartesian product adjust rest of tree accordingly
  • 17. Cost estimations  Estimate and compare costs of executing query using different execution strategies  Choose strategy with lower cost  Cost estimates  Limit number of strategies  Compiled vs interpreted queries (eventually no full scale optimisation for the latter)  Traditional optimisation techniques  Search solution space to a problem for a solution  Minimise cost function  Selection of a strategy (not always optimal)
  • 18. Cost components for query execution  Access to secondary storage (searching, reading, writing blocks)  Storage cost (intermediate files)  Computational cost (searching, sorting, merging in main memory)  Memory usage cost (memory buffers)  Communication cost (distributed DBs) Components are not the same for all cases:  Large DB  Minimise access cost to secondary storage (number of blocks transferred between disks and main memory)  Small DB  Data file in main memory  Minimise computation cost  Distributed DB  Minimise the communication cost between sites
  • 19. Semantic Query Optimisation  Use constraints to guide the query processing:  e.g. given the constraint “No employee earns more than their supervisor” select E.name from employee E M where E.salary > M.salary and M.NI# = E.supervisor The above query is obviously empty.