PowerPoint PresentationIntroduction to Query Processing (1)Introduction to Query Processing (2)1. Translating SQL Queries into Relational Algebra (1)Translating SQL Queries into Relational Algebra (2)2. Algorithms for SELECT and JOIN Operations (1)Algorithms for SELECT and JOIN Operations (2)Algorithms for SELECT and JOIN Operations (3)Algorithms for SELECT and JOIN Operations (4)Algorithms for SELECT and JOIN Operations (5)Algorithms for SELECT and JOIN Operations (7)Algorithms for SELECT and JOIN Operations (8)Algorithms for SELECT and JOIN Operations (9)Algorithms for SELECT and JOIN Operations (10)Algorithms for SELECT and JOIN Operations (11)Algorithms for SELECT and JOIN Operations (12)Slide 17Slide 183. Algorithms for PROJECT and SET Operations (1)Algorithms for PROJECT and SET Operations (2)Algorithms for PROJECT and SET Operations (3)4. Implementing Aggregate Operations and Outer Joins (1)Implementing Aggregate Operations and Outer Joins (2)5. Using Heuristics in Query Optimization (1)Using Heuristics in Query Optimization (2)Using Heuristics in Query Optimization (3)Using Heuristics in Query Optimization (4)Using Heuristics in Query Optimization (5)Using Heuristics in Query Optimization (6)Slide 30Slide 31Using Heuristics in Query Optimization (9)Using Heuristics in Query Optimization (10)Using Heuristics in Query Optimization (11)Using Heuristics in Query Optimization (12)Using Heuristics in Query Optimization (13)Using Heuristics in Query Optimization (15)Using Heuristics in Query Optimization (16)8. Using Selectivity and Cost Estimates in Query Optimization (1)Using Selectivity and Cost Estimates in Query Optimization (2)Using Selectivity and Cost Estimates in Query Optimization (3)Using Selectivity and Cost Estimates in Query Optimization (4)Using Selectivity and Cost Estimates in Query Optimization (5)Using Selectivity and Cost Estimates in Query Optimization (6)Using Selectivity and Cost Estimates in Query Optimization (7)Using Selectivity and Cost Estimates in Query Optimization (8)Using Selectivity and Cost Estimates in Query Optimization (9)Using Selectivity and Cost Estimates in Query Optimization (10)9. Overview of Query Optimization in Oracle10. Semantic Query OptimizationSummaryCopyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-WesleyChapter 19Algorithms for Query Processing and OptimizationCopyright © 2011 Ramez Elmasri and Shamkant NavatheIntroduction to Query Processing (1)Copyright © 2011 Ramez Elmasri and Shamkant NavatheIntroduction to Query Processing (2)Query optimization:The process of choosing an efficient execution strategy for processing a query.Two internal representations of a query:Query TreeQuery GraphCopyright © 2011 Ramez Elmasri and Shamkant Navathe1. Translating SQL Queries into Relational Algebra (1)Query block: The basic unit that can be translated into the algebraic operators and optimized.A query block contains a single SELECT-FROM-WHERE expression, as well as GROUP BY and HAVING clause if these are part of the block.Nested queries within a query are identified as separate query blocks.Aggregate operators in SQL must be included in the extended algebra.Copyright © 2011 Ramez Elmasri and Shamkant NavatheTranslating SQL Queries into Relational Algebra (2)SELECT LNAME, FNAMEFROM EMPLOYEEWHER E SALARY > ( SELECT MAX (SALARY)FROM EMPLOYEEWHER E DNO = 5);SELECT MAX (SALARY)FROM EMPLOYEEWHERE DNO = 5SELECT LNAME, FNAMEFROM EMPLOYEEWHERE SALARY > CπLNAME, FNAME (σSALARY>C(EMPLOYEE)) ℱMAX SALARY (σDNO=5 (EMPLOYEE))Copyright © 2011 Ramez Elmasri and Shamkant Navathe2. Algorithms for SELECT and JOIN Operations (1)Implementing the SELECT OperationExamples:(OP1): SSN='123456789' (EMPLOYEE)(OP2): DNUMBER>5(DEPARTMENT)(OP3): DNO=5(EMPLOYEE)(OP4): DNO=5 AND SALARY>30000 AND SEX=F(EMPLOYEE)(OP5): ESSN=123456789 AND PNO=10(WORKS_ON)Copyright © 2011 Ramez Elmasri and Shamkant NavatheAlgorithms for SELECT and JOIN Operations (2)Implementing the SELECT Operation (contd.):Search Methods for Simple Selection:S1 Linear search (brute force):Retrieve every record in the file, and test whether its attribute values satisfy the selection condition.S2 Binary search:If the selection condition involves an equality comparison on a key attribute on which the file is ordered, binary search (which is more efficient than linear search) can be used. (See OP1).S3 Using a primary index or hash key to retrieve a single record:If the selection condition involves an equality comparison on a key attribute with a primary index (or a hash key), use the primary index (or the hash key) to retrieve the record.Copyright © 2011 Ramez Elmasri and Shamkant NavatheAlgorithms for SELECT and JOIN Operations (3)Implementing the SELECT Operation (contd.):Search Methods for Simple Selection:S4 Using a primary index to retrieve multiple records:If the comparison condition is >, ≥, <, or ≤ on a key field with a primary index, use the index to find the record satisfying the corresponding equality condition, then retrieve all subsequent records in the (ordered) file. S5 Using a clustering index to retrieve multiple records:If the selection condition involves an equality comparison on a non-key attribute with a clustering index, use the clustering index to retrieve all the records satisfying the selection condition.S6 Using a secondary (B+-tree) index:On an equality comparison, this search method can be used to retrieve a single record if the indexing field has unique values (is a key) or to retrieve multiple records if the indexing field is not a key.In addition, it can be used to retrieve records on conditions involving >,>=, <, or <=. (FOR RANGE QUERIES)Copyright © 2011 Ramez Elmasri and Shamkant NavatheAlgorithms for SELECT and JOIN Operations (4)Implementing the SELECT Operation (contd.):Search Methods for Simple Selection:S7 Conjunctive selection:If an attribute involved in any single simple condition in the conjunctive condition has an access path that permits the use of one of the methods S2 to S6, use that condition to retrieve the records and then check whether each retrieved record satisfies the remaining simple conditions in the conjunctive condition.S8 Conjunctive selection using a composite indexIf two or more attributes are involved in equality conditions in the conjunctive condition and a
View Full Document