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

Slides:



Advertisements
Similar presentations
CS CS4432: Database Systems II Logical Plan Rewriting.
Advertisements

CS 540 Database Management Systems
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
Query Compiler. The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical.
CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 183 Database Systems II Query Compiler.
Query Execution Professor: Dr T.Y. Lin Prepared by, Mudra Patel Class id: 113.
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
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.
Query Optimization CS 157B Ch. 14 Mien Siao. Outline Introduction Steps in Cost-based query optimization- Query Flow Projection Example Query Interaction.
CPS216: Advanced Database Systems Notes 06:Query Execution (Sort and Join operators) Shivnath Babu.
Review “Query Languages” Algebra, Calculus, and SQL.
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.
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.
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.
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.
Query Execution Section 15.1 Shweta Athalye CS257: Database Systems ID: 118 Section 1.
Chapters 15-16a1 (Slides by Hector Garcia-Molina, Chapters 15 and 16: Query Processing.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CPS216: Advanced Database Systems Notes 09:Query Optimization (Cost-based optimization) Shivnath Babu.
CS4432: Database Systems II Query Processing- Part 2.
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #8.
QUERY PROCESSING RELATIONAL DATABASE KUSUMA AYU LAKSITOWENING
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.
CS 440 Database Management Systems Lecture 5: Query Processing 1.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
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.
Query Processing COMP3017 Advanced Databases Nicholas Gibbins
CS4432: Database Systems II Query Processing- Part 1 1.
Database Applications (15-415) DBMS Internals- Part IX Lecture 20, March 31, 2016 Mohammad Hammoud.
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.
CS4432: Database Systems II
Prepared by : Ankit Patel (226)
Data Engineering Query Optimization (Cost-based optimization)
CS 245: Database System Principles
Overview of Query Optimization
Indexes.
CS143:Evaluation and Optimization
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 Processing CSD305 Advanced Databases.
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)
Presentation transcript:

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

DataBase Management System (DBMS)High-level Query Q DBMS Data Answer Translates Q into best execution plan for current conditions, runs plan

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.

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 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

parse Query rewriting Physical plan generation execute result SQL query parse tree Best logical query plan statistics Best physical query plan

Physical Plan Generation  B,D  R.A = “c” R S Natural join Best logical plan RS Index scan Table scan Hash join Project

parse Query rewriting Physical plan generation execute result SQL query parse tree Best logical query plan statistics Best physical query plan Enumerate possible physical plans Find the cost of each plan Pick plan with minimum cost

Physical Plan Generation Logical Query Plan P1 P2 …. Pn C1 C2 …. Cn Pick minimum cost one Physical plans Costs

parse Query rewriting Physical plan generation execute result SQL query parse tree logical query planstatistics physical query plan Query Processing - In class order