Abstract
Cardinality estimation is a fundamental challenge in database query optimization. Traditional methods relying on histograms often fail to capture complex data correlations, leading to suboptimal query plans. This paper presents an empirical analysis of deep learning models, including multi-layer perceptrons and tree ensembles, for cardinality estimation. By employing a novel query encoding scheme, these models achieve significant improvements in estimation accuracy and query execution speed across diverse real-world datasets.
Introduction: The Cardinality Estimation Problem
At the core of relational database management systems (RDBMS) lies the query optimizer, responsible for determining the most efficient execution plan for SQL queries. A critical input to this process is cardinality estimation—predicting the number of rows returned by various query operators. Traditional optimizers typically rely on pre-computed statistics like histograms and assume attribute independence. However, real-world data often exhibits strong correlations (e.g., between "Make" and "Model" in a vehicle database), causing traditional methods to produce highly inaccurate estimates and, consequently, slow execution plans.
Methodology
The researchers evaluated several machine learning architectures, including Multi-Layer Perceptrons (MLP), Recurrent Neural Networks (RNN), and Tree Ensembles (Random Forests and Gradient Boosted Trees), against the standard PostgreSQL optimizer.
Query Encoding: The "Secret Sauce"
To process SQL queries, the authors developed a specialized encoding scheme that transforms a query into a fixed-length feature vector. This vector is composed of three main parts:
- Relations ($\mathcal{I}_{relation}$): A one-hot vector indicating the tables involved in the query.
- Selection Predicates ($\mathcal{I}_{selpred}$): Instead of raw values, normalized percentiles (0 to 1) of the attribute's domain are used to improve generalization.
- Joins ($\mathcal{I}_{joinpred}$): A one-hot vector representing the join conditions.
Model Architectures
The primary focus was on simple yet effective architectures. The Multi-Layer Perceptron (MLP) consists of fully connected layers that map the encoded query vector to a predicted selectivity value.
Experimental Setup
The models were tested on three datasets representing different data characteristics:
- IMDB (JOB): A real-world movie dataset with complex, non-linear correlations.
- DMV: Vehicle registration data featuring high skew and functional dependencies.
- TPC-H (Skewed): An industry benchmark modified to test handling of non-uniform distributions.
Key Results and Insights
The empirical study yielded several significant findings:
- Superior Accuracy: Deep learning models reduced average estimation errors by 72% to 98% compared to PostgreSQL's native optimizer.
- Improved Execution Speed: Integrating these estimates into PostgreSQL resulted in query plans that were 7% to 49% faster.
- Model Robustness: While Tree Ensembles were highly accurate for "seen" queries, Neural Networks demonstrated greater robustness when generalizing to unseen query patterns.
- Efficiency: The storage footprint of the trained neural networks is comparable to high-resolution histograms, making them practical for integration.
Limitations and Future Directions
Despite the promising results, several challenges remain. The overhead of generating training data and the initial training phase is significant compared to building traditional histograms. Furthermore, maintaining model accuracy in the face of dynamic data updates (inserts/deletes) requires efficient incremental update strategies. Finally, the engineering complexity of integrating Python-based deep learning frameworks into high-performance database engines remains a hurdle for production deployment.
Summary updated