The Query Compiler Section 16.3 DATABASE SYSTEMS – The Complete Book Presented By:Under the supervision of: Deepti KunduDr. T.Y.Lin.

Slides:



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

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.
The Query Compiler Varun Sud ID: 104. Agenda Parsing  Syntax analysis and Parse Trees.  Grammar for a simple subset of SQL  Base Syntactic Categories.
Subqueries Example Find the name of the producer of ‘Star Wars’.
The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical query plan into.
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.
1 Query Compilation Parsing Logical Query Plan Source: our textbook, slides by Hector Garcia-Molina.
Cost based transformations Initial logical query plan Two candidates for the best logical query plan.
16.2.Algebraic Laws for Improving Query Plans Algebraic Laws for Improving Query Plans Commutative and Associative Laws Laws Involving.
CS 4432query processing1 CS4432: Database Systems II.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
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.
Joins Natural join is obtained by: R NATURAL JOIN S; Example SELECT * FROM MovieStar NATURAL JOIN MovieExec; Theta join is obtained by: R JOIN S ON Example.
The Query Compiler 16.1 Parsing and Preprocessing Meghna Jain(205) Dr. T. Y. Lin.
16.5 Introduction to Cost- based plan selection Amith KC Student Id: 109.
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.
Summary of query compilers (Section16.8) Varun Gupta Department of Computer Science ID-216 CS 257.
Algebraic Laws. {P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer.
T HE Q UERY C OMPILER Prepared by : Ankit Patel (226)
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:
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.
CPS216: Advanced Database Systems Query Rewrite Rules for Subqueries Shivnath Babu.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
Lecture 11: Query processing and optimization Jose M. Peña
Query Execution Section 15.1 Shweta Athalye CS257: Database Systems ID: 118 Section 1.
Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
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 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)
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #8.
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
The Query Compiler Parsing and Preprocessing. Meghna Jain(205)
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution.
Databases : SQL Multi-Relations 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
CS4432: Database Systems II Query Processing- Part 1 1.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Subqueries CIS 4301 Lecture Notes Lecture /23/2006.
1 Ullman et al. : Database System Principles Notes 6: Query Processing.
COMP3017 Advanced Databases
16.2.Algebraic Laws for Improving Query Plans
Prepared by : Ankit Patel (226)
The Query Compiler Parsing and Preprocessing. Meghna Jain(205)
The Relational Algebra and Relational Calculus
Focus: Relational System
Query processing and optimization
16.2.Algebraic Laws for Improving Query Plans
Algebraic Laws.
Deletion in AVL Tree There are 5 cases to consider.
16.3 Parser to Logical Query Plans
Query Compiler By:Payal Gupta Shirali Choksi Professor :Tsau Young Lin.
Completing the Physical-Query-Plan and Chapter 16 Summary ( )
Presentation transcript:

The Query Compiler Section 16.3 DATABASE SYSTEMS – The Complete Book Presented By:Under the supervision of: Deepti KunduDr. T.Y.Lin

Topics to be covered From Parse to Logical Query Plans Conversion to Relational Algebra Removing Subqueries From Conditions Improving the Logical Query Plan Grouping Associative/ Commutative Operators

16.3 From Parse to Logical Query Plans ►

Review Query Preferred logical query plan Parser Preprocessor Logical query plan generator Query Rewriter Section 16.1 Section 16.3

Two steps to turn Parse tree into Preferred Logical Query Plan Replace the nodes and structures of the parse tree, in appropriate groups, by an operator or operators of relational algebra. Take the relational algebra expression and turn it into an expression that we expect can be converted to the most efficient physical query plan.

Reference Relations StarsIn (movieTitle, movieYear, starName) MovieStar (name, address, gender, birthdate)

Conversion to Relational Algebra If we have a with a that has no subqueries, then we may replace the entire construct – the select-list, from-list, and condition – by a relational- algebra expression.

The relational-algebra expression consists of the following from bottom to top: The products of all the relations mentioned in the, which Is the argument of: A selection σ C, where C is the expression in the construct being replaced, which in turn is the argument of: A projection π L, where L is the list of attributes in the

A query : Example SELECT movieTitle FROM Starsin, MovieStar WHERE starName = name AND birthdate LIKE ‘%1960’;

SELECT movieTitle FROM Starsin, MovieStar WHERE starName = name AND birthdate LIKE ‘%1960’;

Translation to an algebraic expression tree

Removing Subqueries From Conditions For parse trees with a that has a subquery Intermediate operator – two argument selection It is intermediate in between the syntactic categories of the parse tree and the relational- algebra operators that apply to relations.

Using a two-argument σ π movieTitle σ StarsIn MovieStar IN π name starName σ birthdate LIKE ‘%1960'

Two argument selection with condition involving IN Now say we have, two arguments – some relation and the second argument is a of the form t IN S. ‘t’ – tuple composed of some attributes of R ‘S’ – uncorrelated subquery Steps to be followed: 1. Replace the by the tree that is the expression for S ( δ is used to remove duplicates) 2. Replace the two-argument selection by a one-argument selection σ C. 3. Give σ C an argument that is the product of R and S.

Two argument selection with condition involving IN σ R tINS σCσC X R δ S

The effect

Improving the Logical Query Plan Algebraic laws to improve logical query plans: Selections can be pushed down the expression tree as far as they can go. Similarly, projections can be pushed down the tree, or new projections can be added. Duplicate eliminations can sometimes be removed, or moved to a more convenient position in the tree. Certain selections can be combined with a product below to turn the pair of operations into an equijoin.

Grouping Associative/ Commutative Operators An operator that is associative and commutative operators may be though of as having any number of operands. We need to reorder these operands so that the multiway join is executed as sequence of binary joins. Its more time consuming to execute them in the order suggested by parse tree. For each portion of subtree that consists of nodes with the same associative and commutative operator (natural join, union, and intersection), we group the nodes with these operators into a single node with many children.

The effect of query rewriting Π movieTitle Starname = name StarsIn σ birthdate LIKE ‘%1960 ’ MovieStar

Final step in producing logical query plan => U U U W R ST VU UV W R S T

An Example to summarize “find movies where the average age of the stars was at most 40 when the movie was made” SELECT distinct m1.movieTitle, m1,movieYear FROM StarsIn m1 WHERE m1.movieYear – 40 <= ( SELECT AVG (birthdate) FROM StartsIn m2, MovieStar s WHERE m2.starName = s.name AND m1.movieTitle = m2.movieTitle AND m1.movieYear = m2.movieyear );

SELECT distinct m1.movieTitle, m1,movieYear FROM StarsIn m1 WHERE m1.movieYear – 40 <= ( SELECT AVG (birthdate) FROM StartsIn m2, MovieStar s WHERE m2.starName = s.name AND m1.movieTitle = m2.movieTitle AND m1.movieYear = m2.movieyear );

Selections combined with a product to turn the pair of operations into an equijoin…

Condition pushed up the expression tree…

`

Selections combined…