Chapter11 - Database Management Systems, R. Ramakrishnan...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Database Management Systems, R. Ramakrishnan and J. Gehrke External Sorting Chapter 11 Database Management Systems, R. Ramakrishnan and J. Gehrke Why Sort? A classic problem in computer science! Data requested in sorted order e.g., find students in increasing gpa order Sorting is first step in bulk loading B+ tree index. Sorting useful for eliminating duplicate copies in a collection of records (Why?) Sort-merge join algorithm involves sorting. Problem: sort 1Gb of data with 1Mb of RAM. why not virtual memory? Database Management Systems, R. Ramakrishnan and J. Gehrke 2-Way Sort: Requires 3 Buffers Pass 1: Read a page, sort it, write it. only one buffer page is used Pass 2, 3, , etc.: three buffer pages used. Main memory buffers INPUT 1 INPUT 2 OUTPUT Disk Disk Database Management Systems, R. Ramakrishnan and J. Gehrke Two-Way External Merge Sort Each pass we read + write each page in file. N pages in the file => the number of passes So toal cost is: Idea: Divide and conquer: sort subfiles and merge = + log 2 1 N ( 29 2 1 2 N N log + Input file 1-page runs 2-page runs 4-page runs 8-page runs PASS 0 PASS 1 PASS 2 PASS 3 9 3,4 6,2 9,4 8,7 5,6 3,1 2 3,4 5,6 2,6 4,9 7,8 1,3 2 2,3 4,6 4,7 8,9 1,3 5,6 2 2,3 4,4 6,7 8,9 1,2 3,5 6 1,2 2,3 3,4 4,5 6,6 7,8 Database Management Systems, R. Ramakrishnan and J. Gehrke General External Merge Sort To sort a file with N pages using B buffer pages: Pass 0: use B buffer pages. Produce sorted runs of B pages each. Pass 2, , etc.: merge B-1 runs . N B / B Main memory buffers INPUT 1 INPUT B-1 OUTPUT Disk Disk INPUT 2 . . ....
View Full Document

This note was uploaded on 04/06/2010 for the course CS COP 6371 taught by Professor Dr.hua during the Spring '10 term at University of Central Florida.

Page1 / 18

Chapter11 - Database Management Systems, R. Ramakrishnan...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online