Cardinality Estimation in DBMS: A Comprehensive Benchmark Evaluation

Yuxing Han, Ziniu Wu, Peizhi Wu, Rong Zhu, Jingyi Yang, Liang Wei Tan, Kai Zeng, Gao Cong, Yanzhao Qin, Andreas Pfadler, Zhengping Qian, Jingren Zhou, Jiangneng Li, Bin CuiPVLDB 2021 · DOI

Abstract

Cardinality estimation (CardEst) plays a significant role in generating high-quality query plans for a query optimizer in DBMS. In the last decade, an increasing number of advanced CardEst methods (especially ML-based) have been proposed with outstanding estimation accuracy and inference latency. However, there exists no study that systematically evaluates the quality of these methods and answer the fundamental problem: to what extent can these methods improve the performance of query optimizer in real-world settings, which is the ultimate goal of a CardEst method. In this paper, we comprehensively and systematically compare the effectiveness of CardEst methods in a real DBMS. We establish a new benchmark for CardEst, which contains a new complex real-world dataset STATS and a diverse query workload STATS-CEB. We integrate multiple most representative CardEst methods into an open-source database system PostgreSQL, and comprehensively evaluate their true effectiveness in improving query plan quality, and other important aspects affecting their applicability, ranging from inference latency, model size, and training time, to update efficiency and accuracy. We find that the widely used estimation accuracy metric (Q-Error) cannot truly reflect the query plan quality generated by CardEst methods. Therefore, we propose a new metric P-Error to evaluate the performance of CardEst methods, which overcomes the limitation of Q-Error and is able to reflect the overall end-to-end performance.

Introduction

The Query Optimizer is the core component of a database system that determines the most efficient execution plan for a SQL query. Its success depends heavily on Cardinality Estimation (CardEst)—the process of predicting the number of rows returned by sub-queries. Inaccurate estimates often lead to suboptimal execution plans and significant performance degradation.

While recent "learned" CardEst methods have shown promise in terms of raw accuracy (often measured by Q-Error), their actual impact on end-to-end query performance in real-world database management systems (DBMS) remains poorly understood. This research addresses this gap by integrating 12 state-of-the-art CardEst methods into PostgreSQL and evaluating them against a new, more rigorous benchmark.

The STATS Benchmark and P-Error Metric

Existing benchmarks like JOB-LIGHT (based on IMDB) are often too simple to differentiate advanced methods. To provide a more realistic challenge, this study introduces the STATS dataset, derived from real-world Stack Exchange data. As shown in the comparison below, STATS features significantly higher skew and more complex correlations than the commonly used IMDB dataset.

Comparison of IMDB and STATS dataset characteristics.

Accompanying the dataset is the STATS-CEB workload, consisting of 146 queries with diverse join structures (chain, star, mixed). Furthermore, the authors propose P-Error as a superior metric to the traditional Q-Error. P-Error measures the cost ratio between the plan generated by an estimator and the optimal plan. Unlike Q-Error, P-Error correlates strongly (>0.8) with actual query runtime because it captures how estimation errors impact final plan selection.

Evaluation and Results

The study categorizes methods into Traditional (e.g., PostgreSQL histograms), Query-driven ML (e.g., MSCN), and Data-driven ML (e.g., FLAT, BayesCard). The end-to-end evaluation reveals that data-driven methods, particularly those based on Probabilistic Graphical Models (PGMs), offer the best balance of accuracy and efficiency.

End-to-end query performance comparison across different CardEst methods.

As seen in the results table, the FLAT method achieved a 47.8% improvement in end-to-end time on the STATS-CEB workload compared to the PostgreSQL baseline. This performance is remarkably close to the theoretical limit of 49.8% achieved by "TrueCard" (using actual cardinalities). In contrast, many query-driven methods struggled with workload shifts or high inference latency.

Key Insights

  • Metric Misalignment: Q-Error is a poor predictor of query performance. A single large error on a critical join can ruin a plan, even if the average Q-Error is low.
  • Scalability and Latency: Modeling the entire database schema as one large join is often impractical. "Divide and conquer" approaches used by FLAT and BayesCard scale better. Additionally, for simple queries, the overhead of ML inference can outweigh its benefits.
  • Practicality: BayesCard stands out for its update efficiency, capable of incorporating millions of new rows in just 12 seconds, making it suitable for dynamic environments.

Conclusion

This comprehensive evaluation demonstrates that while learned CardEst methods have immense potential to improve DBMS performance, their development must shift focus from raw accuracy to plan quality (P-Error). Future work should explore hybrid models that adapt to varying workloads and focus on minimizing the impact of errors on the final execution plan.

Summary updated

BibTeX
@article{han2021cardinality,
  author = {Yuxing Han and Ziniu Wu and Peizhi Wu and Rong Zhu and Jingyi Yang and Liang Wei Tan and Kai Zeng and Gao Cong and Yanzhao Qin and Andreas Pfadler and Zhengping Qian and Jingren Zhou and Jiangneng Li and Bin Cui},
  title = {{Cardinality Estimation in DBMS: A Comprehensive Benchmark Evaluation}},
  journal = {Proc. VLDB Endow.},
  year = {2021},
  doi = {10.14778/3503585.3503586},
}
Figure