> For the complete documentation index, see [llms.txt](https://til.notdu.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.notdu.com/database/intro-to-database-systems/sorting-and-aggregations/external-merge-sort.md).

# External Merge Sort

Divide-and-conquer sorting algorithm that splits the data set into separate runs and then sorts them individually.

Phase #1 - Storting&#x20;

Sort blocks of data that fit in main-memory and then write back the sorted blocks to a file on disk

Phase #2 - Merging

Combine sorted sub-files into a single larger file.
