CardBench: A Benchmark for Learned Cardinality Estimation in Relational Databases

## Abstract

Abstract Cardinality estimation is crucial for enabling high query performance in relational databases. Recently learned cardinality estimation models have been proposed to improve accuracy
but there is no systematic benchmark or datasets which allows researchers to evaluate the progress made by new learned approaches and even systematically develop new learned approaches.
In this paper, we are releasing a benchmark, containing thousands of queries over 20 distinct real-world databases
for learned cardinality estimation. In contrast to other initial benchmarks, our benchmark is much more diverse and can be used for training and testing learned models systematically.
Using this benchmark, we explored whether learned cardinality estimation can be transferred to an unseen dataset in a zero-shot manner. We trained GNN-based and
transformer-based models to study the problem in three setups: 1-) instance-based, 2-) zero-shot, and 3-) fine-tuned. Our results show that while we get promising results for zero-shot cardinality estimation on simple single table queries; as soon as we add joins, the accuracy drops.
However, we show that with fine-tuning, we can still utilize pre-trained models for cardinality estimation, significantly reducing training overheads compared to instance specific models.
We are open sourcing our scripts to collect statistics, generate queries and training datasets to foster more extensive research, also from the ML community on the important problem of cardinality estimation and in particular improve on recent directions such as pre-trained cardinality estimation.

## 1 Introduction

Cardinality estimation (CE), the problem of determining the number of intermediate records that will be returned by a database query, is one of the key building block in modern databases for optimizing performance,
and has been studied extensively by the database research community.
CE is used by query optimizers to choose between alternative query execution plans. A query plan that produces the smallest intermediate results and processes the least amount of data usually leads to better execution times, and hence is preferred.
Thus CE is critical for optimization decisions such as choosing performant join orders, deciding on whether or not to use an index, and picking the best join method. It has been shown [] that "bad" cardinality estimates lead to "bad" execution plans that can have multiple orders of magnitude worse performance. CE is also critical in database recommenders to choose between alternative indexes, materializes views, and storage layouts.

Traditional CE techniques used in modern database systems have well-known limitations, as they make simplistic data modeling assumptions, such as data uniformity and independence of columns in the tables.
Learned CE model following an instance-based approach have been shown to improve upon the state-of-art techniques used by database systems today [, , , , , ].
Despite their better accuracy, learned CE models have not been adapted in practice, due to their high training overheads, among other reasons. As a result, pre-trained CE models, which are trained on a corpus of diverse datasets on transferable features, are highly desirable to alleviate the training costs and increase adaption.

##### Our Main Contributions.

In this paper we release CardBench, a benchmark containing thousands of queries on 20 distinct databases, and scripts to compute data summary statistics and generate queries.
We generated two training datasets; one with queries over single tables with multiple filter predicates, and one with queries with a binary join between two tables, and multiple filter predicates on each table.
Further, we release a query generator and flexible infrastructure that can be used and extended to generate even more complex training queries.
In comparison to existing CE benchmarks, CardBench includes a much higher number of datasets and training data (i.e., queries and cardinalities) to experiment with and compare different types of learned CE approaches.

To show the benchmark in-action, in this paper we have trained GNN-based and transformer-based CE models, under 3 setups: 1-) instance-based (i.e., a CE model trained only for the particular dataset), 2-) pre-trained CE model in zero-shot mode, 3-) pre-trained CE model with fine-tuning on the dataset.
Our results show that although CE is harder to learn with a pre-trained model in a zero-shot setting, but with a small amount of samples fine-tuning a pre-trained model can achieve high accuracy as good as, if not better than the instance-based methods.
We hope that releasing CardBench to the public community will help to reduce the barrier-of-entry for experimentation with learned CE models and also foster new research, also from the ML community, and lead to further advances on this highly important problem.

## 2 Background and Related Work

Learned Cardinality Estimation. Traditional CE methods rely on heuristics and simple analytical models [] (e.g., one-dimensional histograms or sketches). Recently, there have been various approaches for learned cardinality estimation [, , , , , , , , ].
While early learned approaches used classical regression models, more recently deep learning based approaches [, ] have been proposed which show highly promising accuracy over traditional approaches.
All of these methods are instance-based: they utilize instances-specific features like names of tables and columns; they are evaluated and trained on the same database.
There are two main approaches: workload driven and data driven. Workload driven approaches need to run a representative set of queries (10 to 100 thousands) to collect true cardinalities as labels for the training samples, incurring a very high overhead. These models also need to be re-trained as the representative workloads shift.
To avoid this high overhead of running thousands of queries to collect the true cardinalities per dataset, more recently so called data-driven learned cardinality estimators have been proposed [, ].
In contrast to the workload-driven approaches, data-driven approaches learn the multi-variate data distribution within and across tables without running any query plan but simply by learning data distributions of the base tables.
Data driven approaches still require one model per dataset and need to be re-trained as the data gets updates, which still incurs training overheads.
As such, very recently some first generalizable cardinality estimators [] have been proposed that can be used on datasets in a zero-shot manner; i.e., the model can be used without the need to learn one instance-specific model per dataset. Moreover, zero-shot models also promise that they can automatically provide accurate estimates even if the underlying data of the dataset is updated (i.e., new rows are added or existing ones are updated or deleted).
The core idea is that such zero-shot models are pre-trained on a broad spectrum of different datasets and use transferable features, such as table sizes, allowing them to generalize to unseen datasets.
We argue that more research is needed on pre-trained models on more compelx queries. For this purpose, we provide a very first large-scale training corpus to foster research in this direction.

##### Cardinality Estimation Benchmarks.

To benchmark cardinality estimation models, the early papers have mainly relied on either home-grown benchmarks with non-public datasets or they have used some available benchmarks that have been originally designed for other purposes. One central benchmark that has been used so far extensively by many papers is the Join Order Benchmark (JOB) [], which is based on real-world data from IMDb, containing interesting data distributions and correlations. JOB contains 79 queries, which challenge cardinality estimation. This is in stark contrast to many other database benchmarks such as the TPC benchmarks which use synthetic data that is way simpler and thus does not represent a real challenge for cardinality estimation.
However, one benchmark with one dataset is not sufficient to benchmark learned cardinality estimation and show its robustness towards various different real-world domains. As such, in the recent years, there have been further efforts to create additional benchmarks that can be used to test cardinality estimation models. For example, [] proposes a new benchmark, which contains one new real-world dataset STATS and a generated query workload that is more diverse in terms of query and data characteristics than JOB.
Another benchmark [], which aims in a similar direction uses two different datasets - IMDB and StackExchange (SE) - and contains 16K unique queries and true cardinalities.
However, these two benchmarks still mainly target instance-specific models which can be seen by the fact that they only contain one or two different datasets, which is clearly no sufficient for testing pre-trained models that require a representative set of different datasets.
In this paper, we thus present a benchmark that targets the pre-trained cardinality estimation and thus includes a much more diverse set of 20 different datasets which can be used for pre-training and testing.

## 3 CardBench

This section describes CardBench, an open-source benchmark(^1^11All data are released under the CC BY 4.0 International license, all source files are released under the Apache 2.0 license. [https://github.com/google-research/google-research/tree/master/CardBench_zero_shot_cardinality_training](https://github.com/google-research/google-research/tree/master/CardBench_zero_shot_cardinality_training)) for CE,
with a focus on enabling the training and testing of pre-trained zero-shot CE models but also instance-specific CE as well as fine-tuning pre-trained CE models.

Dataset Selection: Table 1 list the CardBench datasets. The datasets were chosen to be diverse, complex and cover a wide range of data distributions to stress CE models. All the datasets are publicly available or are based on publicly available datasets (we list the sources in the CardBench repository). Datasets marked with ($\sim$) in Table 1 are created by random sampling the original datasets to reduce their size. Smaller datasets reduce the cost of statistics calculation and running queries. For example, the size of the original *github_repos* dataset is 3 petabytes, using random sampling the version we use in CardBench is 300 gigabytes in size. The number of datasets included with CardBench was chosen to allow for training zero-shot models, which is validated by our experiments and previous work [],

Queries and Training Data: Our training data are SQL queries represented as graphs annotated with dataset statistics and the query cardinality as the label (Table 2, right). CardBench includes two sets of training data, *Single Table* and *Binary Join* (Table 1). *Single Table* queries filter a single table using 1 to 4 filter predicates. *Binary Join* queries join two tables that are also filtered with 1 to 3 filter predicates per table. The two training dataset configurations can demonstrate the challenges of more complex queries on CE models (see Section 5). To obtain the training labels (i.e. the query cardinalities) we used Google Big Query, executing the queries of *Single Table* and *Binary Join* required 7 cpu time years.
As such, releasing the queries with their true cardinalities significantly lowers the entry barrier for research on learned CE models.

**Table 1: Dataset and Workload Information**
| Database Name | Table Count | Single Table Queries | Binary Join Queries |
| --- | --- | --- | --- |
| accidents | 3 | 9125 | 8454 |
| airline | 19 | 6568 | 13096 |
| ^(∼) cms_synthetic_patient_data_omop | 24 | 12229 | 7833 |
| consumer | 3 | 5961 | 5571 |
| ^(∼) covid19_weathersource_com | 4 | 9366 | 10186 |
| ^(∼) crypto_bitcoin_cash | 2 | 14315 | 12404 |
| employee | 6 | 12675 | 10417 |
| ^(∼) ethereum_blockchain | 7 | 19756 | 17424 |
| ^(∼) geo_openstreetmap | 16 | 16346 | 15000 |
| ^(∼) github_repos | 8 | 5268 | 6789 |
| ^(∼) human_variant_annotation | 26 | 13862 | 14085 |
| ^(∼) idc_v10 | 19 | 8613 | 6470 |
| movielens | 13 | 14488 | 15757 |
| ^(∼) open_targets_genetics | 13 | 9734 | 9058 |
| ^(∼) samples | 8 | 8893 | 11369 |
| ^(∼) stackoverflow | 14 | 14305 | 12773 |
| tpch_10G | 8 | 11727 | 13181 |
| ^(∼) usfs_fia | 11 | 13822 | 11695 |
| ^(∼) uspto_oce_claims | 10 | 5925 | 6123 |
| ^(∼) wikipedia | 15 | 6659 | 7375 |

The number of queries we include per dataset varies, as shown in Table 1. The query generator (described in Section 3.1.2) uses dataset information and statistics and follows a random process to create realistic queries. Although we generate the same number of queries per datasets, during query execution we filter out queries that are duplicate, return zero results or timeout while running. As a result, the successfully run queries that become the training data vary per dataset. We opted not to cap the number of queries per dataset and leave it to the benchmark user to use as many queries as they deem useful. For example, for the experiments shown in Section 5 we use the same number of queries across all datasets to ensure a fair cross-comparison.

Accuracy Metric The q-error is a common metric in database systems research for evaluating the accuracy of CE models [, , ]. It calculates the relative deviation of the predicted cardinality from the true cardinality for a given query. The Q-error for a single query is calculated as follows:

$$ $\textrm{Q-error}=\max\big{(}\frac{\hat{y}}{y},\frac{y}{\hat{y}}\big{)}\in[1,+ \infty),$ (1) $$

where $y$ and $\hat{y}$ represent true and predicted cardinalities, respectively. We particularly focus on P50 and P95 q-errors aggregated across all queries within a dataset to evaluate the models’ accuracy in common and tail cases.
We refer to Section 5.1.1 for the details of how CardBench is used to train and evaluate zero-shot, instance and fine-tuned CE models.

Figure: Figure 1: CardBench Benchmark Creation Steps. The scripts to create the benchmark along with the training data (query graphs) released as open-source.
Refer to caption: x1.png

### 3.1 Benchmark Creation

The process we follow to create CardBench is illustrated in Figure 1 and comprises of three major steps a) statistics calculation, b) query generation and execution, c) annotated query graph generation. The first and second steps of the process involve running SQL queries to calculate statistics and collect the query plans and training labels. Thus, creating CardBench is expensive and for that reason alongside the pipeline that creates the benchmark we release the statistics of the datasets, the queries with their cardinalities and the query graphs.

#### 3.1.1 Dataset Statistics Calculation

In CardBench we include a set of data statistics and summaries which can be used as input features for CE models, we expect traditional query optimizers to calculate and store most of the statistics we use, but as not all query optimizers maintain the same set of statistics or calculate them in the same way, the first step in our infrastructure is statistics calculation. Therefore the statistics used by CardBench are database system agnostic. The calculated statistics are stored in a database and used to create the SQL queries as well as the training data.
Table 2 lists the statistics we calculate/collect.

Primary foreign key relationships (pk-fk) are part of a database schema design []. A pk-fk relationship is a logical connection between the columns of two tables semantically linking their information. Naturally we want to use pk-fk relationships when creating synthetic workloads. A challenge we faced is that open source datasets do not usually specify pk-fk relationships, instead we discover pk-fk relationship between columns of different tables using the steps outlined in Appendix A.1.

**Table 2: (left) Query Graph (heterogeneous) features. Features can be numeric (∈R) or categorical (∈Z). Symbol denote features utilized in query workload generation, and denotes ones used by our models (§5). Notes: ${}^{\textrm{(i)}}$ §3.1.1; ${}^{\textrm{ (ii)}}$ Always = “Pearson”; ${}^{\textrm{ (iii)}}$ $\in\{\texttt{join},\texttt{scan}\}$; ${}^{\textrm{ (iv)}}$ $\in\{=,>,<,\geq,\leq,\texttt{IS},\texttt{IS NOT},\texttt{BETWEEN},\texttt{AND}\}$. (right) Query Graph depiction with corresponding SQL query statement.**
| Node Type | Feature |  | Node Type | Feature |
| --- | --- | --- | --- | --- |
| tables | rows∈R |  | attributes | name∈Z |
|  | name∈Z |  |  | data_type∈Z |
| correlations | correlation∈R |  |  | null_frac∈R |
|  | validity∈Z |  |  | num_unique∈R |
|  | type${}_{\in\mathbb{Z}}^{\textrm{ (ii)}}$ |  |  | percentiles_100_numeric∈R |
| ops | operator${}_{\in\mathbb{Z}}^{\varheart\textrm{ (iii)}}$ |  |  | percentiles_100_string∈Z |
| predicates | predicate_operator${}_{\in\mathbb{Z}}^{\varheart\textrm{ (iv)}}$ |  |  | min_string∈Z |
|  | estimated_selectivity∈R |  |  | max_string∈Z |
|  | offset∈R |  |  | min_numeric∈Z |
|  | constant∈Z |  |  | max_numeric∈Z |
|  | encoded_constant∈R |  |  |  |

#### 3.1.2 SQL Query Generation and Execution

This step of the process generates a set of SQL queries per dataset and executes it to collect the query cardinalities, the training labels. We use the workload generator proposed by  [] (^2^22https://github.com/DataManagementLab/zero-shot-cost-estimation, license: Apache License 2.0). The generator takes as input the calculated statistics for each dataset and also a configuration that specifies the SQL query shapes to be produced. We have modified the original workload generator so that all queries return the cardinality as their final result.

#### 3.1.3 Annotated Query Graph Generation

After the queries are executed, we convert the SQL queries into a graph representation which is annotated with statistics.
We focus on transferable features and not dataset or workload specific features such as table and attribute names. This approach enables learning of zero-shot CE models. An example is shown in Table 2, on the right we present the sql query and its representation as a graph. The graph nodes are annotated with the features listed on the left of Table 2. The query graph has table nodes (in blue), column nodes (in green), operator nodes (in red), predicates (in yellow) and correlations across column of the same table (white circles with red outline). The only feature that is calculated as part of this step is the predicate *estimated_selectivity*, as both dataset statistics and query are needed. Selectivity is a fraction that represents the part of the input that satisfies a predicate [] and is used to estimate cardinality. We estimate selectivity for filter predicate nodes using the methods described in  [].

## 4 Cardinality Estimation Models

In this section, we discuss details of our model for which supports zero-shot CE.

### 4.1 Data Engineering

Features: The set of features (numerical or categorical) that the models use are specified in Table 2. In order to train a zero-shot model that can generalize to new datasets, we only include transferable features that are dataset-agnostic. This means that we exclude dataset-specific information such as table or column names. Furthermore, we select detailed statistics (e.g., histogram, correlation) as input features so the model can learn the underlying data distribution.

Pre-processing: For numerical features and the cardinality label, we employ a data transformation process to enhance their representation. First, we apply a logarithmic transformation to the data, which helps to reduce the impact of outliers. We then perform standardization to ensure that all features are on the same scale. For categorical features, we adopt one-hot encoding to allow effective learning of relationships between different categories. Additionally, we filter out queries with zero cardinality or zero predicates. In practice, such queries are relatively rare, and their inclusion could introduce noise into the training process.

### 4.2 Graph Neural Network Model

The graph representation of SQL queries provides a natural way to capture the relationship between different elements of a query. This representation allows us to directly leverage Graph Neural Network (GNN) which is designed to learn from graph-structured data. We build a GNN model to predict cardinality of queries based on the design of the GNN-based cost model from []. The GNN model first initializes the hidden state for each node by applying a node-type specific Multi-Layer-Perceptrons (MLP) to the node’s input feature vector (a concatenation of the input feature values of that node). It then updates the node hidden states via bottom-up message passing from leaf to root nodes, following the natural query processing order. Finally, the hidden state of the root node is read out as the learned graph-level embedding. This embedding is passed into an MLP-based cardinality model to get the final prediction.

### 4.3 Graph Transformer Model

In addition to GNN, Graph transformer is an emerging type of neural network architecture specifically designed for graphs. Similar to traditional transformers, which capture the relationship between tokens in a sequence with self-attention, graph transformer extends the attention mechanism to graphical data, where the relationships between different nodes are constrained by the graph structure [].
Compared to traditional transformers, we make following adaptation(^3^33Figure 6 in the appendix illustrates the architecture of the attention block of the graph transformer model designed to embed SQL query graphs.):

Heterogeneous input embedding layer: The SQL query graph is a heterogeneous graph with multiple node types that contain different features. For each node type, we use a separate input embedding layer to project node features to a fixed-dimension input node embedding.

Shortest distance spatial encoding: Following the methodology of Graphormer [], we compute the shortest path distance between node pairs to construct a spatial encoding matrix. This matrix is incorporated as a learnable bias that adds to the input before the softmax in the self-attention block.

Directional causal mask: To ensure information flow adheres strictly to the DAG’s structure, we implement a causal masking mechanism based on the topological ordering of the nodes.

Virtual node readout: Inspired by Graphormer, we augment the query graph by introducing a virtual node as the direct child of all other nodes. Given that the virtual node attends to all other nodes in the query graph, its embedding serves as the graph-level representation for cardinality prediction.

## 5 Experimental Findings

In this section, we present our empirical findings, evaluating the accuracy of various model configurations for cardinality prediction across all datasets in CardBench.

### 5.1 Evaluation Setup

#### 5.1.1 Model Configurations

We assess cardinality prediction performance using three distinct ML model configurations: instance-based, zero-shot, and fine-tuned.

Instance-based Models: In this configuration, we train and evaluate individual models using a single dataset. For each dataset, queries are randomly partitioned into training and validation sets with 85:15 train-validation split. An additional 500 queries are reserved as a standalone test set to evaluate final model accuracy.

Zero-shot Models: This configuration investigates the generalizability of cardinality prediction models to out-of-distribution data, i.e., data from another dataset apart from the training data. We train and validate the model on queries from 19 datasets, maintaining the 85:15 train-validation split. The model is then tested on the standalone test set of the remaining 20th dataset. This test set contains the same queries used in the instance-based setting to ensure a fair comparison.

Fine-tuned Models: This configuration investigates whether fine-tuning a pre-trained zero-shot model improves accuracy and sample efficiency. We fine-tune the model initially trained on 19 datasets using the 20th dataset. The fine-tuned model’s accuracy is then evaluated using the same 500 holdout queries from this 20th dataset.

The average training times under each configuration are(^4^44Listed in instance-based, zero-shot, fine-tuned order.) 1.3hr, 1.4hr and 11min (single-table queries), and 1.3hr, 1.5hr, and 11min (binary join queries) for the GNN-based model on a 8-core VM (4GB memory). For the Transformer-based model the average training times are 3.3hr, 11.8hr and 1.6hr (single-table queries), 11.1hr, 11.1hr and 2.1hr (binary join queries) on a V100 GPU. We observe that training the zero-shot model over extended epochs can often result in lower accuracy due to over-fitting to the training set. Therefore, we cap the maximum number of training epochs for zero-shot training to 20, and set a maximum training epochs of 100 for the other two configurations.

#### 5.1.2 Baseline

We compare the learned cardinality approaches against a baseline algorithm that represents heuristics employed in conventional DBMS such as PostgreSQL(^5^55https://www.postgresql.org/). This baseline algorithm assumes data independence between columns and computes the selectivity of conjunctive (AND)
predicates using the formula: $sel(p_{1}\land p_{2})=sel(p_{1})\cdot sel(p_{2})$.
The selectivity of other relational predicates is estimated according to the description in Section 3.1.3.

For binary joins, the baseline approach makes the simplifying assumption that the smaller table contains the primary key, which participates in the join condition, hence the cardinality of the binary join is computed as the estimated output cardinality of the scan operator of the larger table (an assumption commonly made by database systems).

Figure: Figure 2: Box plots of P50 (left) and P95 (right) q-errors of different model configurations for queries on a single table, aggregated across 20 test datasets.
Refer to caption: x3.png

Figure: Figure 3: Box plots of P50 (left) and P95 (right) q-errors of different model configurations for queries contains a binary join, aggregated across 20 test datasets.
Refer to caption: x4.png

### 5.2 Accuracy of Cardinality Prediction

We evaluate the accuracy of cardinality prediction by comparing the baseline method, GNN models, and graph transformer models, each under different configurations as described in Section 5.1.1. We run a single experiment on each of the 20 test datasets in CardBench per model configuration. We then collect and aggregate the accuracy metrics across all experiments per model configuration. For training instance-based and zero-shot models, 4500 queries are randomly selected per dataset to form the training and validation set. Fine-tuning utilizes a smaller subset of 500 queries per dataset.

#### 5.2.1 Single Table Cardinality Prediction

Figure 2 shows the box-and-whisker plots of P50 and P95 q-errors of different model configurations for queries on a single table, aggregated across 20 test datasets in CardBench. The baseline algorithm demonstrates strong median accuracy results in single-table cardinality prediction, with the majority of datasets achieving a q-error below $1.5$.
However, accuracy degrades significantly at the tail due to the failure of both the uniform distribution and independence assumptions that the baseline approach makes, especially for more complex queries.

GNN-based models outperform transformer-based models in most cases, despite the latter’s larger receptive field through attention mechanisms. This suggests that iterative message passing along query graph paths adequately captures the structure of SQL queries. Notably, instance-based models achieve the highest accuracy, with the GNN model demonstrating an average P50 q-error of $1.1$ and a P95 q-error of $24.08$, and the transformer model demonstrating an average P50 q-error of $1.15$ and a P95 q-error of $136.87$. It is achieved by implicitly learning dataset-specific joint-column data distributions, enabling tailored predictions. In contrast to instance-based models, zero-shot models struggle to generalize such knowledge to unseen datasets, resulting in a lower accuracy (especially at the tail). Fine-tuning pre-trained models, even with a modest 500 samples, significantly improves accuracy for both GNN and transformer models, highlighting the importance of incorporating table and column-specific distributions for accurate cardinality prediction.

#### 5.2.2 Binary Join Cardinality Prediction

Cardinality prediction for queries with binary joins is much more challenging than single table because cross-table distribution and multi-column correlation, which are difficult to model, significantly impact join cardinality. Figure 3 shows the P50 and P95 q-errors for queries with binary joins. In contrast to single-table prediction, the baseline algorithm exhibits significant inaccuracy in binary join query CE, with a median q-error of $55.54$ and P95 q-error of $4.4\times 10^{6}$, respectively. This appears to be a result of the oversimplified assumption that queries join two tables via single-column primary and foreign keys, without considering more complex cross-table relationships that are intractable using traditional heuristics.

Learning-based models significantly outperform the baseline though, particularly at the 95th percentile. Instance-based models, which learn cross-table distributions within a dataset, achieve low median q-errors of 1.16 (GNN) and 1.20 (transformer). While their P95 q-errors are higher (37.55 for GNN, 43.96 for transformer), the results suggest that estimating join cardinality via learned distributions is feasible. However, out-of-distribution cardinality prediction for binary joins proves more challenging, as zero-shot models experience a dramatic increase in q-errors (up to 20x at the median, 5300x at P95). As with single-table results, even a small amount of data used for fine-tuning improves the accuracy of pre-trained models considerably.

Figure: Figure 4: Box plots of P50 (left) and P95 (right) q-errors of instance-based vs. fine-tuned models of GNN (top) and Transformer (bottom) with varying training sample size for queries on a single table, aggregated across 20 test datasets.
Refer to caption: x5.png

Figure: Figure 5: Box plots of P50 (left) and P95 (right) q-errors of instance-based vs. fine-tuned models of GNN (top) and Transformer (bottom) with varying training sample size for queries contains a binary join, aggregated across 20 test datasets.
Refer to caption: x6.png

### 5.3 Varying Sample Size

We study the impact of varying amounts of training data on model accuracy by considering three sample sizes: 250, 500, and 1000. For each sample size, we train an instance-based model or fine-tune a pre-trained model, and evaluate it on the same 500 samples as described in Section 5.1.1. We repeat this process for both the GNN and transformer-based models. The results for single table and binary join cardinality predictions are summarized in figure 4 and figure 5 respectively. We observe same patterns between GNN and transformer. The model accuracy improves as more training data is provided, for both instance-based and fine-tuned models.

Comparing instance-based training with fine-tuning, we find that the fine-tuned models are more sample-efficient. Fine-tuned models achieve similar median and tail Q-errors as instance-based models trained with twice the amount of data. This is evidence that fine-tuned models benefit from the generalization power of a pre-trained model, which has learned from a large number of data patterns over many datasets.
When using only 500 samples from each of the binary join datasets, the average P50 and P95 Q-errors across 20 datasets are: 1.57 & 280 for the instanced-based GNN model, and 1.32 & 120 for the fine-tuned GNN model. There is a significant improvement especially for the tail queries due to learnings transferred from more diverse data patterns seen by the pre-trained model. Nonetheless, the accuracy gap
between instance-based and fine-tuned models reduces as the sample size increases. This suggests that fine-tuning on a pre-trained model is more advantageous when there is limited amount of training data available for a new dataset.

## 6 Conclusion and Broader Impact

In this paper, we release CardBench a benchmark for CE in relational databases. CardBench contains code to 1-) compute various data statistics, 2-) generate queries and execute them, and 3-) create the training data (the annotated querygraphs). We are also releasing two training datasets with queries over 20 datasets and their true cardinalities: one containing queries with single table queries and the other with binary joins. We trained both instance-based and zero-shot models, and observed that CE is a extremely challenging problem to learn in a zero-shot manner. However, when using pre-trained models with a small amount of fine-tuning, we can achieve accuracy similar to instance-based models, with much lower training overhead.

With CardBench, we hope to provide a systematic mechanism to track progress, especially on recent directions such as pre-trained CE models.
Moreover, we think that CardBench is highly important to foster further research on CE models, from the ML and DB communities.
The training datasets were constructed with high overhead (7 cpu years of query runtime). Releasing such a training set lowers the barrier of entry for developing and training new CE models. Furthermore, we hope that the benchmark itself will be extended with new datasets and more complex queries using the tools and code we provide and thus push the boundaries of learned CE models further.

## Appendix A Appendix

### A.1 Primary-Foreign Key Relationships

Primary foreign key (pk-fk) relationships are part of a database schema design []. A pk-fk relationship is a logical connection between the columns of two tables semantically linking their information. In the real world, most of the times two tables are joined using the columns that participate in the pk-fk relationship. Naturally we want to use pk-fk relationships when creating synthetic workloads. A challenge we faced is that open source datasets do not usually specify pk-fk relationships, instead we discover pk-fk relationship between columns of different tables using the steps outlined below. One assumptions we make is that data is organized in a snowflake schema, this is the norm in practice and what is assumed by most database benchmarks (TPC-H [], SSB [], TPC-DS[], TPC-C[], JOB[]).

- 1.
Identify candidate primary keys per table using a uniqueness threshold and choose one with the most unique values. A primary key should be unique for each row of a table [], we relax this condition and require that for a column to be a primary key more than 90% of rows must be unique values.
- 2.
Split tables of a dataset in fact and dimension tables(^6^66[https://en.wikipedia.org/wiki/Snowflake_schema](https://en.wikipedia.org/wiki/Snowflake_schema)). The criteria we use is a size threshold (fact tables should be a few times larger than dimension tables) as well as a check if a primary key exists for dimension tables.
- 3.
For each dimension table and pk column identify a fk column in the fact table(s). Out of all possible candidates we choose the pk-fk pair with the most join results, which we obtain by running a join query using the candidate pk-fk column pair as the join condition.

### A.2 Graph Transformer

Figure 6 shows an overview of attention block of the graph transformer.

Figure: Figure 6: An overview of the attention block of the graph transformer
Refer to caption: x7.png

## Peer Reviews

confidence: 3
contribution: 2
initial_rating: 5
presentation: 2
questions: see weakness above
soundness: 2
strengths: The paper details a systematic data preparation process, including SQL query generation, dataset statistics calculation, and annotated query graph creation, which offers a replicable approach for dataset-agnostic testing.

The paper’s emphasis on creating a model that can generalize to unseen datasets is a unique and relevant shift in the CE field, considering the increasing need for adaptable models in dynamic data environments.
summary: This paper proposes a benchmarking framework aimed at cardinality estimation within relational databases, using advanced learning methods like GNNs and Transformers.
weaknesses: 1. The authors said that they have collected data from 20 datasets with diverse sources compared with existing benchmarks. But I can't see this comparsion to conclude that how novel this part is. It deserves detailed discussion.

2. Although it includes single-table and multi-table queries, it lacks support for deeply nested and highly complex SQL queries, which are common in real-world database applications. This limitation in query complexity could lead to suboptimal model performance in practical scenarios.

3. Only q-error is used as the main evaluation metric, which may not fully capture model performance. Additional dimensions, such as runtime and resource consumption, could provide a more comprehensive assessment.

---

confidence: 3
contribution: 2
initial_rating: 3
presentation: 2
questions: D1: This paper proposes several synthetic cardinality estimation datasets. But what are the patterns and distributions in these datasets?

D2: Why are these datasets comprehensive and diverse? From a database view, are these proposed datasets complete? It is better to add more justifications.

D3: This paper proposes zero-shot estimation but only investigates limited GNNs. In cardinality estimation, whether sampling-based approaches or summary-based approaches, all work under a zero-shot setting. These approaches do not need any training instances. But this paper does not explore these approaches.

D4: Even for GNN-based baselines, they are too simple. 

D5: How about the training time and inference time compared with the time of the training-free methods? If the training-free methods are better than the proposed method, it is meaningless to propose a pre-trained model.

D6: This paper only explores the performance on cardinality estimation error. But how to prove it can achieve better performance on downstream applications? It is better to deploy this model on a real database system to see its improvements.
soundness: 2
strengths: S1: Cardinality estimation is critical for the database community.

S2: This paper proposes several datasets, which will be useful for academic and industry communities.

S3: Zero-shot cardinality estimation seems to be useful.
summary: The paper introduces CardBench, a benchmark for evaluating learned cardinality estimation models in relational databases. Cardinality estimation is vital for query optimization, but existing models lack a comprehensive benchmark for systematic evaluation. CardBench provides this with extensive queries across 20 real-world databases. The study evaluates GNN and transformer-based models in instance-based, zero-shot, and fine-tuned setups, highlighting challenges in zero-shot accuracy with complex queries but demonstrating the potential of fine-tuning pre-trained models. By releasing scripts and data, the authors encourage further research, showing that pre-trained models can achieve high accuracy with reduced training overhead.
weaknesses: W1: The details of the datasets are unclear.

W2: The baselines are too weak and lack state-of-the-art and representative cardinality estimation baselines.

W3: The experiments lack detailed analysis of the proposed models regarding the zero-shot setting.

---

confidence: 3
contribution: 3
initial_rating: 5
presentation: 2
questions: Please refer to the weakness section and I am concerned about the realistic usage of this proposed benchmark or it is an ``made" problem.
soundness: 3
strengths: + A large-scale benchmark dataset for Cardinality Estimation
+ Good evaluations and benchmark analyses.
+ Clear organizations and easy to read.
summary: This paper proposes the cardbench, a benchmark dataset for cardinality estimation in relational databases, which contains over 20 distinct real-world databases. This proposed dataset shows clear diverse and proposes several baseline models including the GNN and transformer modules to form a benchmark evaluation of this benchmark dataset.
weaknesses: + My major concern is about the benchmark contributions to this research field. In the related work section, the authors talked about how existing benchmarks only contain one or two datasets which is insufficient for testing pretraining models. Thus my question is, how does this proposed benchmark test these pretrained models? It seems the authors only test typical GNN or Transformer architectures. 
This dataset seems not to be comprehensive as a benchmark in this research field.
+ Besides, gathering different datasets or re-organizing them also may help the aforementioned problems. Why is this proposed benchmark unique? I am concerned about the realistic usage and if this is a real problem for the community.
+ There are also several minor issues, including the presentations for the Sect. 3 and the table format for table 1. These presentations could be improved.

---

confidence: 4
contribution: 2
initial_rating: 5
presentation: 2
questions: Please see weaknesses.
soundness: 2
strengths: - CardBench includes a broad range of datasets, 20 distinct real-world datasets, that provide a more comprehensive evaluation framework for learned cardinality estimation models compared to existing benchmarks.
- The benchmark facilitates systematic testing of various learned CE approaches, allowing researchers to assess model performance comprehensively. By open-sourcing the benchmark, query generator, and associated scripts, the authors foster collaboration and further research in the field, lowering barriers for other researchers to experiment with learned cardinality estimation.
- The paper is clearly written and organised.
summary: The paper presents CardBench, a benchmark for evaluating learned cardinality estimation models in relational databases. CE is vital for optimizing query performance, yet traditional methods often lack accuracy. CardBench offers a diverse set of datasets and queries, featuring hundreds of thousands of queries across 20 real-world datasets, enabling systematic assessments of new CE approaches.
Experiments with GNN and transformer-based models were conducted under three setups: instance-based, zero-shot, and fine-tuning. While zero-shot estimation shows promise for simple queries, its accuracy declines with complex joins. However, fine-tuning pre-trained models can enhance performance significantly, reducing training costs.
The authors emphasize that CardBench will lower barriers for research in learned CE and encourage further exploration from the machine learning community.
weaknesses: - There are several typos that need to be corrected in future revisions.
- It would be beneficial to include more detailed statistical experimental results. While boxplots effectively illustrate the distribution of results, providing exact values enables precise comparisons between data points.
- The descriptions of the GNN and Transformer models used in the experiments are lacking. More detailed explanations would help readers gain better insights into the methodologies.
- The paper should discuss how the performance of other state-of-the-art methods compares on CardBench, which would provide context and strengthen the findings.

Meta-review: The paper introduces CardBench, a benchmark comprising thousands of queries across 20 distinct databases, along with scripts to compute data summary statistics and generate queries. Using this benchmark, the paper evaluates learned cardinality estimation in a zero-shot setting. GNN-based and transformer-based models are trained and analyzed under three setups: (1) instance-based, (2) zero-shot, and (3) fine-tuned.

**Strengths**
- CardBench provides a timely platform that could facilitate future research in cardinality estimation.
- The experimental results reveal some interesting insights into the challenges and performance of current approaches.

**Weaknesses**

- Reviewers are not totally convinced whether the collected datasets are comprehensive enough. 
- The paper only tests typical GNN and transformer based architectures, which are insufficient. Reviewers suggest to show how other state-of-the-art methods compare on CardBench. 

While CardBench has the potential to contribute to the field of cardinality estimation, the major weaknesses, including concerns about dataset comprehensiveness and insufficient evaluation with diverse methods, limit its overall impact. Without addressing these issues, the benchmark’s contribution appears to fall below the bar for acceptance.

Decision: Reject