Faster Relational Algorithms Using Geometric Data Structures

Aryan Esmailpour, Stavros Sintos

TL;DR

This paper introduces a novel framework to run geometric optimization algorithms—specifically $k$-center, $k$-median, and $k$-means clustering—directly on relational database joins without ever fully materializing the massive join outputs. By developing a randomized, on-the-fly variant of the Balanced Box-Decomposition (BBD) tree, the authors achieve a speedup factor of $k$ over the current state-of-the-art relational clustering algorithms.

What Problem Does This Paper Address?

Most machine learning and data science workflows assume flat-file inputs (like a single CSV file). However, real-world enterprise data lives in relational databases spread across multiple tables. To run standard clustering algorithms, engineers typically perform a massive JOIN operation to create a single flat feature dataset.

This "materialization" step is incredibly expensive because the join output can be polynomially larger than the input tables themselves. For example, joining a few tables containing 8 million total rows can easily blow up into a dataset of over 22 million rows. Existing relational algorithms try to circumvent this by avoiding full materialization, but they often suffer from large approximation errors or expensive runtimes that scale poorly with $k$ (the number of clusters). This paper tackles the challenge of designing faster relational clustering algorithms that maintain strong approximation guarantees without materializing the join.

Methods

The authors bridge the gap between computational geometry and database theory by adapting the Balanced Box-Decomposition (BBD) tree—a hierarchical data structure traditionally used for fast geometric queries like range counting and nearest neighbor search.

Building a standard BBD tree over a join result would normally require materializing the data first, defeating the purpose. To solve this, the authors introduce the Randomized BBD (RBBD) tree. Instead of building the entire tree upfront, the RBBD tree is expanded on-the-fly (lazily).

When a geometric query traverses a node whose children haven't been built yet, the algorithm computes the children dynamically using two key database primitives:

  1. Relational Counting and Sampling Oracles: Utilizing database algorithms (like Yannakakis' algorithm) to count (CountRect) or sample (SampleRect) tuples within a geometric bounding box directly from the underlying tables in near-linear time ($O(N)$).
  2. Randomized Centroid Shrink: Instead of scanning all points to find a balanced spatial split (which is impossible without materialization), the RBBD tree uses a small random sample ($\epsilon$-sample) to approximate the split.

This allows the algorithm to simulate complex geometric query procedures by only exploring a logarithmic number of tree nodes.

Hierarchical spatial partitioning and tree structure of a BBD tree

Datasets

The paper is primarily theoretical and focuses on algorithmic proofs. It references the Yelp review dataset (consisting of five relations: Review, User, Business, Category, and Attributes) as a motivating real-world example of how relational joins cause data blow-ups during feature engineering. No new datasets or empirical benchmarks were introduced.

Key Insights and Ideas

  • Lazy Geometric Expansion: You don't need to see the whole dataset to build a spatial tree. By combining database sampling oracles with lazy evaluation, you can build just the branches of the tree that your geometric algorithm actually touches.
  • Sampling Suffices for Spatial Splitting: The exact "centroid shrink" operation in standard BBD trees can be replaced with a randomized approximation using $\epsilon$-samples without degrading the tree's depth guarantees ($O(\log N)$) or its geometric query accuracy.
  • A General Framework: This isn't just a trick for $k$-means. Any geometric algorithm that interacts with data via a BBD tree can be converted into a fast relational algorithm using this framework, including problems in diversity maximization and fairness-aware selection.

Key Results

The proposed framework reduces the runtime dependency on the number of clusters ($k$) by a factor of $k$ across all three classic clustering objectives ($k$-center, $k$-median, and $k$-means) for acyclic queries, achieving a linear dependency on both $k$ and database size $N$.

  • $k$-Center Clustering: Achieves a $(1+\epsilon)\gamma$-approximation in $\tilde{O}(kN^{\text{fhw}} + T_{\gamma}^{\text{cen}}(k))$ time, eliminating the $k^2$ factor from previous methods (where $\text{fhw}$ is the fractional hypertree width, a measure of query complexity).
  • $k$-Median & $k$-Means Clustering: Achieves a linear dependency on $k$ and $N$ ($\tilde{O}(kN^{\text{fhw}} + T_{\gamma}(k))$), significantly outperforming prior methods that scaled with $k^2$ or $k^4$.
Comparison of the proposed relational clustering algorithms against state-of-the-art methods

Limitations and Future Work

  • Optimality Question: While $\tilde{O}(k N)$ is a massive improvement, it remains an open question whether $O(1)$-approximation algorithms can be designed to run in $\tilde{O}(N)$ time (completely independent of $k$ during the database scan phase).
  • Lower Bounds: The authors note that standard computational geometry lower bounds for $k$-center clustering have not yet been fully mapped to the relational setting to prove absolute optimality.
  • Extension to Other Structures: The current work focuses on BBD trees, but exploring relational versions of other geometric data structures like quad-trees, kd-trees, or partition trees remains future work.

Summary updated

BibTeX
@article{esmailpour2026faster,
  author = {Aryan Esmailpour and Stavros Sintos},
  title = {{Faster Relational Algorithms Using Geometric Data Structures}},
  journal = {Proc. ACM Manag. Data},
  year = {2026},
  doi = {10.1145/3801898},
}
Figure