LevelHeaded: Making Worst-Case Optimal Joins Work in the Common Case

Christopher R. Aberger, Andrew Lamb, Kunle Olukotun, Christopher RéarXiv 2017

Abstract

Modern data pipelines increasingly require a seamless integration of relational querying (Business Intelligence) and linear algebra (Machine Learning). Traditional systems force a trade-off between specialized math libraries and relational databases, often incurring significant data movement overhead. LevelHeaded is a novel in-memory query engine that unifies these workloads using Worst-Case Optimal Joins (WCOJ). By optimizing WCOJ for common-case SQL and sparse/dense linear algebra, LevelHeaded outperforms traditional RDBMS on matrix operations by orders of magnitude while remaining competitive with state-of-the-art BI engines.

Introduction

The current data landscape is bifurcated. Developers must choose between Relational Database Management Systems (RDBMS) for SQL-heavy tasks and specialized Linear Algebra (LA) packages for machine learning. RDBMS struggle with the multi-way joins inherent in LA, while LA packages lack the high-level optimization and indexing of databases. Attempts to "glue" these systems together often result in performance bottlenecks due to data serialization and format conversion.

LevelHeaded occupies a unique performance niche, balancing high LA and BI performance.

LevelHeaded addresses this by treating linear algebra operations as relational joins. It aims to be a single architecture that is competitive for both BI and LA workloads, bridging the gap between "best-of-breed" specialized engines.

Methodology

The core of LevelHeaded is the use of Worst-Case Optimal Joins (WCOJ). Unlike standard pairwise joins that process tables two at a time, WCOJ algorithms process multiple relations simultaneously, attribute by attribute. This approach provides theoretical performance bounds for complex graph queries and, as this paper demonstrates, can be highly effective for standard SQL and LA.

Unified Representation

LevelHeaded represents both tables and matrices using a trie (prefix tree) data structure with dictionary encoding. This physical layout allows the engine to handle sparse and dense data efficiently. Linear algebra operations, such as matrix multiplication, are translated into standard SQL joins and aggregations, which are then processed through a specialized pipeline.

Matrix multiplication is unified into the relational model by translating SQL into Generalized Hypertree Decompositions (GHD) and unrolling them into WCOJ loops.

Key Optimizations

To make WCOJ practical for the "common case," the authors implemented several innovations:

  • SQL to GHD Translation: A framework to translate standard SQL into Generalized Hypertree Decompositions (GHDs), enabling WCOJ to handle filters and aggregations.
  • Attribute Elimination: The engine identifies unused columns and dense matrix chunks, allowing it to delegate heavy computation to high-performance libraries like Intel MKL with minimal overhead.
  • Cost-Based Optimizer: A novel optimizer for WCOJ that selects attribute processing orders based on cardinality heuristics, significantly reducing total work.
  • Adaptive GROUP BY: The engine dynamically switches between hash maps and bitsets based on data sparsity to manage skew.

Evaluation

LevelHeaded was evaluated against industry-standard benchmarks, including TPC-H for BI and various matrix kernels for LA.

Performance Results

  • Linear Algebra: LevelHeaded outperformed traditional relational engines like MonetDB and HyPer by orders of magnitude on sparse matrix operations.
  • Business Intelligence: On TPC-H queries, LevelHeaded remained within 31% of the performance of HyPer, a top-tier in-memory SQL engine.
  • Optimization Impact: The cost-based optimizer selected execution plans up to 8815x faster than previous WCOJ implementations.
  • End-to-End Applications: In a voter classification pipeline involving both joins and logistic regression, LevelHeaded was an order of magnitude faster than Spark or Pandas/Scikit-learn due to the elimination of data format conversions.

Conclusion

LevelHeaded demonstrates that a single query engine based on Worst-Case Optimal Joins can effectively unify BI and LA workloads. By treating math as joins and optimizing for the common case, it provides a high-performance alternative to fragmented data pipelines. Future work includes extending the engine to support out-of-core datasets and distributed environments.

Summary updated

BibTeX
@misc{aberger2017levelheaded,
  author = {Christopher R. Aberger and Andrew Lamb and Kunle Olukotun and Christopher Ré},
  title = {{LevelHeaded: Making Worst-Case Optimal Joins Work in the Common Case}},
  year = {2017},
  eprint = {1708.07859},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1708.07859},
}
Figure