Range Aggregate Queries (RAQs)—such as calculating the average sales volume in a specific geographic region—are fundamental to data analytics. However, as datasets scale to billions of rows, providing exact answers in real-time becomes computationally prohibitive. To address this, Approximate Query Processing (AQP) has traditionally relied on statistical sketches or histograms. Recently, machine learning (ML) models have been employed to "learn" the underlying data distribution.
While promising, data-modeling approaches suffer from two significant drawbacks: a lack of theoretical guarantees and an inability to exploit patterns within the queries themselves. NeuroSketch addresses these issues by shifting the focus from modeling the data to modeling the query function directly.
Theoretical Foundation: The DQD Bound
A core contribution of this work is the Data distribution and Query Dependent (DQD) bound. This mathematical proof establishes that a neural network of a specific size can approximate a query function within a defined error limit. Unlike traditional database operations where more data increases latency, the DQD bound reveals a "larger is easier" paradox: as the dataset size ($n$) grows, the observed query answers converge more stably to the true underlying distribution, making the target function easier for the neural network to learn.
The complexity of learning is also governed by the Lipschitz constant of the distribution query function (LDQ). Smooth functions with low LDQ are easier to approximate, while highly erratic functions require greater model capacity.
The NeuroSketch Framework
NeuroSketch implements a "divide and conquer" strategy to handle complex, non-smooth query functions in practice. The framework follows a four-stage pipeline:
- Partitioning: The query space is recursively divided using a kd-tree.
- Merging: To optimize storage and computation, regions with low complexity—measured by the Average Query function Change (AQC)—are merged.
- Training: Small, independent neural networks are trained for each specialized region. This allows the system to allocate more parameters to the most challenging parts of the query space.
- Querying: Incoming queries are routed through the index to the appropriate neural network for a near-instantaneous forward pass.
Neural Network Construction
The framework's ability to approximate the query function is rooted in its construction methodology. By treating query answers as points in a high-dimensional space, the neural network effectively "memorizes" key points to reconstruct the overall function surface.
Experimental Results
NeuroSketch was evaluated against diverse datasets, including real-world air quality data (PM), massive geospatial location signals (Veraset), and industry-standard benchmarks (TPC-DS).
- Performance: NeuroSketch answers queries in microseconds, outperforming state-of-the-art learned engines like DeepDB and DBEst by 3 to 4 orders of magnitude.
- Accuracy: The system consistently achieves lower error rates, particularly for complex aggregates like Standard Deviation (STD) and Median, which are often difficult for traditional AQP methods.
- Efficiency: The entire model typically requires less than 1MB of storage, a stark contrast to competing ML models that can exceed 1GB.
Conclusion and Future Work
By modeling queries rather than data, NeuroSketch provides a theoretically grounded and highly efficient path for approximate query processing. While currently optimized for static datasets, future work aims to support dynamic updates and improve robustness against sudden workload shifts. This approach demonstrates that for large-scale analytics, learning the "answer" can be far more efficient than learning the "data."
Summary updated