AI Query Compilation for Unified and Optimized Execution

Yeounoh Chung, Helena Caminal, Fatma OzcanarXiv 2026

TL;DR

This vision paper proposes a novel architectural paradigm that compiles hybrid AI queries—combining standard SQL relational operators and Large Language Model (LLM) inference—into a single, unified tensor compute graph using JAX and XLA. By executing the entire query holistically on hardware accelerators (TPUs/GPUs), this approach eliminates severe PCIe data movement bottlenecks and unlocks global compiler optimizations like automatic multi-device sharding.

What Problem Does This Paper Address?

Modern data analytics increasingly relies on "AI queries" that augment traditional SQL with AI semantic operators (e.g., using an LLM to classify user reviews or extract information). Currently, systems handle these hybrid workloads using a split execution model: traditional relational operations (like scans and filters) run eagerly on a CPU-based database engine, while the expensive LLM inference is offloaded to a separate machine learning serving framework running on GPUs or TPUs.

The authors identify a two-fold penalty caused by this dichotomy:

  1. The Data Movement Wall: Massive amounts of intermediate data (such as raw text, embeddings, or giant token logit matrices) must constantly be transferred back and forth across the Host-to-Device (H2D) PCIe boundary.
  2. Optimization Blind Spots: Because the SQL optimizer and the ML compiler operate in isolated environments, they cannot perform global cross-boundary optimizations, such as fusing a SQL filter directly with an LLM layer.

Methods

The core idea is to bridge the gap between relational databases and deep learning by lowering standard relational database operations (scans, filters, aggregations) into the exact same tensor compute graphs used by modern LLMs.

The proposed compilation pipeline works as follows:

  • Frontend Compilation: The system parses the hybrid SQL query into an Abstract Syntax Tree (AST). It then traverses the tree and maps SQL clauses directly to standard JAX functions and primitives based on a structural translation registry (e.g., mapping a WHERE clause to a vectorized boolean mask, and an AI_IF operator to a Flax causal language model forward pass).
  • Unified Execution via XLA: The resulting unified JAX program is compiled into a single accelerator executable using XLA's Just-In-Time (@jax.jit) compiler.
Figure 1: High-level view of the unified AI Query compilation flow.
  • Boundary Consolidation: Relational filters and reductions (like SUM) are evaluated directly on the TPU chip alongside the LLM. Instead of copying gigabytes of intermediate logits back to the CPU host, only the final scalar or generated tokens are returned.
  • Compiler-Driven Auto-Sharding: Because the entire query is a single tensor program, the compiler can use XLA’s GSPMD/PMAP to automatically and concurrently shard both the relational data arrays and the model weights across multiple accelerator devices.
Figure 3: Frontend compilation flow from SQL AST to unified JAX program.

Datasets

The prototype was evaluated using analytics queries from SemBench, specifically utilizing the Rotten Tomatoes Critic Reviews and Movies datasets. The authors scaled the workload up to 49,664 rows to evaluate performance and horizontal multi-device scaling behaviors.

Key Insights and Ideas

  • Data Compression via On-Chip Reduction: For a typical batch size, an LLM can generate over 1GB of output logits that traditional systems must copy over the PCIe bus for processing. By performing the SQL aggregation directly on the TPU, the data transfer footprint drops from gigabytes to kilobytes.
  • The Selectivity Trade-off: A unified static tensor graph requires processing rows in fixed micro-batches. The authors discovered that when a SQL filter is highly selective (e.g., skipping 90% of the data), the traditional split model can actually be faster because the CPU can eagerly skip LLM invocation entirely. This highlights a critical trade-off between compilation uniformity and dynamic data skipping.
  • Simplifying Parallelism: Instead of developers manually writing and synchronizing two independent parallelization strategies (one for CPU cores and one for tensor/pipeline model sharding), the unified compiler automates end-to-end multi-device partitioning.

Key Results

The authors evaluated their prototype on a Google TPUVM with four TPU v5e devices against an eager mixture baseline:

  • Speedups: For semantic filtering workloads (Query 1), the unified approach achieved up to a 5.34x latency speedup and a 5.30x throughput speedup over the baseline.
  • Throughput Gains: For hybrid queries where more rows qualify for LLM inference, throughput speedups reached up to 9.87x.
  • Data Transfer Reduction: In a complex cartesian cross-join query (Query 4), the unified approach avoided materializing duplicate pairs on the host, requiring a negligible 3.9 MB copy transfer size compared to the baseline's massive 3.9 GB transfer at 2,000 rows.
  • Linear Scaling: The system demonstrated near-perfect linear horizontal scaling, achieving a 4.00x speedup when scaling from 1 to 4 TPU devices.
Figure 4: Latency breakdown for Queries 1-3 for the base- line (split execution) and the unified approach. Note that we compile once (1st Run) and re-use the compiled program to amortize the compilation cost across the subsequent micro- batches (Amort).

Limitations and Future Work

As a vision paper, the authors outline several open technical challenges:

  • Semantic-Aware Cost-Based Optimization: Database optimizers need new cost models to intelligently decide when to use unified compiled execution versus traditional split execution based on data selectivity.
  • Dynamic Shape Compilation: JAX/XLA relies heavily on static tensor shapes, forcing the current prototype to pad inputs to maximum sequence lengths, which wastes memory. True dynamic-shape tracing is needed.
  • Multi-Query Concurrency: Currently, JAX programs queue serially (FIFO), leading to latency bottlenecks under multi-tenant workloads. A runtime scheduler capable of continuous batching across independent queries is required.
  • Dynamic Data Skipping: On-device mechanisms must be developed so that unified compilation can dynamically skip computations on the TPU when a relational predicate evaluates to false.

Summary updated

BibTeX
@misc{chung2026ai,
  author = {Yeounoh Chung and Helena Caminal and Fatma Ozcan},
  title = {{AI Query Compilation for Unified and Optimized Execution}},
  year = {2026},
  eprint = {2608.10139},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.10139},
}
Figure