Abstract
Traditional Database Management Systems (DBMS) face significant engineering hurdles in supporting the rapidly evolving landscape of specialized AI hardware. TQP (Tensor Query Processor) addresses this by translating SQL queries into tensor programs that execute on existing AI frameworks like PyTorch and TVM. By leveraging the massive engineering investments in tensor computation runtimes (TCRs), TQP achieves high performance and seamless portability across CPUs, GPUs, and TPUs with a fraction of the code required by traditional engines.
Introduction: The Hardware Wall
Modern data processing is hitting a "hardware wall." While general-purpose CPU performance gains have plateaued, specialized AI hardware—including GPUs, TPUs, and custom ASICs—has seen explosive growth. For DBMS developers, supporting this diversity typically requires writing custom, low-level kernels for every new chip, an unsustainable engineering burden.
Furthermore, modern data pipelines frequently interleave relational analytics (SQL) with machine learning (ML). Moving data between specialized databases and ML frameworks creates significant performance bottlenecks. TQP proposes a "free-ride" strategy: instead of building custom engines for every chip, it builds a database engine on top of the TCRs that already provide optimized support for modern hardware.
System Architecture and Methods
TQP is designed as a compiler stack that maps relational algebra to tensor computations. The process begins by treating tables as collections of tensors; numerical columns are stored as 1D tensors, while strings are represented as 2D numeric tensors (padded character arrays).
As shown in the architecture overview, the system consists of four primary layers:
- Parsing Layer: Converts SQL (via Spark SQL) into an internal Intermediate Representation (IR).
- Optimization Layer: Performs rule-based transformations on the IR to improve efficiency.
- Planning Layer: Maps IR operators to specific tensor programs.
- Execution Layer: Generates the final executable, such as a PyTorch script or a compiled TVM model.
The core innovation lies in implementing complex relational operators using standard tensor primitives. For example, filters are implemented using boolean masks (masked_select), and joins are executed via a sort-based approach using primitives like sort, bincount, and bucketize. This allows TQP to implement complex operators in roughly 150–180 lines of code, compared to the thousands of lines required by systems like Spark or DuckDB.
Evaluation and Results
The system was evaluated using the industry-standard TPC-H benchmark (Scale Factors 1 to 10). TQP is notable for being one of the first GPU-capable systems to successfully execute all 22 queries in the TPC-H suite.
Key Performance Metrics
- GPU Acceleration: On a GPU, TQP can be 1.5x to 48x faster than a single-core CPU baseline. As seen in the performance table, TQP and its join-optimized variant (TQPJ) consistently outperform specialized GPU engines like BlazingSQL and Omnisci on many queries.
- CPU Competitiveness: On CPU hardware, TQP remains competitive with state-of-the-art vectorized engines like DuckDB.
- Portability: TQP demonstrated extreme versatility, running identical queries on Intel/AMD integrated GPUs, NVIDIA discrete GPUs, Google TPUs, and even within web browsers via WebAssembly.
- AI Integration: For workloads mixing SQL and ML predictions, TQP delivered up to a 9x speedup over traditional baselines by eliminating data movement between disparate systems.
Insights and Future Work
A primary insight of this research is that standard tensor operations—originally designed for neural networks—are expressive enough to implement full relational benchmarks efficiently. By targeting the tensor API rather than the hardware, TQP automatically inherits performance and portability updates from the underlying ML frameworks.
However, limitations remain. TQP's inter-operator scaling (distributing work across many CPU cores) currently lags behind mature systems like Apache Spark. Future work includes developing a "TCR-aware" optimizer to better handle the specific costs of tensor operations and expanding support for complex data types like decimals and advanced string operations, which are currently less optimized in standard tensor runtimes.
Summary updated