Algebraic Laws. {P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer.

Slides:



Advertisements
Similar presentations
1 Query Evaluation Partially using Prof. Hector Garcia-Molina’s slides (Notes06, Notes07) Donghui Zhang Northeastern.
Advertisements

Relational Calculus   Logic, like whiskey, loses its beneficial effect when taken in too large quantities. --Lord Dunsany.
CS CS4432: Database Systems II Logical Plan Rewriting.
SQL Query Examples Database Management COP4540, SCS, FIU.
16.3 Parser to Logical Query Plans SQL(not RAE) Figure 16.2 select distinct movietitle from starsIn where starname in (select name from moviestar.
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.
Cost-Based Transformations. Why estimate costs? Well, sometimes we don’t need cost estimations to decide applying some heuristic transformation. –E.g.
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.
Algebraic Laws For the binary operators, we push the selection only if all attributes in the condition C are in R.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Query Compiler By:Payal Gupta Roll No:106(225) Professor :Tsau Young Lin.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
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.
1 Query Compilation Parsing Logical Query Plan Source: our textbook, slides by Hector Garcia-Molina.
SQL. 1.SQL is a high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
Cost based transformations Initial logical query plan Two candidates for the best logical query plan.
CS Spring 2002Notes 61 CS 277: Database System Implementation Notes 6: Query Processing Arthur Keller.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
Cost-Based Transformations. Why estimate costs? Sometimes we don’t need cost estimations to decide applying some heuristic transformation. –E.g. Pushing.
CS 4432query processing1 CS4432: Database Systems II.
SQL SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
Query Optimization. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
The Query Compiler 16.1 Parsing and Preprocessing Meghna Jain(205) Dr. T. Y. Lin.
16.2 ALGEBRAIC LAWS FOR IMPROVING QUERY PLANS Ramya Karri ID: 206.
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.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
CS 4432query processing - lecture 121 CS4432: Database Systems II Lecture #12 Query Processing Professor Elke A. Rundensteiner.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
Relational Algebra CIS 4301 Lecture Notes Lecture /28/2006.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
Advanced Databases: Lecture 8 Query Optimization (III) 1 Query Optimization Advanced Databases By Dr. Akhtar Ali.
Advanced Database Systems Notes:Query Processing (Overview) Shivnath Babu.
Cost based transformations Initial logical query plan Two candidates for the best logical query plan.
EN : Adv. Storage and TP Systems Cost-Based Query Optimization.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
DBMS 2001Notes 6: Query Compilation1 Principles of Database Management Systems 6: Query Compilation and Optimization Pekka Kilpeläinen (partially based.
CPS216: Advanced Database Systems Notes 08:Query Optimization (Plan Space, Query Rewrites) Shivnath Babu.
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.
CPS216: Advanced Database Systems Query Rewrite Rules for Subqueries Shivnath Babu.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
CPS216: Data-Intensive Computing Systems Introduction to Query Processing Shivnath Babu.
Query Compiler A.Sri Harsha From Parse Trees to Logical Query Plans.
Chapters 15-16a1 (Slides by Hector Garcia-Molina, Chapters 15 and 16: Query Processing.
More Relation Operations 2014, Fall Pusan National University Ki-Joune Li.
16.3 Parser to Logical Query Plans SQL(not RAE) Figure 16.2 select distinct movietitle from starsIn where starname in (select name from moviestar.
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)
CS 245Notes 61 CS 245: Database System Principles Notes 6: Query Processing Hector Garcia-Molina.
CS4432: Database Systems II Query Processing- Part 1 1.
CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu.
1 Ullman et al. : Database System Principles Notes 6: Query Processing.
16.2.Algebraic Laws for Improving Query Plans
The Query Compiler Parsing and Preprocessing. Meghna Jain(205)
CS 245: Database System Principles
Overview of Query Optimization
Focus: Relational System
16.2.Algebraic Laws for Improving Query Plans
CS 245: Database System Principles
Algebraic Laws.
CPSC-608 Database Systems
Deletion in AVL Tree There are 5 cases to consider.
CPSC-608 Database Systems
16.3 Parser to Logical Query Plans
Query Compiler By:Payal Gupta Shirali Choksi Professor :Tsau Young Lin.
CPS216: Data-Intensive Computing Systems Query Processing (Overview)
Presentation transcript:

Algebraic Laws

{P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer SQL query parse tree logical query plan “improved” l.q.p l.q.p. +sizes statistics

Algebraic laws for transforming logical query plans Commutative and associative laws: Above laws are applicable for both sets and bags

Laws Involving Selection (  ) Splitting laws Order is flexible

Algebraic Laws involving selection For the binary operators, we push the selection only if all attributes in the condition C are in R.

Example: Consider R(A,B) and S(B,C) and the expression below:  A=1 AND B<C (R  S) 1.Splitting AND  A=1 (  B < C (R  S)) 2.Push  to S  A=1 (R   B < C (S)) 3.Push  to R  A=1 (R)   B < C (S)

Pushing selections Usually selections are pushed down the expression tree. The following example shows that it is sometimes useful to pull selection up in the tree. StarsIn(title,year,starName) Movie(title,year,length,studioName) CREATE VIEW MoviesOf1996 AS SELECT * FROM MOVIE WHERE year=1996; Query: Which stars worked for which studios in 1996? SELECT starName,studioName FROM MoviesOf1996 NATURAL JOIN StarsIN;

pull selection up then push down

Laws for (bag) Projection A simple law: Project out attributes that are not needed later. –i.e. keep only the input attr. and any join attribute.

Examples for pushing projection Schema R(a,b,c), S(c,d,e)

Example: Pushing Projection Schema: StarsIn(title,year,starName) Query: SELECT starName FROM StarsIn WHERE year = 1996; Should we transform to  ? Depends!  starName  year=1996 StarsIn  starName  year=1996 StarsIn  starName,year

Reasons for not pushing the projection If there is an index on StarsIn.year, such index is useless in the projected relation  starName,year (StarsIn) –While such an index is very useful for the selection on “ year=1996 ”

Improving logical query plans 1.Push  as far down as possible (sometimes pull them up first). 2.Do splitting of complex conditions in  in order to push  even further. 3.Push  as far down as possible, introduce new early  (but take care for exceptions) 4.Combine  with  to produce  - joins or equi-joins Choose an order for joins

Example of improvement SELECT title FROM StarsIn, MovieStar WHERE starName = name AND birthdate LIKE '%1960';  title  starname=name AND birthdate LIKE ‘%1960’ StarsIn  MovieStar  title StarsIn MovieStar starName=name  birthdate LIKE ‘%1960’

 title StarsIn MovieStar starName=name  birthdate LIKE ‘%1960’  name And a better plan introducing a projection to filter out useless attributes: