Dtb Database Systems. Announcement

Size: px
Start display at page:

Download "Dtb Database Systems. Announcement"

Transcription

1 Dtb Database Systems ( 資料庫系統 ) December 10, 2008 Lecture #11 1 Announcement Assignment #5 will be out on the course webpage today. 2 1

2 External Sorting Chapter 13 3 Why learn sorting again? O (n*n): bubble, insertion, selection, sorts O (n log n): heap, merge, quick, sorts Sorting huge dataset (say 10 GB) CPU time complexity may mean little on practical (database) systems Why? 4 2

3 External Sorting Defined Refer to sorting methods when the data is too large to fit in main memory. E.g., sort 10 GB of data in 100 MB of main memory. During sorting, some intermediate steps may require data to be stored externally on disk. Disk I/O cost is much greater than CPU instruction cost Average disk page I/O cost: 10 ms vs. 4 GHz CPU clock: 0.25 ns. Minimize thedisk I/Os (rather than numberof comparisons). 5 Outline (easy chapter) Why does a DMBS sort data? Simple 2 way merge sort Generalize B way merge sort Optimization Replacement sort Blocked I/O optimization Double buffering Using an existing B+ tree index vs. external sorting 6 3

4 When does a DBMS sort data? Users may want answers to query in some order E.g., students t sorted tdby increasing i age Sorting is the first step in bulk loading a B+ tree index Sorting is used for eliminating duplicate copies (in set operations) Join requires a sorting step. Sort join algorithm requires sorting. 7 Bulk Loading of a B+ Tree Step 1: Sort data entries. Insert pointer to first (leaf) page in a new (root) page. Step 2: Build Index entries for leaf pages. Root 6* 10* Sorted pages of data entries; not yet in B+ tree 3* 4* 6* 9* 10* 11* 12* 13* 20* 22* 23* 31* 35* 36* 38* 41* 44* 8 4

5 Example of Sort Merge Join sid sname rating age 22 dustin yuppy lubber guppy rusty sid bid day rname /4/96 guppy /3/96 yuppy /10/96 dustin /12/96 lubber /11/96 lubber /12/96 dustin 9 A Simple Two Way Merge Sort External sorting: data >> memory size Say you only have 3 (memory) buffer pages. You have 7 pages of data to sort. Output is a sorted file of 7 pages. How would you do it? How would you do it if you have 4 buffer pages? How would you do it if you have n buffer pages? Input file 3,4 6,2 9,4 8,7 5,6 3,1 2 Memory buffer 10 5

6 A Simple Two Way Merge Sort Basic idea is divide and conquer. Sort smaller runs and merge them into bigger runs. Pass 0: read each page, sort records in each page, and write the page out to disk. (1 buffer page is used) 3,4 6,2 9,4 8,7 5,6 3,1 2 3,4 2,6 4,9 7,8 5,6 1,3 2 2,3 4,6 2,3 4,4 6,7 8,9 4,7 8,9 1,2 2,3 3,4 4,5 6,6 7,8 9 1,3 5,6 2 1,2 3,5 6 Input file PASS 0 1-page runs PASS 1 2-page runs PASS 2 4-page runs PASS 3 8-page runs 11 A Simple Two Way Merge Sort Pass 1: read two pages, merge them, and write them out to disk. (3 buffer pages are used) Pass 2 3: repeat above step till one sorted 8 page pg run. Each run is defined as a sorted subfile. What is the disk I/O cost per run? 3,4 6,2 9,4 8,7 5,6 3,1 2 3,4 2,6 4,9 7,8 5,6 1,3 2 2,3 4,6 2,3 4,4 6,7 8,9 4,7 8,9 1,2 2,3 3,4 4,5 6,6 7,8 9 1,3 5,6 2 1,2 3,5 6 Input file PASS 0 1-page runs PASS 1 2-page runs PASS 2 4-page runs PASS 3 8-page runs 12 6

7 2 Way Merge Sort Say the number of pages in a file is 2 k : Pass 0 produces 2 k sorted runs of one page each Pass 1 produces 2 k 1 sorted runs of two pages each Pass 2 produces 2 k 2 sorted runs of four pages each Pass k produces one sorted runs of 2 k pages. Each pass requires read + write each page in file: 2*N For a N pages file, the number of passes = ceiling ( log 2 N) + 1 So total cost (disk I/Os) is 2*N*( ceiling(log 2 N) + 1) 13 General External Merge Sort More than 3 buffer pages. How can we utilize them? To sort a file with N pages using B buffer pages: Pass 0: use B buffer pages. Produce N / B sorted runs of B pages each. Pass 1..k: use B 1 buffer pages to merge B 1 runs, and use 1 buffer page for output. INPUT 1... INPUT 2 OUTPUT Disk INPUT B-1 B Main memory buffers Disk 14 7

8 General External Merge Sort (B=4) 3,4 6,2 9,4 8,7 5,6 3,1 2,10 15,3 16,5 13,8 19,1 32,8 Pass 0: Read four unsorted pages, sort them, and write them out. Produce 3 runs of 4 pages each. start start start 2,3 4,4 6,7 8,9 1,2 3,3 5,6 10,15 1,5 8,8 13,1619,32 merging 1,1 2,2 3,3 Pass 1: Read three pages, one page from each of 3 runs, merge them, and write them out. Produce 1 run of 12 pages. 15 Cost of External Merge Sort # of passes: 1 + ceiling(log B 1 ceiling(n/b)) Disk I/O Cost = 2*N*(# 2N(# of passes) E.g., with 5 buffer pages, to sort 108 page file: Pass 0: ceiling(108/5) = 22 sorted runs of length 5 pages each (last run is only 3 pages) Pass 1: ceiling(22/4) = 6 sorted runs of length 20 pages each (last run is only 8 pages) Pass 2: 2 sorted runs, of length 80 pages and 28 pages Pass 3: Sorted file of 108 pages # of passes = 1 + ceiling (log 4 ceiling(108/5)) = 4 Disk I/O costs = 2*108*4 =

9 # Passes of External Sort N B=3 B=5 B=9 B=17 B=129 B= , , , ,000, ,000, ,000, ,000,000, Further Optimization Possible? Opportunity #1: create bigger length run in pass 0 First sorted runhaslengthb. Is it possible to create bigger length in the first sorted runs? Opportunity #2: consider block I/Os Block I/O: reading & writing consecutive blocks Can the merge passes use block I/O? Opportunity #3: minimize CPU/disk idle time How to keep both CPU & disks busy at the same time? 18 9

10 Opportunity 1: create bigger runs on the 1st pass 34 3,4 62 6,2 94 9,4 87 8,7 56 5,6 31 3, ,10 15,3 16,5 13,8 19,11 32,8 Current Set Buffer Input Buffer Output Buffer 19 Replacement Sort (Optimize Merge Sort) Pass 0 can output approx. 2B sorted pages on average. How? Divide B buffer pages into 3 parts: Current set buffer (B 2): unsorted or unmerged pages. Input buffer (1 page): one unsorted page. Output buffer (1 page): output sorted page. Algorithm: Pick the tuple in the current set with the smallest k value > largest value in output buffer. Append k to output buffer. This creates a hole in current set, so move a tuple from input buffer to current set buffer. When the input buffer is empty of tuples, read in a new unsorted page

11 Replacement Sort Example (B=4) 3,4 6,2 9,4 8,7 5,6 3,1 2,10 15,3 16,5 13,8 19,1 32,8 Current Set Buffer Input Buffer Output Buffer 3,4 6,2 9,4 3,4 6,2 9,4 3,4 6,9 4 4,4 6,9 8, ,3 4 On disk 8,4 6,9 When do you start a new run? All tuple values in the current set < the last tuple value in output buffer 7 2,3 21 Minimizing I/O Cost vs. Number of I/Os So far, the cost metric is the number of disk I/Os. This is inaccuratefor tworeasons: (1) Block I/O is a much cheaper (per I/O request) than equal number of individual I/O requests. Block I/O: read/write several consecutive pages at the same time. (2) CPU cost still matters a bit. Keep CPU busy while we wait for disk I/Os. Double Buffering Technique

12 Further Optimization Possible? Opportunity #1: create bigger length run in the 1st round First sorted runhaslengthb. Is it possible to create bigger length in the first sorted runs? Opportunity #2: consider block I/Os Block I/O: reading & writing consecutive blocks is much faster than separate blocks Can the merge passes use block I/O? Opportunity #3: minimizecpu/disk idle time How to keep both CPU & disks busy at the same time? 23 General External Merge Sort (B=4) How to change it to Block I/O (block = 2 pages)? 3,4 6,2 9,4 8,7 5,6 3,1 2,10 15,3 16,5 13,8 19,1 32,8 Pass 0: Read four unsorted pages, sort them, and write them out. Produce 3 runs of 4 pages each. start start start 2,3 4,4 6,7 8,9 1,2 3,3 5,6 10,15 1,5 8,8 13,1619,32 merging 1,1 2,2 3,3 Pass 1: Read three pages, one page from each of 3 runs, merge them, and write them out. Produce 1 run of 12 pages

13 Block I/O Block access: read/write b pages as a unit. Assume the buffer pool has B pages, and file has N pages. Look at cost of external merge sort (with replacement optimization) using Block I/O: Block I/O has little affect on pass 0. Pass 0 produces initial N (= N/2B) runs of length 2B pages. Pass 1..k, we can merge F= B/b 1 runs. The total number of passes (to create one run of N pages) is 1 + log F (N ). 25 Further Optimization Possible? Opportunity #1: create bigger length run in the 1st round First sorted runhaslengthb. Is it possible to create bigger length in the first sorted runs? Opportunity #2: consider block I/Os Block I/O: reading & writing consecutive blocks Can the merge passes use block I/O? Opportunity #3: minimize CPU/disk idle time While CPU is busy sorting or merging, disk is idle. How to keep both CPU & disks busy at the same time? 26 13

14 Double Buffering Keep CPU busy, minimizes waiting for I/O requests. While the CPU is working on the current run, start to prefetch data for the next run (called shadow blocks). Potentially, more passes; in practice, most files still sorted in 2 3 passes. INPUT 1 INPUT 1' INPUT 2 OUTPUT INPUT 2' OUTPUT' Disk INPUT k INPUT k' b block size Disk B main memory buffers, k-way merge 27 Using B+ Trees for Sorting Assumption: Table to be sorted has B+ tree index on sorting column(s). Idea: Can retrieve records in order by traversing leaf pages. Is this a good idea? Cases to consider: B+ tree is clustered B+tree is notclustered 28 14

15 Clustered B+ Tree Used for Sorting Cost: root to the leftmost leaf, then retrieve all leaf pages (Alternative 1) If Alternative 2 is used? Additional cost of retrieving data records: each page fetched just once. Cost better than external sorting? Data Records Index (Directs search) Data Entries ("Sequence set") 29 Unclustered B+ Tree Used for Sorting Alternative(2) for data entries; each data entry contains rid of a data record. In general, one I/O per data record. Index (Directs search) Data Entries ("Sequence set") Data Records 30 15

16 External Sorting vs. Unclustered Index N Sorting p=1 p=10 p= ,000 10,000 1,000 2,000 1,000 10, ,000 10,000 40,000 10, ,000 1,000, , , ,000 1,000,000 10,000,000 1,000,000 8,000,000 1,000,000 10,000, ,000,000 10,000,000 80,000,000 10,000, ,000,000 1,000,000,000 * p: # of records per page * B=1,000 and block size=32 for sorting * p=100 is the more realistic value. 31 We are done with Chapter 13 Chapter 14 (only section 14.4) 32 16

17 Equality Joins With One Join Column SELECT * FROM Reserves R1, Sailors S1 WHERE R1.sid=S1.sid R S is very common, so must be carefully optimized. R X S is large; so, R X S followed by a selection is inefficient. Assume: M pages in R, p R tuples per page, N pages in S, p S tuples per page. In our examples, R is Reserves and S is Sailors. We will consider more complex join conditions later. 33 Two Classes of Algorithms to Implement Join Operation Algorithms in class 1 require enumerating all tuples in the cross product and discardtuples thatdo not meetthe the join condition. Simple Nested Loops Join Blocked Nested Loops Join Algorithms in class 2 avoid enumerating the cross product. Index Nested Loops Join Sort Merge Join Hash Join 34 17

18 Simple Nested Loops Join foreach tuple r in R do foreach tuple s in S do if ri == sj then add <r, s> to result For each tuple in the outer relation R, scan the entire inner relation S (scan S total of p R * Mtimes!). Cost: M + p R * M * N = *1000*500 I/Os => very huge. How can we improve simple nested loops join? 35 Page Oriented Nested Loops Join foreach page of R do foreach page of S do for all matching tuples r in R block and s in S page, add <r, s> to result Cost: M + M*N = *500 = 501,000 => still huge. If smaller relation (S) is outer, cost = *1000 = 500,

19 Block Nested Loops Join foreach block of B 2 pages of R do foreach page of S do for all matching tuples r in R block and s in S page, add <r, s> to result Use one page as an input buffer for scanning the inner S, one page as the output buffer, and use all remaining pages to hold ``block ofouter outer R. For each matching tuple r in R block, s in S page, add <r, s> to result. Then read next R block, scan S, etc. 37 Block Nested Loops Join: Efficient Matching Pairs If B is large, it may be slow to find matching pairs between tuplesin S page and R block (R block hasb 2 pages). The solution is to build a main memory hash table for R block. R & S... Hash table for block of R... Join Result... Input buffer for S Output buffer 38 19

20 Examples of Block Nested Loops Cost: Scan of outer + #outer blocks * scan of inner #outer blocks = ceiling (# of pages of outer / blocksize) With Reserves (R) as outer, and 102 buffer pages: Cost of scanning R is 1000 I/Os; a total of 10 blocks. Per block of R, scan Sailors (S); 10*500 I/Os. Total cost = * 500 = 6000 page I/Os => huge improvement over page oriented nested loops join. With 100 page block of Sailors as outer: Cost of scanning S is 500 I/Os; a total of 5 blocks. Per block of S, we scan Reserves; 5*1000 I/Os. Total cost = *1000 = 5500 page I/Os For blocked access (block I/Os are more efficient), it may be best to divide buffers evenly between R and S. 39 Index Nested Loops Join foreach tuple r in R do foreach tuple s in S where ri == sj do add <r, s> to result If there is an index on the join column of one relation (say S), can make it the inner and exploit the index. Cost: M + ( (M*p R ) * cost of finding matching S tuples) For each R tuple, cost of probing S index is about 1.2 for hash index, 2 4 for B+ tree. Cost of finding S tuples (assume Alt. (2) or (3) for data entries) depends on clustering. Clustered index: 1 I/O (typical) Unclustered index: up to 1 I/O per matching S tuple

21 Examples of Index Nested Loops Hash index (Alt. 2) on sid of Sailors (as inner): Scan Reserves: 1000 page I/Os, 100*1000 tuples. For each Reserves tuple: 1.2 I/Os to get data entry in index, plus 1 I/O to get (the exactly one) matching Sailors tuple. Total: ,000 * 2.2 = 221,000 I/Os. Hash index (Alt. 2) on sid of Reserves (as inner): Scan Sailors: 500 page I/Os, 80*500 tuples. For each Sailors tuple: 1.2 I/Os to find index page with data entries, plus cost of retrieving matching Reserves tuples. Assume uniform distribution, 2.5 reservations per sailor (100,000 / 40,000). Cost of retrieving them is 1 or 2.5 I/Os depending on whether the index is clustered. Total (Clustered): ,000 * 2.2 = 88,500 I/Os. Given choices, put the relation with higher # tuples as inner loop. Index Nested Loop performs better than simple nested loop. 41 Sort Merge Join Sort R and S on the join column [merge sort], then scan them to do a ``merge (on join col.) [scan merge], and output result tuples. Scan merge: Advance scan of R until current R tuple >= current S tuple, then advance scan of S until current S tuple >= current R tuple; do this until current R tuple = current S tuple. At this point, all R tuples with same value in Ri (current R group) and all S tuples with same value in Sj (current S group) match; output <r, s> for all pairs of such tuples. Then resume scanning R and S

22 Scan Merge Gs sid sname rating age Ts 1 22 dustin yuppy a 3a 5 28 lubber b 3b 5a 44 guppy b 58 rusty a 6b Tr sid bid day rname /4/96 guppy /3/96 yuppy /10/96 dustin /12/96 lubber /11/96 lubber /12/96 dustin 43 Cost of Merge Sort Join R is scanned once; each S group is scanned once per matching R tuple. (Multiple scans of an S group are likely to find needed pages in buffer.) Cost: 2 (M log M + N log N) + (M+N) Assume enough buffer pages to sort both Reserves and Sailors in 2 passes The cost of merge sorting two relations is 2 M log M + 2 N log N. The cost of scan merge two sorted relations is M+N. Total join cost: 2*2* *2* = 7500 page I/Os. Any possible refinement to reduce cost? 44 22

23 Refinement of Sort Merge Join Combine the merging phase in sorting with the scan merge for the join. Allocate one buffer space for each run (in the merge pass) in R & S. Buffer size B > squar_root(l), where L is the size of the larger relation. Why? # runs = 2(L/2B) = L/B < B [replacement sort] Cost: read+write each relation in Pass 0 + read each relation in (only) merging pass (not counting the writing of result tuples). Cost goes down from 7500 to 4500 I/Os L R S sort-merge scan-merge 45 Hash Join Hash both relations on the join attribute using the same hash function h. Tuples in R partition_i (bucket) can only match with tuples in S partition_i. For i=1..k, check for matching pairs in R partition_i and S partition_i. Forefficient matching pairs, apply hashing to tuples of R partition using another hash function h

24 Hash Join Partition both relations using hash fn h: R tuples in partition i will only match S tuples in partition i. Read in a partition of R, hash it using h2 (<> h!). Scan matching partition of S, search for matches. Original Relation... Disk Partitions of R & S OUTPUT INPUT 2 hash function h B-1 B main memory buffers hash fn h2 Hash table for partition Ri h2 1 Partitions 1 2 B-1 Disk Join Result Disk Input buffer for Si Output buffer B main memory buffers Disk47 Observations on Hash Join #partitions k < B 1 (need one buffer page for reading), and B 2 > size of largest partition to be held in memory. Assume uniformly sized partitions, and maximize k, we get: k= B 1, and B 2 > M/(B 1), i.e., B must be > square_root(m) M If we build an in memory hash table to speed up the matching of tuples, a little more memory is needed. If the hash function does not partition uniformly, one or more R partitions may not fit in memory. Canapply apply hash join technique recursively to do the join of this R partition with corresponding S partition

25 Cost of Hash Join In partitioning phase, read+write both relns; 2(M+N). Inmatching phase, readboth relns; M+N I/Os. In our running example, this is a total of 4500 I/Os. Sort Merge Join vs. Hash Join: Same amount of buffer pages. Same cost of 3(M+N) I/Os. Hash hjoin shown to be highly hl parallelizable. li Sort Merge less sensitive to data skew; result is sorted. 49 Complex Join Conditions So far, we have only discussed single equality join condition. How about equalities over several attributes? (e.g., R.sid=S.sid AND R.rname=S.sname): For Index Nested Loops join, build index on <sid, sname> on R(if R is inner); or use existing indexes on sid or sname. For Sort Merge and Hash Join, sort/partition on combination of the two join columns

Implementation of Relational Operations

Implementation of Relational Operations Implementation of Relational Operations Module 4, Lecture 1 Database Management Systems, R. Ramakrishnan 1 Relational Operations We will consider how to implement: Selection ( ) Selects a subset of rows

More information

Evaluation of Relational Operations. Relational Operations

Evaluation of Relational Operations. Relational Operations Evaluation of Relational Operations Chapter 14, Part A (Joins) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Relational Operations v We will consider how to implement: Selection ( )

More information

Implementing Joins 1

Implementing Joins 1 Implementing Joins 1 Last Time Selection Scan, binary search, indexes Projection Duplicate elimination: sorting, hashing Index-only scans Joins 2 Tuple Nested Loop Join foreach tuple r in R do foreach

More information

Evaluation of Relational Operations

Evaluation of Relational Operations Evaluation of Relational Operations Yanlei Diao UMass Amherst March 13 and 15, 2006 Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Relational Operations We will consider how to implement: Selection

More information

Evaluation of Relational Operations

Evaluation of Relational Operations Evaluation of Relational Operations Chapter 12, Part A Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Relational Operations We will consider how to implement: Selection ( ) Selects a subset

More information

Evaluation of relational operations

Evaluation of relational operations Evaluation of relational operations Iztok Savnik, FAMNIT Slides & Textbook Textbook: Raghu Ramakrishnan, Johannes Gehrke, Database Management Systems, McGraw-Hill, 3 rd ed., 2007. Slides: From Cow Book

More information

Implementation of Relational Operations. Introduction. CS 186, Fall 2002, Lecture 19 R&G - Chapter 12

Implementation of Relational Operations. Introduction. CS 186, Fall 2002, Lecture 19 R&G - Chapter 12 Implementation of Relational Operations CS 186, Fall 2002, Lecture 19 R&G - Chapter 12 First comes thought; then organization of that thought, into ideas and plans; then transformation of those plans into

More information

Evaluation of Relational Operations

Evaluation of Relational Operations Evaluation of Relational Operations Chapter 14 Comp 521 Files and Databases Fall 2010 1 Relational Operations We will consider in more detail how to implement: Selection ( ) Selects a subset of rows from

More information

Overview of Query Processing. Evaluation of Relational Operations. Why Sort? Outline. Two-Way External Merge Sort. 2-Way Sort: Requires 3 Buffer Pages

Overview of Query Processing. Evaluation of Relational Operations. Why Sort? Outline. Two-Way External Merge Sort. 2-Way Sort: Requires 3 Buffer Pages Overview of Query Processing Query Parser Query Processor Evaluation of Relational Operations Query Rewriter Query Optimizer Query Executor Yanlei Diao UMass Amherst Lock Manager Access Methods (Buffer

More information

Announcement. Reading Material. Overview of Query Evaluation. Overview of Query Evaluation. Overview of Query Evaluation 9/26/17

Announcement. Reading Material. Overview of Query Evaluation. Overview of Query Evaluation. Overview of Query Evaluation 9/26/17 Announcement CompSci 516 Database Systems Lecture 10 Query Evaluation and Join Algorithms Project proposal pdf due on sakai by 5 pm, tomorrow, Thursday 09/27 One per group by any member Instructor: Sudeepa

More information

CAS CS 460/660 Introduction to Database Systems. Query Evaluation II 1.1

CAS CS 460/660 Introduction to Database Systems. Query Evaluation II 1.1 CAS CS 460/660 Introduction to Database Systems Query Evaluation II 1.1 Cost-based Query Sub-System Queries Select * From Blah B Where B.blah = blah Query Parser Query Optimizer Plan Generator Plan Cost

More information

CompSci 516 Data Intensive Computing Systems

CompSci 516 Data Intensive Computing Systems CompSci 516 Data Intensive Computing Systems Lecture 9 Join Algorithms and Query Optimizations Instructor: Sudeepa Roy CompSci 516: Data Intensive Computing Systems 1 Announcements Takeaway from Homework

More information

Sorting a file in RAM. External Sorting. Why Sort? 2-Way Sort of N pages Requires Minimum of 3 Buffers Pass 0: Read a page, sort it, write it.

Sorting a file in RAM. External Sorting. Why Sort? 2-Way Sort of N pages Requires Minimum of 3 Buffers Pass 0: Read a page, sort it, write it. Sorting a file in RAM External Sorting Chapter 13 Three steps: Read the entire file from disk into RAM Sort the records using a standard sorting procedure, such as Shell sort, heap sort, bubble sort, Write

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals- Part VIII Lecture 16, March 19, 2014 Mohammad Hammoud Today Last Session: DBMS Internals- Part VII Algorithms for Relational Operations (Cont d) Today s Session:

More information

Evaluation of Relational Operations: Other Techniques. Chapter 14 Sayyed Nezhadi

Evaluation of Relational Operations: Other Techniques. Chapter 14 Sayyed Nezhadi Evaluation of Relational Operations: Other Techniques Chapter 14 Sayyed Nezhadi Schema for Examples Sailors (sid: integer, sname: string, rating: integer, age: real) Reserves (sid: integer, bid: integer,

More information

Administriva. CS 133: Databases. General Themes. Goals for Today. Fall 2018 Lec 11 10/11 Query Evaluation Prof. Beth Trushkowsky

Administriva. CS 133: Databases. General Themes. Goals for Today. Fall 2018 Lec 11 10/11 Query Evaluation Prof. Beth Trushkowsky Administriva Lab 2 Final version due next Wednesday CS 133: Databases Fall 2018 Lec 11 10/11 Query Evaluation Prof. Beth Trushkowsky Problem sets PSet 5 due today No PSet out this week optional practice

More information

Evaluation of Relational Operations. SS Chung

Evaluation of Relational Operations. SS Chung Evaluation of Relational Operations SS Chung Cost Metric Query Processing Cost = Disk I/O Cost + CPU Computation Cost Disk I/O Cost = Disk Access Time + Data Transfer Time Disk Acess Time = Seek Time +

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals- Part VII Lecture 15, March 17, 2014 Mohammad Hammoud Today Last Session: DBMS Internals- Part VI Algorithms for Relational Operations Today s Session: DBMS

More information

15-415/615 Faloutsos 1

15-415/615 Faloutsos 1 Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications Lecture #14: Implementation of Relational Operations (R&G ch. 12 and 14) 15-415/615 Faloutsos 1 Outline introduction selection

More information

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #10: Query Processing

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #10: Query Processing CS 4604: Introduction to Database Management Systems B. Aditya Prakash Lecture #10: Query Processing Outline introduction selection projection join set & aggregate operations Prakash 2018 VT CS 4604 2

More information

External Sorting Implementing Relational Operators

External Sorting Implementing Relational Operators External Sorting Implementing Relational Operators 1 Readings [RG] Ch. 13 (sorting) 2 Where we are Working our way up from hardware Disks File abstraction that supports insert/delete/scan Indexing for

More information

Database Management System

Database Management System Database Management System Lecture Join * Some materials adapted from R. Ramakrishnan, J. Gehrke and Shawn Bowers Today s Agenda Join Algorithm Database Management System Join Algorithms Database Management

More information

Overview of Query Evaluation. Overview of Query Evaluation

Overview of Query Evaluation. Overview of Query Evaluation Overview of Query Evaluation Chapter 12 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Overview of Query Evaluation v Plan: Tree of R.A. ops, with choice of alg for each op. Each operator

More information

Midterm Review CS634. Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke

Midterm Review CS634. Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke Midterm Review CS634 Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke Coverage Text, chapters 8 through 15 (hw1 hw4) PKs, FKs, E-R to Relational: Text, Sec. 3.2-3.5, to pg.

More information

Faloutsos 1. Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Outline

Faloutsos 1. Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Outline Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications Lecture #14: Implementation of Relational Operations (R&G ch. 12 and 14) 15-415 Faloutsos 1 introduction selection projection

More information

CS330. Query Processing

CS330. Query Processing CS330 Query Processing 1 Overview of Query Evaluation Plan: Tree of R.A. ops, with choice of alg for each op. Each operator typically implemented using a `pull interface: when an operator is `pulled for

More information

Implementing Relational Operators: Selection, Projection, Join. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Implementing Relational Operators: Selection, Projection, Join. Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Implementing Relational Operators: Selection, Projection, Join Database Management Systems, R. Ramakrishnan and J. Gehrke 1 Readings [RG] Sec. 14.1-14.4 Database Management Systems, R. Ramakrishnan and

More information

CS542. Algorithms on Secondary Storage Sorting Chapter 13. Professor E. Rundensteiner. Worcester Polytechnic Institute

CS542. Algorithms on Secondary Storage Sorting Chapter 13. Professor E. Rundensteiner. Worcester Polytechnic Institute CS542 Algorithms on Secondary Storage Sorting Chapter 13. Professor E. Rundensteiner Lesson: Using secondary storage effectively Data too large to live in memory Regular algorithms on small scale only

More information

ECS 165B: Database System Implementa6on Lecture 7

ECS 165B: Database System Implementa6on Lecture 7 ECS 165B: Database System Implementa6on Lecture 7 UC Davis April 12, 2010 Acknowledgements: por6ons based on slides by Raghu Ramakrishnan and Johannes Gehrke. Class Agenda Last 6me: Dynamic aspects of

More information

Presenter: Eunice Tan Lam Ziyuan Yan Ming fei. Join Algorithm

Presenter: Eunice Tan Lam Ziyuan Yan Ming fei. Join Algorithm Presenter: Eunice Tan Lam Ziyuan Yan Ming fei Join Algorithm Example Table Table Sailors sid sname rating Age 22 Dustin 7 45 28 Yuppy 9 35 31 Lubber 8 55 36 Guppy 6 36 44 rusty 5 35 Table Reserves sid

More information

Overview of Query Evaluation

Overview of Query Evaluation Overview of Query Evaluation Chapter 12 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Overview of Query Evaluation Plan: Tree of R.A. ops, with choice of alg for each op. Each operator

More information

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 External Sorting Chapter 13 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Sort? A classic problem in computer science! Data requested in sorted order e.g., find students in increasing

More information

Cost-based Query Sub-System. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class.

Cost-based Query Sub-System. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Cost-based Query Sub-System Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications Queries Select * From Blah B Where B.blah = blah Query Parser Query Optimizer C. Faloutsos A. Pavlo

More information

CompSci 516 Data Intensive Computing Systems. Lecture 11. Query Optimization. Instructor: Sudeepa Roy

CompSci 516 Data Intensive Computing Systems. Lecture 11. Query Optimization. Instructor: Sudeepa Roy CompSci 516 Data Intensive Computing Systems Lecture 11 Query Optimization Instructor: Sudeepa Roy Duke CS, Fall 2017 CompSci 516: Database Systems 1 Announcements HW2 has been posted on sakai Due on Oct

More information

Database Systems. Announcement. December 13/14, 2006 Lecture #10. Assignment #4 is due next week.

Database Systems. Announcement. December 13/14, 2006 Lecture #10. Assignment #4 is due next week. Database Systems ( 料 ) December 13/14, 2006 Lecture #10 1 Announcement Assignment #4 is due next week. 2 1 Overview of Query Evaluation Chapter 12 3 Outline Query evaluation (Overview) Relational Operator

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals- Part VI Lecture 14, March 12, 2014 Mohammad Hammoud Today Last Session: DBMS Internals- Part V Hash-based indexes (Cont d) and External Sorting Today s Session:

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals- Part VI Lecture 17, March 24, 2015 Mohammad Hammoud Today Last Two Sessions: DBMS Internals- Part V External Sorting How to Start a Company in Five (maybe

More information

Overview of Implementing Relational Operators and Query Evaluation

Overview of Implementing Relational Operators and Query Evaluation Overview of Implementing Relational Operators and Query Evaluation Chapter 12 Motivation: Evaluating Queries The same query can be evaluated in different ways. The evaluation strategy (plan) can make orders

More information

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 External Sorting Chapter 13 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Sort? v A classic problem in computer science! v Data requested in sorted order e.g., find students in increasing

More information

QUERY EXECUTION: How to Implement Relational Operations?

QUERY EXECUTION: How to Implement Relational Operations? QUERY EXECUTION: How to Implement Relational Operations? 1 Introduction We ve covered the basic underlying storage, buffering, indexing and sorting technology Now we can move on to query processing Relational

More information

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Last Class Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos A. Pavlo Lecture#12: External Sorting (R&G, Ch13) Static Hashing Extendible Hashing Linear Hashing Hashing

More information

Final Exam Review. Kathleen Durant CS 3200 Northeastern University Lecture 22

Final Exam Review. Kathleen Durant CS 3200 Northeastern University Lecture 22 Final Exam Review Kathleen Durant CS 3200 Northeastern University Lecture 22 Outline for today Identify topics for the final exam Discuss format of the final exam What will be provided for you and what

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals- Part V Lecture 13, March 10, 2014 Mohammad Hammoud Today Welcome Back from Spring Break! Today Last Session: DBMS Internals- Part IV Tree-based (i.e., B+

More information

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Why Sort? Why Sort? select... order by

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Why Sort? Why Sort? select... order by Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications Lecture 12: external sorting (R&G ch. 13) Faloutsos 15-415 1 Why Sort? Faloutsos 15-415 2 Why Sort? select... order by e.g.,

More information

Query and Join Op/miza/on 11/5

Query and Join Op/miza/on 11/5 Query and Join Op/miza/on 11/5 Overview Recap of Merge Join Op/miza/on Logical Op/miza/on Histograms (How Es/mates Work. Big problem!) Physical Op/mizer (if we have /me) Recap on Merge Key (Simple) Idea

More information

R & G Chapter 13. Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops:

R & G Chapter 13. Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops: Relational Query Optimization R & G Chapter 13 Review Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops: simple, exploits extra memory

More information

Last Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Why do we need to sort? Today's Class

Last Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Why do we need to sort? Today's Class Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos A. Pavlo Lecture#12: External Sorting (R&G, Ch13) Static Hashing Extendible Hashing Linear Hashing Hashing vs.

More information

Final Exam Review. Kathleen Durant PhD CS 3200 Northeastern University

Final Exam Review. Kathleen Durant PhD CS 3200 Northeastern University Final Exam Review Kathleen Durant PhD CS 3200 Northeastern University 1 Outline for today Identify topics for the final exam Discuss format of the final exam What will be provided for you and what you

More information

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15

Examples of Physical Query Plan Alternatives. Selected Material from Chapters 12, 14 and 15 Examples of Physical Query Plan Alternatives Selected Material from Chapters 12, 14 and 15 1 Query Optimization NOTE: SQL provides many ways to express a query. HENCE: System has many options for evaluating

More information

Query Evaluation Overview, cont.

Query Evaluation Overview, cont. Query Evaluation Overview, cont. Lecture 9 Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke Architecture of a DBMS Query Compiler Execution Engine Index/File/Record Manager

More information

CSE 444: Database Internals. Section 4: Query Optimizer

CSE 444: Database Internals. Section 4: Query Optimizer CSE 444: Database Internals Section 4: Query Optimizer Plan for Today Problem 1A, 1B: Estimating cost of a plan You try to compute the cost for 5 mins We will go over the solution together Problem 2: Sellinger

More information

Query Evaluation Overview, cont.

Query Evaluation Overview, cont. Query Evaluation Overview, cont. Lecture 9 Feb. 29, 2016 Slides based on Database Management Systems 3 rd ed, Ramakrishnan and Gehrke Architecture of a DBMS Query Compiler Execution Engine Index/File/Record

More information

Implementation of Relational Operations: Other Operations

Implementation of Relational Operations: Other Operations Implementation of Relational Operations: Other Operations Module 4, Lecture 2 Database Management Systems, R. Ramakrishnan 1 Simple Selections SELECT * FROM Reserves R WHERE R.rname < C% Of the form σ

More information

Spring 2017 QUERY PROCESSING [JOINS, SET OPERATIONS, AND AGGREGATES] 2/19/17 CS 564: Database Management Systems; (c) Jignesh M.

Spring 2017 QUERY PROCESSING [JOINS, SET OPERATIONS, AND AGGREGATES] 2/19/17 CS 564: Database Management Systems; (c) Jignesh M. Spring 2017 QUERY PROCESSING [JOINS, SET OPERATIONS, AND AGGREGATES] 2/19/17 CS 564: Database Management Systems; (c) Jignesh M. Patel, 2013 1 Joins The focus here is on equijoins These are very common,

More information

Chapter 12: Query Processing. Chapter 12: Query Processing

Chapter 12: Query Processing. Chapter 12: Query Processing Chapter 12: Query Processing Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 12: Query Processing Overview Measures of Query Cost Selection Operation Sorting Join

More information

Overview of Query Processing

Overview of Query Processing ICS 321 Fall 2013 Overview of Query Processing Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/20/2013 Lipyeow Lim -- University of Hawaii at Manoa 1

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) DBMS Internals- Part V Lecture 15, March 15, 2015 Mohammad Hammoud Today Last Session: DBMS Internals- Part IV Tree-based (i.e., B+ Tree) and Hash-based (i.e., Extendible

More information

EXTERNAL SORTING. Sorting

EXTERNAL SORTING. Sorting EXTERNAL SORTING 1 Sorting A classic problem in computer science! Data requested in sorted order (sorted output) e.g., find students in increasing grade point average (gpa) order SELECT A, B, C FROM R

More information

Evaluation of Relational Operations: Other Techniques

Evaluation of Relational Operations: Other Techniques Evaluation of Relational Operations: Other Techniques [R&G] Chapter 14, Part B CS4320 1 Using an Index for Selections Cost depends on #qualifying tuples, and clustering. Cost of finding qualifying data

More information

Chapter 12: Query Processing

Chapter 12: Query Processing Chapter 12: Query Processing Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Overview Chapter 12: Query Processing Measures of Query Cost Selection Operation Sorting Join

More information

Locality. Christoph Koch. School of Computer & Communication Sciences, EPFL

Locality. Christoph Koch. School of Computer & Communication Sciences, EPFL Locality Christoph Koch School of Computer & Communication Sciences, EPFL Locality Front view of instructor 2 Locality Locality relates (software) systems with the physical world. Front view of instructor

More information

Query Processing. Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016

Query Processing. Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016 Query Processing Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016 Slides re-used with some modification from www.db-book.com Reference: Database System Concepts, 6 th Ed. By Silberschatz,

More information

CSE 444: Database Internals. Sec2on 4: Query Op2mizer

CSE 444: Database Internals. Sec2on 4: Query Op2mizer CSE 444: Database Internals Sec2on 4: Query Op2mizer Plan for Today Problem 1A, 1B: Es2ma2ng cost of a plan You try to compute the cost for 5 mins We go over the solu2on together Problem 2: Sellinger Op2mizer

More information

Chapter 13: Query Processing

Chapter 13: Query Processing Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 13.1 Basic Steps in Query Processing 1. Parsing

More information

Evaluation of Relational Operations: Other Techniques

Evaluation of Relational Operations: Other Techniques Evaluation of Relational Operations: Other Techniques Chapter 12, Part B Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 1 Using an Index for Selections v Cost depends on #qualifying

More information

Overview of DB & IR. ICS 624 Spring Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Overview of DB & IR. ICS 624 Spring Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa ICS 624 Spring 2011 Overview of DB & IR Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1/12/2011 Lipyeow Lim -- University of Hawaii at Manoa 1 Example

More information

CompSci 516: Database Systems

CompSci 516: Database Systems CompSci 516 Database Systems Lecture 9 Index Selection and External Sorting Instructor: Sudeepa Roy Duke CS, Fall 2017 CompSci 516: Database Systems 1 Announcements Private project threads created on piazza

More information

Advanced Database Systems

Advanced Database Systems Lecture IV Query Processing Kyumars Sheykh Esmaili Basic Steps in Query Processing 2 Query Optimization Many equivalent execution plans Choosing the best one Based on Heuristics, Cost Will be discussed

More information

CS330. Some Logistics. Three Topics. Indexing, Query Processing, and Transactions. Next two homework assignments out today Extra lab session:

CS330. Some Logistics. Three Topics. Indexing, Query Processing, and Transactions. Next two homework assignments out today Extra lab session: CS330 Indexing, Query Processing, and Transactions 1 Some Logistics Next two homework assignments out today Extra lab session: This Thursday, after class, in this room Bring your laptop fully charged Extra

More information

! A relational algebra expression may have many equivalent. ! Cost is generally measured as total elapsed time for

! A relational algebra expression may have many equivalent. ! Cost is generally measured as total elapsed time for Chapter 13: Query Processing Basic Steps in Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 1. Parsing and

More information

Chapter 13: Query Processing Basic Steps in Query Processing

Chapter 13: Query Processing Basic Steps in Query Processing Chapter 13: Query Processing Basic Steps in Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 1. Parsing and

More information

Overview of Query Evaluation. Chapter 12

Overview of Query Evaluation. Chapter 12 Overview of Query Evaluation Chapter 12 1 Outline Query Optimization Overview Algorithm for Relational Operations 2 Overview of Query Evaluation DBMS keeps descriptive data in system catalogs. SQL queries

More information

CSE 444: Database Internals. Lectures 5-6 Indexing

CSE 444: Database Internals. Lectures 5-6 Indexing CSE 444: Database Internals Lectures 5-6 Indexing 1 Announcements HW1 due tonight by 11pm Turn in an electronic copy (word/pdf) by 11pm, or Turn in a hard copy in my office by 4pm Lab1 is due Friday, 11pm

More information

Principles of Data Management. Lecture #9 (Query Processing Overview)

Principles of Data Management. Lecture #9 (Query Processing Overview) Principles of Data Management Lecture #9 (Query Processing Overview) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Today s Notable News v Midterm

More information

Administrivia. CS 133: Databases. Cost-based Query Sub-System. Goals for Today. Midterm on Thursday 10/18. Assignments

Administrivia. CS 133: Databases. Cost-based Query Sub-System. Goals for Today. Midterm on Thursday 10/18. Assignments Administrivia Midterm on Thursday 10/18 CS 133: Databases Fall 2018 Lec 12 10/16 Prof. Beth Trushkowsky Assignments Lab 3 starts after fall break No problem set out this week Goals for Today Cost-based

More information

Evaluation of Relational Operations: Other Techniques

Evaluation of Relational Operations: Other Techniques Evaluation of Relational Operations: Other Techniques Chapter 14, Part B Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke 1 Using an Index for Selections Cost depends on #qualifying

More information

Join Algorithms. Lecture #12. Andy Pavlo Computer Science Carnegie Mellon Univ. Database Systems / Fall 2018

Join Algorithms. Lecture #12. Andy Pavlo Computer Science Carnegie Mellon Univ. Database Systems / Fall 2018 Join Algorithms Lecture #12 Database Systems 15-445/15-645 Fall 2018 AP Andy Pavlo Computer Science Carnegie Mellon Univ. 2 ADMINISTRIVIA Project #2 Checkpoint #1 is due TODAY No class on Wednesday October

More information

Relational Query Optimization. Overview of Query Evaluation. SQL Refresher. Yanlei Diao UMass Amherst October 23 & 25, 2007

Relational Query Optimization. Overview of Query Evaluation. SQL Refresher. Yanlei Diao UMass Amherst October 23 & 25, 2007 Relational Query Optimization Yanlei Diao UMass Amherst October 23 & 25, 2007 Slide Content Courtesy of R. Ramakrishnan, J. Gehrke, and J. Hellerstein 1 Overview of Query Evaluation Query Evaluation Plan:

More information

Indexing. Chapter 8, 10, 11. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Indexing. Chapter 8, 10, 11. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Indexing Chapter 8, 10, 11 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Tree-Based Indexing The data entries are arranged in sorted order by search key value. A hierarchical search

More information

EECS 647: Introduction to Database Systems

EECS 647: Introduction to Database Systems EECS 647: Introduction to Database Systems Instructor: Luke Huan Spring 2009 External Sorting Today s Topic Implementing the join operation 4/8/2009 Luke Huan Univ. of Kansas 2 Review DBMS Architecture

More information

External Sorting. Chapter 13. Comp 521 Files and Databases Fall

External Sorting. Chapter 13. Comp 521 Files and Databases Fall External Sorting Chapter 13 Comp 521 Files and Databases Fall 2012 1 Why Sort? A classic problem in computer science! Advantages of requesting data in sorted order gathers duplicates allows for efficient

More information

Question 1. Part (a) [2 marks] what are different types of data independence? explain each in one line. Part (b) CSC 443 Term Test Solutions Fall 2017

Question 1. Part (a) [2 marks] what are different types of data independence? explain each in one line. Part (b) CSC 443 Term Test Solutions Fall 2017 Question 1. [12 marks] Short Answer Question Part (a) [2 marks] what are different types of data independence? explain each in one line Logical data independence: Protection from changes in logical structure

More information

Relational Query Optimization

Relational Query Optimization Relational Query Optimization Module 4, Lectures 3 and 4 Database Management Systems, R. Ramakrishnan 1 Overview of Query Optimization Plan: Tree of R.A. ops, with choice of alg for each op. Each operator

More information

Spring 2017 EXTERNAL SORTING (CH. 13 IN THE COW BOOK) 2/7/17 CS 564: Database Management Systems; (c) Jignesh M. Patel,

Spring 2017 EXTERNAL SORTING (CH. 13 IN THE COW BOOK) 2/7/17 CS 564: Database Management Systems; (c) Jignesh M. Patel, Spring 2017 EXTERNAL SORTING (CH. 13 IN THE COW BOOK) 2/7/17 CS 564: Database Management Systems; (c) Jignesh M. Patel, 2013 1 Motivation for External Sort Often have a large (size greater than the available

More information

Announcements. Two typical kinds of queries. Choosing Index is Not Enough. Cost Parameters. Cost of Reading Data From Disk

Announcements. Two typical kinds of queries. Choosing Index is Not Enough. Cost Parameters. Cost of Reading Data From Disk Announcements Introduction to Database Systems CSE 414 Lecture 17: Basics of Query Optimization and Query Cost Estimation Midterm will be released by end of day today Need to start one HW6 step NOW: https://aws.amazon.com/education/awseducate/apply/

More information

Database Management System. Relational Algebra and operations

Database Management System. Relational Algebra and operations Database Management System Relational Algebra and operations Basic operations: Selection ( ) Selects a subset of rows from relation. Projection ( ) Deletes unwanted columns from relation. Cross-product

More information

Operator Implementation Wrap-Up Query Optimization

Operator Implementation Wrap-Up Query Optimization Operator Implementation Wrap-Up Query Optimization 1 Last time: Nested loop join algorithms: TNLJ PNLJ BNLJ INLJ Sort Merge Join Hash Join 2 General Join Conditions Equalities over several attributes (e.g.,

More information

Sorting & Aggregations

Sorting & Aggregations Sorting & Aggregations Lecture #11 Database Systems /15-645 Fall 2018 AP Andy Pavlo Computer Science Carnegie Mellon Univ. 2 Sorting Algorithms Aggregations TODAY'S AGENDA 3 WHY DO WE NEED TO SORT? Tuples

More information

Review. Relational Query Optimization. Query Optimization Overview (cont) Query Optimization Overview. Cost-based Query Sub-System

Review. Relational Query Optimization. Query Optimization Overview (cont) Query Optimization Overview. Cost-based Query Sub-System Review Relational Query Optimization R & G Chapter 12/15 Implementation of single Relational Operations Choices depend on indexes, memory, stats, Joins Blocked nested loops: simple, exploits extra memory

More information

Hash-Based Indexing 165

Hash-Based Indexing 165 Hash-Based Indexing 165 h 1 h 0 h 1 h 0 Next = 0 000 00 64 32 8 16 000 00 64 32 8 16 A 001 01 9 25 41 73 001 01 9 25 41 73 B 010 10 10 18 34 66 010 10 10 18 34 66 C Next = 3 011 11 11 19 D 011 11 11 19

More information

Query Processing and Advanced Queries. Query Optimization (4)

Query Processing and Advanced Queries. Query Optimization (4) Query Processing and Advanced Queries Query Optimization (4) Two-Pass Algorithms Based on Hashing R./S If both input relations R and S are too large to be stored in the buffer, hash all the tuples of both

More information

University of Waterloo Midterm Examination Sample Solution

University of Waterloo Midterm Examination Sample Solution 1. (4 total marks) University of Waterloo Midterm Examination Sample Solution Winter, 2012 Suppose that a relational database contains the following large relation: Track(ReleaseID, TrackNum, Title, Length,

More information

Architecture and Implementation of Database Systems (Summer 2018)

Architecture and Implementation of Database Systems (Summer 2018) Jens Teubner Architecture & Implementation of DBMS Summer 2018 1 Architecture and Implementation of Database Systems (Summer 2018) Jens Teubner, DBIS Group jens.teubner@cs.tu-dortmund.de Summer 2018 Jens

More information

Announcements. Reading Material. Today. Different File Organizations. Selection of Indexes 9/24/17. CompSci 516: Database Systems

Announcements. Reading Material. Today. Different File Organizations. Selection of Indexes 9/24/17. CompSci 516: Database Systems CompSci 516 Database Systems Lecture 9 Index Selection and External Sorting Announcements Private project threads created on piazza Please use these threads (and not emails) for all communications on your

More information

CSE 544 Principles of Database Management Systems

CSE 544 Principles of Database Management Systems CSE 544 Principles of Database Management Systems Alvin Cheung Fall 2015 Lecture 6 Lifecycle of a Query Plan 1 Announcements HW1 is due Thursday Projects proposals are due on Wednesday Office hour canceled

More information

External Sorting Sorting Tables Larger Than Main Memory

External Sorting Sorting Tables Larger Than Main Memory External External Tables Larger Than Main Memory B + -trees for 7.1 External Challenges lurking behind a SQL query aggregation SELECT C.CUST_ID, C.NAME, SUM (O.TOTAL) AS REVENUE FROM CUSTOMERS AS C, ORDERS

More information

Data Storage. Query Performance. Index. Data File Types. Introduction to Data Management CSE 414. Introduction to Database Systems CSE 414

Data Storage. Query Performance. Index. Data File Types. Introduction to Data Management CSE 414. Introduction to Database Systems CSE 414 Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution Query Optimization Introduction to Database Systems CSE 414 Lecture 16: Basics of Data Storage

More information

University of Waterloo Midterm Examination Solution

University of Waterloo Midterm Examination Solution University of Waterloo Midterm Examination Solution Winter, 2011 1. (6 total marks) The diagram below shows an extensible hash table with four hash buckets. Each number x in the buckets represents an entry

More information

Chapter 12: Query Processing

Chapter 12: Query Processing Chapter 12: Query Processing Overview Catalog Information for Cost Estimation $ Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions Transformation

More information

Why Sort? Data requested in sorted order. Sor,ng is first step in bulk loading B+ tree index. e.g., find students in increasing GPA order

Why Sort? Data requested in sorted order. Sor,ng is first step in bulk loading B+ tree index. e.g., find students in increasing GPA order External Sor,ng Outline Exam will be graded a5er everyone takes it There are two,mes to be fair on an exam, when it s wriaen and when it s graded you only need to trust that I ll be fair at one of them.

More information