Status “Lifetime of a Query” –Query Rewrite –Query Optimization –Query Execution Optimization –Use cost-estimation to iterate over all possible plans,

Slides:



Advertisements
Similar presentations
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Evaluation of Relational Operations Chapter 12, Part A.
Advertisements

Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
Selinger Optimizer Lecture 10 October 15, 2009 Sam Madden.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Algorithms for SELECT and JOIN Operations (8) Implementing the JOIN Operation: Join (EQUIJOIN, NATURAL.
1 40T1 60T2 30T3 10T4 20T5 10T6 60T7 40T8 20T9 R S C C R JOIN S?
6.830 Lecture 9 10/1/2014 Join Algorithms. Database Internals Outline Front End Admission Control Connection Management (sql) Parser (parse tree) Rewriter.
Lecture 8 Join Algorithms. Intro Until now, we have used nested loops for joining data – This is slow, n^2 comparisons How can we do better? – Sorting.
CS 540 Database Management Systems
Query Execution, Concluded Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 18, 2003 Some slide content may.
Join Processing in Databases Systems with Large Main Memories
Lecture 13: Query Execution. Where are we? File organizations: sorted, hashed, heaps. Indexes: hash index, B+-tree Indexes can be clustered or not. Data.
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.
1 Implementation of Relational Operations Module 5, Lecture 1.
CS 245Notes 71 CS 245: Database System Principles Notes 7: Query Optimization Hector Garcia-Molina.
1  Simple Nested Loops Join:  Block Nested Loops Join  Index Nested Loops Join  Sort Merge Join  Hash Join  Hybrid Hash Join Evaluation of Relational.
SPRING 2004CENG 3521 Join Algorithms Chapter 14. SPRING 2004CENG 3522 Schema for Examples Similar to old schema; rname added for variations. Reserves:
1 Optimization - Selection. 2 The Selection Operation Table: Reserves(sid, bid, day, agent) A page (block) can hold 100 Reserves tuples There are 1,000.
Quick Review of Apr 22 material Sections 13.1 through 13.3 in text Query Processing: take an SQL query and: –parse/translate it into an internal representation.
Query Optimization 3 Cost Estimation R&G, Chapters 12, 13, 14 Lecture 15.
CS186 Final Review Query Optimization.
Introduction to Database Systems 1 Join Algorithms Query Processing: Lecture 1.
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.
Evaluation of Relational Operations. Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
1 Implementation of Relational Operations: Joins.
Example. Bulk Nested-Loop Joins Using Buffers: e.g. 22 blocks.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 14 – Join Processing.
Access Path Selection in a Relational Database Management System Selinger et al.
Lecture 4 - Query Optimization Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Query Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
Relational Operator Evaluation. Overview Index Nested Loops Join If there is an index on the join column of one relation (say S), can make it the inner.
RELATIONAL JOIN Advanced Data Structures. Equality Joins With One Join Column External Sorting 2 SELECT * FROM Reserves R1, Sailors S1 WHERE R1.sid=S1.sid.
Lecture 9 Query Optimization.
Implementing Natural Joins, R. Ramakrishnan and J. Gehrke with corrections by Christoph F. Eick 1 Implementing Natural Joins.
Review Jun 5th, HW#5.2 TableTupleTuple/pagePage R S R R.a = S.b S (52buffers)
CPS216: Advanced Database Systems Notes 09:Query Optimization (Cost-based optimization) Shivnath Babu.
Introduction to Query Optimization, R. Ramakrishnan and J. Gehrke 1 Introduction to Query Optimization Chapter 13.
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
CPSC 404, Laks V.S. Lakshmanan1 Evaluation of Relational Operations – Join Chapter 14 Ramakrishnan and Gehrke (Section 14.4)
Query Execution. Where are we? File organizations: sorted, hashed, heaps. Indexes: hash index, B+-tree Indexes can be clustered or not. Data can be stored.
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
CS 440 Database Management Systems Lecture 5: Query Processing 1.
More Optimization Exercises. Block Nested Loops Join Suppose there are B buffer pages Cost: M + ceil (M/(B-2))*N where –M is the number of pages of R.
Hash Tables and Query Execution March 1st, Hash Tables Secondary storage hash tables are much like main memory ones Recall basics: –There are n.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
Implementation of Database Systems, Jarek Gryz1 Evaluation of Relational Operations Chapter 12, Part A.
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.
Alon Levy 1 Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Deletes.
Chapter 13 Query Optimization Yonsei University 1 st Semester, 2015 Sanghyun Park.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Evaluation of Relational Operations Chapter 14, Part A (Joins)
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 6.
CS 440 Database Management Systems
Database Applications (15-415) DBMS Internals- Part VII Lecture 16, October 25, 2016 Mohammad Hammoud.
Data Engineering Query Optimization (Cost-based optimization)
Evaluation of Relational Operations
Database Management Systems (CS 564)
Evaluation of Relational Operations: Other Operations
Relational Operations
External Joins Query Optimization 10/4/2017
Chapters 15 and 16b: Query Optimization
Implementation of Relational Operations
Lecture 13: Query Execution
CS222P: Principles of Data Management Notes #13 Set operations, Aggregation, Query Plans Instructor: Chen Li.
Sorting We may build an index on the relation, and then use the index to read the relation in sorted order. May lead to one disk block access for each.
Yan Huang - CSCI5330 Database Implementation – Query Processing
Evaluation of Relational Operations: Other Techniques
CS222P: Principles of Data Management UCI, Fall 2018 Notes #11 Join!
Presentation transcript:

Status “Lifetime of a Query” –Query Rewrite –Query Optimization –Query Execution Optimization –Use cost-estimation to iterate over all possible plans, pick one of minimum cost –Saw how to cost 1 relation ops –Saw how to cost joins –Saw that join ordering is complex Inner vs. outer (e.g., AB ≠ BA) Join ordering (e.g., A(BC) ≠ (AB)C) Join type (e.g., nested loops vs. sort-merge) –We will return to Shapiro at the end of class O(2n-1)! Plans; n = 7 -> > 6 Billion

Selinger Pruning How does Selinger reduce the search space? –Only considers left-deep plans –Pushes all cross products to the top –Uses a dynamic programming algorithm

(Basic) Selinger Dynamic Prog Alg. if (bestPlan[S].cost ≠ ∞ ) ; array lookup ; independent of ; ordering of S return bestPlan[S] if (|S| = 1) bestPlan[S].plan = scan S bestPlan[S].cost = cost(scan S) return bestPlan[S] for each size 1 non-empty subset S 1 of S P 1 = findBestPlan(S 1 ) P 2 = findBestPlan(S - S 1 ) A = best algorithm for joining P 1, P 2 ;inner v outer? cost = P 1.cost + P 2.cost + cost(A) if (cost < bestPlan[S].cost) bestPlan[S].plan ={execute P 1.plan, execute P 2.plan, join P 1 and P 2 using A } bestPlan[S].cost = cost return bestPlan[S] findBestPlan(JoinList S)

Merge-Sort Phase 1: Repeat until S is done Read a run of S Sort Write out (Repeat with R) Phase 2: Read concurrently from each run of S and R Merge runs, then join overlapping regions

Simple Hash i=0 Choose partition of hash range {v i, v i+1 } Scan S, hash, if in partition, insert into hash table Otherwise, write back out Scan R, hash, probe into hash table, output matches Otherwise, write back out Repeat with reduced R and S, in round i+1

GRACE Hash Choose sqrt(|R|) partitions, with one page memory per partition Hash R into partitions, flushing pages as they fill Hash S into partitions, flushing pages as they fill For each partition p Build a hash table H on R tuples in p Hash S tuples in p into H, output matches

Comparison Choose sqrt(|R|) partitions, with one page memory per partition Hash R into partitions, flushing pages as they fill Hash S into partitions, flushing pages as they fill For each partition p Build a hash table H on R tuples in p Hash S tuples in p into H, output matches GRACE i=0 Choose partition of hash range {v i, v i+1 } Scan S, hash, if in partition, insert into hash table Otherwise, write back out Scan R, hash, probe into hash table, output matches Otherwise, write back out Repeat with reduced R and S, in round i+1 Simple Phase 1: Repeat until S is done Read a run of S Sort Write out (Repeat with R) Phase 2: Read concurrently from each run of S and R Merge runs, then join overlapping regions Sort-Merge