16.2 ALGEBRAIC LAWS FOR IMPROVING QUERY PLANS Ramya Karri ID: 206.

Slides:



Advertisements
Similar presentations
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Advertisements

CS4432: Database Systems II
CS CS4432: Database Systems II Logical Plan Rewriting.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
Algebraic and Logical Query Languages Spring 2011 Instructor: Hassan Khosravi.
1 Lecture 12: Further relational algebra, further SQL
Relational Operations on Bags Extended Operators of Relational Algebra.
Query Execution Since our SQL queries are very high level the query processor does a lot of processing to supply all the details. An SQL query is translated.
Query Compiler. The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical.
Query Execution Optimizing Performance. Resolving an SQL query Since our SQL queries are very high level, the query processor must do a lot of additional.
COMP 451/651 Optimizing Performance
The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical query plan into.
CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 183 Database Systems II Query Compiler.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
Oct 28, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
ONE PASS ALGORITHM PRESENTED BY: PRADHYUMAN RAOL ID : 114 Instructor: Dr T.Y. LIN.
Relational Algebra on Bags A bag is like a set, but an element may appear more than once. –Multiset is another name for “bag.” Example: {1,2,1,3} is a.
The Query Compiler Section 16.3 DATABASE SYSTEMS – The Complete Book Presented By:Under the supervision of: Deepti KunduDr. T.Y.Lin.
CS Spring 2002Notes 61 CS 277: Database System Implementation Notes 6: Query Processing Arthur Keller.
CS 4432query processing - lecture 131 CS4432: Database Systems II Lecture #13 Query Processing Professor Elke A. Rundensteiner.
ONE PASS ALGORITHM PRESENTED BY: PRADHYUMAN RAOL ID : 114 Instructor: Dr T.Y. LIN.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
Relational Operations on Bags Extended Operators of Relational Algebra.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CS 4432logical query rewriting - lecture 151 CS4432: Database Systems II Lecture #15 Logical Query Rewriting Professor Elke A. Rundensteiner.
16.5 Introduction to Cost- based plan selection Amith KC Student Id: 109.
Algebraic Laws Commutative and Associative Laws Commutativity for Sets and Bags (Ch5): R x S = S x R (Proof) R  S = S  R (ch5 e) R U S = S U.
Cs3431 Relational Algebra : #I Based on Chapter 2.4 & 5.1.
Instructor: Mohamed Eltabakh
Algebraic Laws. {P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer.
Nov 18, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
Murali Mani Relational Algebra. Murali Mani What is Relational Algebra? Defines operations (data retrieval) for relational model SQL’s DML (Data Manipulation.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
Relational Algebra Basic Operations Algebra of Bags.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
CSCE Database Systems Chapter 15: Query Execution 1.
CS 245Notes 61 CS 245: Database System Principles Notes 6: Query Processing Hector Garcia-Molina.
CS 245Notes 61 CS 245: Database System Principles Notes 6: Query Processing Hector Garcia-Molina.
From Professor Ullman, Relational Algebra.
Query Compiler A.Sri Harsha From Parse Trees to Logical Query Plans.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Chapter 5 Relational Algebra Pearson Education © 2014.
Databases : Relational Algebra - Complex Expression 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof.
More Relation Operations 2015, Fall Pusan National University Ki-Joune Li.
More Relation Operations 2014, Fall Pusan National University Ki-Joune Li.
Relational Algebra Instructor: Mohamed Eltabakh 1 Part II.
1 Algebra of Queries Classical Relational Algebra It is a collection of operations on relations. Each operation takes one or two relations as its operand(s)
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
CS 245Notes 61 CS 245: Database System Principles Notes 6: Query Processing Hector Garcia-Molina.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
1. Chapter 2: The relational Database Modeling Section 2.4: An algebraic Query Language Chapter 5: Algebraic and logical Query Languages Section 5.1:
Relational Algebra - Part 1
16.2.Algebraic Laws for Improving Query Plans
CS257 Query Optimization.
Operators Expression Trees Bag Model of Data
Instructor: Mohamed Eltabakh
More Relation Operations
16.2.Algebraic Laws for Improving Query Plans
CS 245: Database System Principles
Basic Operations Algebra of Bags
Algebraic Laws.
One-Pass Algorithms for Database Operations (15.2)
5.1 Relational Operations on Bags
CPSC-608 Database Systems
Query Compiler By:Payal Gupta Shirali Choksi Professor :Tsau Young Lin.
Relational Algebra Chapter 4 - part I.
Presentation transcript:

16.2 ALGEBRAIC LAWS FOR IMPROVING QUERY PLANS Ramya Karri ID: 206

Optimizing the Logical Query Plan The translation rules converting a parse tree to a logical query tree do not always produce the best logical query tree. It is often possible to optimize the logical query tree by applying relational algebra laws to convert the original tree into a more efficient logical query tree. Optimizing a logical query tree using relational algebra laws is called heuristic optimization

Relational Algebra Laws These laws often involve the properties of: – commutativity - operator can be applied to operands independent of order. E.g. A + B = B + A - The “+” operator is commutative. – associativity - operator is independent of operand grouping. E.g. A + (B + C) = (A + B) + C - The “+” operator is associative.

Associative and Commutative Operators The relational algebra operators of cross-product (×), join ( ⋈ ), union, and intersection are all associative and commutative. Commutative R X S = S X R R ⋈ S = S ⋈ R R  S = S  R R ∩ S = S ∩ R Associative (R X S) X T = S X (R X T) (R ⋈ S) ⋈ T= S ⋈ (R ⋈ T) (R  S)  T = S  (R  T) (R ∩ S) ∩ T = S ∩ (R ∩ T)

Laws Involving Selection Complex selections involving AND or OR can be broken into two or more selections: (splitting laws) σ C1 AND C2 (R) = σ C1 ( σ C2 (R)) σ C1 OR C2 (R) = ( σ C1 (R) )  S ( σ C2 (R) ) Example – R={a,a,b,b,b,c} – p1 satisfied by a,b, p2 satisfied by b,c – σ p1vp2 (R) = {a,a,b,b,b,c} – σ p1 (R) = {a,a,b,b,b} – σ p2 (R) = {b,b,b,c} – σ p1 (R) U σ p2 (R) = {a,a,b,b,b,c}

Laws Involving Selection (Contd..) Selection is pushed through both arguments for union: σ C (R  S) = σ C (R)  σ C (S) Selection is pushed to the first argument and optionally the second for difference: σ C (R - S) = σ C (R) - S σ C (R - S) = σ C (R) - σ C (S)

Laws Involving Selection (Contd..) All other operators require selection to be pushed to only one of the arguments. For joins, may not be able to push selection to both if argument does not have attributes selection requires. σ C (R × S) = σ C (R) × S σ C (R ∩ S) = σ C (R) ∩ S σ C (R ⋈ S) = σ C (R) ⋈ S σ C (R ⋈ D S) = σ C (R) ⋈ D S

Laws Involving Selection (Contd..) Example Consider relations R(a,b) and S(b,c) and the expression σ (a=1 OR a=3) AND b<c (R ⋈ S) σ a=1 OR a=3 (σ b<c (R ⋈ S)) σ a=1 OR a=3 (R ⋈ σ b<c (S)) σ a=1 OR a=3 (R) ⋈ σ b<c (S)

Laws Involving Projection Like selections, it is also possible to push projections down the logical query tree. However, the performance gained is less than selections because projections just reduce the number of attributes instead of reducing the number of tuples.

Laws Involving Projection Laws for pushing projections with joins: π L (R × S) = π L( π M (R) × π N (S)) π L (R ⋈ S) = π L(( π M (R) ⋈ π N (S)) π L (R ⋈ D S) = π L(( π M (R) ⋈ D π N (S))

Laws Involving Projection Laws for pushing projections with set operations. Projection can be performed entirely before union. π L (R U B S) = π L (R) U B π L (S) Projection can be pushed below selection as long as we also keep all attributes needed for the selection ( M = L  attr(C)). π L ( σ C (R)) = π L ( σ C ( π M (R)))

Laws Involving Join We have previously seen these important rules about joins: 1. Joins are commutative and associative. 2. Selection can be distributed into joins. 3. Projection can be distributed into joins.

Laws Involving Duplicate Elimination The duplicate elimination operator (δ) can be pushed through many operators. R has two copies of tuples t, S has one copy of t, δ (RUS)=one copy of t δ (R) U δ (S)=two copies of t

Laws Involving Duplicate Elimination Laws for pushing duplicate elimination operator (δ): δ (R × S) = δ (R) × δ (S) δ (R S) = δ (R) δ (S) δ (R D S) = δ (R) D δ (S) δ ( σ C(R) = σ C ( δ (R))

Laws Involving Duplicate Elimination The duplicate elimination operator (δ) can also be pushed through bag intersection, but not across union, difference, or projection in general. δ (R ∩ S) = δ (R) ∩ δ (S)

Laws Involving Grouping The grouping operator (γ) laws depend on the aggregate operators used. There is one general rule, however, that grouping subsumes duplicate elimination: δ(γL(R)) = γL(R) The reason is that some aggregate functions are unaffected by duplicates (MIN and MAX) while other functions are (SUM, COUNT, and AVG).