> 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/using-b+-trees-for-sorting.md).

# Using B+ Trees For Sorting

If the table that must be sorted already has a B+ Tree index on the sort attributes, then we can use that to accelerate sorting

Retrieve tuples in desired sort order by simply traversing the leaf pages of the tree

Cases to consider:

* Clustered B+ Tree
* Unclustered B+ Tree
