{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter11 - External Sorting Chapter 11 Database Management...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Database Management Systems, R. Ramakrishnan and J. Gehrke 1 External Sorting Chapter 11
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Database Management Systems, R. Ramakrishnan and J. Gehrke 2 Why Sort? A classic problem in computer science! Data requested in sorted order  – e.g., find students in increasing  gpa  order Sorting is first step in  bulk loading  B+ tree index. Sorting useful for eliminating  duplicate copies  in a  collection of records (Why?) Sort-merge  join algorithm involves sorting. Problem: sort 1Gb of data with 1Mb of RAM. – why not virtual memory?
Image of page 2
Database Management Systems, R. Ramakrishnan and J. Gehrke 3 2-Way Sort: Requires 3 Buffers Pass 1: Read a page, sort it, write it. – only one buffer page is used Pass 2, 3, …, etc.: –  three buffer pages used. Main memory buffers INPUT 1 INPUT 2 OUTPUT Disk Disk
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Database Management Systems, R. Ramakrishnan and J. Gehrke 4 Two-Way External Merge Sort 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 subfiles and merge = + log 2 1 N ( 29 2 1 2 N N log + 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 5,6 2,6 4,9 7,8 1,3 2 2,3 4,6 4,7 8,9 1,3 5,6 2 2,3 4,4 6,7 8,9 1,2 3,5 6 1,2 2,3 3,4 4,5 6,6 7,8
Image of page 4
Database Management Systems, R. Ramakrishnan and J. Gehrke 5 General External Merge Sort To sort a file with  N  pages using  B  buffer pages: Pass 0: use  buffer pages.  Produce              sorted runs of  B   pages each.   Pass 2, …,  etc.: merge  B-1  runs N B / B Main memory buffers INPUT 1 INPUT B-1 OUTPUT Disk Disk INPUT 2 . . .
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern