External Sorting
(From Chapter 13)
External Sorting (From Chapter 13) - - PDF document
External Sorting (From Chapter 13) Why Sort? Some
(From Chapter 13)
Only one buffer page used
Input file 1-page runs PHASE 1 3,4 6,2 9,4 8,7 5,6 3,1 2
Input file 1-page runs 2-page runs 4-page runs 8-page runs PHASE 1 PASS 1 PASS 2 PASS 3 3,4 6,2 9,4 8,7 5,6 3,1 2 2 PHASE 2
Only one buffer page used
Input file 4-page runs 3,4 6,2 9,4 8,7 5,6 3,1 9,2 6,1 8,2 3,4 5,5 6,3
Pass 1: Merge two runs of length 1 (page) Pass 2: Merge two runs of length 2 (pages) … until 1 run of length N Three buffer pages used
Input file 4-page runs 3,4 6,2 9,4 8,7 5,6 3,1 9,2 2,3 5,6 6,7 4,4 8,9 1,1 2,3 6,1 6,9 8,2 3,4 5,5 5,5 6,8 2,3 6,3 3,4
2,3
Input file 8-page runs 3,4 6,2 9,4 8,7 5,6 3,1 9,2 2,2 4,4 6,6 9,9 1,1 3,3 6,1 7,8 8,2 3,4 5,5 6,3 … 5,6
Input file 4-page runs 3,4 6,2 9,4 8,7 5,6 3,1 9,2 2,3 5,6 6,7 4,4 8,9 1,1 2,3 6,1 6,9 8,2 3,4 5,5 5,5 6,8 2,3 6,3 3,4
2,3 4,4
Again, potentially more passes; in practice, most
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
!" # ("Sequence set")
!" # ("Sequence set")
Parallel sorting is the name of the game
Typical DBMS: 15 minutes World record: 3.5 seconds
Minute Sort: How many can you sort in 1 minute? Dollar Sort: How many can you sort for $1.00?
PennySort!!!