SlideShare una empresa de Scribd logo
1 de 10
 Query Optimization
 Why Query Optimization?
 Join Size Estimation?
 Estimation of Number of Distinct Values.
 Query optimization is the process of selecting
the most efficient query-evaluation plan from
among the many strategies usually possible
for processing a given query, especially if the
query is complex.
 In simple scenes the query optimizer come
up with query-evaluation plan that computes
the same result as a given expression, but it
is a least costly way of generating result.
 Faster processing of a query.
 Lesser cost per query.
 High performance of the system.
 Lesser stress on the database.
 Efficient use of database engine.
 Lesser memory is consumed.
 Catalog information:-
 nr : number of tuples in a relation r.
 br : number of blocks containing tuples of r.
 sr : size of a tuple of r.
 fr : blocking factor of r — i.e., the number of tuples of r that fit into one block.
 V(A, r): number of distinct values that appear in r for attribute A; same as the size
of A(r).
 SC(A, r): selection cardinality of attribute A of relation r; average number of
records that satisfy equality on A.
 If tuples of r are stored together physically in a file, then:











rf
rn
rb
 The Cartesian product r x s contains nr .ns tuples; each
tuple occupies sr + ss bytes.
 If R  S = , then r s is the same as r x s. i.e. the
relation has no attributes in common.
 If R  S is a key for R, then a tuple of s will join with at
most one tuple from r
◦ therefore, the number of tuples in r s is no greater than the
number of tuples in s.
 If R  S forms a foreign key in S referencing R, then the
number of tuples in r s is exactly the same as the
number of tuples in s.
 In the example query depositor customer, customer-
name in depositor is a foreign key of customer
◦ hence, the result has exactly ndepositor tuples, which is 5000
 If R  S = {A} is not a key for R or S.
If we assume that every tuple t in R produces
tuples in R S, the number of tuples in R S is
estimated to be:
If the reverse is true, the estimate obtained will
be:
The lower of these two estimates is probably the
more accurate one.
),( sAV
nn sr 
),( rAV
nn sr 
Selections:  (r)
 If  forces A to take a specified value: V(A, (r)) = 1.
 e.g., A = 3
 If  forces A to take on one of a specified set of
values:
V(A, (r)) = number of specified values.
 (e.g., (A = 1 V A = 3 V A = 4 )),
 If the selection condition  is of the form A op r
estimated V(A, (r)) = V(A.r) * s
 where s is the selectivity of the selection.
 In all the other cases: use approximate estimate of
min(V(A,r), n (r) )
◦ More accurate estimate can be got using probability theory,
but this one works fine generally
Joins: r s
 If all attributes in A are from r
estimated V(A, r s) = min (V(A,r), n r s)
 If A contains attributes A1 from r and A2
from s, then estimated V(A, r s) =
min(V(A1,r)*V(A2 – A1,s), V(A1 –
A2,r)*V(A2,s), nr s)
◦ More accurate estimate can be got using
probability theory, but this one works fine generally
THANKYOU…!!!

Más contenido relacionado

La actualidad más candente

16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
koolkampus
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
koolkampus
 

La actualidad más candente (20)

Query processing and Query Optimization
Query processing and Query OptimizationQuery processing and Query Optimization
Query processing and Query Optimization
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
 
Query processing and Query Optimization
Query processing and Query OptimizationQuery processing and Query Optimization
Query processing and Query Optimization
 
Xml databases
Xml databasesXml databases
Xml databases
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
 
Fibonacci search
Fibonacci searchFibonacci search
Fibonacci search
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
Database Systems Concepts, 5th Ed
Database Systems Concepts, 5th EdDatabase Systems Concepts, 5th Ed
Database Systems Concepts, 5th Ed
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
Shadow paging
Shadow pagingShadow paging
Shadow paging
 

Destacado

13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
koolkampus
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query Optimization
Ali Usman
 
8 query processing and optimization
8 query processing and optimization8 query processing and optimization
8 query processing and optimization
Kumar
 
CEMEX_SeniorDesignPosterUpdate4.21.3.pptx
CEMEX_SeniorDesignPosterUpdate4.21.3.pptxCEMEX_SeniorDesignPosterUpdate4.21.3.pptx
CEMEX_SeniorDesignPosterUpdate4.21.3.pptx
Arda Onkol
 
Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...
Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...
Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...
Venance Kitaly
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
avniS
 
Data warehouse architecture
Data warehouse architectureData warehouse architecture
Data warehouse architecture
pcherukumalla
 
Components of a Data-Warehouse
Components of a Data-WarehouseComponents of a Data-Warehouse
Components of a Data-Warehouse
Abdul Aslam
 

Destacado (18)

Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query Optimization
 
8 query processing and optimization
8 query processing and optimization8 query processing and optimization
8 query processing and optimization
 
Quarry Optimization Module
Quarry Optimization ModuleQuarry Optimization Module
Quarry Optimization Module
 
CEMEX_SeniorDesignPosterUpdate4.21.3.pptx
CEMEX_SeniorDesignPosterUpdate4.21.3.pptxCEMEX_SeniorDesignPosterUpdate4.21.3.pptx
CEMEX_SeniorDesignPosterUpdate4.21.3.pptx
 
Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...
Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...
Kitaly Venance D. - Blast Design Optimization to Improve Material Fragmentati...
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Query processing
Query processingQuery processing
Query processing
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query Processing
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Data Warehouse 101
Data Warehouse 101Data Warehouse 101
Data Warehouse 101
 
DATA WAREHOUSING
DATA WAREHOUSINGDATA WAREHOUSING
DATA WAREHOUSING
 
Data warehouse architecture
Data warehouse architectureData warehouse architecture
Data warehouse architecture
 
Introduction to Data Warehousing
Introduction to Data WarehousingIntroduction to Data Warehousing
Introduction to Data Warehousing
 
Components of a Data-Warehouse
Components of a Data-WarehouseComponents of a Data-Warehouse
Components of a Data-Warehouse
 
Data Warehousing and Data Mining
Data Warehousing and Data MiningData Warehousing and Data Mining
Data Warehousing and Data Mining
 

Similar a Query Optimization

4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
koolkampus
 

Similar a Query Optimization (20)

Ch14
Ch14Ch14
Ch14
 
1. linear model, inference, prediction
1. linear model, inference, prediction1. linear model, inference, prediction
1. linear model, inference, prediction
 
2 data structure in R
2 data structure in R2 data structure in R
2 data structure in R
 
relational algebra
relational algebrarelational algebra
relational algebra
 
MODULE 5- EDA.pptx
MODULE 5- EDA.pptxMODULE 5- EDA.pptx
MODULE 5- EDA.pptx
 
Pertemuan 5_Relation Matriks_01 (17)
Pertemuan 5_Relation Matriks_01 (17)Pertemuan 5_Relation Matriks_01 (17)
Pertemuan 5_Relation Matriks_01 (17)
 
Multinomial Model Simulations
Multinomial Model SimulationsMultinomial Model Simulations
Multinomial Model Simulations
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
 
Cis435 week03
Cis435 week03Cis435 week03
Cis435 week03
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
Ch2
Ch2Ch2
Ch2
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.ppt
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 
Data Representation of Strings
Data Representation of StringsData Representation of Strings
Data Representation of Strings
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 
Eryk_Kulikowski_a3
Eryk_Kulikowski_a3Eryk_Kulikowski_a3
Eryk_Kulikowski_a3
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Relation model part 1
Relation model part 1Relation model part 1
Relation model part 1
 
Query optimization in database
Query optimization in databaseQuery optimization in database
Query optimization in database
 
Lllll
LllllLllll
Lllll
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
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
SoniaTolstoy
 
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
QucHHunhnh
 

Último (20)

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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet 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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 

Query Optimization

  • 1.
  • 2.  Query Optimization  Why Query Optimization?  Join Size Estimation?  Estimation of Number of Distinct Values.
  • 3.  Query optimization is the process of selecting the most efficient query-evaluation plan from among the many strategies usually possible for processing a given query, especially if the query is complex.  In simple scenes the query optimizer come up with query-evaluation plan that computes the same result as a given expression, but it is a least costly way of generating result.
  • 4.  Faster processing of a query.  Lesser cost per query.  High performance of the system.  Lesser stress on the database.  Efficient use of database engine.  Lesser memory is consumed.
  • 5.  Catalog information:-  nr : number of tuples in a relation r.  br : number of blocks containing tuples of r.  sr : size of a tuple of r.  fr : blocking factor of r — i.e., the number of tuples of r that fit into one block.  V(A, r): number of distinct values that appear in r for attribute A; same as the size of A(r).  SC(A, r): selection cardinality of attribute A of relation r; average number of records that satisfy equality on A.  If tuples of r are stored together physically in a file, then:            rf rn rb
  • 6.  The Cartesian product r x s contains nr .ns tuples; each tuple occupies sr + ss bytes.  If R  S = , then r s is the same as r x s. i.e. the relation has no attributes in common.  If R  S is a key for R, then a tuple of s will join with at most one tuple from r ◦ therefore, the number of tuples in r s is no greater than the number of tuples in s.  If R  S forms a foreign key in S referencing R, then the number of tuples in r s is exactly the same as the number of tuples in s.  In the example query depositor customer, customer- name in depositor is a foreign key of customer ◦ hence, the result has exactly ndepositor tuples, which is 5000
  • 7.  If R  S = {A} is not a key for R or S. If we assume that every tuple t in R produces tuples in R S, the number of tuples in R S is estimated to be: If the reverse is true, the estimate obtained will be: The lower of these two estimates is probably the more accurate one. ),( sAV nn sr  ),( rAV nn sr 
  • 8. Selections:  (r)  If  forces A to take a specified value: V(A, (r)) = 1.  e.g., A = 3  If  forces A to take on one of a specified set of values: V(A, (r)) = number of specified values.  (e.g., (A = 1 V A = 3 V A = 4 )),  If the selection condition  is of the form A op r estimated V(A, (r)) = V(A.r) * s  where s is the selectivity of the selection.  In all the other cases: use approximate estimate of min(V(A,r), n (r) ) ◦ More accurate estimate can be got using probability theory, but this one works fine generally
  • 9. Joins: r s  If all attributes in A are from r estimated V(A, r s) = min (V(A,r), n r s)  If A contains attributes A1 from r and A2 from s, then estimated V(A, r s) = min(V(A1,r)*V(A2 – A1,s), V(A1 – A2,r)*V(A2,s), nr s) ◦ More accurate estimate can be got using probability theory, but this one works fine generally