NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Share the Tensor Tea: How Databases can Leverage the Machine Learning Ecosystem

Yuki Asada, Victor Fu, Apurva Gandhi, Advitya Gemawat, Lihao Zhang, Dong He, Vivek Gupta, Ehi Nosakhare, Dalitso Banda, Rathijit Sen, Matteo Interlandi

Introduction

The database community has long faced a fragmentation challenge. Achieving peak performance often requires developers to write highly specialized, hand-tuned code for specific hardware architectures, such as SIMD or GPUs. This specialization makes database engines difficult to port and maintain as new hardware emerges.

In contrast, the Machine Learning (ML) community has thrived by adopting the tensor abstraction. Frameworks like PyTorch and TensorFlow allow researchers to write high-level code that runs seamlessly across diverse hardware—from laptop CPUs to massive GPU clusters and even web browsers. TQP (Tensor Query Processor) bridges this gap by treating database queries like neural networks, bringing the ease of deployment and the rich toolset of the ML ecosystem to relational databases.

The TQP Architecture

TQP functions as a compiler stack that translates standard SQL relational operators into tensor programs. The workflow consists of four primary layers:

  1. Parsing: Converts a physical plan from a frontend (e.g., Apache Spark) into an internal Intermediate Representation (IR).
  2. Optimization: A rule-based optimizer performs IR-to-IR transformations to streamline the query.
  3. Planning: Maps relational operators—such as Joins, Filters, and Aggregates—into tensor program implementations in PyTorch.
  4. Execution: Lowers the final plan into a target backend, such as TorchScript, ONNX, or TVM.

By representing tabular data as columnar tensors, TQP executes relational logic using the highly optimized linear algebra kernels found in ML runtimes.

Key Insights: Unifying SQL and ML

One of the most significant advantages of TQP is the elimination of the "impedance mismatch" between databases and ML models. Traditionally, running an ML model on database data required exporting the data to a separate service. In TQP, the SQL query is a tensor program. This allows ML models to be embedded directly into the query plan, eliminating data movement overhead.

Integration of SQL logic and ML prediction in a single execution graph.

Furthermore, TQP gains "free" access to the ML developer ecosystem. For instance, developers can use TensorBoard to visualize SQL query plans and profile operator performance. Hardware portability is also simplified; switching a query from a CPU to a GPU requires only a single line of code, leveraging the underlying hardware abstraction of the tensor runtime.

Performance Evaluation

The authors evaluated TQP using the TPC-H benchmark (queries Q6 and Q14) and the Amazon Product Reviews dataset for prediction-heavy queries.

Query execution time comparison across different backends for TPC-H queries.

TQP demonstrates significant performance gains over established systems:

  • CPU Performance: TQP is approximately 3x faster than Apache Spark on identical CPU hardware.
  • GPU Acceleration: TQP on a GPU is 20x faster than Spark (CPU) and 4x faster than BlazingSQL, a specialized GPU-accelerated SQL engine.
  • End-to-End Prediction: The system successfully implements the PREDICT keyword in SQL, combining relational filters with state-of-the-art Transformers or traditional Scikit-learn models in a single execution graph.

Limitations and Future Outlook

While promising, TQP is currently a prototype with several areas for improvement. String handling remains a challenge, as tensors are natively designed for numerical data; TQP currently right-pads strings into numeric tensors, which is functional but less efficient. Additionally, while TQP can run SQL in a browser via ONNX and WebAssembly, performance in this environment is currently slower than native execution due to JavaScript/WASM overhead. Future work includes expanding frontend support beyond Apache Spark and exploring deeper integration with the ONNX Runtime (ORT).

Summary updated

BibTeX
@article{asada2022share,
  author = {Yuki Asada and Victor Fu and Apurva Gandhi and Advitya Gemawat and Lihao Zhang and Dong He and Vivek Gupta and Ehi Nosakhare and Dalitso Banda and Rathijit Sen and Matteo Interlandi},
  title = {{Share the Tensor Tea: How Databases can Leverage the Machine Learning Ecosystem}},
  journal = {Proc. VLDB Endow.},
  year = {2022},
}
Figure