Efficiently Approximating Selectivity Functions using Low Overhead Regression Models

Anshuman Dutt, Chi Wang, Vivek R. Narasayya, Surajit ChaudhuriPVLDB 2020

Abstract

Query optimizers rely heavily on accurate selectivity estimation to generate efficient execution plans. Traditional methods like histograms often fail to capture complex correlations between attributes, leading to suboptimal plans. While supervised machine learning models offer a promising alternative, their adoption is hindered by the prohibitive cost of generating large, accurately labeled training datasets. This paper presents a novel framework that utilizes iterative training and approximate labeling to build high-performance learned selectivity estimators. The resulting models are 10-100x more accurate than traditional commercial optimizers while reducing construction costs by an order of magnitude.

Introduction

The "brain" of any database system is its query optimizer, which determines the most efficient way to execute a query. A critical input to this process is selectivity estimation—the prediction of the fraction of rows satisfying specific filters or joins. Traditional approaches, primarily based on histograms, are fast but struggle with multi-attribute correlations. For instance, a query filtering on both "Model" and "Make" in an automobile database involves highly correlated fields that independent histograms cannot accurately model.

While supervised learning models can learn these correlations, they face a significant "training data bottleneck." Generating ground-truth selectivity labels for thousands of training queries requires executing those queries against the full dataset, a process that can take hours or days.

Methodology

To address the construction cost challenge, the authors propose two key algorithmic innovations: IterTrain and ApproxLabel.

Iterative Training (IterTrain)

Instead of pre-determining a large training set size, IterTrain starts with a minimal pool of labeled examples. It uses k-fold cross-validation to monitor model accuracy. If the target error threshold is not met, the training set size is increased geometrically. This approach ensures that only the necessary amount of labeling work is performed to reach the desired accuracy.

The IterTrain process uses a feedback loop to grow the training set size until target accuracy is achieved.

Approximate Labeling (ApproxLabel)

The ApproxLabel technique recognizes that regression models are robust to minor noise in training data. Instead of scanning entire tables to find exact selectivity, it uses small random samples. Concentration inequalities (such as Chernoff and Hoeffding bounds) are employed to ensure these approximate labels provide sufficient guidance for the model without introducing significant bias, speeding up label generation by over 10x.

Model Architecture and Feature Engineering

The framework utilizes XGBoost (Gradient Boosted Trees) for the regression model. XGBoost was selected for its fast training times and compact model size (approximately 16KB), allowing it to fit within a CPU's L1 cache for microsecond-level inference.

A critical component of the model's performance is the decimal encoding of IN clauses. Categorical bitmaps are converted into numerical features that the tree-based model can efficiently process.

Encoding of SQL query predicates into numerical features for the regression model.

Experimental Evaluation

The approach was evaluated using industry-standard benchmarks (TPC-H, TPC-DS) and a 97GB real-world sales dataset. The results demonstrate significant improvements across several dimensions:

  • Accuracy: The learned models achieved 95th-percentile errors that were 10-100x lower than those of traditional commercial optimizers.
  • Efficiency: The combination of IterTrain and ApproxLabel reduced total construction time by more than 10x compared to standard one-shot training.
  • Operational Impact: Improved selectivity estimates translated directly into better execution plans. In a test of 500 queries, 30% saw at least a 1.2x speedup, and 10% were 10x faster by avoiding poor join orders.

Conclusion

This research demonstrates that learned selectivity estimators can be both highly accurate and practical to build. By focusing on reducing the labeling bottleneck through iterative training and sampling-based approximation, the framework enables the deployment of sophisticated ML-based optimizers in production environments with minimal overhead. Future work includes extending these techniques to more complex operators and developing incremental maintenance strategies for dynamic datasets.

Summary updated

BibTeX
@article{dutt2020efficiently,
  author = {Anshuman Dutt and Chi Wang and Vivek R. Narasayya and Surajit Chaudhuri},
  title = {{Efficiently Approximating Selectivity Functions using Low Overhead Regression Models}},
  journal = {Proc. VLDB Endow.},
  year = {2020},
}
Figure