Database-19-QueryProcessing.pptx

# Query processing and optimization 34 using heuristics

• 62

This preview shows pages 34–44. Sign up to view the full content.

Query Processing and Optimization 34

This preview has intentionally blurred sections. Sign up to view the full version.

Using Heuristics in Query Optimization Query tree : A tree data structure that corresponds to a relational algebra expression. It represents the input relations of the query as leaf nodes of the tree , and represents the relational algebra operations as internal nodes. An execution of the query tree consists of executing an internal node operation whenever its operands are available and then replacing that internal node by the relation that results from executing the operation. Query graph : A graph data structure that corresponds to a relational calculus expression. It does not indicate an order on which operations to perform first. There is only a single graph corresponding to each query. Query Processing and Optimization 35
Using Heuristics in Query Optimization Example: For every project located in ‘Stafford’, retrieve the project number, the controlling department number and the department manager’s last name, address and birthdate. Relation algebra: PNUMBER, DNUM, LNAME, ADDRESS, BDATE ((( PLOCATION=‘STAFFORD’ (PROJECT)) DNUM=DNUMBER (DEPARTMENT)) MGRSSN=SSN (EMPLOYEE)) SQL query: Q2: SELECT P.NUMBER,P.DNUM,E.LNAME, E.ADDRESS, E.BDATE FROM PROJECT AS P,DEPARTMENT AS D, EMPLOYEE AS E WHERE P.DNUM=D.DNUMBER AND D.MGRSSN=E.SSN AND P.PLOCATION=‘STAFFORD’; Query Processing and Optimization 36

This preview has intentionally blurred sections. Sign up to view the full version.

Using Heuristics in Query Optimization Query Processing and Optimization 37
Using Heuristics in Query Optimization Heuristic Optimization of Query Trees: The same query could correspond to many different relational algebra expressions — and hence many different query trees. The task of heuristic optimization of query trees is to find a final query tree that is efficient to execute. Example: Q: SELECT LNAME FROM EMPLOYEE, WORKS_ON, PROJECT WHERE PNAME = ‘AQUARIUS’ AND PNUMBER=PNO AND ESSN=SSN AND BDATE > ‘1957-12-31’; Query Processing and Optimization 38

This preview has intentionally blurred sections. Sign up to view the full version.

Query Processing and Optimization 39
Query Processing and Optimization 40

This preview has intentionally blurred sections. Sign up to view the full version.

Query Processing and Optimization 41
Using Heuristics in Query Optimization General Transformation Rules for Relational Algebra Operations: 1. Cascade of : A conjunctive selection condition can be broken up into a cascade (sequence) of individual operations: c1 AND c2 AND ... AND cn (R) = c1 ( c2 (...( cn (R))...) ) 2. Commutativity of : The operation is commutative: c1 ( c2 (R)) = c2 ( c1 (R)) 3. Cascade of : In a cascade (sequence) of operations, all but the last one can be ignored: List1 ( List2 (...( Listn (R))...) ) = List1 (R) 4. Commuting with : If the selection condition c involves only the attributes A1, ..., An in the projection list, the two operations can be commuted: A1, A2, ..., An ( c (R)) = c ( A1, A2, ..., An (R)) Query Processing and Optimization 42

This preview has intentionally blurred sections. Sign up to view the full version.

Using Heuristics in Query Optimization General Transformation Rules for Relational Algebra Operations (contd.): 5. Commutativity of ( and x ): The operation is commutative as is the x operation: R C S = S C R; R x S = S x R 6. Commuting with (or x ): If all the attributes in the selection condition c involve only the attributes of one of the relations being joined—say, R—
This is the end of the preview. Sign up to access the rest of the document.
• Fall '09
• SUNANHAN
• Query optimizer, JOIN Operations

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern