CardBench: A Benchmark for Learned Cardinality Estimation in Relational Databases.

Yannis Chronis, Yawen Wang, Yu Gan, Sami Abu-El-Haija, Chelsea Lin, Carsten Binnig, Fatma Özcan · DOI · OpenReview

TL;DR

This paper introduces CardBench, a comprehensive benchmark and open-source toolkit for evaluating learned cardinality estimation (CE) models in relational databases. It addresses the lack of standardized datasets and benchmarks for this crucial task, enabling systematic progress in developing more accurate and efficient CE techniques, particularly for pre-trained models.

What Problem Does This Paper Address?

Cardinality estimation (CE) is a fundamental component of database query optimizers. It predicts the number of rows a query will return, guiding the optimizer to choose the most efficient execution plan. Traditional CE methods often rely on simplistic assumptions about data distribution and independence, leading to significant inaccuracies, especially for complex queries. While learned CE models have shown promise, they often suffer from high training overheads and a lack of standardized benchmarks for evaluation and comparison. This makes it difficult to assess their true potential, especially for generalizable, pre-trained models that can adapt to unseen datasets.

Methods

The authors introduce CardBench, a benchmark designed to facilitate the training and evaluation of learned CE models, with a particular focus on pre-trained, zero-shot, and fine-tuned approaches. The benchmark creation process involves:

  • Dataset Selection: Curating 20 diverse, real-world databases to stress CE models.
  • Statistics Calculation: Computing database-agnostic statistics that can serve as input features for learned models.
  • Query Generation and Execution: Generating SQL queries (single-table filters and binary joins) and executing them to obtain ground truth cardinalities. This process is computationally intensive, requiring significant CPU time.
  • Annotated Query Graph Generation: Representing SQL queries as graph structures with annotated features, suitable for graph-based learning models.

For model evaluation, they employ two main architectures:

  • Graph Neural Networks (GNNs): Leveraging graph structures to capture relationships between query elements.
  • Graph Transformers: Adapting transformer architectures for graph data, utilizing attention mechanisms.

They evaluate these models under three configurations:

  • Instance-based: Training a separate model for each dataset.
  • Zero-shot: Using a pre-trained model directly on unseen datasets without further training.
  • Fine-tuned: Fine-tuning a pre-trained model on a small subset of data from the target dataset.

Datasets

The paper introduces CardBench, a benchmark comprising:

  • 20 distinct real-world databases: Chosen for their diversity, complexity, and varied data distributions.
  • Two training datasets:
    • Single Table Queries: Queries with 1-4 filter predicates on a single table.
  • Binary Join Queries: Queries joining two tables, each with 1-3 filter predicates.
  • Scripts for statistics calculation, query generation, and annotated query graph creation.

This benchmark is significantly larger and more diverse than previous ones, aiming to support the development and evaluation of pre-trained CE models.

Key Insights and Ideas

  • The critical need for a diverse benchmark: Existing benchmarks are often too limited in scope (e.g., single dataset, specific query types), hindering the development of robust, generalizable CE models. CardBench's 20 datasets aim to fill this gap.
  • Zero-shot CE is challenging, especially with joins: While promising for simple single-table queries, learned models struggle to generalize to unseen datasets when joins are involved, indicating the complexity of cross-table relationships.
  • Fine-tuning is a powerful paradigm: Even a small amount of fine-tuning on a pre-trained model can significantly boost accuracy and sample efficiency, achieving performance comparable to instance-based models but with much lower training overhead.
  • GNNs show an edge over Transformers for query graphs: Despite transformers' larger receptive fields, GNNs' iterative message-passing approach along query graph paths seems more effective at capturing the structure of SQL queries for CE.
  • Traditional heuristics falter on complex queries: The baseline PostgreSQL approach, while decent for single-table queries, shows significant inaccuracy for binary joins, highlighting the limitations of its simplifying assumptions.

Key Results

  • Single Table Queries:
    • Instance-based models achieve the highest accuracy (e.g., GNN: P50 q-error 1.1, P95 q-error 24.08).
  • Zero-shot models struggle, showing lower accuracy, especially at the tail.
  • Fine-tuning with just 500 samples significantly improves accuracy, approaching instance-based performance.
  • Binary Join Queries:
    • The baseline approach exhibits very poor performance (median q-error 55.54, P95 q-error 4.4 x 10^6).
  • Instance-based models perform well (GNN: median q-error 1.16, P95 q-error 37.55).
  • Zero-shot models see a dramatic accuracy drop (up to 20x median, 5300x P95 q-errors).
  • Fine-tuning again shows substantial improvements, especially for tail queries, demonstrating the benefit of transferred knowledge.
  • Training Times: Instance-based and zero-shot training can take hours, while fine-tuning takes minutes (e.g., 11 minutes for GNN on single-table queries).

Limitations and Future Work

  • Limitations:
    • The paper acknowledges that zero-shot CE is challenging, particularly for complex queries involving joins.
  • While fine-tuning is effective, it still requires some data from the target dataset.
  • The current benchmark focuses on single-table and binary join queries; more complex multi-way joins are not explicitly covered.
  • Future Work:
    • The authors hope CardBench will foster more research in pre-trained CE models, including those from the ML community.
  • They encourage extending the benchmark with new datasets and more complex query types using the provided tools.
  • Further exploration of pre-trained models for more complex query scenarios is suggested.

Summary updated

BibTeX
@misc{chronis2024cardbench,
  author = {Yannis Chronis and Yawen Wang and Yu Gan and Sami Abu-El-Haija and Chelsea Lin and Carsten Binnig and Fatma Özcan},
  title = {{CardBench: A Benchmark for Learned Cardinality Estimation in Relational Databases.}},
  year = {2024},
  eprint = {2408.16170},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.16170},
}
Figure