QUEST: Query Optimization in Unstructured Document Analysis

Zhaoze Sun, Qiyan Deng, Chengliang Chai, Kaisen Jin, Xinyu Guo, Han Han, Ye Yuan, Guoren Wang, Lei Cao · DOI

Abstract

As Large Language Models (LLMs) are increasingly integrated into data systems to transform unstructured text into structured tables, they have become the primary performance and cost bottleneck. Traditional relational optimization rules often fail to account for the variable costs and semantic complexities of LLM-based extraction. This paper introduces QUEST, a novel query optimizer that treats LLMs as expensive database operators. By implementing a two-level indexing strategy and "instance-optimized" execution plans—where the order of operations is determined on a per-document basis—QUEST reduces monetary costs by up to 6x while simultaneously boosting extraction accuracy (F1 score) by 10%–27%.

Introduction

Data systems are evolving to handle unstructured sources like legal contracts, medical records, and web pages by converting them into queryable SQL tables using LLMs. However, unlike traditional database operations that incur negligible CPU costs, LLM inferences are expensive in terms of both latency and financial expenditure. Existing systems typically rely on standard relational optimization rules, such as pushing filters down as early as possible. QUEST argues that these rules are ineffective for LLMs due to variable costs associated with document length, "token bloat" from processing irrelevant text, and the semantic mismatch inherent in standard Retrieval-Augmented Generation (RAG).

The QUEST Architecture

QUEST introduces three primary innovations designed to minimize the "token tax" associated with unstructured data analysis:

1. Two-Level Indexing

To avoid scanning every document in a collection, QUEST employs a hierarchical indexing strategy. A document-level index uses summaries to prune irrelevant files entirely, while a segment-level index uses chunks to pinpoint the exact location of specific attributes within a document. This ensures the LLM only processes the most relevant text segments.

2. Evidence-Augmented Retrieval

Standard vector searches often fail when a query (e.g., "age") does not semantically resemble the answer (e.g., "born in 1988"). QUEST addresses this by sampling a small portion (5%) of the dataset to observe how attributes actually appear in the text. These patterns serve as "evidence" to improve RAG accuracy across the rest of the collection, bypassing the need for manual prompt engineering.

3. Instance-Optimized Query Execution

In a departure from traditional databases that create a single execution plan for an entire table, QUEST generates a plan per document. This "instance-optimized" approach recognizes that the cost of extracting an attribute varies by document. If a specific filter is easy (and thus cheap) to verify in Document A, QUEST executes it first. If that same filter is expensive in Document B, QUEST may prioritize a different filter or a join to determine if the expensive extraction can be skipped entirely.

4. Join Transformation

QUEST treats joins as dynamic filters. By extracting values from one side of a join and converting them into an "IN" clause for the other side, the system significantly reduces the volume of documents that require LLM processing.

Experimental Evaluation

The authors evaluated QUEST against state-of-the-art baselines, including ZenDB, Lotus, and Palimpzest, across three diverse datasets: Legal Case Reports (LCR), WikiText, and the Structured Web Data Extraction (SWDE) dataset.

Key Results

  • Cost Efficiency: QUEST achieved between 30% and 6x cost savings in token consumption. On the long-form LCR dataset, it proved 6x more cost-effective than Lotus.
  • Accuracy Improvements: The system improved F1 scores by 10%–27%, largely due to the Evidence-Augmented Retrieval mechanism which identifies context that standard vector searches miss.
  • Reduced Latency: By minimizing the total number of LLM calls and the tokens processed per call, QUEST operates roughly 2x faster than its competitors.

Discussion and Future Work

QUEST demonstrates that extraction should be treated as a "lazy operation," where data is only extracted when absolutely necessary. Furthermore, it challenges the "pushdown dogma" of standard SQL, proving that if a join attribute is easier to extract than a filter attribute, performing a "Join-as-Filter" first is more economical.

Currently, QUEST focuses on Select-Project-Join (SPJ) queries. Future work includes extending the optimizer to support complex aggregations (e.g., SUM, AVG) and group-by operations. Additionally, the authors aim to explore approximate query processing (AQP) to further reduce costs by analyzing only a representative subset of documents.

Summary updated

BibTeX
@article{sun2025quest,
  author = {Zhaoze Sun and Qiyan Deng and Chengliang Chai and Kaisen Jin and Xinyu Guo and Han Han and Ye Yuan and Guoren Wang and Lei Cao},
  title = {{QUEST: Query Optimization in Unstructured Document Analysis}},
  journal = {Proc. VLDB Endow.},
  year = {2025},
  doi = {10.14778/3749646.3749713},
}
Figure