













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














gathers duplicates allows for efficient searches
why not let the OS handle it with virtual memory?
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 pages and merge 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 2,6 4,9 7,8 5,6 1,3^2 2, 4, 4, 8, 1, 5,6 2 2, 4, 6, 8, 1, 3, 6 1, 2, 3, 4, 6, 7,
Pass 0: use B buffer pages. Produce sorted runs of B pages each. Pass 2, …, etc.: merge B-1 runs. B Main memory buffers INPUT 1 INPUT B- OUTPUT Disk^ Disk INPUT 2
Pass 0: = 22 sorted runs of 5 pages each (last run is only 3 pages) Pass 1: = 6 sorted runs of 20 pages each (last run is only 8 pages) Pass 2: = 2 sorted runs, 80 pages and 28 pages Pass 3: Sorted file of 108 pages €
Imagine a snowplow moving around a circular track on which snow falls at a steady rate. At any instant, there is a certain amount of snow S on the track. Some falling snow comes in front of the plow, some behind. During the next revolution of the plow, all of this is removed, plus 1/2 of what falls during that revolution. Thus, the plow removes 2S amount of snow.
The “snowplow” analogy
What is min length of a run? How does this arise?
What is max length of a run? How does this arise?
OUTPUT OUTPUT' Disk (^) Disk INPUT 1 INPUT k INPUT 2 INPUT 1' INPUT 2' INPUT k' block size b B main memory buffers, k-way merge
B+ tree is clustered Good idea! B+ tree is not clustered Could be a very bad idea!
Cost: root to the left-most leaf, then retrieve all leaf pages (Alternative 1) If Alternative 2 is used? Additional cost of retrieving data records: each page fetched just once. Fill factor of < 100% introduces a small overhead extra pages fetched Always better than external sorting! (Directs search) Data Records Index Data Entries ("Sequence set")
p : # of records per page B=1,000 and block size=32 for sorting p=100 is the more realistic value.
Pass 0: Produces sorted runs of size B (# buffer pages). Later passes: merge runs. # of runs merged at a time depends on B , and block size. Larger block size means less I/O cost per page. Larger block size means smaller # runs merged. In practice, # of runs rarely more than 2 or 3.