CS4432: Database Systems II Query Processing- Part 1 1.

Slides:



Advertisements
Similar presentations
1 Lecture 23: Query Execution Friday, March 4, 2005.
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 14, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
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.
Query Compiler. The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical.
SPRING 2004CENG 3521 Query Evaluation Chapters 12, 14.
Query Execution Optimizing Performance. Resolving an SQL query Since our SQL queries are very high level, the query processor must do a lot of additional.
COMP 451/651 Optimizing Performance
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Overview of Query Evaluation Chapter 12.
CS Spring 2002Notes 61 CS 277: Database System Implementation Notes 6: Query Processing Arthur Keller.
1 Lecture 22: Query Execution Wednesday, March 2, 2005.
1 Anna Östlin Pagh and Rasmus Pagh IT University of Copenhagen Advanced Database Technology March 25, 2004 QUERY COMPILATION II Lecture based on [GUW,
CS 4432query processing1 CS4432: Database Systems II.
1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
CS 4432query processing - lecture 171 CS4432: Database Systems II Lecture #17 Join Processing Algorithms (cont). Professor Elke A. Rundensteiner.
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.
1 Relational Operators. 2 Outline Logical/physical operators Cost parameters and sorting One-pass algorithms Nested-loop joins Two-pass algorithms.
CPS216: Advanced Database Systems Notes 03:Query Processing (Overview, contd.) Shivnath Babu.
CPS216: Advanced Database Systems Notes 06:Query Execution (Sort and Join operators) Shivnath Babu.
CSCE Database Systems Chapter 15: Query Execution 1.
Advanced Database Systems Notes:Query Processing (Overview) Shivnath Babu.
Query Execution Optimizing Performance. Resolving an SQL query Since our SQL queries are very high level, the query processor must do a lot of additional.
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.
CS 338Query Evaluation7-1 Query Evaluation Lecture Topics Query interpretation Basic operations Costs of basic operations Examples Textbook Chapter 12.
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.
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.
CS4432: Database Systems II Query Processing- Part 3 1.
CS411 Database Systems Kazuhiro Minami 11: Query Execution.
CS 257 Chapter – 15.9 Summary of Query Execution Database Systems: The Complete Book Krishna Vellanki 124.
CS4432: Database Systems II Query Processing- Part 2.
Relational Operator Evaluation. Overview Application Programmer (e.g., business analyst, Data architect) Sophisticated Application Programmer (e.g.,
Data Engineering SQL Query Processing Shivnath Babu.
CSCE Database Systems Chapter 15: Query Execution 1.
Query Processing CS 405G Introduction to Database Systems.
Lecture 17: Query Execution Tuesday, February 28, 2001.
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
Query Execution Query compiler Execution engine Index/record mgr. Buffer manager Storage manager storage User/ Application Query update Query execution.
Tallahassee, Florida, 2016 COP5725 Advanced Database Systems Query Processing Spring 2016.
1 Lecture 23: Query Execution Monday, November 26, 2001.
1 Overview of Query Evaluation Chapter Outline  Query Optimization Overview  Algorithm for Relational Operations.
Query Processing COMP3017 Advanced Databases Nicholas Gibbins
CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu.
1 Ullman et al. : Database System Principles Notes 6: Query Processing.
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
15.1 – Introduction to physical-Query-plan operators
CS 440 Database Management Systems
Database Management System
Chapter 15 QUERY EXECUTION.
Query Execution Presented by Khadke, Suvarna CS 257
Database Management Systems (CS 564)
Focus: Relational System
Query Execution Presented by Jiten Oswal CS 257 Chapter 15
Overview of Query Evaluation
Implementation of Relational Operations
Lecture 13: Query Execution
Lecture 23: Query Execution
Lecture 22: Query Execution
CPS216: Data-Intensive Computing Systems Query Processing (Overview)
Lecture 20: Query Execution
Presentation transcript:

CS4432: Database Systems II Query Processing- Part 1 1

2 Example Data: relation R (A, B, C) relation S (C, D, E) Query: SELECT B, D FROM R, S WHERE R.A = “ c ” and S.E = 2 and R.C=S.C Select B, D From R, S Where R.A = “ c ” And S.E = 2 And R.C=S.C

3 Relational Algebra – Possible Query Plans OR:  B,D [  R.A= “ c ”  S.E=2  R.C = S.C (RXS)] Plan 1 Select B, D From R, S Where R.A = “ c ” And S.E = 2 And R.C=S.C

4 Plan 2 Relational Algebra – Possible Query Plans Select B, D From R, S Where R.A = “ c ” And S.E = 2 And R.C=S.C Natural join (C is common column)

5 Select B, D From R, S Where R.A = “ c ” And S.E = 2 And R.C=S.C Plan 2

6 Plan 3 Relational Algebra – Possible Query Plans Select B, D From R, S Where R.A = “ c ” And S.E = 2 And R.C=S.C Natural join (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 Assume indexes on R.A and S.C

7 =“c”=“c” Check E=2? output: Select B, D From R, S Where R.A = “ c ” And S.E = 2 And R.C=S.C Plan 3

8 Query Compilation, Optimization and Execution

Overview of Query Execution 9 SQL Query  Compile  Optimize  Execute

Example 10 Query : Find the movies with stars born in 1960 SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘ %1960 ’ ); SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘ %1960 ’ );

Step 1: Generate Parse Tree 11

Step 2: Relational Algebra & Logical Plan 12 SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘ %1960 ’ ); SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘ %1960 ’ ); Expression TreeLogical Query Plan Expression Tree is a midway between a parse tree and relational algebra

Step 3: Optimize & Create Several Logical Plans 13 SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘ %1960 ’ ); SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘ %1960 ’ ); Plan 1 Plan 2 Question: Push project to StarsIn?

Overview of Query Execution 14 SQL Query  Compile  Optimize  Execute

Step 4: Estimate the Sizes That is done for each plan 15

Step 5: Consider Physical Plans Physical plan means how each operator will execute (which algorithm) – E.g., Join can be nested-loop, hash-based, merge-based, or sort-based Each logical plan will map to multiple physical plans 16 Logical Plan One Physical Plan

Overview of Query Execution 17 SQL Query  Compile  Optimize  Execute

Step 6: Estimate the Cost This is done for each physical plan 18 Select the cheapest to execute…

Overview of Query Execution 19 SQL Query  Compile  Optimize  Execute

Evaluating Relational Operators 20

Common Techniques Algorithms for evaluating relational operators use some simple ideas extensively: Indexing: Can use WHERE conditions to retrieve small set of tuples (selections, joins) Iteration: Sometimes, faster to scan all tuples even if there is an index. (And sometimes, we can scan the data entries in an index instead of the table itself.) Partitioning: By using sorting or hashing, we can partition the input tuples and replace an expensive operation by similar operations on smaller inputs. 21

Another Categorization One Pass Algorithms – Need one pass over the input relation(s) – Puts limitations on the size of the inputs vs. memory Two Pass Algorithms – Need two pass over the input relation(s) – Puts limitations on the size of the inputs vs. memory Multi-Pass Algorithms – Scale to any size and may need several passes over the input relation(s) 22

Common Statistics over Relation R 23 B(R): # of blocks to hold all R tuples T(R): # tuples in R S(R): # of bytes in each of R’s tuple V(R, A): # distinct values in attribute R.A M: # of memory buffers available R R R is “clustered”  R’s tuples are packed into blocks  Accessing R requires B(R) I/Os R is “not clustered”  R’s tuples are distributed over the blocks  Accessing R requires T(R) I/Os

Example: Join (R,S) 24 One Pass Iteration Open(): read S into memory GetNext(): for b in blocks of R: for t in tuples of b: if t matches tuple s: return join (t,s) return NotFound Close(): Clean memory Assume S is smaller than R Key Metrics: – M >= B(S) + 1 I/O Cost: – B(S) + B(R) Notes: – Can use prefetching for R