CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu.

Slides:



Advertisements
Similar presentations
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Advertisements

CS CS4432: Database Systems II Logical Plan Rewriting.
CS 540 Database Management Systems
CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 1 Database Systems II Introduction.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
CPS 516: Data-intensive Computing Systems Instructor: Shivnath Babu TA: Jie Li.
Query Compiler. The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical.
Chapter 14 An Overview of Query Optimization. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Figure 14.1 Typical architecture for.
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.
CS 4432query processing1 CS4432: Database Systems II.
CS Winter 2002Notes 11 CMPS 277: officially Relational Databases but this quarter Database Implementation Notes 01: Introduction Arthur Keller.
CS 4432logical query rewriting - lecture 151 CS4432: Database Systems II Lecture #15 Logical Query Rewriting Professor Elke A. Rundensteiner.
Databases and Database Management System. 2 Goals comprehensive introduction to –the design of databases –database transaction processing –the use of.
CS 245Notes 11 CS 245: Database System Principles Notes 01: Introduction Hector Garcia-Molina.
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
T HE Q UERY C OMPILER Prepared by : Ankit Patel (226)
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.
Database Systems Chapter 1 The Worlds of Database Systems.
CPS 216: Advanced Database Systems Shivnath Babu.
CPS 216: Advanced Database Systems Shivnath Babu Fall 2006.
Advanced Database Systems Notes:Query Processing (Overview) Shivnath Babu.
CS4432Notes 11 CS 4432 Database Systems II Lecture 1: Introduction.
CPS216: Advanced Database Systems Notes 07:Query Execution 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.
CS4432Notes 11 CS 4432 Database Systems II Lecture 1: Introduction Professor Elke A. Rundensteiner Today: Tim Sutherland.
DBMS 2001Notes 1: Introduction1 Principles of Database Management Systems (Tietokannanhallintajärjestelmät) Pekka Kilpeläinen Fall 2001.
CSCE 520 Final Exam Study Guide. Next Class Guest Lecture on Hadoop – Dr. John Rose Interesting site: – Big Data Jobs Around The Nation (And What They.
Overviews of ITCS 6161/8161: Advanced Topics on Database Systems Dr. Jianping Fan Department of Computer Science UNC-Charlotte
CPS216: Advanced Database Systems Query Rewrite Rules for Subqueries Shivnath Babu.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
DBMS 2001Notes 5: Query Processing1 Principles of Database Management Systems 5: Query Processing Pekka Kilpeläinen (partially based on Stanford CS245.
CPS 216: Advanced Database Systems Class Project Shivnath Babu.
CPS216: Data-Intensive Computing Systems Introduction to Query Processing Shivnath Babu.
CS 4432query processing1 CS4432: Database Systems II Lecture #11 Professor Elke A. Rundensteiner.
From Relational Algebra to SQL CS 157B Enrique Tang.
Chapters 15-16a1 (Slides by Hector Garcia-Molina, Chapters 15 and 16: Query Processing.
CPS216: Advanced Database Systems Notes 09:Query Optimization (Cost-based optimization) Shivnath Babu.
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.
Data Engineering SQL Query Processing Shivnath Babu.
CPS 216: Advanced Database Systems Shivnath Babu.
CS 440 Database Management Systems Lecture 5: Query Processing 1.
Rundensteiner-CS34311 CS3431 – Database Systems I Logistics Instructor: Elke A. Rundensteiner
CS 540 Database Management Systems
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
CS4432: Database Systems II Query Processing- Part 1 1.
Database Applications (15-415) DBMS Internals- Part IX Lecture 20, March 31, 2016 Mohammad Hammoud.
Chapter 11 Database System Implementation Spring 2001 Prof. Sang Ho Lee School of Computing, Soongsil Univ.
CS3431-B111 CS3431 – Database Systems I Logistics Instructor: Mohamed Eltabakh
CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu.
1 Ullman et al. : Database System Principles Notes 6: Query Processing.
1/14/2005Yan Huang - CSCI5330 Database Implementation – Query Optimization Query Optimization.
Query Optimization Heuristic Optimization
CS 245: Database System Principles Notes 01: Introduction
CS 245: Database System Principles Notes 01: Introduction
CS4432: Database Systems II
Prepared by : Ankit Patel (226)
Focus: Relational System
CS 245: Database System Principles
Instructor 彭智勇 武汉大学软件工程国家重点实验室 电话:
Query Optimization.
CPS216: Data-Intensive Computing Systems Query Processing (contd.)
Yan Huang - CSCI5330 Database Implementation – Query Processing
CPS216: Advanced Database Systems Notes 03:Query Processing (Overview, contd.) Shivnath Babu.
CPS216: Data-Intensive Computing Systems Query Processing (Overview)
Completing the Physical-Query-Plan and Chapter 16 Summary ( )
Presentation transcript:

CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu

Query Processing Declarative SQL Query  Query Plan Focus: Relational System (i.e., data is organized as tables, or relations) NOTE: You will not be tested on how well you know SQL. Understanding the SQL introduced in class will be sufficient (a primer follows). SQL is described in Chapter 6, GMUW.

Course Outline 50% of the class is about core DBMS concepts –Query execution, query optimization, transactions, recovery, etc. –Textbook material 50% of the class is on “what is happening today in data management” –New developments on textbook material –Web search – Google, Yahoo! –Solid State Drives (Flash Drives) –Simplifying database mgmt., self-tuning databases –Data streams –Data integration (structured data + unstructured data) –Data mining

Course Logistics Reference: Database Systems: The Complete Book, by H. Garcia-Molina, J. D. Ullman, and J. Widom Web site: Grading: –Project 30% –Homework Assignments 20% –Midterm 20% –Final 30%

SQL Primer Select From Where Example Filter Query over R(A,B,C): Select B From R Where R.A = “c”  R.C > 10 We will focus on SPJ, or Select-Project-Join Queries

SQL Primer (contd.) Select From Where Example Join Query over R(A,B,C) and S(C,D,E): Select B, D From R, S Where R.A = “c”  S.E = 2  R.C = S.C We will focus on SPJ, or Select-Project-Join-Queries

RABC S CDE a11010x2 b12020y2 c21030z2 d23540x1 e34550y3 AnswerB D 2 x Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

How do we execute this query? - Do Cartesian product - Select tuples - Do projection One idea Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

R X SR.AR.BR.CS.CS.DS.E a x 2 a y 2. c x 2. Bingo! Got one... Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

Relational Algebra - can be used to describe plans Ex: Plan I  B,D  R.A =“c”  S.E=2  R.C=S.C  X RS

Relational Algebra Primer (Chapter 5, GMUW) Select:  R.A =“c”  R.C=10 Project:  B,D Cartesian Product: R X S Natural Join: R S

Relational Algebra - can be used to describe plans Ex: Plan I  B,D  R.A =“c”  S.E=2  R.C=S.C  X RS OR:  B,D [  R.A=“c”  S.E=2  R.C = S.C (RXS)]

Another idea:  B,D  R.A = “c”  S.E = 2 R(A,B,C) S(C,D,E) Plan II natural join Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

R S A B C  ( R )  ( S ) C D E a 1 10 A B C C D E 10 x 2 b 1 20c x 2 20 y 2 c y 2 30 z 2 d z 2 40 x 1 e y 3 Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

Plan III Use R.A and S.C Indexes (1) Use R.A index to select R tuples with R.A = “c” (2) For each R.C value found, use S.C index to find matching tuples (3) Eliminate S tuples S.E  2 (4) Join matching R,S tuples, project B,D attributes, and place in result

R S A B C C D E a x 2 b y 2 c z 2 d x 1 e y 3 c 7 15 AC I1I1 I2I2 =“c” check=2? output: next tuple:

parse Query rewriting Physical plan generation execute result SQL query parse tree logical query planstatistics physical query plan Query Optimization Query Execution Overview of Query Processing

Example Query Select B,D From R,S Where R.A = “c”  R.C=S.C

Example: Parse Tree SELECT FROM WHERE AND B R S R.A=“c” R.CS.C= D Select B,D From R,S Where R.A = “c”  R.C=S.C

Along with Parsing … Semantic checks –Do the projected attributes exist in the relations in the From clause? –Ambiguous attributes? –Type checking, ex: R.A > 17.5 Expand views

parse Query rewriting Physical plan generation execute result SQL query parse tree logical query plan statistics physical query plan Initial logical plan “Best” logical plan Logical plan Rewrite rules

Initial Logical Plan Relational Algebra :  B,D [  R.A=“c”  R.C = S.C (RXS)] Select B,D From R,S Where R.A = “c”  R.C=S.C  B,D  R.A = “c” Λ R.C = S.C X RS

Apply Rewrite Rule (1)  B,D [  R.C=S.C [  R.A=“c” (R X S)]]  B,D  R.A = “c” Λ R.C = S.C X RS  B,D  R.A = “c” X RS  R.C = S.C

Apply Rewrite Rule (2)  B,D [  R.C=S.C [  R.A=“c” (R)] X S]  B,D  R.A = “c” X R S  R.C = S.C  B,D  R.A = “c” X RS  R.C = S.C

Apply Rewrite Rule (3)  B,D [[  R.A=“c” (R)] S]  B,D  R.A = “c” R S  B,D  R.A = “c” X R S  R.C = S.C Natural join

parse Query rewriting Physical plan generation execute result SQL query parse tree logical query plan statistics physical query plan Initial logical plan “Best” logical plan Logical plan Rewrite rules