QCATS: Query Context-Aware Transformer Slicing for Efficient Predictive Query Processing

Yueying Li, Zhongle Xie, Ke Chen, Lidan ShouarXiv 2026

TL;DR

QCATS (Query Context-Aware Transformer Slicing) accelerates in-database Transformer inference by using SQL predicates and metadata to pre-select specialized "expert slices" of the model. By shifting from fine-grained token-level routing to coarse-grained query-level routing, it achieves up to a 4.42× latency reduction and significant memory savings while maintaining the accuracy of dense models.

What Problem Does This Paper Address?

Modern analytical databases increasingly use Transformers (like BERT or Qwen) within SQL pipelines to analyze unstructured text. However, these models are computationally expensive. While techniques like Mixture-of-Experts (MoE) can reduce costs by only activating parts of a model, they typically operate at the token level.

In a database context, token-level routing is inefficient. It introduces dynamic scheduling overhead and "control-flow divergence," where different tokens in the same batch need different parts of the GPU, killing hardware utilization. Furthermore, existing systems treat models as "black boxes," ignoring the rich relational context—like SQL WHERE clauses or metadata—that could tell the system exactly which parts of the model are needed for a specific query.

Methods

The authors propose a two-stage framework to make Transformer inference "database-aware":

  1. Stage I: Offline Expert Construction: Instead of training a new model, QCATS decomposes a pre-trained dense Transformer. By profiling neuron activations across different semantic domains (e.g., "Food" vs. "Electronics"), they partition Feed-Forward Network (FFN) layers into a shared set (general knowledge) and multiple semantic sets (specialized experts).
  2. Stage II: Query-Time Context-Aware Routing: When a query arrives, a lightweight router analyzes the SQL predicates and metadata statistics to generate a "query context." This context is used to select the most relevant expert slices before the data even hits the model. This enables static routing, where every tuple in a query batch follows the same execution path.
Fig. 4: Overview of QCATS.

To further boost performance, the authors implemented Hierarchical Bucketing. This system-level optimization groups data first by their selected experts (ensuring batch homogeneity) and then by text length (minimizing wasted computation from padding).

Datasets

The framework was evaluated on four real-world datasets representing diverse domains:

  • Amazon Review: E-commerce product rating prediction.
  • Kickstarter: Crowdfunding campaign success prediction.
  • OSHA: Industrial accident severity classification.
  • CVE: Cybersecurity vulnerability severity prediction.

The authors also generated a benchmark of 50 SQL templates per dataset to simulate realistic analytical workloads involving joins, filters, and aggregations.

Key Insights and Ideas

  • Semantic Mismatch: The authors observed that different query contexts activate distinct, sparse subsets of neurons. For example, a sentiment analysis task on "Food" reviews uses different "circuits" than the same task on "Clothing" reviews.
  • Query-Level Locality: Because database queries naturally process large batches of similar data (e.g., all rows where category = 'Electronics'), we can move the routing logic out of the model's inner loops and into the query planner.
  • Static vs. Dynamic Routing: By pre-selecting experts at the query level, QCATS avoids the "fragmented GPU parallelism" that plagues traditional MoE models, allowing for much higher throughput.
Fig. 2: Average FFN neuron activations for text tuples selected by eight queries (Q1–Q8).

Key Results

  • Speedup: QCATS achieved between 2.73× and 4.42× end-to-end latency reduction compared to dense BERT-base and Qwen-0.6B models.
  • Memory Efficiency: By only loading the required expert slices into VRAM, QCATS significantly reduced the peak memory footprint, which is crucial for deploying large models in resource-constrained database environments.
  • Accuracy Preservation: Despite only using 25% of the FFN parameters during inference, QCATS maintained predictive accuracy comparable to (and sometimes exceeding) the original dense baselines.
  • System Gains: The asynchronous CPU-GPU pipeline and hierarchical bucketing were shown to be essential, as they prevented the system from becoming CPU-bound during data preprocessing.

Limitations and Future Work

  • Domain Specificity: The current expert library is constructed based on a fixed set of semantic groups. While the router can be fine-tuned, a major shift in data distribution might require rebuilding the expert slices.
  • Predictive vs. Generative: The paper focuses on "predictive" queries (classification, scoring) where outputs are short. The authors note that applying this to long-form autoregressive generation (like LLM chatting) remains future work.
  • Scaling: While tested on BERT and Qwen-0.6B, the authors plan to evaluate QCATS on even larger Transformer backbones and more complex, multi-domain workloads.

Summary updated

BibTeX
@misc{li2026qcats,
  author = {Yueying Li and Zhongle Xie and Ke Chen and Lidan Shou},
  title = {{QCATS: Query Context-Aware Transformer Slicing for Efficient Predictive Query Processing}},
  year = {2026},
  eprint = {2610.09894},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.09894},
}
Figure