Académique Documents
Professionnel Documents
Culture Documents
Chapter 13
Why Sort?
INPUT 1
OUTPUT
INPUT 2
2,3
4,4 1,2
So toal cost is: 6,7 3,5
4-page runs
( )
8,9 6
2 N log 2 N + 1 PASS 3
1,2
Idea: Divide and conquer: 2,3
sort subfiles and merge 3,4 8-page runs
4,5
6,6
7,8
9
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 4
pages each.
... INPUT 2
... OUTPUT ...
INPUT B-1
Disk Disk
B Main memory buffers
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 5
Cost = 2N * (# of passes)
More on Heapsort
Double Buffering
To reduce wait time for I/O request to
complete, can prefetch into `shadow block’.
INPUT 1'
INPUT 2
OUTPUT
INPUT 2'
OUTPUT'
b
block size
Disk INPUT k
Disk
INPUT k'
Data Entries
If Alternative 2 is used?
("Sequence set")
Additional cost of
Index
(Directs search)
Data Entries
("Sequence set")
Data Records
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 16
Summary
External sorting is important; DBMS may dedicate
part of buffer pool for sorting!
External merge sort minimizes disk I/O cost:
Quicksort: Quick!