Presentation is loading. Please wait.

Presentation is loading. Please wait.

Query Compiler A.Sri Harsha 211 16.3 From Parse Trees to Logical Query Plans.

Similar presentations


Presentation on theme: "Query Compiler A.Sri Harsha 211 16.3 From Parse Trees to Logical Query Plans."— Presentation transcript:

1 Query Compiler A.Sri Harsha 211 16.3 From Parse Trees to Logical Query Plans

2 Agenda Converting Parse tree to Logical query Plan Conversion to Relational Algebra Algebraic Laws Removing Sub-queries from Conditions More Algebraic Laws Grouping Associative/Commutative Operators

3 Converting Parse tree to logical query plan Replace nodes and structures of parse tree by operators of relational algebra Turn it to an expression that can be converted to the most efficient physical query plan Parse Tree Logical Query plan Relational Algebra expression

4 Conversion to Relational Algebra Parse Tree Π movieTitl e σ StarName = name AND birthdate LIKE '%1960' X StarsInMovieStar

5 Algebraic Laws Commutativity: R x S = S x R R S = S R R U S = S U R R ∩ S = S ∩ R Associativity: (R x S) x T = R x (S x T)‏ (R S) T = R (S T)‏ (R U S) U T = R U (S U T)‏ (R ∩ S) ∩ T = R ∩ (S ∩ T)‏

6 Suppose we have a two-argument selection in which the first argument represents some relation R and the second argument is a of the form t IN S, where expression S is an uncorrelated subquery, and t is a tuple composed of some attributes of R. Removing Sub-queries from Conditions Replace the by the tree that is the expression for S. If S may have duplicates, then it is necessary to include a operation at the root of the expression of S, so the expression being formed does not produce more copies of tuples than the original query does. Replace the two-argument selection by a one-argument selection C, where C is the condition that equates each component of the tuple t to the corresponding attribute of the relation S. Give C an argument that is the product of R and S.

7 Removing Sub-queries from Conditions C X δ σ S R σ S R tIN

8 Removing Sub-queries from Conditions movieTitl e Π Π StarsIn Applying the rule for IN conditions StarName = name birthdate LIKE '%1960' σ name

9 More Algebraic Laws

10 Grouping Associative/Commutative Operators Natural Joins or theta-joins can also be obtained with each other under certain circumstances We must replace the natural joins with theta-joins that equate the attributes of the same. We must add of projection to eliminate duplicate copies of attributes involved in a natural join that has become a theta- join 1)The theta-join conditions must be associative.

11 Grouping Associative/Commutative Operators WVU U R S T U U UVW ST R


Download ppt "Query Compiler A.Sri Harsha 211 16.3 From Parse Trees to Logical Query Plans."

Similar presentations


Ads by Google