DatabaseManagementSystems3ed,R.RamakrishnanandJ.Gehrke 1
ExternalSorting
Chapter13
DatabaseManagementSystems3ed,R.RamakrishnanandJ.Gehrke 2
WhySort?
- Aclassicproblemincomputerscience!
- Datarequestedinsortedorder
e.g.,findstudentsinincreasing gpa order
- SortingisfirststepinbulkloadingB+treeindex.
- Sortingusefulforeliminatingduplicatecopiesina
collectionofrecords(Why?)
- Sort-merge joinalgorithminvolvessorting.
- Problem:sort1Gbofdatawith1MbofRAM.
whynotvirtualmemory?
DatabaseManagementSystems3ed,R.RamakrishnanandJ.Gehrke 3
2-WaySort:Requires3Buffers
- Pass1:Readapage,sortit,writeit.
- nlyonebufferpageisused
- Pass2,3,…,etc.:
threebufferpagesused.
Mainmemorybuffers INPUT1 INPUT2 OUTPUT Disk Disk