On Distribution Dependent Sub-Logarithmic Query Time of Learned Indexing

Sepanta Zeighami, Cyrus Shahabi

Introduction

While learned indexes have long outperformed traditional B-trees in practice, the database community has lacked a rigorous theoretical explanation for their speed. Historically, the performance of learned indexes was only proven to match the $O(\log n)$ time of traditional methods, albeit with better constant factors. This paper provides the missing theoretical link, proving that under mild data distribution assumptions, learned indexes can achieve $O(\log \log n)$ or even $O(1)$ expected query time. By shifting from worst-case to expected-case analysis, the authors demonstrate that learned indexes asymptotically outperform the $O(\log n)$ limit of traditional search methods.

The Problem: Breaking the $O(\log n)$ Barrier

In data management, the "rank problem"—finding the position of an element in a sorted array—is foundational. For decades, the gold standard has been binary search or B-trees, both of which operate in $O(\log n)$ time.

Recently, "learned indexes" emerged as a disruptive alternative. Instead of relying on rigid, pointer-based tree structures, they use machine learning models to predict the location of a key. Empirically, these models answer queries orders of magnitude faster than B-trees. However, theoretical analysis lagged behind empirical success. Previous work only managed to prove that learned indexes operate in $O(\log n)$ time with improved space complexity. This paper tackles the fundamental "why": can we theoretically prove that learned indexes are asymptotically faster than traditional methods?

Theoretical Framework and Methods

The authors provide a constructive proof by introducing three specific indexing strategies. Each strategy demonstrates a different trade-off between space complexity and query time:

  1. PCA Index (Piece-wise Constant Approximator): A simple model that divides the data domain into $k$ intervals and stores a constant estimate for each. By utilizing $O(n^{1+\epsilon})$ space (a near-linear overhead), it achieves $O(1)$ expected query time.
  2. RDS Algorithm (Recursive Distribution Search): This approach assumes the Cumulative Distribution Function (CDF) of the data is known and computationally cheap. It recursively narrows the search space by roughly $\sqrt{s}$ at each step (where $s$ is the current search space size), achieving $O(\log \log n)$ expected query time with only $O(1)$ extra space.
  3. RDA Index (Recursive Distribution Approximator): A hierarchical model—similar to the popular Recursive Model Index (RMI)—that materializes the recursive search of RDS into a tree of models. It achieves $O(\log \log n)$ expected query time using $O(n \log n)$ space, matching the space complexity of a standard B-tree.

The core of their mathematical proof relies on the Dvoretzky-Kiefer-Wolfowitz (DKW) bound, a theorem that helps quantify how closely an empirical distribution matches the true underlying distribution of the data.

The Role of Data Distribution

The "magic" of learned indexes does not stem solely from the machine learning models themselves, but from the underlying data distribution.

  • Bounded PDF: The authors show that if the probability density function (PDF) is bounded (i.e., the data isn't infinitely "spiky" or concentrated), the expected error of a predictive model can be strictly controlled.
  • The $\rho$ Factor: The paper introduces a parameter $\rho$, representing the bound on the PDF. When $\rho$ is small, learned indexes are exceptionally fast. When $\rho$ is large—meaning the data is highly clustered, irregular, or features sharp changes in its CDF—the performance gains diminish.
  • Expected vs. Worst-Case: By moving from worst-case analysis to expected query time (averaged over data samples), the authors successfully break the $O(\log n)$ barrier, representing a significant paradigm shift in index performance theory.

Empirical Validation

The authors validated their theoretical bounds using both synthetic and real-world benchmarks:

  • Synthetic Datasets: Tests included uniform distributions, Gaussian distributions (with varying standard deviations to test PDF bounds), and skewed distributions ($x^t$). The PCA index maintained constant query time even as $n$ grew to $10^7$, while the RDA index consistently followed the predicted $O(\log \log n)$ curve.
  • Real-World Datasets: The models were tested against Web server logs (714M timestamps), IoT sensor data (26M events), Amazon book popularity (200M keys), Facebook user IDs (200M keys), OpenStreetMap cell IDs (800M locations), and Wikipedia edit timestamps (200M keys).
  • Explaining Failure Cases: The experiments on the OpenStreetMap (OSM) dataset provided crucial validation for the theory. OSM data has a high distribution-dependent factor ($\rho \approx 10\text{--}20$). The authors showed that for such datasets, the index size must grow significantly to maintain speed, providing a theoretical explanation for why non-learned methods sometimes still win in practice.

Limitations and Future Directions

While this paper establishes a robust theoretical foundation for learned indexes, the authors acknowledge several constraints:

  • Bounded PDF Assumption: The current proofs for $O(\log \log n)$ and $O(1)$ time rely on the data distribution having a bounded and non-zero PDF. While extended to sub-exponential distributions, extremely irregular or "heavy-tailed" distributions may not fit this framework.
  • Static Data: The analysis focuses exclusively on static arrays. Future work is required to determine if these sub-logarithmic bounds hold for dynamic datasets with frequent insertions and deletions.
  • Necessary vs. Sufficient Conditions: The paper successfully identifies sufficient conditions for sub-logarithmic time. Discovering the necessary conditions remains an open challenge for the theoretical computer science community.

Summary updated

BibTeX
@inproceedings{zeighami2023distribution,
  author = {Sepanta Zeighami and Cyrus Shahabi},
  title = {{On Distribution Dependent Sub-Logarithmic Query Time of Learned Indexing}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=4hefw3y2VK},
}
Figure