Abstract
Interactive data exploration is often hampered by the high latency of analytical queries on massive datasets. SpeQL is a novel system that addresses this "friction" by using Large Language Models (LLMs) to predict and precompute SQL queries while a user is still typing. By speculating on query structure and materializing "superset" temporary tables during the human "thinking and typing" phase, SpeQL transforms multi-second waits into millisecond responses.
Introduction
In Business Intelligence (BI) and data warehousing, discovering insights requires iterative, ad-hoc querying. However, running these queries on hundreds of gigabytes or terabytes of data typically takes tens of seconds, discouraging exploration. Traditional optimizations like result caching or materialized views fail here because ad-hoc queries are unpredictable. SpeQL proposes a paradigm shift: treating the time a user spends typing as a computational resource to start execution before the "Enter" key is pressed.
System Architecture
SpeQL's architecture consists of two primary components designed to handle the uncertainty of human input.
The LLM-Guided Speculator
Since incomplete queries are often syntactically invalid, SpeQL employs LLMs (e.g., GPT-4o) to "debug" snippets in real-time and predict the final query based on schema and history. A key technique used is over-projection: the system selects additional columns the user might likely need. This ensures that the precomputed result is a "superset" of the final query, making the system robust to minor user edits.
The Logic-Driven Scheduler
Predicted queries are decomposed into a Directed Acyclic Graph (DAG) of temporary tables. This modularity allows for efficient reuse of intermediate results. If a user modifies a filter constant, SpeQL can often filter an already-materialized temporary table rather than re-scanning the base data. This structure also enables "interactive peeking," where users can hover over subqueries to see intermediate results, aiding in real-time debugging.
Optimization Hierarchy
SpeQL operates across a multi-level optimization hierarchy to maximize performance gains. This ranges from simple result caching to more complex data prefetching.
- Level 0 (Result Cache): Immediate return of previously computed results.
- Level 1 (Precomputed Structures): Materialized intermediate views or temporary tables.
- Level 2 (Prefetched Data): Loading relevant data into DRAM.
- Level 3 (Disk Storage): Standard cold-start execution.
Evaluation and Results
The system was evaluated using the TPC-DS benchmark (10GB to 1TB) and a user study with 24 participants.
- Performance: On a 100GB TPC-DS workload, SpeQL reduced P90 planning latency by 94.4%, compilation latency by 99.99%, and execution latency by 87.2%. In real-world scenarios, users experienced speedups of up to 289x.
- Productivity: 87.5% of participants reported improved productivity, citing the ability to "peek" at intermediate results as a major benefit for debugging and pattern discovery.
- Cost: The operational overhead is approximately $4/hour, a marginal cost compared to the productivity gains of near-instantaneous querying.
Conclusion and Future Work
SpeQL demonstrates that human "idle time" is a valuable resource for database optimization. While highly effective, the system faces challenges in multi-tenant environments and with extremely large datasets where execution time significantly exceeds typing time. Future research will explore speculative indexing and more robust handling of LLM hallucinations to further refine this proactive approach to data exploration.
Summary updated