CPS216: Advanced Database Systems Query Rewrite Rules for Subqueries Shivnath Babu.

Slides:



Advertisements
Similar presentations
Relational Calculus   Logic, like whiskey, loses its beneficial effect when taken in too large quantities. --Lord Dunsany.
Advertisements

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.
Database Modifications CIS 4301 Lecture Notes Lecture /30/2006.
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.
Notions of clustering Clustered relation: tuples are stored in blocks mostly devoted to that relation. Clustering index: tuples (of the relation) with.
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 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.
Query Compiler By:Payal Gupta Roll No:106(225) Professor :Tsau Young Lin.
Notions of clustering Clustered file: e.g. store movie tuples together with the corresponding studio tuple. Clustered relation: tuples are stored in blocks.
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
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.
CS Spring 2002Notes 61 CS 277: Database System Implementation Notes 6: Query Processing Arthur Keller.
CS 4432query processing1 CS4432: Database Systems II.
CMSC424: Database Design Instructor: Amol Deshpande
CMSC724: Database Management Systems Instructor: Amol Deshpande
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.
Algebraic Laws. {P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer.
CS 4432query processing - lecture 121 CS4432: Database Systems II Lecture #12 Query Processing Professor Elke A. Rundensteiner.
CPS216: Advanced Database Systems Notes 03:Query Processing (Overview, contd.) Shivnath Babu.
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.
Access Path Selection in a Relational Database Management System Selinger et al.
CS 255: Database System Principles slides: From Parse Trees to Logical Query Plans By:- Arunesh Joshi Id:
Advanced Database Systems Notes:Query Processing (Overview) Shivnath Babu.
CPS216: Advanced Database Systems Notes 07:Query Execution Shivnath Babu.
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 02:Query Processing (Overview) Shivnath Babu.
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.
Dive into the Query Optimizer Dive into the Query Optimizer: Undocumented Insight Benjamin Nevarez Blog: benjaminnevarez.com
Introduction to Data Manipulation in SQL CIS 4301 Lecture Notes Lecture /03/2006.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
CPS216: Data-Intensive Computing Systems Introduction to Query Processing Shivnath Babu.
Lecture 11: Query processing and optimization Jose M. Peña
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.
Referential Integrity checks, Triggers and Assertions Examples from Chapter 7 of Database Systems: the Complete Book Garcia-Molina, Ullman, & Widom.
© D. Wong Normalization  Purpose: process to eliminate redundancy in relations due to functional or multi-valued dependencies.  Decompose relation.
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.
Data Engineering SQL Query Processing Shivnath Babu.
SQL Exercises – Part I April
CS 440 Database Management Systems Query Optimization 1.
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
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.
Subqueries CIS 4301 Lecture Notes Lecture /23/2006.
CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu.
1 Ullman et al. : Database System Principles Notes 6: Query Processing.
Chap 5. The DB Language (SQL)
16.2.Algebraic Laws for Improving Query Plans
The Query Compiler Parsing and Preprocessing. Meghna Jain(205)
Focus: Relational System
16.2.Algebraic Laws for Improving Query Plans
Algebraic Laws.
Deletion in AVL Tree There are 5 cases to consider.
Query Optimization.
16.3 Parser to Logical Query Plans
CPS216: Data-Intensive Computing Systems Query Processing (contd.)
CPS216: Advanced Database Systems Notes 03:Query Processing (Overview, contd.) Shivnath Babu.
Query Compiler By:Payal Gupta Shirali Choksi Professor :Tsau Young Lin.
Presentation transcript:

CPS216: Advanced Database Systems Query Rewrite Rules for Subqueries Shivnath Babu

More Query Rewrite Rules Transform one logical plan into another –Do not use statistics Equivalences in relational algebra Push-down predicates Do projects early Avoid cross-products if possible Use left-deep trees Use of constraints, e.g., uniqueness Subqueries  Joins (we will study this rewrite rule after we do physical plan selection)

SQL Query with an Uncorrelated Subquery Find the movies with stars born in 1960 MovieStar(name, address, gender, birthdate) StarsIn(title, year, starName) SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘%1960’ );

Parse Tree SELECT FROM WHERE IN title StarsIn ( ) starName SELECT FROM WHERE LIKE name MovieStar birthDate ‘%1960’

Generating Relational Algebra  title  StarsIn IN  name  birthdate LIKE ‘%1960’ starName MovieStar Two-argument selection

Rewrite Rule for Two-argument Selection with Conditions Involving IN  Lexp IN Rexp Two-argument selection  Lexp Rexp δ X

Applying the Rewrite Rule  title  StarsIn IN  name  birthdate LIKE ‘%1960’ starName MovieStar  title  starName=name StarsIn δ  birthdate LIKE ‘%1960’ MovieStar   name

Improving the Logical Query Plan  title starName=name StarsIn  name  birthdate LIKE ‘%1960’ MovieStar  title  starName=name StarsIn δ  birthdate LIKE ‘%1960’ MovieStar   name

SQL Query with an Correlated Subquery MovieStar(name, address, gender, birthdate) StarsIn(title, year, starName) SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE name LIKE ‘Tom%’ and year = birthdate + 30 ); Can we rewrite this query as a single-block join query?