SlideShare a Scribd company logo
1 of 10
5. Query Optimization
5. Query Optimization
▪ The cost is estimated using statistical information from the database
catalog (number of tuples in each relation,size of tuples, etc.)
▪ Enumerating alternative execution plans based on heuristic rules.
- 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.
5. Query Optimization
▪ Example
Heuristic rules
Select lname
from employee, works_on, project
where pname = ‘aquarius’ and
pnumber = pno and
essn=ssn and
bdate > ‘31-12-1957’;
5. Query Optimization
▪ Example
Initial (canonical) query tree

Moving select operations down the tree
5. Query Optimization
▪ Example
Applying the more restrictive select operation first

Replacing Cartesian product by join
5. Query Optimization
▪ Example
Moving project down the tree
5. Query Optimization
♦ 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.
6. Translation Rules
▪ Rules
Apply first operations that reduce size of intermediary results,
Then
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

Then
reorder leaf nodes
avoid Cartesian product
adjust rest of tree accordingly
6. Translation Rules
▪ Examples:
Cascade of select
Select (r, c1 and c2 and c3) select (select (select (r,c1), c2), c3)
Commutatively 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
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)

a2

a1
7. Cost Estimations
How to Estimation
▪ 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
▪ Traditional optimisation techniques,
- Search solution space to a problem for a solution
- Minimise cost function
▪ Selection of a strategy (not always optimal)
7. Cost Estimations
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)

More Related Content

Similar to 2 optimization

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
 
Adbms 40 heuristics in query optimization
Adbms 40 heuristics in query optimizationAdbms 40 heuristics in query optimization
Adbms 40 heuristics in query optimizationVaibhav Khanna
 
Silicon valleycodecamp2013
Silicon valleycodecamp2013Silicon valleycodecamp2013
Silicon valleycodecamp2013Sanjeev Mishra
 
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process Capability
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process CapabilityJavier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process Capability
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process CapabilityJ. García - Verdugo
 
RDataMining slides-regression-classification
RDataMining slides-regression-classificationRDataMining slides-regression-classification
RDataMining slides-regression-classificationYanchang Zhao
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?Brent Ozar
 
م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...
م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...
م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...Egyptian Engineers Association
 
Benchmarking Apache Druid
Benchmarking Apache Druid Benchmarking Apache Druid
Benchmarking Apache Druid Matt Sarrel
 
Benchmarking Apache Druid
Benchmarking Apache DruidBenchmarking Apache Druid
Benchmarking Apache DruidImply
 
Applying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPKApplying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPKJeremy Chen
 
층류 익형의 설계 최적화
층류 익형의 설계 최적화층류 익형의 설계 최적화
층류 익형의 설계 최적화HyunJoon Kim
 
Towards Evaluating Size Reduction Techniques for Software Model Checking
Towards Evaluating Size Reduction Techniques for Software Model CheckingTowards Evaluating Size Reduction Techniques for Software Model Checking
Towards Evaluating Size Reduction Techniques for Software Model CheckingAkos Hajdu
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineeringJulian Hyde
 
Database Agnostic Workload Management (CIDR 2019)
Database Agnostic Workload Management (CIDR 2019)Database Agnostic Workload Management (CIDR 2019)
Database Agnostic Workload Management (CIDR 2019)University of Washington
 

Similar to 2 optimization (20)

9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT
 
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 ...
 
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
 
autoTVM
autoTVMautoTVM
autoTVM
 
Adbms 40 heuristics in query optimization
Adbms 40 heuristics in query optimizationAdbms 40 heuristics in query optimization
Adbms 40 heuristics in query optimization
 
Silicon valleycodecamp2013
Silicon valleycodecamp2013Silicon valleycodecamp2013
Silicon valleycodecamp2013
 
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process Capability
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process CapabilityJavier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process Capability
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W1 Process Capability
 
RDataMining slides-regression-classification
RDataMining slides-regression-classificationRDataMining slides-regression-classification
RDataMining slides-regression-classification
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?
 
Vldb14
Vldb14Vldb14
Vldb14
 
م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...
م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...
م.80-مبادرة #تواصل_تطويرم.أحمد سعيد رفاعهى-دورة حياة تقدير التكلفة بمشروعات ا...
 
Benchmarking Apache Druid
Benchmarking Apache Druid Benchmarking Apache Druid
Benchmarking Apache Druid
 
Benchmarking Apache Druid
Benchmarking Apache DruidBenchmarking Apache Druid
Benchmarking Apache Druid
 
Applying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPKApplying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPK
 
층류 익형의 설계 최적화
층류 익형의 설계 최적화층류 익형의 설계 최적화
층류 익형의 설계 최적화
 
Six sigma
Six sigma Six sigma
Six sigma
 
Six sigma pedagogy
Six sigma pedagogySix sigma pedagogy
Six sigma pedagogy
 
Towards Evaluating Size Reduction Techniques for Software Model Checking
Towards Evaluating Size Reduction Techniques for Software Model CheckingTowards Evaluating Size Reduction Techniques for Software Model Checking
Towards Evaluating Size Reduction Techniques for Software Model Checking
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
Database Agnostic Workload Management (CIDR 2019)
Database Agnostic Workload Management (CIDR 2019)Database Agnostic Workload Management (CIDR 2019)
Database Agnostic Workload Management (CIDR 2019)
 

More from Mr Patrick NIYISHAKA (20)

Summary
SummarySummary
Summary
 
3 summary
3 summary3 summary
3 summary
 
2 ddb architecture
2 ddb architecture2 ddb architecture
2 ddb architecture
 
1 ddb
1 ddb1 ddb
1 ddb
 
2 countermeasures
2 countermeasures2 countermeasures
2 countermeasures
 
2 countermeasures
2 countermeasures2 countermeasures
2 countermeasures
 
3 summary
3 summary3 summary
3 summary
 
1 db security
1 db security1 db security
1 db security
 
4 summary
4 summary4 summary
4 summary
 
3 summary
3 summary3 summary
3 summary
 
2 con control
2 con control2 con control
2 con control
 
1 con exe
1 con exe1 con exe
1 con exe
 
1 basic concepts
1 basic concepts1 basic concepts
1 basic concepts
 
2 recovery
2 recovery2 recovery
2 recovery
 
3 transaction
3 transaction3 transaction
3 transaction
 
3 summary
3 summary3 summary
3 summary
 
1 query processing
1 query processing1 query processing
1 query processing
 
1 query processing
1 query processing1 query processing
1 query processing
 
2 collision
2 collision2 collision
2 collision
 
4 summary
4 summary4 summary
4 summary
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

2 optimization

  • 1. 5. Query Optimization 5. Query Optimization ▪ The cost is estimated using statistical information from the database catalog (number of tuples in each relation,size of tuples, etc.) ▪ Enumerating alternative execution plans based on heuristic rules. - 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.
  • 2. 5. Query Optimization ▪ Example Heuristic rules Select lname from employee, works_on, project where pname = ‘aquarius’ and pnumber = pno and essn=ssn and bdate > ‘31-12-1957’;
  • 3. 5. Query Optimization ▪ Example Initial (canonical) query tree Moving select operations down the tree
  • 4. 5. Query Optimization ▪ Example Applying the more restrictive select operation first Replacing Cartesian product by join
  • 5. 5. Query Optimization ▪ Example Moving project down the tree
  • 6. 5. Query Optimization ♦ 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.
  • 7. 6. Translation Rules ▪ Rules Apply first operations that reduce size of intermediary results, Then 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 Then reorder leaf nodes avoid Cartesian product adjust rest of tree accordingly
  • 8. 6. Translation Rules ▪ Examples: Cascade of select Select (r, c1 and c2 and c3) select (select (select (r,c1), c2), c3) Commutatively 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 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) a2 a1
  • 9. 7. Cost Estimations How to Estimation ▪ 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 ▪ Traditional optimisation techniques, - Search solution space to a problem for a solution - Minimise cost function ▪ Selection of a strategy (not always optimal)
  • 10. 7. Cost Estimations 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)