{'fraction_non_alphanumeric': 0.03364389233954451, 'fraction_numerical': 0.011632341723874905, 'mean_word_length': 4.752860053283184, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learned Cardinalities: Estimating Correlated Joins with Deep Learning

We describe a new deep learning approach to cardinality estimation. MSCN is a multi-set convolutional network, tailored to representing relational query plans, that employs set semantics to capture query features and true cardinalities. MSCN builds on sampling-based estimation, addressing its weaknesses when no sampled tuples qualify a predicate, and in capturing join-crossing correlations. Our evaluation of MSCN using a real-world dataset shows that deep learning significantly enhances the quality of cardinality estimation, which is the core problem in query optimization.


INTRODUCTION
Query optimization is fundamentally based on cardinality estimation. To be able to choose between different plan alternatives, the query optimizer must have reasonably good estimates for intermediate result sizes. It is well known, however, that the estimates produced by all widely-used database systems are routinely wrong by orders of magnitude-causing slow queries and unpredictable performance. The biggest challenge in cardinality estimation are join-crossing correlations [16,18]. For example, in the Internet Movie Database (IMDb), French actors are more likely to participate in romantic movies than actors of other nationalities.
The question of how to better deal with this is an open area of research. One state-of-the-art proposal in this area is Index-Based Join Sampling (IBJS) [17] that addresses this problem by probing qualifying base table samples against existing index structures. However, like other sampling-based techniques, IBJS fails when there are no qualifying samples to start with (i.e., under selective base table predicates) or when no suitable indexes are available. In such cases, these techniques usually fall back to an "educated" guess-causing large estimation errors.
The past decade has seen the widespread adoption of machine learning (ML), and specifically neural networks (deep learning), in many different applications and systems. The database community also has started to explore how machine learning can be leveraged within data management systems. Recent research therefore investigates ML for classical database problems like parameter tuning [2], query optimization [13,23,27], and even indexing [12]. This article is published under a Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0/), which permits distribution and reproduction in any medium as well as allowing derivative works, provided that you attribute the original work to the author(s) and CIDR 2019. 9th Biennial Conference on Innovative Data Systems Research (CIDR '19), January 13-16, 2019, Asilomar, California, USA We argue that machine learning is a highly promising technique for solving the cardinality estimation problem. Estimation can be formulated as a supervised learning problem, with the input being query features and the output being the estimated cardinality. In contrast to other problems where machine learning has been proposed like index structures [12] and join ordering [23], the current techniques based on basic per-table statistics are not very good. In other words, an estimator based on machine learning does not have to be perfect, it just needs to be better than the current, inaccurate baseline. Furthermore, the estimates produced by a machine learning model can directly be leveraged by existing, sophisticated enumeration algorithms and cost models without requiring any other changes to the database system.
In this paper, we propose a deep learning-based approach that learns to predict (join-crossing) correlations in the data and addresses the aforementioned weak spot of sampling-based techniques. Our approach is based on a specialized deep learning model called multi-set convolutional network (MSCN) allowing us to express query features using sets (e.g., both (A B) C and A (B C) are represented as {A, B, C}). Thus, our model does not waste any capacity for memorizing different permutations (all having the same cardinality but different costs) of a query's features, which results in smaller models and better predictions. The join enumeration and cost model are purposely left to the query optimizer.
We evaluate our approach using the real-world IMDb dataset [16] and show that our technique is more robust than sampling-based techniques and even is competitive in the sweet spot of these techniques (i.e., when there are many qualifying samples). This is achieved using a (configurable) low footprint size of about 3 MiB (whereas the sampling-based techniques have access to indexes covering the entire database). These results are highly promising and indicate that ML might indeed be the right hammer for the decades-old cardinality estimation job.

RELATED WORK
Deep learning has been applied to query optimization by three recent papers [13,23,27] that formulate join ordering as a reinforcement learning problem and use ML to find query plans. This work, in contrast, applies supervised learning to solve cardinality estimation in isolation. This focus is motivated by the fact that modern join enumeration algorithms can find the optimal join order for queries with dozens of relations [26]. Cardinality estimation, on the other hand, has been called the "Achilles heel" of query optimization [21] and causes most of its performance issues [16].
Twenty years ago the first approaches to use neural networks for cardinality estimation where published for UDF predicates [14]. Also, regression-based models have been used before for cardinality estimation [1]. A semi-automatic alternative for explicit machine learning was presented in [22], where the feature space is partitioned using decision trees and for each split a different regression model was learned. These early approaches did not use deep learning nor included features derived from statistics, such as our sample-based bitmaps, which encode exactly which sample tuples were selected (and we therefore believe to be good starting points for learning correlations). The same holds for approaches that used machine learning to predict overall resource consumption: running time, memory footprint, I/O, network traffic [6,19], although these models did include course-grained features (the estimated cardinality) based on statistics into the features. Liu et al. [20] used modern ML for cardinality estimation, but did not focus on joins, which are the key estimation challenge [16].
Our approach builds on sampling-based estimation by including cardinalities or bitmaps derived from samples into the training signal. Most sampling proposals create per-table samples/sketches and try to combine them intelligently in joins [3,5,30,31]. While these approaches work well for single-table queries, they do not capture join-crossing correlations and are vulnerable to the 0-tuple problem (cf. Section 4.2). Recent work by Müller et al. [25] aims to reduce the 0-tuple problem for conjunctive predicates (albeit at high computational cost), but still cannot capture the basic case of a single predicate giving zero results. Our reasonably good estimates in 0-tuple situations make MSCN improve over sampling, including even the idea of estimation on materialized join samples (join synopses [28]), which still would not handle 0-tuple situations.

LEARNED CARDINALITIES
From a high-level perspective, applying machine learning to the cardinality estimation problem is straightforward: after training a supervised learning algorithm with query/output cardinality pairs, the model can be used as an estimator for other, unseen queries. There are, however, a number of challenges that determine whether the application of machine learning will be successful: the most important question is how to represent queries ("featurization") and which supervised learning algorithm should be used. Another issue is how to obtain the initial training dataset ("cold start problem"). In the remainder of this section, we first address these questions before discussing a key idea of our approach, which is to featurize information about materialized samples.

Set-Based Query Representation
We represent a query q ∈ Q as a collection (T q , J q , P q ) of a set of tables T q ⊂ T , a set of joins J q ⊂ J and a set of predicates P q ⊂ P participating in the specific query q. T , J , and P describe the sets of all available tables, joins, and predicates, respectively.
Each table t ∈ T is represented by a unique one-hot vector v t (a binary vector of length |T | with a single non-zero entry, uniquely identifying a specific table) and optionally the number of qualifying base table samples or a bitmap indicating their positions.   Similarly, we featurize joins j ∈ J with a unique one-hot encoding. For predicates of the form (col, op, val), we featurize columns col and operators op using a categorical representation with respective unique one-hot vectors, and represent val as a normalized value ∈ [0, 1], normalized using the minimum and maximum values of the respective column. Applied to the query representation (T q , J q , P q ), our MSCN model (cf. Figure 1) takes the following form: Figure 2 shows an example of a featurized query.

Model
Standard deep neural network architectures such as convolutional neural networks (CNNs), recurrent neural networks (RNNs), or simple multi-layer perceptrons (MLPs) are not directly applicable to this type of data structure, and would require serialization, i.e., conversion of the data structure to an ordered sequence of elements. This poses a fundamental limitation, as the model would have to spend capacity to learn to discover the symmetries and structure of the original representation. For example, it would have to learn to discover boundaries between different sets in a data structure consisting of multiple sets of different size, and that the order of elements in the serialization of a set is arbitrary.
Given that we know the underlying structure of the data a priori, we can bake this information into the architecture of our deep  Table set Join set Predicate set  learning model and effectively provide it with an inductive bias that facilitates generalization to unseen instances of the same structure, e.g., combinations of sets with a different number of elements not seen during training.
Here, we introduce the multi-set convolutional network (MSCN) model. Our model architecture is inspired by recent work on Deep Sets [32], a neural network module for operating on sets. A Deep Sets module (sometimes referred to as set convolution) rests on the observation that any function f (S) on a set S that is permutation invariant to the elements in S can be decomposed into the form ρ[ x ∈S ϕ(x)] with appropriately chosen functions ρ and ϕ. For a more formal discussion and proof of this property, we refer to Zaheer et al. [32]. We choose simple fully-connected multi-layer neural networks (MLPs) to parameterize the functions ρ and ϕ and rely on their function approximation properties [4] to learn flexible mappings f (S) for arbitrary sets S. Applying a learnable mapping for each set element individually (with shared parameters) is similar to the concept of a 1 × 1 convolution, often used in CNNs for image classification [29].
Our query representation consists of a collection of multiple sets, which motivates the following choice for our MSCN model architecture: for every set S, we learn a set-specific, per-element neural network MLP S (v s ), i.e., applied on every feature vector v s for every element s ∈ S individually 1 . The final representation w S for this set is then given by the average 2 over the individual transformed representations of its elements, i.e., w S = 1/|S | s ∈S MLP S (v s ). We choose an average (instead of, e.g., a simple sum) to ease generalization to different numbers of elements in the set S, as otherwise the overall magnitude of the signal would vary depending on the number of elements in S. In practice, we implement a vectorized version of our model that operates on mini-batches of data. As the number of set elements in each data sample in a mini-batch can vary, we pad all samples with zero-valued feature vectors that act as dummy set elements so that all samples within a mini-batch have the same number of set elements. We mask out dummy set elements in the averaging operation, so that only the original set elements contribute to the average. Finally, we merge the individual set representations by concatenation and subsequently pass them through a final output MLP: where N is the total number of sets and [·, ·] denotes vector concatenation. Note that this representation includes the special case where each set representation w S is transformed by a subsequent individual output function (as required by the original theorem in [32]). One could alternatively 1 An alternative approach here would be to combine the feature vectors before feeding them into the MLP. For example, if there are multiple tables, each of them represented by a unique one-hot vector, we could compute the logical disjunction of these one-hot vectors and feed that into the model. Note that this approach does not work if we want to associate individual one-hot vectors with additional information such as the number of qualifying base table samples. 2 Note that an average of one-hot vectors uniquely identifies the combination of one-hot vectors, e.g. which individual tables are present in the query. process each w S individually first and only later merge and pass through another MLP. We decided to merge both steps into a single computation for computational efficiency.
Unless otherwise noted, all MLP modules are two-layer fullyconnected neural networks with ReLU(x) = max(0, x) activation functions. For the output MLP, we use a sigmoid(x) = 1/(1 + exp(−x)) activation function for the last layer instead and only output a scalar, so that w out ∈ [0, 1]. We use ReLU activation functions for hidden layers as they show strong empirical performance and are fast to evaluate. All other representation vectors w T , w J , w P , and hidden layer activations of the MLPs are chosen to be vectors of dimension d, where d is a hyperparameter, optimized on a separate validation set via grid search.
We normalize the target cardinalities c target as follows: we first take the logarithm to more evenly distribute target values, and then normalize to the interval [0, 1] using the minimum and maximum value after logarithmization obtained from the training set 3 . The normalization is invertible, so we can recover the unnormalized cardinality from the prediction w out ∈ [0, 1] of our model. We train our model to minimize the mean q-error [24] q (q ≥ 1). The q-error is the factor between an estimate and the true cardinality (or vice versa). We further explored using mean-squared error and geometric mean q-error as objectives (cf. Section 4.8). We make use of the Adam [10] optimizer for training.

Generating Training Data
One key challenge of all learning-based algorithms is the "cold start problem", i.e., how to train the model before having concrete information about the query workload. Our approach is to obtain an initial training corpus by generating random queries based on schema information and drawing literals from actual values in the database.
A training sample consists of table identifiers, join predicates, base table predicates, and the true cardinality of the query result. To avoid a combinatorial explosion, we only generate queries with up to two joins and let the model generalize to more joins. Our query generator first uniformly draws the number of joins |J q | (0 ≤ |J q | ≤ 2) and then uniformly selects a table that is referenced by at least one table. For |J q | > 0, it then uniformly selects a new table that can join with the current set of tables (initially only one), adds the corresponding join edge to the query and (overall) repeats this process |J q | times. For each base table t in the query, it then uniformly draws the number of predicates |P t q | (0 ≤ |P t q | ≤ num non-key columns). For each predicate, it uniformly draws the predicate type (=, <, or >) and selects a literal (an actual value) from the corresponding column. We configured our query generator to only generate unique queries. We then execute these queries to obtain their true result cardinalities, while skipping queries with empty results. Using this process, we obtain the initial training set for our model.

Enriching the Training Data
A key idea of our approach is to enrich the training data with information about materialized base table samples. For each table in a query, we evaluate the corresponding predicates on a materialized sample and annotate the query with the number of qualifying samples s (0 ≤ s ≤ 1000 for 1000 materialized samples) for this table. We perform the same steps for an (unseen) test query at estimation time allowing the ML model to utilize this knowledge.
We even take this idea one step further and annotate each table in a query with the positions of the qualifying samples represented as bitmaps. As we show in Section 4, adding this feature has a positive impact on our join estimates since the ML model can now learn what it means if a certain sample qualifies (e.g., there might be some samples that usually have many join partners). In other words, the model can learn to use the patterns in the bitmaps to predict output cardinalities.

Training and Inference
Building our model involves three steps: i) generate random (uniformly distributed) queries using schema and data information, ii) execute these queries to annotate them with their true cardinalities and information about qualifying materialized base table samples, and iii) feed this training data into an ML model. All of these steps are performed on an immutable snapshot of the database.
To predict the cardinality of a query, the query first needs to be transformed into its feature representation (cf. Section 3.1). Inference itself involves a certain number of matrix multiplications, and (optionally) querying materialized base table samples (cf. Section 3.4). Training the model with more query samples does not increase the prediction time. In that respect, the inference speed is largely independent from the quality of the predictions. This is in contrast to purely sampling-based approaches that can only increase the quality of their predictions by querying more samples.

EVALUATION
We evaluate our approach using the IMDb dataset which contains many correlations and therefore proves to be very challenging for cardinality estimators [16]. The dataset captures more than 2.5 M movie titles produced over 133 years by 234,997 different companies with over 4 M actors.
We use three different query workloads 4 : i) a synthetic workload generated by the same query generator as our training data (using a different random seed) with 5,000 unique queries containing both (conjunctive) equality and range predicates on non-key columns with zero to two joins, ii) another synthetic workload scale with 500 queries designed to show how the model generalizes to more joins, and iii) JOB-light, a workload derived from the Join Order Benchmark (JOB) [16]    table attributes. The only range predicate is on production_year. Table 1 shows the distribution of queries with respect to the number of joins in the three query workloads. The non-uniform distribution in the synthetic workload is caused by our elimination of duplicate queries. As competitors we use PostgreSQL version 10.3, Random Sampling (RS), and Index-Based Join Sampling (IBJS) [17]. RS executes base table predicates on materialized samples to estimate base table cardinalities and assumes independence for estimating joins. If there are no qualifying samples for a conjunctive predicate, it tries to evaluate the conjuncts individually and eventually falls back to using the number of distinct values (of the column with the most selective conjunct) to estimate the selectivity. IBJS represents the state-of-the-art for estimating joins and probes qualifying base table samples against existing index structures. Our IBJS implementation uses the same fallback mechanism as RS.
We train and test our model on an Amazon Web Services (AWS) ml.p2.xlarge instance using the PyTorch framework 5 and use CUDA. We use 100,000 random queries with zero to two joins and 1,000 materialized samples as training data (cf. Section 3.3). We split the training data into 90% training and 10% validation samples. To obtain true cardinalities for our training data, we use HyPer [8]. Figure 3 shows the q-error of MSCN compared to our competitors. While PostgreSQL's errors are more skewed towards the positive spectrum, RS tends to underestimate joins, which stems from the fact that it assumes independence. IBJS performs extremely well in the median and 75th percentile but (like RS) suffers from empty base table samples. MSCN is competitive with IBJS in the median while being significantly more robust. Considering that IBJS is using much more data-in the form of large primary and foreign key indexes-in contrast to the very small state MSCN is using (less than 3 MiB),   To provide more details, we also show the median, percentiles, maximum, and mean q-errors in Table 2. While IBJS provides the best median estimates, MSCN outperforms the competitors by up to two orders of magnitude at the end of the distribution.

0-Tuple Situations
Purely sampling-based approaches suffer from empty base table samples (0-tuple situations) which can occur under selective predicates. While this situation can be mitigated using, e.g., more samples or employing more sophisticated-yet still sampling-basedtechniques (e.g., [25]), it remains inherently difficult to address by these techniques. In this experiment, we show that deep learning, and MSCN in particular, can handle such situations fairly well. In fact, 376 (22%) of the 1636 base table queries in the synthetic workload have empty samples (using MSCN's random seed). We will use this subset of queries to illustrate how MSCN deals with situations where it cannot build upon (runtime) sampling information (i.e., all bitmaps only contain zeros). We also include Random Sampling (which uses the same random seed-i.e., the same set of materialized samples as MSCN) and PostgreSQL in this experiment.
The results, shown in Table 3, demonstrate that MSCN addresses the weak spot of purely sampling-based techniques and therefore would complement them well.
Recall that Random Sampling extrapolates the output cardinality based on the number of qualifying samples (zero in this case). Thus, it cannot simply extrapolate from this number and has to fall back to an educated guess-in our RS implementation either using the product of selectivities of individual conjuncts or using the number of distinct values of the column with the most selective predicate. Independent of the concrete implementation of this fallback, it remains an educated guess. MSCN, in contrast, can use the signal of individual query features (in this case the specific table and predicate features) to provide a more precise estimate.

Removing Model Features
Next, we highlight the contributions of individual model features to the prediction quality (cf. Figure 4) MSCN (no samples) produces reasonable estimates with an overall 95th percentile q-error of 25.3, purely relying on (inexpensive to obtain) query features. Adding sample cardinality information to the model improves both base table and join estimates. The 95th percentile q-errors of base table, one join, and two join estimates reduce by 1.72×, 3.60×, and 3.61×, respectively. Replacing cardinalities with bitmaps further improves these numbers by 1.47×, 1.35×, and 1.04×. This shows that the model can use the information embedded in the bitmaps to provide better estimates.

Generalizing to More Joins
To estimate a larger query, one can of course break the query down into smaller sub queries, estimate them individually using the model, and combine their selectivities. However, this means that we would need to assume independence between two sub queries which is known to deliver poor estimates with real-world datasets such as IMDb (cf. join estimates of Random Sampling in Section 4).
The question that we want to answer in this experiment is how MSCN can generalize to queries with more joins than it was trained on. For this purpose, we use the scale workload with 500 queries with zero to four joins (100 queries each). Recall that we trained the model only with queries that have between zero and two joins. Thus, this experiment shows how the model can estimate queries with three and four joins without having seen such queries during training (cf. Figure 5). From two to three joins, the 95th percentile q-error  Table 4: Estimation errors on the JOB-light workload.
increases from 7.66 to 38.6. To give a point of reference, PostgreSQL has a 95th percentile q-error of 78.0 for the same queries. And finally, with four joins, MSCN's 95th percentile q-error increases further to 2,397 (PostgreSQL: 4,077). Note that 58 out of the 500 queries in this workload exceed the maximum cardinality seen during training. 12 of these queries have three joins and another 46 have four joins. When excluding these outliers, the 95th percentile q-errors for three and four joins decrease to 23.8 and 175, respectively.

JOB-light
To show how MSCN generalizes to a workload that was not generated by our query generator, we use JOB-light. Table 4 shows the estimation errors. Recall that most queries in JOB-light have equality predicates on dimension table attributes. Considering that MSCN was trained with a uniform distribution between =, <, and > predicates, it performs reasonably well. Also, JOB-light contains many queries with a closed range predicate on production_year, while the training data only contains open range predicates. Note that JOB-light also includes five queries that exceed the maximum cardinality that MSCN was trained on. Without these queries, the 95th percentile q-error is 115.
In summary, this experiment shows that MSCN can generalize to workloads with distributions different from the training data.

Hyperparameter Tuning
We tuned the hyperparameters of our model, including the number of epochs (the number of passes over the training set), the batch size (the size of a mini-batch), the number of hidden units, and the learning rate. More hidden units means larger model sizes and increased training and prediction costs with the upside of allowing the model to capture more data, while learning rate and batch size both influence convergence behavior during training.
We varied the number of epochs (100, 200), the batch size (64, 128, 256, 512, 1024, 2048), the number of hidden units (64, 128, 256,  512, 1024, 2048), and fixed the learning rate to 0.001, resulting in 72 different configurations. For each configuration, we trained three models 6 using 90,000 samples and evaluated their performance on the validation set consisting of 10,000 samples. On average over the three runs, the configuration with 100 epochs, a batch size of 1024 samples, and 256 hidden units performed best on the validation data. Across many settings, we observed that 100 epochs perform better than 200 epochs. This is an effect of overfitting: the model captures the noise in the training data such that it negatively impacts its prediction quality. Overall, we found that our model 6 Note that the weights of the neural network are initialized using a different random seed in each training run. To provide reasonably stable numbers, we tested each configuration three times. q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q performs well across a wide variety of settings. In fact, the mean q-error only varied by 1% within the best 10 configurations and by 21% between the best and the worst configuration. We also experimented with different learning rates (0.001, 0.005, 0.0001) and found 0.001 to perform best. We thus use 100 epochs, a batch size of 1024, 256 hidden units, and a learning rate of 0.001 as our default configuration.

Model Costs
Next, we analyze the training, inference, and space costs of MSCN with our default hyperparameters. Figure 6 shows how the validation set error (the mean q-error of all queries in the validation set) decreases with more epochs. The model requires fewer than 75 passes (over the 90,000 training queries) to converge to a mean q-error of around 3 on the 10,000 validation queries. An average training run with 100 epochs (measured across three runs) takes almost 39 minutes.
The prediction time of our model is in the order of a few milliseconds, including the overhead introduced by the PyTorch framework. In theory (neglecting the PyTorch overhead), a prediction using a deep learning model (as stated earlier) is dominated by matrix multiplications which can be accelerated using modern GPUs. We thus expect performance-tuned implementations of our model to achieve very low prediction latencies. Since we incorporate sampling information, the end-to-end prediction time will be in the same order of magnitude as that of (per-table) sampling techniques.

Optimization Metrics
Besides optimizing the mean q-error, we also explored using meansquared error and geometric mean q-error as optimization goals. Mean-squared error would optimize the squared differences between the predicted and true cardinalities. Since we are more interested in minimizing the factor between the predicted and the true cardinalities (q-error) and use this metric for our evaluation, optimizing the q-error directly yielded better results. Optimizing the geometric mean of the q-error makes the model put less emphasis on heavy outliers (that would lead to large errors). While this approach looked promising at first, it turned out to be not as reliable as optimizing the mean q-error.

DISCUSSION
We have shown that our model can beat state-of-the-art approaches for cardinality estimation. It does a good job in addressing 0-tuple situations and in capturing join-crossing correlations, especially when combined with runtime sampling. To make it suitable for general-purpose cardinality estimation, it can be extended into multiple dimensions, including complex predicates, uncertainty estimation, and updatability. In the following, we will discuss these and sketch possible solutions.
Generalization. MSCN can to some extent generalize to queries with more joins than seen during training (cf. Section 4.4). Nevertheless, generalizing to queries that are not in the vicinity of the training data remains challenging.
Of course, our model can be trained with queries from an actual workload or their structures. In practice, we could replace any literals in user queries with placeholders to be filled with actual values from the database. This would allow us to focus on the relevant joins and predicates.
Adaptive training. To improve training quality, we could adaptively generate training samples: based on the error distribution of queries in the validation set, we would generate new training samples that shine more light on difficult parts of the schema.

Strings.
A simple addition to our current implementation are equality predicates on strings. To support these, we could hash the string literals to a (small) integer domain. Then an equality predicate on a string is essentially the same as an equality predicate on an ID column where the model also needs to process a non-linear input signal.
Complex predicates. Currently, our model can only estimate queries with predicate types that it has seen during training. Complex predicates, such as LIKE or disjunctions, are not yet supported since we currently do not represent them in the model. An idea to allow for any complex predicate would be to purely rely on the sampling bitmaps in such cases. Note that this would make our model vulnerable to 0-tuple situations. To mitigate that problem, we could featurize information from histograms. Also, the distribution of bitmap patterns might vary significantly from simple predicates observed at training time, to more complicated predicates at test time, which can make generalization challenging.
More bitmaps. At the moment, we use a single bitmap indicating the qualifying samples per base table. To increase the likelihood for qualifying samples, we could additionally use one bitmap per predicate. For example, for a query with two conjunctive base table predicates, we would have one bitmap for each predicate, and another bitmap representing the conjunction. In a column store that evaluates one column at a time, we can obtain this information almost for free. We have already shown that MSCN can use the information embedded in the bitmaps to make better predictions. We expect that it would benefit from the patterns in these additional bitmaps.
This approach should also help MSCN with estimating queries with arbitrary (complex) predicates where it needs to rely on information from the (many) bitmaps. Of course, this approach does not work in 0-tuple situations, or more specifically in situations where none of the (predicate) bitmaps indicates any qualifying samples.

Uncertainty estimation.
An open question is when to actually trust the model and rely on its predictions. One approach is to use strict constraints for generating the training data and enforce them at runtime, i.e., only use the model when all constraints hold (i.e., only PK/FK joins, only equality predicates on certain columns). A more appealing approach would be to implement uncertainty estimation into the model. However, for a model like ours, this is a non-trivial task and still an area of active research. There are some recent methods [7,9,15] that we plan to investigate in future work.
Updates. Throughout this work, we have assumed an immutable (read-only) database. To handle data and schema changes, we can either completely re-train the model or we can apply some modifications to our model that allow for incremental training.
Complete re-training comes with considerable compute costs (for re-executing queries to obtain up-to-date cardinalities and for re-training the model) but would allow us to use a different data encoding. For example, we could use larger one-hot vectors to accommodate for new tables and we could re-normalize values in case of new minimum or maximum values. Queries (training samples) of which we know to still have the same cardinality (e.g., since there has not been any update to the respective data range) would of course not need to re-executed.
In contrast, incremental training (as implied by its name) would not require us to re-train with the original set of samples. Instead, we could re-use the model state and only apply new samples. One challenge with incremental training is to accommodate changes in the data encoding, including one-hot encodings and the normalization of values. To recall, there are two types of values that we normalize: literals in predicates (actual column values) and output cardinalities (labels). For both types, setting a high limit on the maximum value seems most appropriate. The main challenge, however, is to address catastrophic forgetting, which is an effect that can be observed with neural networks when data distribution shifts over time. The network would overfit to the most recent data and forget what it has learned in the past. Addressing this problem is an area of active research with some recent proposals [11].

CONCLUSIONS
We have introduced a new approach to cardinality estimation based on MSCN, a new deep learning model. We have trained MSCN with generated queries, uniformly distributed within a constrained search space. We have shown that it can learn (join-crossing) correlations and that it addresses the weak spot of sampling-based techniques, which is when no samples qualify. Our model is a first step towards reliable ML-based cardinality estimation and can be extended into multiple dimensions, including complex predicates, uncertainty estimation, and updatability.
Another application of our set-based model is the prediction of the number of unique values in a column or in a combination of columns (i.e., estimating the result size of a group-by operator). This is another hard problem where current approaches achieve undesirable results and where machine learning seems promising.