1 / 11

Query Compiler

Query Compiler. 16.3 From Parse Trees to Logical Query Plans. A.Sri Harsha 211. Agenda. Converting Parse tree to Logical query Plan Conversion to Relational Algebra Algebraic Laws Removing Sub-queries from Conditions More Algebraic Laws

Download Presentation

Query Compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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 Parse Tree Replace nodes and structures of parse tree by operators of relational algebra Relational Algebra expression Turn it to an expression that can be converted to the most efficient physical query plan Logical Query plan

  4. Conversion to Relational Algebra Parse Tree Π movieTitle σ StarName = name AND birthdate LIKE '%1960' X StarsIn MovieStar

  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. Removing Sub-queries from Conditions Suppose we have a two-argument selection in which the first argument represents some relation R and the second argument is a <Condition> of the form t INS, where expression S is an uncorrelated subquery, and t is a tuple composed of some attributes of R. • Replace the <Condition> by the tree that is the expression for S. If S may have duplicates, then it is necessary to include a <delta> 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 <sigma>C, where C is the condition that equates each component of the tuple t to the corresponding attribute of the relation S. • Give <sigma>C an argument that is the product of R and S.

  7. Removing Sub-queries from Conditions σ σ C X R <Condition> δ R t IN S S

  8. Removing Sub-queries from Conditions Applying the rule for IN conditions Π movieTitle StarName = name Π StarsIn 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 • The theta-join conditions must be associative.

  11. Grouping Associative/Commutative Operators U U V W U U V W R S T U R S T

More Related