CPS216: Data-Intensive Computing Systems Query Processing (Overview)

Slides:



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

Databases and Information Systems 1 Prof. Dr. Stefan Böttcher Fakultät EIM, Institut für Informatik Universität Paderborn WS 2009 / 2010 Contents: selectivity.
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.
SQL and Relational Algebra Zaki Malik September 02, 2008.
Query Compiler. The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical.
1 Distributed Databases CS347 Lecture 14 May 30, 2001.
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 4432logical query rewriting - lecture 151 CS4432: Database Systems II Lecture #15 Logical Query Rewriting Professor Elke A. Rundensteiner.
Query Processing & Optimization
Algebraic Laws. {P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer.
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
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/COMP4910/Melikyan1 Relational Query Optimization How are SQL queries are translated into relational algebra? How does the optimizer estimates.
Advanced Databases: Lecture 8 Query Optimization (III) 1 Query Optimization Advanced Databases By Dr. Akhtar Ali.
CSCE Database Systems Chapter 15: Query Execution 1.
Advanced Database Systems Notes:Query Processing (Overview) Shivnath Babu.
CPS216: Advanced Database Systems Notes 07:Query Execution Shivnath Babu.
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.
Query Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
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.
CPS216: Data-Intensive Computing Systems Introduction to Query Processing Shivnath Babu.
CS 4432query processing1 CS4432: Database Systems II Lecture #11 Professor Elke A. Rundensteiner.
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.
CS4432: Database Systems II Query Processing- Part 2.
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.
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
CS4432: Database Systems II Query Processing- Part 1 1.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
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 Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
Query Optimization Heuristic Optimization
Advanced Database Systems: DBS CB, 2nd Edition
CPS216: Data-intensive Computing Systems
CS4432: Database Systems II
An Algebraic Query Language
CS257 Query Optimization.
The Query Compiler Parsing and Preprocessing. Meghna Jain(205)
Data Engineering Query Optimization (Cost-based optimization)
CS 245: Database System Principles
Overview of Query Optimization
Query Execution Presented by Khadke, Suvarna CS 257
CS143:Evaluation and Optimization
Lecture 21: ML Optimizers
Focus: Relational System
Database Applications (15-415) DBMS Internals- Part IX Lecture 21, April 1, 2018 Mohammad Hammoud.
CS 245: Database System Principles
Algebraic Laws.
Query Execution Presented by Jiten Oswal CS 257 Chapter 15
CPSC-608 Database Systems
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.
Query Compiler By:Payal Gupta Shirali Choksi Professor :Tsau Young Lin.
Presentation transcript:

CPS216: Data-Intensive Computing Systems Query Processing (Overview) Shivnath Babu

Query Processing Declarative SQL Query  Query Plan 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. Focus: Relational System (i.e., data is organized as tables, or relations)

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

SQL Primer (contd.) We will focus on SPJ, or Select-Project-Join-Queries Select <attribute list> From <relation list> Where <condition list> 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

R A B C S C D E a 1 10 10 x 2 b 1 20 20 y 2 c 2 10 30 z 2 d 2 35 40 x 1 e 3 45 50 y 3 Answer B 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? Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C - Do Cartesian product - Select tuples - Do projection One idea

R X S R.A R.B R.C S.C S.D S.E a 1 10 10 x 2 a 1 10 20 y 2 Select B,D . c 2 10 10 x 2 Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C Bingo! Got one...

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

Relational Algebra Primer (Chapter 5, GMUW) Select: sR.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 sR.A=“c” S.E=2  R.C=S.C X R S OR: B,D [ sR.A=“c” S.E=2  R.C = S.C (RXS)]

Another idea: Plan II B,D sR.A = “c” sS.E = 2 Select B,D 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

Select B,D R S A B C s (R) s(S) C D E a 1 10 A B C C D E 10 x 2 b 1 20 c 2 10 10 x 2 20 y 2 c 2 10 20 y 2 30 z 2 d 2 35 30 z 2 40 x 1 e 3 45 50 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 1 10 10 x 2 b 1 20 20 y 2 c 2 10 30 z 2 d 2 35 40 x 1 e 3 45 50 y 3 c 7 15 =“c” <c,2,10> A C I1 I2 <10,x,2> check=2? output: <2,x> next tuple: <c,7,15>

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

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

SELECT <SelList> FROM <FromList> WHERE <Cond> Example: Parse Tree <Query> <SFW> SELECT <SelList> FROM <FromList> WHERE <Cond> <Attribute> <SelList> <RelName> <FromList> <Cond> AND <Cond> B <Attribute> R <RelName> <Attr> <Op> <Const> D S R.A = “c” Select B,D From R,S Where R.A = “c”  R.C=S.C <Attr> <Op> <Attr> R.C = S.C

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

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

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

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

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

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

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