Professional Documents
Culture Documents
R & G Chapter 13
Brian Cooper
Yahoo! Research
Sorry Google
500 million unique visitors per month
74 percent of U.S. users use Y! (per month)
13 percent of U.S. users online time is on Y!
Why sort?
Why sort?
Apple
Grapefruit
Banana
Apple
Blueberry
Orange
Grapefruit
Mango
Kiwi
Kiwi
Mango
Strawberry
Orange
Blueberry
Strawberry
So?
Quicksort
Mergesort
Heapsort
Selection sort
Insertion sort
Radix sort
Bubble sort
Etc.
Banana
Grapefruit
Apple
Orange
Mango
Kiwi
Strawberry
Blueberry
Banana
Grapefruit
Apple
Orange
Mango
Kiwi
Strawberry
Blueberry
Banana
Grapefruit
Banana
Grapefruit
Apple
Orange
Apple
Orange
Mango
Kiwi
Kiwi
Mango
Strawberry
Blueberry
Blueberry
Strawberry
Apple
Banana
Grapefruit
Orange
Blueberry
Kiwi
Mango
Strawberry
Apple
Banana
Blueberry
Grapefruit
Kiwi
Mango
Orange
Strawberry
2-way sort
Unsorted
RAM
Sorted
Sorted
RAM
Sorted
Sorted
RAM
Sorted!
Pass 0
Pass 1: went from P pages to P/2 runs
Pass 2: went from P/2 runs to P/4 runs
N >> P
So O(N lg N) >> O(P lg P)
Example:
8 KB pages
100 byte records
= 80 records per page
= 12,500 pages
Can we do better?
Sorted!
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
Example
Input
Output
LogB-1 P/B + 1
Example
X = Blocking factor
B = buffer pages
(B/X X) input buffer blocks, one output buffer
block
Result
Stop merging
Initiate I/O
Wait
Complete I/O
Resume merging
Input
Output
Input
Output
Input
Output
Input
Output
Input
Output
Input
Output
Yay!
Clustered B+ tree
Lime Mango
Tomato Wolfberry
Apple Banana
Blueberry
Grapefrui
t
Tomato
Pear
Nectarine
Kiwi
Blueberry
Lime
Pear Strawberr
y
Kiwi Lemon
Nectarine
- Orange
Clustered B+ tree
Apple Banana
Blueberry
Grapefrui
t
Kiwi Lemon
Lime Mango
Tomato
Pear
Nectarine
Kiwi
Blueberry
Lime
Nectarine
- Orange
Pear Strawberr
y
Tomato Wolfberry
Data in B+ tree:
Height + Width
Example
Data in B+ tree
Summary