Abstract
The use of large-scale machine learning methods is becoming ubiquitous in many applications ranging from business intelligence to self-driving cars. These methods require a complex computation pipeline consisting of various types of operations, e.g., relational operations for pre-processing or post-processing the dataset, and matrix operations for core model computations. Many existing systems focus on efficiently processing matrix-only operations, and assume that the inputs to the relational operators are already pre-computed and are materialized as intermediate matrices. However, the input to a relational operator may be complex in machine learning pipelines, and may involve various combinations of matrix operators. Hence, it is critical to realize scalable and efficient relational query processors that directly operate on big matrix data. This paper presents new efficient and scalable relational query processing techniques on big matrix data for in-memory distributed clusters. The proposed techniques leverage algebraic transformation rules to rewrite query execution plans into ones with lower computation costs. A distributed query plan optimizer exploits the sparsity-inducing property of merge functions as well as Bloom join strategies for efficiently evaluating various flavors of the join operation. Furthermore, optimized partitioning schemes for the input matrices are developed to facilitate the performance of join operations based on a cost model that minimizes the communication overhead. The proposed relational query processing techniques are prototyped in Apache Spark. Experiments on both real and synthetic data demonstrate that the proposed techniques achieve up to two orders of magnitude performance improvement over state-of-the-art systems on a wide range of applications.
Introduction: Bridging the Gap Between Relational and Matrix Data
In modern large-scale machine learning (ML), data scientists often work across two distinct paradigms: the relational language of data cleaning (SQL-like selections and joins) and the linear algebra language of model training (matrix multiplications and transposes). Traditionally, these domains are siloed. Data is cleaned in a relational database, exported as a massive matrix, and then processed by a specialized matrix engine.
This siloed approach introduces significant overhead. When relational and matrix operations are interleaved, standard systems often materialize massive intermediate matrices, leading to memory exhaustion and redundant computation. MatRel addresses this by treating matrices as first-class relational citizens, enabling a unified optimization framework for end-to-end ML pipelines.
System Architecture and Implementation
MatRel is built as an extension to Apache Spark, specifically leveraging the Spark SQL stack. By integrating directly with the Catalyst optimizer, MatRel can optimize query plans that contain both relational and matrix primitives.
As shown in the architecture, MatRel introduces a Matrix Query Optimizer and a Matrix Data Partitioner. These components allow the system to handle operations like matrix transpose, element-wise multiplication, and complex joins natively within the Spark environment. Matrices are represented using a relational schema—typically (RowID, ColID, Value)—which allows standard relational optimizations to be applied to linear algebra tasks.
Optimization Strategies
The core performance gains in MatRel stem from three primary innovations:
1. Algebraic Transformation Rules
MatRel employs a "push-down" paradigm similar to predicate push-down in traditional databases. By identifying mathematical equivalencies, the system can rewrite expensive matrix-matrix operations into much cheaper matrix-vector or scalar operations. For instance, if a query requires the sum of rows from a matrix product ($A \times B$), MatRel can push the summation operator "under" the multiplication, summing $B$ first.
2. Relational-Matrix Joins
The system defines several join flavors, such as "Direct Overlay" (matching indices) and "Value-to-Value" joins. To optimize these, MatRel utilizes Bloom joins to filter out mismatched entries early and identifies sparsity-inducing merge functions. This ensures that sparse matrices do not "densify" into memory-intensive formats during intermediate processing steps.
3. Communication-Aware Partitioning
Distributed joins are often bottlenecked by network shuffles. MatRel uses a cost model to determine the optimal partitioning strategy (Row, Column, or Broadcast) for a given join predicate. This minimizes data movement across the cluster, which is critical for scaling to massive datasets.
Performance Evaluation
The authors evaluated MatRel against state-of-the-art systems like SystemML and SciDB using both real-world social network data (e.g., LiveJournal, soc-pokec) and synthetic matrices.
- Speedup: In benchmarks such as Poisson Non-negative Matrix Factorization (PNMF), MatRel achieved up to 100x performance improvement.
- Memory Efficiency: Unlike standard Spark MLlib, which often suffers from Out-of-Memory (OOM) errors due to densification, MatRel maintains sparsity throughout the pipeline.
- Join Optimization: For "Transpose Overlay" joins, MatRel's optimizer can avoid physical transpose operations entirely by rewriting the join logic, significantly outperforming SciDB.
Conclusion and Future Directions
MatRel demonstrates that integrating relational query processing with big matrix data can yield massive efficiency gains. By treating linear algebra as a set of relational operations, the system unlocks powerful optimization rules that were previously inaccessible. Future work includes extending optimization rules to complex non-equality predicates and exploring hardware acceleration via GPUs to further enhance local matrix computations.
Summary updated