Research Challenges in Relational Database Management Systems for LLM Queries

Kerem Akillioglu, Anurag Chakraborty, Sairaj Voruganti, M. Tamer ÖzsuarXiv 2025 · OpenReview

Abstract

Large language models (LLMs) have become essential for applications such as text summarization, sentiment analysis, and automated question-answering. Recently, LLMs have also been integrated into relational database management systems (RDBMS) to enhance querying and support advanced data processing. Companies such as Amazon, Databricks, Google, and Snowflake offer LLM invocation directly within SQL, denoted as LLM queries, to boost data insights. However, open-source solutions currently have limited functionality and poor performance. In this work, we present an early exploration of two open-source systems and one enterprise platform, using five representative queries to expose functional, performance, and scalability limits in today's SQL-invoked LLM integrations. We identify three main issues: enforcing structured outputs, optimizing resource utilization, and improving query planning. We implemented initial solutions and observed improvements in accommodating LLM powered SQL queries. These early gains demonstrate that tighter integration of LLM+DBMS is the key to scalable and efficient processing of LLM queries.

Introduction

The integration of Large Language Models (LLMs) into Relational Database Management Systems (RDBMS) represents a significant shift in data processing. By allowing SQL queries to invoke LLMs directly, users can perform semantic reasoning—such as sentiment analysis or text summarization—on structured data using familiar declarative syntax. However, as this collaboration from the University of Waterloo highlights, current open-source implementations face severe functional and performance hurdles that prevent them from being production-ready.

The Integration Gap: Functional and Performance Hurdles

The primary challenge in LLM-SQL integration lies in the fundamental mismatch between the rigid, deterministic nature of RDBMS and the "fuzzy," probabilistic nature of LLMs. Standard query engines treat LLM calls as "black-box" User-Defined Functions (UDFs), which leads to several critical issues:

  1. Functional Fragility: LLMs often produce conversational filler (e.g., "Sure, the sentiment is...") that breaks SQL functions expecting strict types, such as booleans for WHERE clauses or numeric values for AVG().
  2. Resource Inefficiency: Query optimizers lack cost models for LLM calls. An LLM invocation can be 1,000x more expensive than a standard join, yet current optimizers may place these expensive operators before selective filters, leading to unnecessary and costly inference.
  3. Scalability Constraints: Without native batching or prefix sharing, processing even moderate datasets (e.g., 17,000 rows) can take hours or even days.
Figure 1: Logical query plans for the five benchmarked queries, showing LLM operators integrated into relational trees.

As shown in Figure 1, LLM operations like llm_filter and llm_complete must be integrated into standard relational trees. However, if the optimizer is unaware of the LLM's cost, it cannot effectively reorder rows to group similar data together for KV-cache reuse or optimize the placement of the LLM call within the execution plan.

Experimental Methodology

The authors conducted an early exploration benchmarking three systems:

  • PostgreSQL with pgAI: An extension that allows calling LLMs via UDFs.
  • DuckDB with FlockMTL: A system using custom C++ functions to invoke LLMs.
  • MotherDuck: An enterprise cloud-based DuckDB platform using OpenAI’s GPT-4o-mini.

Tests were conducted using a local LLaMA 3.1 8B model served via Ollama and vLLM on an NVIDIA A100 GPU. The evaluation utilized the Rotten Tomatoes dataset (approximately 17,712 rows) for relational queries (Q1–Q4) and the Stanford Question Answering Dataset (SQuAD) for Retrieval-Augmented Generation (Q5).

Key Results and Analysis

The evaluation revealed a stark contrast between open-source and enterprise solutions. Most open-source systems failed complex queries out of the box due to formatting inconsistencies in LLM outputs.

Table 1: Success rates of different systems across five representative LLM queries, highlighting functional fragility in open-source implementations.

As summarized in Table 1, only MotherDuck—leveraging GPT-4o-mini’s native structured output—successfully completed the majority of the relational queries. Open-source systems struggled significantly with filters (Q2, Q3) and aggregations (Q4) because the LLM would return conversational text instead of the required schema-compliant values.

Performance results were equally concerning. For a simple projection query (Q1) on 17,000 rows, MotherDuck completed the task in 16 minutes, while pgAI (via Ollama) required approximately 719 minutes (12 hours). This latency gap is largely attributed to the "Batching Paradox": while batching multiple rows into one prompt improves throughput, it complicates row-to-result mapping in standard UDF frameworks, often forcing systems to process one row at a time to ensure reliability.

Discussion and Future Work

To bridge this gap, the authors suggest that future RDBMS must become "LLM-aware." Key areas for development include:

  • Constrained Decoding: Implementing tools like XGrammar to force LLMs to follow specific grammars, ensuring they always return valid SQL types.
  • LLM-Aware Cost Models: Developing optimizers that understand the high cost of LLM calls and can reorder rows to maximize prefix sharing and KV-cache reuse.
  • Approximate Query Processing: Exploring the use of small, cheap models to filter the majority of rows before sending the remaining data to a larger, more capable LLM.

The findings demonstrate that while LLM-powered SQL queries offer immense potential for semantic data processing, a tighter integration between the LLM and the DBMS engine is essential for achieving production-scale efficiency.

Summary updated

BibTeX
@misc{akillioglu2025research,
  author = {Kerem Akillioglu and Anurag Chakraborty and Sairaj Voruganti and M. Tamer Özsu},
  title = {{Research Challenges in Relational Database Management Systems for LLM Queries}},
  year = {2025},
  eprint = {2508.20912},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.20912},
}
Figure