SlideShare a Scribd company logo
1 of 23
4/13/2014
Query Execution Time Calculation and
Query Optimization
OBJECTIVE
The objective of this presentation is
to show how to calculate the time
required during the execution of a
query and then optimize the query.
4/13/2014
1. Query Execution Time
4/13/2014
What is Query?
Query is piece of code that is send to a Database in order to get
information back from database. It is used to interact with Databse.
What is Query ExecutionTime?
Query ExecutionTime means time required by query to get the
required information from the database.
4/13/2014
HowTo Calculate ??? ?
Execution of any query involve CPU time and time to access data from
disk. CPU speed are increasing much faster than the disk access time. CPU time
as it depends on the low level details of execution code so it is harder to calculate.
We have used System time in order to get Execution time.
As the System time represent the computer system's notion of the
passing of time.
System time is measured by a system clock, which is typically
implemented as a simple count of the number of ticks
Implementation:-
The system clock is typically implemented as a programmable interval
timer that periodically interrupts the CPU, which then starts executing a timer
interrupt service routine.That routine typically adds one tick to the system clock
(a simple counter) and handles other periodic housekeeping tasks before
returning to whatever the CPU was doing before the interruption.
4/13/2014
 Screen Shots:-
 Advantage:-
If we get the execution time then we can reduce that time by using some
query optimization method.
It also Help in Query Scheduling, Progress Monitoring and also control to
System size.
2. Query Optimization
4/13/2014
 Introduction
 Steps in Cost-based query optimization- Query Flow
 Transformation of Relational Expressions
 Optimization Algorithms
 Future Scope
 Conclusion
4/13/2014
Query Optimization
 What is Query Optimization??? ?
Query optimization is a function of many relational database management
systems.
The query optimizer attempts to determine the most efficient way to
execute a given query by considering the possible query plans.
 Why ?
◦ Many different ways of executing a given query.
◦ Huge differences in Execution Time.
◦ Increase performance of the system.
◦ Uses Less Memory.
◦ Lesser Stress on the Database.
4/13/2014
Query Optimization
 Example:
◦ select * from person where ssn = “123”
◦ Size of person = 1MB
◦ Sequential Scan:
 Takes 1MB / (20mb/s) = 50ms
◦ Use an index on SSN (assuming one exists):
 Approx 4 Random I/Os = 40ms
Query Optimization
4/13/2014
 Introduction
 Steps in Time-based query optimization- Query Flow
 Transformation of Relational Expressions
 Optimization Algorithms
 Future Scope
 Conclusion
4/13/2014
Steps inTime Based Query Optimization:-
1. Parsing.
2. Transformation.
3. Implementation.
4. Plan selection based onTime estimates.
Query Flow:-
Processor
Code Generator
Optimizer
Parser
SQL
Query Language
Relational Calculus
Relational and Physical Algebra
Record at a time calls
 SQL– Structured query Language. It is used to take or any type of
data from database or to Interact with database.
 Query Parser –Verify validity of the SQL statement.Translate
query into an internal structure using relational calculus.
 Query Optimizer – Find the best expression from various
different algebraic expressions.
 Code Generator/Interpreter -It takes the physical and
relational algebra as a input and gave it to the query processor.
 Query Processor – Execute the calls obtained from the code
generator.
4/13/2014
Steps inTime Based Query Optimization:-
Query Optimization
4/13/2014
 Introduction
 Steps in Time-based query optimization- Query Flow
 Transformation of Relational Expressions
 Optimization Algorithms
 Future Scope
 Conclusion
4/13/2014
Equivalence of Expressions
 Two relational expressions equivalent iff:
◦ Their result is identical on all legal databases
 Equivalence rules:
◦ Allow replacing one expression with another
 Examples:
1.
2. Selections are commutative
))(()( 2121
EE   
))(())(( 1221
EE   
4/13/2014
 Pictorial representation of Some more equivalence Rule :-
Transformation to Relational Algebra
4/13/2014
 Simple Algorithm
 Start with the original expression
 Apply all possible applicable rules to get a new set of
expressions
 Repeat with this new set of expressions
 Till no new expressions are generated
4/13/2014
 Find the names of all customers with an account at a Brooklyn branch
whose account balance is over $1000.
customer_name(branch_city = “Brooklyn”  balance > 1000
(branch (account depositor)))
 Apply the rules one by one
customer_name((branch_city = “Brooklyn”  balance > 1000
(branch account)) depositor)
customer_name(((branch_city = “Brooklyn” (branch)) ( balance > 1000
(account))) depositor)
Example
Query Optimization
4/13/2014
 Introduction
 Steps in Time-based query optimization- Query Flow
 Transformation of Relational Expressions
 Optimization Algorithms
 Future Scope
 Conclusion
Optimization Algorithms
4/13/2014
 Two Types:
◦ Exhaustive:
That attempt to find the best plan and have dynamic
programming.
◦ Heuristic:
That are simpler, but are not guaranteed to find the optimal
plan.
4/13/2014
Heuristic Optimization
 Dynamic programming is expensive.
 Use heuristics to reduce the number of choices.
 Typically rule-based:
◦ Perform selection early (reduces the number of tuples)
◦ Perform projection early (reduces the number of attributes)
◦ Perform most restrictive selection and join operations before other
similar operations.
 Some systems use only heuristics, others combine heuristics with
partial time-based optimization.
Steps inTypical Heuristic Optimization
4/13/2014
1. Deconstruct conjunctive selections into a sequence of single
selection operations .
2. Move selection operations down the query tree for the earliest
possible execution .
3. Execute first those selection and join operations that will produce
the smallest relations.
4. Replace Cartesian product operations that are followed by a
selection condition by join operations.
5. Deconstruct and move as far down the tree as possible lists of
projection attributes, creating new projections where needed.
6. Identify those subtrees whose operations can be pipelined, and
execute them using pipelining).
4/13/2014
Advantages of Query Optimization
1. Faster Processing of Query.
2. Lesser Cost Per Query.
3. High Performance of The System.
4. Lesser Stress on Database.
5. Lesser Memory is Consumed.
Query Optimization
4/13/2014
 Introduction.
 Steps in Time-based query optimization- Query Flow.
 Transformation of Relational Expressions.
 Optimization Algorithms.
4/13/2014
Thanks

More Related Content

What's hot

Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)Ravinder Kamboj
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query OptimizationRavinder Kamboj
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query ProcessingMythili Kannan
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query OptimizationAli Usman
 
Query evaluation and optimization
Query evaluation and optimizationQuery evaluation and optimization
Query evaluation and optimizationlavanya marichamy
 
8 query processing and optimization
8 query processing and optimization8 query processing and optimization
8 query processing and optimizationKumar
 
Explaining the explain_plan
Explaining the explain_planExplaining the explain_plan
Explaining the explain_planarief12H
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithmTrupti Agrawal
 
Phases of distributed query processing
Phases of distributed query processingPhases of distributed query processing
Phases of distributed query processingNevil Dsouza
 
SQL Optimization With Trace Data And Dbms Xplan V6
SQL Optimization With Trace Data And Dbms Xplan V6SQL Optimization With Trace Data And Dbms Xplan V6
SQL Optimization With Trace Data And Dbms Xplan V6Mahesh Vallampati
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Avelin Huo
 
Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization Hafiz faiz
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimizationWBUTTUTORIALS
 
Heuristic approch monika sanghani
Heuristic approch  monika sanghaniHeuristic approch  monika sanghani
Heuristic approch monika sanghaniMonika Sanghani
 

What's hot (20)

Query processing
Query processingQuery processing
Query processing
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 
Query optimisation
Query optimisationQuery optimisation
Query optimisation
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query Optimization
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query Processing
 
Query processing
Query processingQuery processing
Query processing
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query Optimization
 
Query trees
Query treesQuery trees
Query trees
 
Chapter15
Chapter15Chapter15
Chapter15
 
Query evaluation and optimization
Query evaluation and optimizationQuery evaluation and optimization
Query evaluation and optimization
 
8 query processing and optimization
8 query processing and optimization8 query processing and optimization
8 query processing and optimization
 
Explaining the explain_plan
Explaining the explain_planExplaining the explain_plan
Explaining the explain_plan
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Phases of distributed query processing
Phases of distributed query processingPhases of distributed query processing
Phases of distributed query processing
 
SQL Optimization With Trace Data And Dbms Xplan V6
SQL Optimization With Trace Data And Dbms Xplan V6SQL Optimization With Trace Data And Dbms Xplan V6
SQL Optimization With Trace Data And Dbms Xplan V6
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
Query Decomposition and data localization
Query Decomposition and data localization Query Decomposition and data localization
Query Decomposition and data localization
 
Query processing System
Query processing SystemQuery processing System
Query processing System
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Heuristic approch monika sanghani
Heuristic approch  monika sanghaniHeuristic approch  monika sanghani
Heuristic approch monika sanghani
 

Similar to Query Execution Time and Query Optimization.

Applications of parellel computing
Applications of parellel computingApplications of parellel computing
Applications of parellel computingpbhopi
 
Hardware enhanced association rule mining
Hardware enhanced association rule miningHardware enhanced association rule mining
Hardware enhanced association rule miningStudsPlanet.com
 
Final report group2
Final report group2Final report group2
Final report group2George Sam
 
Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...
Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...
Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...Lucidworks
 
Less11 3 e_loadmodule_1
Less11 3 e_loadmodule_1Less11 3 e_loadmodule_1
Less11 3 e_loadmodule_1Suresh Mishra
 
SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...
SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...
SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...South Tyrol Free Software Conference
 
Performance Testing
Performance TestingPerformance Testing
Performance TestingAnu Shaji
 
Performance testing basics
Performance testing basicsPerformance testing basics
Performance testing basicsCharu Anand
 
Optimization of FCFS Based Resource Provisioning Algorithm for Cloud Computing
Optimization of FCFS Based Resource Provisioning Algorithm for Cloud ComputingOptimization of FCFS Based Resource Provisioning Algorithm for Cloud Computing
Optimization of FCFS Based Resource Provisioning Algorithm for Cloud ComputingIOSR Journals
 
Database performance management
Database performance managementDatabase performance management
Database performance managementscottaver
 
Performance testing jmeter
Performance testing jmeterPerformance testing jmeter
Performance testing jmeterBhojan Rajan
 
Performance Test Plan - Sample 1
Performance Test Plan - Sample 1Performance Test Plan - Sample 1
Performance Test Plan - Sample 1Atul Pant
 
Evolving the Optimal Relevancy Ranking Model at Dice.com
Evolving the Optimal Relevancy Ranking Model at Dice.comEvolving the Optimal Relevancy Ranking Model at Dice.com
Evolving the Optimal Relevancy Ranking Model at Dice.comSimon Hughes
 
An Analysis on Query Optimization in Distributed Database
An Analysis on Query Optimization in Distributed DatabaseAn Analysis on Query Optimization in Distributed Database
An Analysis on Query Optimization in Distributed DatabaseEditor IJMTER
 
Adding Value in the Cloud with Performance Test
Adding Value in the Cloud with Performance TestAdding Value in the Cloud with Performance Test
Adding Value in the Cloud with Performance TestRodolfo Kohn
 
Migration to the cloud
Migration to the cloudMigration to the cloud
Migration to the cloudEPAM Systems
 

Similar to Query Execution Time and Query Optimization. (20)

Door to perfomance testing
Door to perfomance testingDoor to perfomance testing
Door to perfomance testing
 
Applications of parellel computing
Applications of parellel computingApplications of parellel computing
Applications of parellel computing
 
dd presentation.pdf
dd presentation.pdfdd presentation.pdf
dd presentation.pdf
 
Hardware enhanced association rule mining
Hardware enhanced association rule miningHardware enhanced association rule mining
Hardware enhanced association rule mining
 
Final report group2
Final report group2Final report group2
Final report group2
 
Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...
Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...
Evolving The Optimal Relevancy Scoring Model at Dice.com: Presented by Simon ...
 
Visual Studio Profiler
Visual Studio ProfilerVisual Studio Profiler
Visual Studio Profiler
 
Less11 3 e_loadmodule_1
Less11 3 e_loadmodule_1Less11 3 e_loadmodule_1
Less11 3 e_loadmodule_1
 
SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...
SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...
SFScon 21 - Eduardo Guerra - A Lean Software Analytics Canvas for Agile Small...
 
Performance Testing
Performance TestingPerformance Testing
Performance Testing
 
Performance testing basics
Performance testing basicsPerformance testing basics
Performance testing basics
 
Optimization of FCFS Based Resource Provisioning Algorithm for Cloud Computing
Optimization of FCFS Based Resource Provisioning Algorithm for Cloud ComputingOptimization of FCFS Based Resource Provisioning Algorithm for Cloud Computing
Optimization of FCFS Based Resource Provisioning Algorithm for Cloud Computing
 
Database performance management
Database performance managementDatabase performance management
Database performance management
 
Performance testing jmeter
Performance testing jmeterPerformance testing jmeter
Performance testing jmeter
 
Performance Test Plan - Sample 1
Performance Test Plan - Sample 1Performance Test Plan - Sample 1
Performance Test Plan - Sample 1
 
Evolving the Optimal Relevancy Ranking Model at Dice.com
Evolving the Optimal Relevancy Ranking Model at Dice.comEvolving the Optimal Relevancy Ranking Model at Dice.com
Evolving the Optimal Relevancy Ranking Model at Dice.com
 
Software Performance
Software Performance Software Performance
Software Performance
 
An Analysis on Query Optimization in Distributed Database
An Analysis on Query Optimization in Distributed DatabaseAn Analysis on Query Optimization in Distributed Database
An Analysis on Query Optimization in Distributed Database
 
Adding Value in the Cloud with Performance Test
Adding Value in the Cloud with Performance TestAdding Value in the Cloud with Performance Test
Adding Value in the Cloud with Performance Test
 
Migration to the cloud
Migration to the cloudMigration to the cloud
Migration to the cloud
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

Query Execution Time and Query Optimization.

  • 1. 4/13/2014 Query Execution Time Calculation and Query Optimization
  • 2. OBJECTIVE The objective of this presentation is to show how to calculate the time required during the execution of a query and then optimize the query. 4/13/2014
  • 3. 1. Query Execution Time 4/13/2014 What is Query? Query is piece of code that is send to a Database in order to get information back from database. It is used to interact with Databse. What is Query ExecutionTime? Query ExecutionTime means time required by query to get the required information from the database.
  • 4. 4/13/2014 HowTo Calculate ??? ? Execution of any query involve CPU time and time to access data from disk. CPU speed are increasing much faster than the disk access time. CPU time as it depends on the low level details of execution code so it is harder to calculate. We have used System time in order to get Execution time. As the System time represent the computer system's notion of the passing of time. System time is measured by a system clock, which is typically implemented as a simple count of the number of ticks Implementation:- The system clock is typically implemented as a programmable interval timer that periodically interrupts the CPU, which then starts executing a timer interrupt service routine.That routine typically adds one tick to the system clock (a simple counter) and handles other periodic housekeeping tasks before returning to whatever the CPU was doing before the interruption.
  • 5. 4/13/2014  Screen Shots:-  Advantage:- If we get the execution time then we can reduce that time by using some query optimization method. It also Help in Query Scheduling, Progress Monitoring and also control to System size.
  • 6. 2. Query Optimization 4/13/2014  Introduction  Steps in Cost-based query optimization- Query Flow  Transformation of Relational Expressions  Optimization Algorithms  Future Scope  Conclusion
  • 7. 4/13/2014 Query Optimization  What is Query Optimization??? ? Query optimization is a function of many relational database management systems. The query optimizer attempts to determine the most efficient way to execute a given query by considering the possible query plans.  Why ? ◦ Many different ways of executing a given query. ◦ Huge differences in Execution Time. ◦ Increase performance of the system. ◦ Uses Less Memory. ◦ Lesser Stress on the Database.
  • 8. 4/13/2014 Query Optimization  Example: ◦ select * from person where ssn = “123” ◦ Size of person = 1MB ◦ Sequential Scan:  Takes 1MB / (20mb/s) = 50ms ◦ Use an index on SSN (assuming one exists):  Approx 4 Random I/Os = 40ms
  • 9. Query Optimization 4/13/2014  Introduction  Steps in Time-based query optimization- Query Flow  Transformation of Relational Expressions  Optimization Algorithms  Future Scope  Conclusion
  • 10. 4/13/2014 Steps inTime Based Query Optimization:- 1. Parsing. 2. Transformation. 3. Implementation. 4. Plan selection based onTime estimates. Query Flow:- Processor Code Generator Optimizer Parser SQL Query Language Relational Calculus Relational and Physical Algebra Record at a time calls
  • 11.  SQL– Structured query Language. It is used to take or any type of data from database or to Interact with database.  Query Parser –Verify validity of the SQL statement.Translate query into an internal structure using relational calculus.  Query Optimizer – Find the best expression from various different algebraic expressions.  Code Generator/Interpreter -It takes the physical and relational algebra as a input and gave it to the query processor.  Query Processor – Execute the calls obtained from the code generator. 4/13/2014 Steps inTime Based Query Optimization:-
  • 12. Query Optimization 4/13/2014  Introduction  Steps in Time-based query optimization- Query Flow  Transformation of Relational Expressions  Optimization Algorithms  Future Scope  Conclusion
  • 13. 4/13/2014 Equivalence of Expressions  Two relational expressions equivalent iff: ◦ Their result is identical on all legal databases  Equivalence rules: ◦ Allow replacing one expression with another  Examples: 1. 2. Selections are commutative ))(()( 2121 EE    ))(())(( 1221 EE   
  • 14. 4/13/2014  Pictorial representation of Some more equivalence Rule :-
  • 15. Transformation to Relational Algebra 4/13/2014  Simple Algorithm  Start with the original expression  Apply all possible applicable rules to get a new set of expressions  Repeat with this new set of expressions  Till no new expressions are generated
  • 16. 4/13/2014  Find the names of all customers with an account at a Brooklyn branch whose account balance is over $1000. customer_name(branch_city = “Brooklyn”  balance > 1000 (branch (account depositor)))  Apply the rules one by one customer_name((branch_city = “Brooklyn”  balance > 1000 (branch account)) depositor) customer_name(((branch_city = “Brooklyn” (branch)) ( balance > 1000 (account))) depositor) Example
  • 17. Query Optimization 4/13/2014  Introduction  Steps in Time-based query optimization- Query Flow  Transformation of Relational Expressions  Optimization Algorithms  Future Scope  Conclusion
  • 18. Optimization Algorithms 4/13/2014  Two Types: ◦ Exhaustive: That attempt to find the best plan and have dynamic programming. ◦ Heuristic: That are simpler, but are not guaranteed to find the optimal plan.
  • 19. 4/13/2014 Heuristic Optimization  Dynamic programming is expensive.  Use heuristics to reduce the number of choices.  Typically rule-based: ◦ Perform selection early (reduces the number of tuples) ◦ Perform projection early (reduces the number of attributes) ◦ Perform most restrictive selection and join operations before other similar operations.  Some systems use only heuristics, others combine heuristics with partial time-based optimization.
  • 20. Steps inTypical Heuristic Optimization 4/13/2014 1. Deconstruct conjunctive selections into a sequence of single selection operations . 2. Move selection operations down the query tree for the earliest possible execution . 3. Execute first those selection and join operations that will produce the smallest relations. 4. Replace Cartesian product operations that are followed by a selection condition by join operations. 5. Deconstruct and move as far down the tree as possible lists of projection attributes, creating new projections where needed. 6. Identify those subtrees whose operations can be pipelined, and execute them using pipelining).
  • 21. 4/13/2014 Advantages of Query Optimization 1. Faster Processing of Query. 2. Lesser Cost Per Query. 3. High Performance of The System. 4. Lesser Stress on Database. 5. Lesser Memory is Consumed.
  • 22. Query Optimization 4/13/2014  Introduction.  Steps in Time-based query optimization- Query Flow.  Transformation of Relational Expressions.  Optimization Algorithms.