The Case for a Learned Sorting Algorithm
Ani Kristo, Kapil Vaidya, Ugur Çetintemel, Sanchit Misra, Tim Kraska
Abstract
Sorting is one of the most fundamental algorithms in Computer Science and a common operation in databases not just for sorting query results but also as part of joins (i.e., sort-merge-join) or indexing. In this work, we introduce a new type of distribution sort that leverages a learned model of the empirical CDF of the data. Our algorithm uses a model to efficiently get an approximation of the scaled empirical CDF for each record key and map it to the corresponding position in the output array. We then apply a deterministic sorting algorithm that works well on nearly-sorted arrays (e.g., Insertion Sort) to establish a totally sorted order. We compared this algorithm against common sorting approaches and measured its performance for up to 1 billion normally-distributed double-precision keys. The results show that our approach yields an average 3.38x performance improvement over C++ STL sort, which is an optimized Quicksort hybrid, 1.49x improvement over sequential Radix Sort, and 5.54x improvement over a C++ implementation of Timsort, which is the default sorting function for Java and Python.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get 5b3c24b2-8044-47c0-ae5d-28aa44298de0Cited by top-tier papers12
- Are We Ready For Learned Cardinality Estimation?Xiaoying Wang, Changbo Qu, Weiyuan Wu, Jiannan Wang et al.VLDB 2021 · 156 citations
- SNARF: A Learning-Enhanced Range FilterKapil Vaidya, Tim Kraska, Subarna Chatterjee, Eric R. Knorr et al.VLDB 2022 · 39 citations
- Sorting with PredictionsXingjian Bai, Christian CoesterNeurIPS 2023 · 29 citations
- The Case for Learned In-Memory JoinsIbrahim Sabek, Tim KraskaVLDB 2023 · 27 citations
- LSched: A Workload-Aware Learned Query Scheduler for Analytical Database SystemsIbrahim Sabek, Tenzin Samten Ukyab, Tim KraskaSIGMOD 2022 · 25 citations
Related papers
- Theoretical Analysis of Learned Database Operations under Distribution Shift through Distribution LearnabilitySepanta Zeighami, Cyrus ShahabiICML 2024 · 5 citations
- Can Learned Models Replace Hash Functions?Ibrahim Sabek, Kapil Vaidya, Dominik Horn, Andreas Kipf et al.VLDB 2023 · 29 citations
- HIRE: A Hybrid Learned Index for Robust and Efficient Performance under Mixed WorkloadsXinyi Zhang, Liang Liang, Anastasia Ailamaki, Jianliang XuSIGMOD 2026 · 2 citations
- These Rows Are Made for Sorting and That's Just What We'll DoLaurens Kuiper, Hannes MühleisenICDE 2023 · 6 citations
- SOLAR: Scalable Distributed Spatial Joins Through Learning-Based OptimizationYongyi Liu, Ahmed Abdelmaguid, Ahmed R. Mahmood, Amr Magdy et al.ICDE 2026
