In-Database Regression in Input Sparsity Time

Rajesh Jayaram, Alireza Samadian, David P. Woodruff, Peng Ye

Introduction

Machine learning models often rely on data spread across multiple relational database tables. Joining these tables creates a massive, computationally expensive "feature matrix." This paper introduces a method to perform high-accuracy linear regression directly on the joined data without ever materializing the join. By leveraging clever sketching and sampling techniques, the algorithm runs in "input-sparsity time"—meaning its computation speed scales with the size of the original small tables rather than the potentially astronomical size of the joined result.

The Problem: Join Explosion

In modern data science, the feature matrix used for machine learning is rarely a single static file. Instead, it is often the result of a join query across multiple database tables (e.g., joining a Users table with a Purchases table).

Visualizing a database join ($J = T_1 \bowtie T_2$) and its block decomposition.

The fundamental issue is the "Join Explosion." If Table A has $n_1$ rows and Table B has $n_2$ rows, their join can have up to $n_1 \times n_2$ rows. For large databases, this joined table is too massive to store or compute efficiently. Traditional machine learning algorithms—and even standard "sketching" techniques—require reading every row of this joined matrix, making regression on joined data computationally prohibitive.

Previous "FAQ-based" (Functional Aggregate Query) methods could solve this in sub-linear time relative to the join size, but they scaled poorly as the number of features ($d$) increased. This paper seeks the "holy grail" of efficiency: algorithms that run in time proportional to the number of non-zero entries in the original tables (input sparsity), regardless of how large the join becomes.

Methodology: Sketching the Join

The authors utilize Subspace Embeddings (SE), a dimensionality reduction technique where a large matrix $A$ is multiplied by a much smaller random matrix $S$ to create a "sketch" $SA$. This sketch preserves the underlying geometry of the data, allowing you to solve regression on the small sketch and get an answer that is nearly optimal for the original large data.

The core innovation is an algorithm that computes this sketch for a join $J = T_1 \bowtie T_2$ without ever forming $J$. Their approach involves:

  1. Block Decomposition: They view the join as a collection of "blocks" based on the join keys.
  2. Hybrid Sketching (The Big/Small Split):
    • Big Blocks: For blocks with many rows, they use a "Fast Tensor-Sketch," a known technique for sketching Kronecker products.
  3. Small Blocks: For smaller blocks, they introduce a novel Leverage Score Sampling routine. Leverage scores identify which rows are "most important" to the regression.
  4. Fast $\ell_2$ Sampling: To avoid looking at every row in the small blocks, they develop a tree-based sampling primitive. This allows them to sample rows from the join with probability proportional to their importance, using only the information in the original tables $T_1$ and $T_2$.

By treating "heavy" blocks and "light" blocks differently, the algorithm stays efficient regardless of whether the join is skewed or uniform.

Key Results

The authors evaluated their approach on two real-world relational datasets: LastFM (predicting user listening habits based on tags) and MovieLens 25m (predicting movie ratings across Ratings, Users, and Movies tables).

  • Massive Speedups: On the MovieLens dataset (23 features), their algorithm achieved a 10-fold speedup over the previous state-of-the-art FAQ-based methods for two-table joins.
  • High Accuracy: Despite the massive speedup, the relative error remained remarkably low—only 0.66% in the MovieLens test.
  • Scalability to General Joins: For a three-table join on MovieLens, they achieved a 3-fold speedup with a negligible Mean Squared Error (MSE) relative error of 0.28%.
  • Theoretical Dominance: The paper provides the first "input-sparsity time" algorithms for these problems, significantly improving the theoretical complexity bounds compared to prior work. They prove that for two-table joins, you can achieve "machine precision" in time truly proportional to the number of non-zeros in the input tables.

Limitations and Future Work

While the two-table case is solved with high theoretical rigor for standard regression, extending this to arbitrary $m$-table joins is primarily focused on ridge regression (which includes a regularization term). Solving ordinary least squares for complex, multi-table acyclic joins in input-sparsity time remains a difficult theoretical challenge.

Additionally, the complexity bounds include polynomial factors of the number of features ($d$). If $d$ becomes extremely large (e.g., millions, such as with massive one-hot encoded categorical data), the overhead of the sketching process might grow, though it would still likely outperform materializing the entire join.

Summary updated

BibTeX
@inproceedings{jayaram2021database,
  author = {Rajesh Jayaram and Alireza Samadian and David P. Woodruff and Peng Ye},
  title = {{In-Database Regression in Input Sparsity Time}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=MK5pGNLFS8e},
}
Figure