SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.

Slides:



Advertisements
Similar presentations
Chapter 13: Query Processing
Advertisements

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.
Quick Review of Apr 17 material Multiple-Key Access –There are good and bad ways to run queries on multiple single keys Indices on Multiple Attributes.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Query Processing (overview)
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
CS Spring 2002Notes 61 CS 277: Database System Implementation Notes 6: Query Processing Arthur Keller.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
CS 4432query processing1 CS4432: Database Systems II.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
Query Processing & Optimization
©Silberschatz, Korth and Sudarshan14.1Database System Concepts 3 rd Edition Chapter 14: Query Optimization Overview Catalog Information for Cost Estimation.
Algebraic Laws. {P1,P2,…..} {P1,C1>...} parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute Pi answer.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
CS 4432query processing - lecture 121 CS4432: Database Systems II Lecture #12 Query Processing Professor Elke A. Rundensteiner.
Dr. Kalpakis CMSC 461, Database Management Systems Query Processing.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Query Processing Chapter 12
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 12 Query Processing and Optimization.
Advanced Database Systems Notes:Query Processing (Overview) Shivnath Babu.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Chapter 13 Query Processing Melissa Jamili CS 157B November 11, 2004.
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 Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
12.1Database System Concepts - 6 th Edition Chapter 12: Query Processing Overview Measures of Query Cost Selection Operation Join Operation Sorting 、 Other.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 13: Query Processing.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Chapter 13: Query Processing Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting Join Operation Other Operations.
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.
Computing & Information Sciences Kansas State University Tuesday, 03 Apr 2007CIS 560: Database System Concepts Lecture 29 of 42 Tuesday, 03 April 2007.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
CS 4432query processing1 CS4432: Database Systems II Lecture #11 Professor Elke A. Rundensteiner.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
Lecture 1- Query Processing Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Chapter 12 Query Processing. Query Processing n Selection Operation n Sorting n Join Operation n Other Operations n Evaluation of Expressions 2.
Chapter 12 Query Processing (1) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
Chapter 13: Query Processing
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Chapters 15-16a1 (Slides by Hector Garcia-Molina, Chapters 15 and 16: Query Processing.
QUERY PROCESSING RELATIONAL DATABASE KUSUMA AYU LAKSITOWENING
CS 245Notes 61 CS 245: Database System Principles Notes 6: Query Processing Hector Garcia-Molina.
Data Engineering SQL Query Processing Shivnath Babu.
Computing & Information Sciences Kansas State University Wednesday, 08 Nov 2006CIS 560: Database System Concepts Lecture 32 of 42 Monday, 06 November 2006.
13.1 Chapter 13: Query Processing n Overview n Measures of Query Cost n Selection Operation n Sorting n Join Operation n Other Operations n Evaluation.
Chapter 13: Query Processing. Overview Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions.
File Processing : Query Processing 2008, Spring Pusan National University Ki-Joune Li.
Query Processing and Query Optimization Database System Implementation CSE 507 Some slides adapted from Silberschatz, Korth and Sudarshan Database System.
Computing & Information Sciences Kansas State University Wednesday, 02 Apr 2008CIS 560: Database System Concepts Lecture 27 of 42 Wednesday, 02 April 2008.
Query Processing and Optimization Muheet Ahmed Butt.
Chapter 13: Query Processing
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
CS4432: Database Systems II Query Processing- Part 1 1.
Query Processing  Basic Steps in Query Processing – an overview  Measures of Query Cost  Query Processing- Several algorithms  Selection Operation.
CPS216: Advanced Database Systems Notes 02:Query Processing (Overview) Shivnath Babu.
1 Ullman et al. : Database System Principles Notes 6: Query Processing.
Chapter 4: Query Processing
Database Management System
Chapter 12: Query Processing
File Processing : Query Processing
Query Processing B.Ramamurthy Chapter 12 11/27/2018 B.Ramamurthy.
Focus: Relational System
Algebraic Laws.
Chapter 12 Query Processing (1)
Query Processing.
CPS216: Data-Intensive Computing Systems Query Processing (Overview)
Presentation transcript:

SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview

SCUHolliday - COEN 17814–2 Steps in Query Processing 1. Parsing and translation 2. Optimization3. Evaluation

SCUHolliday - COEN 17814–3 Steps in Query Processing Parsing and translation u Translate the query into its internal form. Put into relational algebra-like expression. u Parser checks syntax, verifies relations Optimization Evaluation u The query-execution engine takes a query- evaluation plan, executes that plan, and returns the answers to the query.

SCUHolliday - COEN 17814–4 Optimization A relational algebra expression may have many equivalent expressions u E.g.,  balance  2500 (  balance (account)) is equivalent to  balance (  balance  2500 (account)) Each relational algebra operation can be evaluated using one of several different algorithms Annotated expression specifying detailed evaluation strategy is called an evaluation-plan. u E.g., can use an index on balance to find accounts with balance < 2500, u or can perform complete relation scan and discard accounts with balance  2500

SCUHolliday - COEN 17814–5 Query Optimization Amongst all equivalent evaluation plans choose the one with lowest cost. u Cost is estimated using statistical information from the database catalog e.g. number of tuples in each relation, size of tuples, etc. We want to know u How to measure query costs u Algorithms for evaluating relational algebra operations u How to combine algorithms for individual operations in order to evaluate a complete expression

SCUHolliday - COEN 17814–6 Measures of Query Cost Cost is generally measured as total elapsed time for answering query u Many factors contribute to time cost disk accesses, CPU, or even network communication Typically disk access is the predominant cost, and is also relatively easy to estimate. Measured by taking into account u Number of seeks * average-seek-cost u Number of blocks read * average-block-read-cost u Number of blocks written * average-block-write-cost Cost to write a block is greater than cost to read a block –data is read back after being written to ensure that the write was successful

SCUHolliday - COEN 17814–7 Cost For simplicity we just use number of block transfers from disk as the cost measure u We also ignore CPU costs for simplicity Costs depends on the size of the buffer in main memory u Having more memory reduces need for disk access u Amount of real memory available to buffer depends on other concurrent OS processes, and hard to determine ahead of actual execution u We often use worst case estimates, assuming only the minimum amount of memory needed for the operation is available Real systems take CPU cost into account, differentiate between sequential and random I/O, and take buffer size into account

SCUHolliday - COEN 17814–8 Example RABC S CDE a11010x2 b12020y2 c21030z2 d23540x1 e34550y3

SCUHolliday - COEN 17814–9 Example Select B,D From R,S Where R.A = “c” and S.E = 2 and R.C=S.C  B,D (  R.A =“c”  S.E=2  R.C=S.C )(R X S)

SCUHolliday - COEN 17814–10 RABC S CDE a11010x2 b12020y2 c21030z2 d23540x1 e34550y3 AnswerB D 2 x

SCUHolliday - COEN 17814–11 How do we execute query? - Do Cartesian product - Select tuples - Do projection One idea

SCUHolliday - COEN 17814–12 RXSR.AR.BR.CS.CS.DS.E a x 2 a y 2. C x 2. Bingo! Got one...

SCUHolliday - COEN 17814–13 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)]

SCUHolliday - COEN 17814–14 Another idea:  B,D  R.A = “c”  S.E = 2 R S Plan II natural join

SCUHolliday - COEN 17814–15 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

SCUHolliday - COEN 17814–16 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

SCUHolliday - COEN 17814–17 R S A B C C D E a x 2 b y 2 c z 2 d x 1 e y 3 AC I1I1 I2I2 =“c” check=2? output: next tuple:

SCUHolliday - COEN 17814–18 Example: SQL query SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘%1960’ ); (Find the movies with stars born in 1960) StarsIn = title, year, starName MovieStar = name, address, gender, birthdate

SCUHolliday - COEN 17814–19 Example: Parse Tree SELECT FROM WHERE IN title StarsIn ( ) starName SELECT FROM WHERE LIKE name MovieStar birthDate ‘%1960’

SCUHolliday - COEN 17814–20 Example: Generating Relational Algebra  title  StarsIn IN  name  birthdate LIKE ‘%1960’ starName MovieStar Fig. 7.15: An expression using a two-argument , midway between a parse tree and relational algebra

SCUHolliday - COEN 17814–21 Example: Logical Query Plan  title  starName=name StarsIn  name  birthdate LIKE ‘%1960’ MovieStar Fig. 7.18: Applying the rule for IN conditions 

SCUHolliday - COEN 17814–22 Example: Improved Logical Query Plan  title starName=name StarsIn  name  birthdate LIKE ‘%1960’ MovieStar Fig. 7.20: An improvement on fig Question: Add project to StarsIn?

SCUHolliday - COEN 17814–23 Example: Estimate Result Sizes Need expected size StarsIn MovieStar 

SCUHolliday - COEN 17814–24 Selection Operation File scan – search algorithms that locate and retrieve records that fulfill a selection condition. Algorithm A1 (linear search). Scan each file block and test all records to see whether they satisfy the selection condition. u Cost estimate (number of disk blocks scanned) = b r u If selection is on a key attribute, cost = ( b r /2) stop on finding record u Linear search can be applied regardless of selection condition or ordering of records in the file, or availability of indices

SCUHolliday - COEN 17814–25 Selection continued A2 (binary search). Applicable if selection is an equality comparison on the attribute on which file is ordered. u Assume that the blocks of a relation are stored contiguously u Cost estimate (number of disk blocks to be scanned):  log 2 (b r )  — cost of locating the first tuple by a binary search on the blocks Plus number of blocks containing records that satisfy selection condition

SCUHolliday - COEN 17814–26 Selection with Index Scan A3 (primary index on candidate key, equality). Retrieve a single record that satisfies the corresponding equality condition A4 (primary index on nonkey, equality) Retrieve multiple records. u Records will be on consecutive blocks A5 (equality on search-key of secondary index). u Retrieve a single record if the search-key is a candidate key u Retrieve multiple records if search-key is not a candidate key Can be very expensive! each record may be on a different block – one block access for each retrieved record

SCUHolliday - COEN 17814–27 Cross Product and Join We want a way to estimate the size of the results of joins and cross products. The cross product r  s contains n r * n s tuples and each tuple occupies b r + b s bytes If R  S = , then r s is the same as r  s

SCUHolliday - COEN 17814–28 Join Size Estimation If R  S is a key for R, then we know that a tuple of s will join with at most one tuple from r, so the number of tuples in r s is no greater than the number of tuples in s. If R  S is a foreign key for S referencing R, then the number of tuples in r s is exactly the number of tuples in s. R S AX 35… 36… 37… KA k135 k235 k337

SCUHolliday - COEN 17814–29 parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute {P1,P2,…..} {(P1,C1),(P2,C2)...} Pi answer SQL query parse tree logical query plan “improved” l.q.p l.q.p. +sizes statistics