Tensor Query Processing: How to ride the AI investment wave for database analytics?

Carlo CurinoSEBD 2023

Abstract

Traditional database engines, optimized for CPU architectures, face significant challenges in adapting to the rapidly evolving landscape of parallel hardware like GPUs and TPUs. This paper explores a novel framework developed by Microsoft researchers that compiles standard SQL queries into tensor abstractions compatible with AI runtimes such as PyTorch and ONNX. By treating relational algebra as a series of tensor operations, the system leverages massive industry investments in AI compilers and hardware. Our evaluation shows that this approach, implemented in just 20,000 lines of Python, outperforms established CPU-based analytics engines and matches the performance of specialized GPU databases.

Introduction

For decades, the architecture of database management systems (DBMS) has been tethered to the evolution of the CPU. However, the explosive growth of Artificial Intelligence (AI) has shifted the center of gravity in hardware development toward highly parallel computational devices, including Graphics Processing Units (GPUs) and Tensor Processing Units (TPUs). While AI frameworks have rapidly evolved to exploit these architectures, database analytics has largely remained on a separate, slower-moving track.

This divergence creates a "Portability Gap." Building high-performance database engines for specific GPU architectures is an expensive, labor-intensive process that often requires significant rewrites when new hardware generations emerge. This research proposes a transformative solution: instead of building database engines alongside AI stacks, we can build them on top of them.

Methodology: SQL as Tensor Operations

The core innovation of this research is the mapping of relational algebra—the mathematical foundation of SQL—onto tensor operations. This framework bridges the gap between structured tables and multi-dimensional tensors through several key mechanisms:

1. Tensor Abstraction

The system compiles SQL queries into intermediate representations (IR) used by popular AI runtimes like PyTorch, ONNX, and TVM. This allows the database engine to "speak the same language" as the most advanced AI compilers currently in development.

2. Tensor-Relational Operators

A specialized set of operators was designed to translate relational logic (joins, filters, aggregations) into tensor-friendly computations. This ensures that relational semantics are preserved while benefiting from tensor-centric optimizations.

3. Kernel Fusion

By utilizing existing AI kernel-fusion compilers, the framework can automatically merge multiple query steps into a single execution block. This significantly reduces memory overhead and maximizes hardware utilization—a technique that is standard in deep learning but often complex to implement in traditional SQL engines.

4. Lightweight Implementation

The efficiency of this approach is demonstrated by its implementation. Using only approximately 20,000 lines of Python code, the researchers offloaded the heavy lifting of hardware optimization to the existing AI infrastructure, proving that a massive C++ codebase is no longer a prerequisite for high-performance data processing.

Key Insights and Results

The research yields several critical insights into the future of data systems:

  • Hardware Agnosticism: By targeting tensor abstractions, the system becomes inherently hardware-agnostic. It can run on diverse GPU architectures or custom TPUs with minimal effort, effectively "future-proofing" the engine against hardware shifts.
  • Performance Parity: Despite its simplicity, the system outperforms state-of-the-art CPU-based systems, including SQL Server, Apache Spark, and Snowflake. Furthermore, it matches or exceeds the performance of "GPU-native" analytics systems specifically tuned for graphics hardware.
  • SQL + ML Convergence: Mapping SQL to tensors enables a seamless blend of traditional analytics and machine learning. A single pipeline can perform data filtering and model inference without the latency of moving data between disparate systems.

Limitations and Future Work

While the results are promising, the framework is currently a research prototype. Transitioning to a production-ready system involves addressing complex edge cases and the rigorous reliability requirements of enterprise environments. Furthermore, the current implementation lacks several "obvious" optimizations, suggesting that the performance ceiling for tensor-based query processing is likely much higher than currently demonstrated.

Conclusion

By "riding the AI wave," the database community can bypass the need to reinvent hardware-specific optimizations. This tensor-centric approach suggests a more efficient, portable, and unified future for both data analytics and machine learning.

Summary updated

BibTeX
@inproceedings{curino2023tensor,
  author = {Carlo Curino},
  title = {{Tensor Query Processing: How to ride the AI investment wave for database analytics?}},
  booktitle = {SEBD},
  year = {2023},
}
Figure