Initial QGM. Q1.CDept=‘mgmt’ And Q1.Grade>=Q2.$1 took Max took Q1 Q2 Q3 SELECT Grade FROM took Q3 WHERE Q3.CName=Q1.CName SELECT Max(Grade) AS Grade FROM.

Slides:



Advertisements
Similar presentations
SQL: The Query Language Part 2
Advertisements

Examples of Physical Query Plan Alternatives
Query Optimization Reserves Sailors sid=sid bid=100 rating > 5 sname (Simple Nested Loops) Imperative query execution plan: SELECT S.sname FROM Reserves.
Query Optimization May 31st, Today A few last transformations Size estimation Join ordering Summary of optimization.
Joining Relations in SQL Objectives of the Lecture : To consider the Natural & Generalised Joins using the SQL1 standard; To consider the Natural & Generalised.
Lecture 07: Relational Algebra
Implementation of Relational Operations (Part 2) R&G - Chapters 12 and 14.
Final Jeopardy Question Type Category 1 Here. Type Category 2 Here 100 Type Category 4 Here Type Category 5 Here Type.
Query Optimization Goal: Declarative SQL query
Incremental Maintenance for Non-Distributive Aggregate Functions work done at IBM Almaden Research Center Themis Palpanas (U of Toronto) Richard Sidle.
Oct 28, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
Querying Database ISYS 363. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy.
S. KWAN Relational Join1 A Relational Join operation could be thought of as being implemented with a series of operations: CARTESIAN PRODUCT RELATIONAL.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Magic Decorrelation: An Optimization Technique for SQL queries CS525 Lecture WPI.
Chapter 4 Parallel Sort and GroupBy 4.1Sorting, Duplicate Removal and Aggregate 4.2Serial External Sorting Method 4.3Algorithms for Parallel External Sort.
CS186 Final Review Query Optimization.
Querying Database ISYS 363. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy.
Querying Database. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy Calculated.
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.
Query Optimization R&G, Chapter 15 Lecture 16. Administrivia Homework 3 available today –Written exercise; will be posted on class website –Due date:
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
More SQL: Complex Queries, Triggers, Views, and Schema Modification UMM AL QURA UNIVERSITY College of Computer Dr. Ali Al Najjar 1.
SQL Queries and Subqueries Zaki Malik September 04, 2008.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4– Structured Query.
Jennifer Widom Relational Design Theory Boyce-Codd Normal Form.
Relational Operator Evaluation. Overview Index Nested Loops Join If there is an index on the join column of one relation (say S), can make it the inner.
Box 1Box 4Box 3Box 2 Box 5Box 8Box 7Box 6 My Shadow Box.
Query Optimization Imperative query execution plan: Declarative SQL query Ideally: Want to find best plan. Practically: Avoid worst plans! Goal: Purchase.
1 XQuery to SQL by XML Algebra Tree Brad Pielech, Brian Murphy Thanks: Xin.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 5 © Akhilesh Bajaj, 2000, 2002, 2003, All.
1 Database Systems ( 資料庫系統 ) December 3, 2008 Lecture #10.
Copyright © Curt Hill Queries in SQL More options.
Optimization of Nested Queries Sujatha Thanigaimani COSC 6421.
Further GroupBy & Extend Operations Objectives of the Lecture : To consider “whole relation” Grouping; To consider the SQL Grouping option Having; To consider.
Copyright 2003 Curt Hill Queries in SQL Syntax and semantics.
Querying Database ISYS 363.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Introduction to Query Optimization Chapter 13.
1 SQL Additional Notes. 2  1 Group and Aggregation*  2 Execution Order*  3 Join*  4 Find the maximum  5 Line Format SQL Additional Notes *partially.
9 th Grade Spelling Test By: Tara Geidel Word #1 Please type word in the box.
1 SY306 Web and Databases for Cyber Operations Set #13: SQL SELECT Grouping and sub-queries.
Leafy Maths. Investigating leaf size for different trees How can we collect a random sample of 20 leaves? What measurement shall we take?
1 Database Systems ( 資料庫系統 ) Chapter 12 Overview of Query Evaluation November 22, 2004 By Hao-hua Chu ( 朱浩華 )
Chapter 7 SQL HUANG XUEHUA. SQL Select-From-Where Statements SELECT desired attributes FROM one or more tables WHERE condition about tuples of the tables;
南京菩提小组义务献血记实 时近年关, 2012 年 1 月 12 日上午,较平时冷 清的江苏省血液中心采血处忽然热闹起来, 原来是南京菩提小组的道友们集中在此集体 义务献血。
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Introduction To Query Optimization and Examples Chpt
如何利用图书馆 ——— 海南师范大学图书馆( 2014 ) ——— 海南师范大学图书馆( 2014 )
1 CS122A: Introduction to Data Management Lecture 9 SQL II: Nested Queries, Aggregation, Grouping Instructor: Chen Li.
The Counting Game Let’s count from 1 to 10 With the Bunnies.
MMS Parent Portal Do you want to see your child’s grades?
SQL : Query Language Part II CS3431.
Examples of Physical Query Plan Alternatives
Relational Design Theory
Relational Databases Relational Algebra (2)
January 19th – Subqueries 2 and relational algebra
Querying Database ISYS 363.
SQL: Structured Query Language
Number Patterns Grade 6 Patterning Unit.
SQL: Structured Query Language
CS222P: Principles of Data Management Notes #13 Set operations, Aggregation, Query Plans Instructor: Chen Li.
Instructors: Winston Hsu, Hao-Hua Chu Fall 2010
An ABC Book by.
An ABC Book by.
An ABC Book by.
Utah ABC Book By: Period:.
SQL: The Query Language (Part III)
SQL: Structured Query Language
What about −(−6) ? What quantity is in the box?.
Presentation transcript:

Initial QGM

Q1.CDept=‘mgmt’ And Q1.Grade>=Q2.$1 took Max took Q1 Q2 Q3 SELECT Grade FROM took Q3 WHERE Q3.CName=Q1.CName SELECT Max(Grade) AS Grade FROM Child Q4 Q4 SELECT Q1.SName FROM took Q1, temp1 Q2 WHERE Q1.CDept = ‘mgmt’ AND Q1.Grade >= Q2.$1 temp1 SName, CName, CDept, Grade CName, Grade

Performing Feed for the topmost Box

Q1.Grade>=Q2.$1 CDept=‘mgmt’ Max Q1 Q2 supp took distinct Magic_1 SELECT DISTINCT CName FROM supp SELECT MAX (Grade) AS Grade FROM Child SName, CName, CDept, Grade SName, CName, Grade SELECT Q1.SName FROM took Q1, temp1 Q2 WHERE Q1.Grade >= Q2.$1 temp1 Q4 Grade

Q1.Grade>=Q2.$1 CDept=‘mgmt’ Max Q1 Q2 supp took distinct Magic_1 DCOBox SELECT Q4.cName, Q5.$1 FROM Magic_1 Q4, temp1 Q5 Q3.CName=Q1.CName CIBox SELECT Q3.Grade FROM DCOBox Q3 WHERE Q3.CName = Q1.CName Q4Q5 Q3 CName SELECT Q1.SName FROM took Q1, CIBox Q2 WHERE Q1.Grade >= Q2.$1 SName, CName, Grade SName, CName, CDept, Grade CName CName, Grade Grade temp1 Q6

Can merge the C1Box and the topmost box into one box as every tuple in the topmost box joins with atmost one tuple in the C1Box

Q1.Grade>=Q2.Grade Q1.cName=Q2.cName CDept=‘mgmt’ Max Q1 Q2 supp took distinct Magic_1 DCOBox SELECT Q4.cName,Q5.$1 FROM Magic_1 Q4, temp1 Q5 Q4Q5 CName SELECT Q1.sName FROM supp Q1, DCOBox Q2 WHERE Q1.cName=Q2.cName AND Q1.Grade>=Q2.Grade temp1 SName, CName, CDept, Grade SName, CName, Grade CName CName, Grade Grade Q6

Starting Point for the Aggregation Box

Max distinct Magic_1 DCOBox Q4Q5 Q4.CName=Q3.CName Q3 took CName, Grade SELECT Q4.CName, Q5.$1 AS Grade FROM Magic_1 Q4, temp1 Q5 temp1 CName CName, Grade Q6 SELECT Max(Grade) AS Grade FROM Child Q6 SELECT Grade FROM took Q3 WHERE Q3.CName=Q1.CName Grade

Performing Feed for the aggregate Box

Max distinct Magic_1 DCOBox Q4Q5 Q1.CName=Q3.CName Q3 took CName, Grade SELECT Q4.CName,Q5.$1 From Magic_1 Q4, temp1 Q5 Q7.cName=Q4.cName CIBox Q7 DCOBox Q8Q9 distinct Magic_2 CName CName, Grade Grade temp1 SELECT Grade FROM DCOBox Q7 WHERE Q7.CName = Q4.CName SELECT Max(Grade) AS Grade FROM Child Q6 Q6 Grade SELECT Grade FROM took Q3 WHERE Q3.CName = Q1.CName SELECT Q8.CName, Q9.Grade FROM Magic_2 Q8, Child Q9

Performing Absorb for the aggregate Box – introduce the Group By and the LOJ

Max distinct Magic_1 DCOBox Q4Q5 Q1.cName=Q3.cName Q3 took CName, Grade CIBox Q7 DCOBox Q8 Q9 distinct Magic_2 SELECT CName, MAX (Grade) AS Grade FROM Child Q6 GROUPBY Q6.CName Q6 CName CName, Grade Grade CName, Grade SELECT Q4.CName, Q5.Grade FROM Magic_1 Q4 LOJ temp1 Q5 ON CName temp1

The LOJ is unnecessary here, and the C1Box is also unnecessary.

Max Q1.CName=Q3.CName Q3 took DCOBox Q8Q9 distinct Magic_2 Q6 Q1.Grade>=Q2.Grade Q1.CName=Q2.CName SELECT CName, MAX (Grade) AS Grade FROM Child Q6 GROUPBY Q6.CName CName, Grade Grade CName SELECT Q1.SName FROM supp Q1, temp1 Q2 WHERE Q1.CName = Q2.CName AND Q1.Grade >= Q2.Grade Q2 Q1 temp1

Starting Point for the bottommost SPJ Box

Q8.CName=Q3.CName Q3 took DCOBox Q8Q9 distinct Magic_2 CName Grade CName, Grade SELECT Grade FROM took Q3 WHERE Q3.CName = Q1.CName SELECT Q8.CName, Q9.Grade FROM Magic_2 Q8, temp2 Q9 temp2

Performing Absorb for the SPJ Box

Q10.CName=Q3.CName Q3 took DCOBox Q8Q9 distinct Magic_2 Q10 SELECT Q3.CName, Q3.Grade FROM Magic_2 Q10, took Q3 WHERE Q3.CName = Q10.CName SELECT Q9.CName, Q9.Grade FROM temp2 Q9 CName CName, Grade temp2

Remove unnecessary DCOBox

Q10.cName=Q3.cName Q3 took distinct Magic_2 Q10 CName, Grade CName SELECT Q3.CName, Q3.Grade FROM Magic_2 Q10, took Q3 WHERE Q3.CName = Q10.CName

The Final QGM

Q10.CName=Q3.CName Q3 took distinct Magic_2 Q10 CName, Grade Max Q6 Q1.Grade>=Q2.Grade Q1.CName=Q2.CName CDept=‘mgmt’ took SELECT Q3.CName, Q3.Grade FROM Magic_2 Q10, took Q3 WHERE Q3.CName = Q10.CName CName, Grade CName SELECT CName, MAX (Grade) AS Grade FROM Child Q6 GROUPBY Q6.CName SName, CName, CDept, Grade SName, CName, Grade CName, Grade SELECT Q1.sName FROM supp Q1, temp1 Q2 WHERE Q1.CName=Q2.CName AND Q1.Grade>=Q2.Grade Q2Q1 temp1