Table of Contents
Fetching ...

Speculative Ad-hoc Querying

Haoyu Li, Srikanth Kandula, Maria Angels de Luis Balaguer, Aditya Akella, Venkat Arun

TL;DR

SpeQL introduces speculative ad-hoc querying to reduce latency in interactive analytics by predicting and precomputing portions of queries while users compose SQL. It combines an LLM-driven speculator (debugging, autocompletion, over-projection) with a logic-based scheduler that builds a DAG of temporary-table creations and previews, reusing intermediate results to accelerate final queries. Across 103 TPC-DS queries on 10–1000 GB scales, SpeQL achieves substantial reductions in planning, compilation, and execution latency, with a reasonable overhead and demonstrated improvements in user productivity and data exploration. The approach emphasizes privacy, dialect compatibility, and real-time speculative previews, offering a practical pathway to near-instantaneous analytics in large-scale data warehouses.

Abstract

Analyzing large datasets requires responsive query execution, but executing SQL queries on massive datasets can be slow. This paper explores whether query execution can begin even before the user has finished typing, allowing results to appear almost instantly. We propose SpeQL, a system that leverages Large Language Models (LLMs) to predict likely queries based on the database schema, the user's past queries, and their incomplete query. Since exact query prediction is infeasible, SpeQL speculates on partial queries in two ways: 1) it predicts the query structure to compile and plan queries in advance, and 2) it precomputes smaller temporary tables that are much smaller than the original database, but are still predicted to contain all information necessary to answer the user's final query. Additionally, SpeQL continuously displays results for speculated queries and subqueries in real time, aiding exploratory analysis. A utility/user study showed that SpeQL improved task completion time, and participants reported that its speculative display of results helped them discover patterns in the data more quickly. In the study, SpeQL improves user's query latency by up to $289\times$ and kept the overhead reasonable, at $\$4$ per hour.

Speculative Ad-hoc Querying

TL;DR

SpeQL introduces speculative ad-hoc querying to reduce latency in interactive analytics by predicting and precomputing portions of queries while users compose SQL. It combines an LLM-driven speculator (debugging, autocompletion, over-projection) with a logic-based scheduler that builds a DAG of temporary-table creations and previews, reusing intermediate results to accelerate final queries. Across 103 TPC-DS queries on 10–1000 GB scales, SpeQL achieves substantial reductions in planning, compilation, and execution latency, with a reasonable overhead and demonstrated improvements in user productivity and data exploration. The approach emphasizes privacy, dialect compatibility, and real-time speculative previews, offering a practical pathway to near-instantaneous analytics in large-scale data warehouses.

Abstract

Analyzing large datasets requires responsive query execution, but executing SQL queries on massive datasets can be slow. This paper explores whether query execution can begin even before the user has finished typing, allowing results to appear almost instantly. We propose SpeQL, a system that leverages Large Language Models (LLMs) to predict likely queries based on the database schema, the user's past queries, and their incomplete query. Since exact query prediction is infeasible, SpeQL speculates on partial queries in two ways: 1) it predicts the query structure to compile and plan queries in advance, and 2) it precomputes smaller temporary tables that are much smaller than the original database, but are still predicted to contain all information necessary to answer the user's final query. Additionally, SpeQL continuously displays results for speculated queries and subqueries in real time, aiding exploratory analysis. A utility/user study showed that SpeQL improved task completion time, and participants reported that its speculative display of results helped them discover patterns in the data more quickly. In the study, SpeQL improves user's query latency by up to and kept the overhead reasonable, at 4$ per hour.

Paper Structure

This paper contains 35 sections, 15 figures, 2 tables.

Figures (15)

  • Figure 1: SpeQL's workflow as the user edits the query. Each node represents a SELECT statement. SpeQL structures these nodes as a directed acyclic graph (DAG) and schedules their execution. The colored nodes indicate precomputed subqueries, while the result of the user’s highlighted (cursor-placed) query is previewed to the user.
  • Figure 2: SpeQL proposes a multi-level optimization hierarchy to mitigate varying degrees of misprediction.
  • Figure 3: SpeQL's modular architecture.
  • Figure 4: Running example referenced throughout § \ref{['sec::design']}. SpeQL fetches user input, using a speculator to debug (①), autocomplete (②), and over-project (③). The scheduler receives the superset query and constructs a DAG of query commands (④), dispatches the commands to precompute data structures or intermediate results (⑤), and evolves the DAG structure as the new input comes (⑥).
  • Figure 5: SpeQL serves as an intermediary between the user's editor and the analytical SQL database.
  • ...and 10 more figures