iPDB - Optimizing SQL Queries with ML and LLM Predicates
Udesh Kumarasinghe, Tyler Liu, Chunwei Liu, Walid G. Aref · 2026
Read iPDB - Optimizing SQL Queries with ML and LLM Predicates by Udesh Kumarasinghe, Tyler Liu, Chunwei Liu, Walid G. Aref (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2601-16432.txt.
Introduction
Udesh Kumarasinghe and three coauthors speed SQL queries that call learned models. Their 2026 preprint, named iPDB, deals with the base query tongue for data stores. SQL is tuned well for plain stored facts in rows. New apps want queries that call nets and large models as tests. Those calls are slow and cost much if run row by row.
The team tunes such queries with plan tricks for model calls. Tricks span call batch, cache and push down of tests. Fast model queries would join store facts to AI picks in one step. That join serves apps that need both at once. The work brings AI calls in to store tuning.
Catalog record
| CREATOR | Udesh Kumarasinghe, Tyler Liu, Chunwei Liu, Walid G. Aref |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 69 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2601-16432
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
iPDB - Optimizing SQL Queries with ML and LLM Predicates Udesh Kumarasinghe, Tyler Liu, Chunwei Liu, Walid G. Aref Abstract . Structured Query Language (SQL) has remained the standard query language for databases. SQL is highly optimized for processing structured data laid out in relations. Meanwhile, in the present application development landscape, it is highly desirable to utilize the power of learned models to perform complex tasks. Large language models (LLMs) have been shown to understand and extract information from unstructured textual data. However, SQL as a query language and accompanying relational database systems are either incompatible or inefficient for workloads that require leveraging learned models. This results in complex engineering and multiple data migration operations that move data between the data sources and the model inference platform. In this paper, we present iPDB, a relational system that supports in-database machine learning (ML) and large language model (LLM) inferencing using extended SQL syntax. In iPDB, LLMs and ML calls can function as semantic projects, as predicates to perform semantic selects and semantic joins, or for semantic grouping in group-by clauses. iPDB has a novel relational predict operator and semantic query optimizations that enable users to write and efficiently execute semantic SQL queries, outperforming the state-of-the-art. Keywords: In-database LLMs, Optimization, Semantic Operators Code Availability: The source code have been made available at https://github.com/purduedb/iPDB . 1. Introduction Recent advances in AI have opened the way for breakthroughs in applications, e.g., question answering ( 25 ) , information retrieval ( 26 ) , and language understanding ( 27 ) . However, Structured Query Language (SQL) has remained the standard and commonly used query language for databases. Although SQL is optimized for querying tables with structured attributes, e.g., numeric values and strings, it is inefficient on workloads that require semantic reasoning and extracting semantic information from unstructured data, which is highly relevant in today’s application development landscape. The success of deep learning and large language models (LLMs) has led to the application of learned models to perform complex tasks. For instance, LLMs have become highly desirable for extracting semantic information. Several studies have proposed systems that extract and filter information from documents ( 17 ; 15 ; 21 ) . Although these systems demonstrate the potential and applications of semantic query processing, they either introduce an imperative query language, only support unstructured data, or lack optimizations for relational data. To address the gap, we extend standard SQL queries by introducing first-class prediction functions. Specifically, we augment SQL language by incorporating model prediction and LLM inference. These added functions enable context-aware predictions and semantic operations, such as semantic selects, semantic projects, and semantic joins, surpassing the capabilities of traditional relational operations and predicates. For example, given a database table of products where each tuple is an PC component, we can find the list of compatible motherboards and CPUs, by self joining with an natural language condition. The following Listing 1 shows the extended SQL syntax for the query above. ⬇ 1 SELECT c . name , m . name 2 FROM Product AS m JOIN Product AS c 3 ON LLM o4mini ( PROMPT ’ is CPU {{ c . name }} { compatible BOOLEAN } with motherboard {{ m . name }}’) 4 WHERE m . category = ’ Motherboard ’ AND c . category = ’ CPU ’; Listing 1: A semantic SQL query that invokes calls to an LLM to perform a semantic join on the name column of filtered motherboards and CPUs It is evident that this functionality facilitates practical use cases. Incorporating learned model inference into SQL queries provides a generalized syntax for running inference on data stored in the database, enabling a wide array of tasks, e.g., classification, sentiment analysis, summarization, and text generation. Furthermore, having model inference capabilities within SQL enables users to leverage traditional SQL functionality and expressiveness to create more complex semantic queries that cannot be accomplished by simply feeding rows of unprocessed data into models. Additionally, by identifying patterns in semantic queries and performing logical and physical optimizations, it is possible to efficiently execute large-scale inference tasks. These optimizations are vital as LLM workloads are expensive in both runtime and monetary terms ( 15 ) . Although supporting semantic queries in a relational database system is important, realizing an efficient system is non-trivial. We observe the following challenges in implementing this system. • Inference in learned models is expensive and has a higher latency than traditional database operations. Thus, inferencing will be the bottleneck operation in semantic queries, necessitating prioritizing it when optimizing semantic queries. • Schema alignment must be ensured to fit text-native LLMs into relational databases that are schema-driven (i.e., typed columns and constraints). The inference operator must ensure that LLM output can be parsed into consistent column types (i.e., VARCHAR, INT, DOUBLE). • Learned models may produce missing values, values with type mismatches, or hallucinate outputs. The system must minimize the possibility of errors and handle adversities. • Inferencing is prone to runtime errors as a result of external factors e.g., memory overflow, GPU latency, and network errors. The system must handle these errors gracefully. To overcome these challenges, we realize iPDB, a data system with extended SQL and an execution engine that supports semantic queries. iPDB treats learned models as first-class citizens, where users can define, manage, and infer within the clauses of SQL, i.e., SELECT , FROM , WHERE , GROUP BY , and ORDER BY . We utilize DuckDB ( 18 ) , a columnar-based relational engine, to reuse its parser, relational query primitives, storage, and base query engine. However, to execute semantic queries in iPDB, we introduce several new components and extend DuckDB’s parser, planner, optimizer, and execution engine. The parser is extended with model manipulation language and predict/LLM predicates to support semantic queries. The model management capabilities are realized by introducing a new system catalog to store and retrieve model metadata. The inference of learned models is achieved through a new physical predict operator that manages input tuple processing and model probing, and extracts output attributes for schema compliance. Furthermore, new optimizations are introduced within the predict operator and the plan optimizer to minimize the latency of model inference. The following are the key contributions of the iPDB system: • Extended SQL Syntax for model inference, a new PREDICT and an LLM clause that appear among traditional SQL clauses to enable scalar inference, table inference and table generation, LLMs as predicates in the where clause, in semantic grouping, and in order-by clauses. These operators integrate model inference into Relational Algebra to take tables as input, perform model probing, and produce schema-compliant output tables. • New optimizations for LLM calls, e.g., prompt deduplication, multi-row prompt marshaling, semantic-predicate ordering, and semantic vs. traditional operator ordering. • A unified system that extends the relational parser, planner, optimizer, and execution engine to integrate model inference and metadata management, enabling the execution of relational and semantic query processing within a single declarative SQL framework. • Experimental results demonstrate that iPDB with the optimizations achieves up to 1000x improvement in performance over state-of-the-art systems by reducing the number of tokens and model calls while improving accuracy. iPDB treats learned models as first-class citizens