Approximate Query Processing for Data Exploration using Deep Generative Models
Data is generated at an unprecedented rate surpassing our ability to analyze them. The database community has pioneered many novel techniques for Approximate Query Processing (AQP) that could give approximate results in a fraction of time needed for computing exact results. In this work, we explore the usage of deep learning (DL) for answering aggregate queries specifically for interactive applications such as data exploration and visualization. We use deep generative models, an unsupervised learning based approach, to learn the data distribution faithfully such that aggregate queries could be answered approximately by generating samples from the learned model. The model is often compact – few hundred KBs – so that arbitrary AQP queries could be answered on the client side without contacting the database server. Our other contributions include identifying model bias and minimizing it through a rejection sampling based approach and an algorithm to build model ensembles for AQP for improved accuracy. Our extensive experiments show that our proposed approach can provide answers with high accuracy and low latency.
Data driven decision making has become the dominant paradigm for businesses seeking to gain an edge over competitors. However, the unprecedented rate at which data is generated surpasses our ability to analyze them. Approximate Query Processing (AQP) is a promising technique that provides approximate answers to queries at a fraction of the cost needed to answer it exactly. AQP has numerous applications in data exploration and visualization where approximate results are acceptable as long as they can be obtained near real-time.
Case Study. Consider an user who performs data exploration and visualization on a popular dataset such as NYC Taxi dataset. The user issues ad-hoc aggregate queries, involving arbitrary subsets of attributes of interest, such as what is the average number of passengers on trips starting from Manhattan? or what is the average trip duration grouped by hour? and so on. Since this is for exploratory purposes, an imprecise answer is often adequate. A traditional approach is to issue aggregate queries to the database server, get exact or approximate answers accessing the base data or pre-computed/on-demand samples and display the returned results to the user. However, this could suffer from high latency that is not conducive for interactive analysis. In this paper, we propose an alternate approach where the approximate results could be computed entirely at the client side. Specifically, we build a deep generative model that approximates the data distribution with high fidelity and is lightweight (few hundreds of KBs). This model is sent to the client and could be used to generate synthetic samples over which AQP could be performed locally on arbitrary subsets of attributes, without any communication with the server. Our approach is complementary to traditional AQP exploring a new research direction of utilizing deep generative models for data exploration. It offers a lightweight model that can answer arbitrary queries which we experimentally demonstrate exhibit superior accuracy. For queries requiring provable guarantees we default to traditional AQP or exact query evaluation.
I-a Outline of Technical Results
Deep Learning for AQP. Deep Learning (DL)  has become popular due to its excellent performance in many complex applications. In this paper, we investigate the feasibility of using DL for answering aggregate queries for data exploration and visualization. Structured databases seem intrinsically different from prior areas where DL has shined - such as computer vision and natural language processing. Furthermore, the task of generating approximate estimates for an aggregate query is quite different from common DL tasks. However, we show that AQP can be achieved in an effective and efficient manner using DL models.
Deep Generative Models for AQP. Our key insight is to train a DL model to learn the data distribution of the underlying data set effectively. Once such a model is trained, it acts as a concise representation of the dataset. The samples generated from the model have a data distribution that is almost identical to that of the underlying dataset. Hence, existing AQP techniques [36, 37] could be transparently applied on these samples. Furthermore, the model could generate as many samples as required without the need to access the underlying dataset. This makes it very useful for interactive applications as all the computations could be done locally.
Technical Challenges. The key challenge is to identify a DL based distribution estimation approach that is expressive enough to reflect statistical properties of real-world datasets and yet tractable and efficient to train. It must be non-parametric and not make any prior assumption about data characteristics. A large class of DL techniques - dubbed collectively as deep generative models - could be used for this purpose. Intuitively, a deep generative model is an unsupervised approach that learns the probability distribution of the dataset from a set of tuples. Often, learning the exact distribution is challenging, thus generative models learn a model that is very similar to the true distribution of the underlying data. This is often achieved through neural networks that learn a function that maps the approximate distribution to the true distribution. Each of the generative models have their respective advantages and disadvantages. We focus on variational autoencoders  that aim to learn a low dimensional latent representation of the training data that optimizes the log-likelihood of the data through evidence lower bound.
Consider a relation with tuples and attributes . Given a tuple and an attribute , we denote the value of in as . Let be the domain of attribute .
Queries for AQP.
In this paper, we focus on aggregate analytic queries of the general format:
SELECT g, AGG(A) FROM R
WHERE filter GROUP BY G
Of course, both the WHERE and GROUP BY clauses are optional. Each attribute could be used as a filter attribute involved in a predicate or as a measure attribute involved in an aggregate. The filter could be a conjunctive or disjunctive combination of conditions. Each of the conditions could be any relational expression of the format A op CONST where is an attribute and is one of . AGG could be one of the standard aggregates AVG, SUM, COUNT that have been extensively studied in prior AQP literature. One could use other aggregates such as QUANTILES as long as a statistical estimator exists to generate aggregate estimates.
Performance Measures. Let be an aggregate query whose true value is . Let be the estimate provided by the AQP system. Then, we can measure the estimation accuracy through relative error defined as
For a set of queries , the effectiveness of the AQP system could be computed through average relative error. Let and be the true and estimated value of the aggregate for query .
We could also use the average relative error to measure the accuracy of the estimate for GROUP BY queries. Suppose we are given a group by query with groups . It is possible that the sample does not contain all of these groups and the AQP system generates estimates for groups where each . As before, let and be the true and estimated value of the aggregate for group . By assigning 100% relative error for missing groups, the average relative error for group by queries is defined as,
In this section, we provide necessary background about generative models and variational autoencoders in particular.
Generative Models. Suppose we are given a set of data points that are distributed according to some unknown probability distribution . Generative models seek to learn an approximate probability distribution such that is very similar to . Most generative models also allow one to generate samples from the model such that the has similar statistical properties to . Deep generative models use powerful function approximators (typically, deep neural networks) for learning to approximate the distribution.
Variational Autoencoders (VAEs). VAEs are a class of generative models [10, 4, 3] that can model various complicated data distributions and generate samples. They are very efficient to train, have an interpretable latent space and could be adapted effectively to different domains such as images, text and music. Latent variables are an intermediate data representation that captures data characteristics used for generative modelling. Let be the relational data that we wish to model and a latent variable. Let be the probability distribution from which the underlying relation consisting of attributes was derived and as the probability distribution of the latent variable. Then is the distribution of generating data given latent variable. We can model in relation to as marginalizing out of the joint probability . The challenge is that we do not know and . The underlying idea in variational modelling is to infer using .
Variational Inference. We use a method called Variational Inference (VI) to infer in VAE. The main idea of VI is to approach inference as an optimization problem. We model the true distribution using a simpler distribution (denoted as ) that is easy to evaluate, e.g. Gaussian, and minimize the difference between those two distribution using KL divergence metric, which tells us how different is from . Typically, the simpler distribution depends on the attribute type. Gaussian distribution is often appropriate for real numbers while Bernoulli distribution is often used for categorical attributes. Assume we wish to infer using . The KL divergence is specified as:
Encoders and Decoders. A different way to think of this equation is as encoding the data using as an intermediate data representation and generates data given a latent variable . Typically is implemented with a neural network mapping the underlying data space into the latent space (encoder network). Similarly is implemented with a neural network and is responsible to generate data following the distribution given sample latent variables from the latent space (decoder network). The variational objective has a very natural interpretation. We wish to model our data under some error function . In other words, VAE tries to identify the lower bound of , which in practice is good enough as trying to determine the exact distribution is often intractable. For this we aim to maximize over some mapping from latent variables to and minimize the difference between our simple distribution and the true latent distribution . Since we need to sample from in VAE typically one chooses a simple distribution to sample from such as . Since we wish to minimize the distance between and in VAE one typically assumes that is also normal with mean and variance . Both the encoder and the decoder networks are trained end-to-end. After training, data can be generated by sampling from a normal distribution and passing it to the decoder network.
Iv AQP Using Variational AutoEncoders
In this section, we provide an overview of our two phase approach for using VAE for AQP. This requires solving a number of theoretical and practical challenges such as input encodings and approximation errors due to model bias.
Our Approach. Our proposed approach proceeds in two phases. In the model building phase, we train a deep generative model over the dataset such that it learns the underlying data distribution. In this section, we assume that a single model is built for the entire dataset that we relax in Section V. Once the DL model is trained, it can act as a succinct representation of the dataset. In the run-time phase, the AQP system uses the DL model to generate samples from the underlying distribution. The given query is rewritten to run on . The existing AQP techniques could be transparently used to generate the aggregate estimate. Figure 1 illustrates our approach.
Iv-a Using VAE for AQP
In this subsection, we describe how to train a VAE over relational data and use it for AQP.
Input Encoding. In contrast to homogeneous domains such as images and text, relations often consist of mixed data types that could be discrete or continuous. The first step is to represent each tuple as a vector of dimension . For ease of exposition, we consider one-hot encoding and describe other effective encodings in Section IV-E. One-hot encoding represents each tuple as a dimensional vector where the position corresponding to a given domain value is set to 1. Each tuple in a relation with two binary attributes and , is represented as a dimensional binary vector. A tuple with is represented as while a tuple with is represented as . This approach is efficient for small attribute domains but becomes cumbersome if a relation has millions of distinct values.
Model Building and Sampling from VAE. Once all the tuples are encoded appropriately, we could use VAE to learn the underlying distribution. We denote the size of the input and latent dimension by and respectively. For one hot encoding, . As increases, it results in more accurate learning of the distribution at the cost of a larger model. Once the model is trained, it could be used to generate samples . The randomly generated tuples often share similar statistical properties to tuples sampled from the underlying relation and hence are a viable substitute for . One could apply the existing AQP mechanisms on the generated samples and use it to generate aggregate estimates along with confidence intervals.
The sample tuples are generated as follows: we generate samples from the latent space and then apply the decoder network to convert points in latent space to tuples. Recall from Section III that the latent space is often a probability distribution that is easy to sample such as Gaussian. It is possible to speed up the sampling from arbitrary Normal distributions using the reparameterization trick. Instead of sampling from a distribution , we could sample from the standard Normal distribution with zero mean and unit variance. A sample from could be converted to a sample as . Intuitively, this shifts by the mean and scales it based on the variance .
Iv-B Handling Approximation Errors.
We consider approximation error caused due to model bias and propose an effective rejection sampling to mitigate it.
Sampling Error. Aggregates estimated over the sample could differ from the exact results computed over the entire dataset and their difference is called the sampling error. Both the traditional AQP and our proposed approach suffer from sampling error. The techniques used to mitigate it - such as increasing sample size - can also be applied to the samples from the generative model.
Errors due to Model Bias. Another source of error is sampling bias. This could occur when the samples are not representative of the underlying dataset and do not approximate its data distribution appropriately. Aggregates generated over these samples are often biased and need to be corrected. This problem is present even in traditional AQP  and mitigated through techniques such as importance weighting  and bootstrapping [14, 36].
Our proposed approach also suffers from sampling bias due to a subtle reason. Generative models learn the data distribution which is a very challenging problem - especially in high dimensions. A DL model learns an approximate distribution that is close enough. Uniform samples generated from the approximate distribution would be biased samples from the original distribution resulting in biased estimates. As we shall show later in the experiments, it is important to remove or reduce the impact of model bias to get accurate estimates. Bootstrapping is not applicable as it often works by resampling the sample data and performing inference on the sampling distribution from them. Due to the biased nature of samples, this approach provides incorrect results . It is challenging to estimate the importance weight of a sample generated by VAE. Popular approaches such as IWAE  and AIS  do not provide strong bounds for the estimates.
Rejection Sampling. We advocate for a rejection sampling based approach [21, 9] that has a number of appealing properties and is well suited for AQP. Intuitively, rejection sampling works as follows. Let be a sample generated from the VAE model with probabilities and from the original and approximate probability distributions respectively. We accept the sample with probability where is a constant upper bound on the ratio for all . We can see that the closer the ratio is to 1, the higher the likelihood that the sample is accepted. On the other hand, if the two distributions are far enough, then a larger fraction of samples will be rejected. One can generate arbitrary number of samples from the VAE model, apply rejection sampling on them and use the accepted samples to generate unbiased and accurate aggregate estimates.
In order to accept/reject a sample , we need the value of . Estimating this value - such as by going to the underlying dataset - is very expensive and defeats the purpose of using generative models. A better approach is to approximately estimate it purely from the VAE model.
Variational Rejection Sampling Primer. We leverage an approach for variational rejection sampling that was recently proposed in . For the sake of completeness, we describe the approach as applied to AQP. Please refer to  for further details. Sample generation from VAE takes place in two steps. First, we generate a sample in the latent space using the variational posterior and then we use the decoder to convert into a sample in the original space. In order to generate samples from the true posterior , we need to accept/reject sample with acceptance probability
where is an upper bound on the ratio . Estimating the true posterior requires access to the dataset and is very expensive. However, we do know that the value of from the VAE is within a constant normalization factor as . Thus, we can redefine Equation 6 as
We can now conduct rejection sampling if we know the value of . First, we generate a sample from the variational posterior . Next, we draw a random number in the interval uniformly at random. If this number is smaller than the acceptance probability , then we accept the sample and reject it otherwise. That way the number of times that we have to repeat this process until we accept a sample is itself a random variable with geometric distribution p = ; . Thus on average the number of trials required to generate a sample is . By a direct calculation it is easy to show  that . We set the value of as where is an arbitrary threshold function. This definition has a number of appealing properties. First, this function is differentiable and can be easily plugged into the VAE’s objective function thereby allowing us to learn a suitable value of for the dataset during training . Please refer to Section VI for a heuristic method for setting appropriate values of during model building and sample generation. Second, the parameter when set, establishes a trade-off between computational efficiency and accuracy. If , then every sample is accepted (i.e., no rejection) resulting into fast sample generation at the expense of the quality of the approximation to the true underlying distribution. In contrast when , we ensure that almost every sample is guaranteed to be from the true posterior distribution, by making the acceptance probability small and as a result increasing sample generation time. Since should be a probability we change equation Equation 7 to:
Iv-C Towards Accuracy Guarantees
As mentioned in Section I, our approach is complementary to traditional AQP system. Our objective is to design a lightweight deep generative model that could be used to obtain quick-and-dirty aggregate estimates that are often sufficient for preliminary data exploration. Once the user has identified promising queries that requires provable guarantees, we can defer traditional AQP techniques or even obtain exact answers. In this subsection, we describe an initial approach for obtaining the accuracy guarantees. We would like to note that developing a framework to quantify approximation errors of AQP based on deep generative models is a challenging problem and a focus of our future research.
Eliminating Model Bias. Recall from Section IV-B that approximation errors incurred in our approach are due to model bias and sampling error. If the model bias is eliminated, then our problem boils down to the traditional AQP setting. We could readily leverage the rich set of accuracy guarantees and confidence intervals developed for handling sampling error. This is achieved by setting and applying variational rejection sampling (VRS). However, this comes with a large computational cost whereby the vast majority of generated tuples are rejected. Ideally, we would like a granular accuracy-computation tradeoff. Increasing improves the sampling efficiency at the cost of model bias.
Distribution Testing. We adapt techniques designed for high-dimensional two-sample hypothesis testing [45, 50] for choosing appropriate . Suppose we are given two sets of uniform random samples and from the original dataset and the learned model respectively. Let . Suppose that these samples were drawn from probability distributions and . If we can ascertain that the two distributions are the same (i.e. ), by using the corresponding samples, then we can safely ignore the issue of model bias. This is achieved by testing the null hypothesis .
There are two factors that makes this challenging: high-dimensionality and test-statistics for AQP. First, we train VAE model by transforming tuples into a vector whose dimensionality ranges in the thousands. Classical tests such as Kolmogrov-Smirnov are not suitable for testing such high dimensional distributions. Second, hypothesis testing methods rely on a test statistic that is a function of and that could be used to distinguish and . For example, a simple test statistic is to choose an aggregate query such as estimating the average value of some attribute . If the average of computed over and deviates beyond certain threshold we can reject the null hypothesis. However, this is not appropriate for our scenario. We wish to test the null hypothesis for arbitrary aggregate queries. The way out of this conundrum is to use Cross-Match Test [45, 50].
Cross-Match Test for AQP. We begin by projecting tuples in and into the latent space of VAE using the encoder. We abuse the notation by representing the projected tuples as and . Let . We associate a label of if tuple and a label of if . We construct a complete graph where each node corresponds to a tuple in while the edge corresponds the Euclidean distance between the latent space representation of the corresponding tuples. We then compute a minimum weight perfect matching using the Blossom algorithm . The output is a collection of non-overlapping pairs of tuples. Consider a specific pair of tuples . There are three possibilities: both tuples are from , both tuples are from or one each from and . Let be the frequency of pairs from the matching of these three categories. The cross-match test [45, 50] specifies as the test statistic. Let . We accept or reject the null hypothesis based on the probability computed as
Iv-D Variational Autoencoder AQP Workflow
Algorithm 1 provides the pseudocode for the overall workflow of performing AQP using VAE. In the model building phase, we encode the input relation using an appropriate mechanism (see Section IV-E). The VAE model is trained on the encoded input and stored along with appropriate metadata. During the runtime phase, we generate sample from VAE using variational rejection sampling with . We then apply the hypothesis testing to ensure that the two distributions cannot be distinguished. If the null hypothesis is rejected, we generate a new sample with a lower value of . This will ensure that the model bias issue is eliminated. One can then apply existing techniques for generating approximation guarantees and confidence intervals. Note that we use the VAE model for data exploration only after it passed the hypothesis testing.
Iv-E Making VAE practical for relational AQP
In this subsection, we propose two practical improvements for training VAE for AQP over relational data.
Effective Input Encoding. One-hot encoding of tuples is an effective approach for relatively small attribute domains. If the relation has millions of distinct values, then it causes two major issues. First, the encoded vector becomes very sparse resulting in poor performance . Second, it increases the number of parameters learned by the model thereby increasing the model size and the training time.
A promising approach to improve one-hot encoding is to make the representation denser using binary encoding. Without loss of generality, let the domain be its zero-indexed position . We can now concisely represent these values using dimensional vector. Once again consider the example . Instead of representing as a 3-dimensional vectors (i.e., ), we can now represent them in -dimensional vector i.e., . This approach is then repeated for each attribute resulting a -dimensional vector (for attributes) that is exponentially smaller and denser than the one-hot encoding that requires dimensions.
Effective Decoding of Samples. Typically, samples are obtained from VAE in two steps: (a) generate a sample in the latent space i.e., and (b) generate a sample in the original space by passing to the decoder. While this approach is widely used in many domains such as images and music, it is not appropriate for databases. Typically, the output of the decoder is stochastic. In other words, for the same value of , it is possible to generate multiple reconstructed tuples from the distribution . However, blindly generating a random tuple from the decoder output could return an invalid tuple. For images and music, obtaining incorrect values for a few pixels/notes is often imperceptible. However, getting an attribute wrong could result in a (slightly) incorrect estimate Typically, the samples generated are often more correct than wrong. We could minimize the likelihood of an aberration by generating multiple samples for the same value of . In other words, for the same latent space sample , we generate multiple samples in the tuple space. These samples could then be aggregated to obtain a single sample tuple . The aggregation could be based on max (i.e., for each attribute , pick the value that occurred most in ) or weighted random sampling (i.e., for each attribute , pick the value based on the frequency distribution of in ). Both these approaches provide sample tuples that are much more robust resulting in better accuracy estimates.
V AQP using Multiple VAEs
So far we have assumed that a single VAE model is used to learn the data distribution. As our experimental results show, even a single model could generate effective samples for AQP. However, it is possible to improve this performance and generate better samples. One way to accomplish this is to split the dataset into say non-overlapping partitions and learn a VAE model for each of the partitions. Intuitively, we would expect each of the models to learn the finer characteristics of the data from the corresponding partition and thereby generate better samples for that partition. In this section, we investigate the problem of identifying the optimal set of partitions for building VAE models.
V-a Problem Setup
Typically, especially in OLAP settings, tuples are grouped according to hierarchies on given attributes. Such hierarchies reflect meaningful groupings which are application specific such as for example location, product semantics, year, etc. Often, these groupings have a semantic interpretation and building models for such groupings makes more sense than doing so on an arbitrary subset of the tuples in the dataset. As an example, the dataset could be partitioned based on the attribute Country such that all tuples belonging to a particular country is an atomic group. We wish to identify non-overlapping groups of countries such that a VAE model is trained on each group.
More formally, let be the set of existing groups with such that . We wish to identify a partition of where and when . Our objective is to group these subsets into non-overlapping partitions such that the aggregate error of the VAEs over these partitions is minimized.
Efficiently solving this problem involves two steps: (a) given a partition, a mechanism to estimate the error of VAEs trained over the partition without conducting the actual training and (b) an algorithm that uses (a) to identify the best partition over the space of partitions. Both of these challenges are non-trivial.
V-B Bounding VAE Errors
Quantifying VAE Approximation. The parameters of VAE are learned by optimizing an evidence lower bound (ELBO) given by
(from Equation 5) which is a tight bound on the marginal log likelihood. ELBO provides a meaningful way to measure the distribution approximation by the VAE. Recall from Section IV-B that we perform rejection sampling on the VAE that results in a related measure we call R-ELBO (resampled ELBO) defined as
where is the resampled distribution for a user-specified threshold of . Given two VAEs trained on the same dataset for a fixed value of , the VAE with lower R-ELBO provides a better approximation.
Bounding R-ELBO for a Partition. Let us assume that we will train a VAE model for each of the atomic groups . We train the model using variational rejection sampling  for a fixed and compute its R-ELBO. In order to find the optimal partition, we have to compute the value of R-ELBO for arbitrary subsets . The naive approach would be to train a VAE on the union of the data from atomic groups in which is time consuming. Instead, we empirically show that it is possible to bound the R-ELBO of VAE trained on if we know the value of R-ELBO of each of . Let be such a function. In this paper, we take a conservative approach and bound it by sum where is the R-ELBO for group . In other words, bounds the R-ELBO of VAE trained by . It is possible to use other functions that provide tighter bounds.
Empirical Validation. We empirically validated the function on a number of datasets under a variety of settings. Table I show the results for Census and Flights dataset that has been widely used in prior work on AQP such as [31, 16, 18]. Please refer to Section VI for a description of the two datasets. We obtained similar results for other benchmark datasets. For each of the datasets, we constructed multiple atomic groups for different categorical attributes. For example, one could group the Census dataset using attributes such as gender, income, race etc. We ensured that each of the groups are at least 5% of the data set size to avoid outlier groups and if necessary merged smaller groups into a miscellaneous group. We trained a VAE model on each of the groups for different values of using variational rejection sampling and computed their R-ELBO. We then construct all pairs, triples, and other larger subsets of the groups and compare the bound obtained by with the actual R-ELBO value of the VAE trained on the data of these subsets. For each dataset, we evaluated 1000 randomly selected subsets and report the fraction in which the bound was true. As is evident in table I the bound almost always holds.
V-C Choosing Optimal Partition
In this section we assume we are provided with the value of R-ELBO for each of the groups , a bounding function and a user specified value . We propose an algorithm that optimally splits a relation into non overlapping partitions where and when . The key objective is to choose the split in such a way that the is minimized. Note that there are possible partitions and exhaustively enumerating and choosing the best partition is often infeasible. R-ELBO() corresponds to the actual R-ELBO for atomic groups while for , this is estimated using the bounding function . We investigate scenarios that occur in practice.
Optimal Partition using OLAP Hierarchy. In OLAP settings, tuples are grouped according to hierarchies on given attributes that reflect meaningful semantics. We assume the availability of an OLAP hierarchy in the form of a tree where the leaf node corresponds to the atomic groups (e.g., Nikon Digital Cameras) while the intermediate groups correspond to product semantics (e.g., Digital Camera Camera Electronics and so on). We wish to build VAE on meaningful groups of tuples by constraining to be selected from the leafs or intermediate nodes, be mutually exclusive and have the least aggregate R-ELBO score. We observe that the selected nodes forms a tree cut that partitions the OLAP hierarchy into disjoint sub-trees.
Let us begin by considering the simple scenario where the OLAP hierarchy is a binary tree. Let denote an arbitrary node in the hierarchy with left(h) and right(h) returning the left and right children of if they exist. We propose a dynamic programming algorithm to compute the optimal partition. We use the table to denote aggregate R-ELBO of splitting the sub-tree rooted at node using at most partitions where . The base case is simply building the VAE on all the tuples falling under node . When , we evaluate the various ways to split such that the aggregate R-ELBO is minimized. For example, when , there are two possibilities. We could either not split or build two VAE models over left(h) and right(h). The optimal decision could be decided by choosing the option with least aggregate error. In general, we consider all possible ways of apportioning between the left and right sub-trees of and pick the allocation resulting in least error. The recurrence relation is specified by,
The extension to non-binary trees is also straightforward. Let be the children of node . We systematically partition the space of children into various groups of two and identify the best partitioning that gives the least error (eq. 11). A similar dynamic programming approach was also used for constructing histograms over hierarchical data in .
Scenario 2: Partitioning with Contiguous Atomic Groups. Given the atomic groups , a common scenario is to partition them into contiguous subsets. This could be specified as integers where the boundary of the -th subset is specified by and consists of a set of atomic groups . This is often desirable when the underlying attribute has a natural ordering such as year. So we would prefer to train VAE models over data from consecutive years such as instead of arbitrary groupings such as . This problem could be solved in near linear time (i.e., ) by using the approach first proposed in . The key insight is the notion of sparse interval set system that could be used to express any interval using a bounded number of sparse intervals. The authors then use a dynamic programming approach on the set of sparse intervals to identify the best partitioning.
In practice, is often determined by various other factors such as space budget for persisting the generative models. Identifying automatically is an interesting orthogonal problem. Our bounding function for R-ELBO has a natural monotonic property. We empirically found that common heuristics for selecting number of clusters such as Elbow method  works well for our purpose.
We conduct a comprehensive set of experiments and demonstrate that VAE (and deep generative models) are a promising mechanism for AQP. We reiterate that our proposed approach is an alternate way for generating samples, albeit very fast. Most of the prior work for improving AQP estimates could be transparently used on the samples from VAE.
Vi-a Experimental Setup
Hardware and Platform. All our experiments were performed on a server with 16 cores, 128 GB of RAM and NVidia Tesla K80 GPU. We used PyTorch  for training VAE and GAN, bnlearn  for learning Bayesian Networks and MSPN  for mixed sum-product networks (MSPN).
Datasets. We conducted our experiments on two real-world datasets: Census  and Flights [6, 15]. Both datasets have complex correlated attributes and conditional dependencies that make AQP challenging. The Census dataset has 8 categorical attributes and 6 numerical attributes and contains demographic and employment information. The Flights dataset has 6 categorical and 6 numerical attributes and contains information about on-arrival statistics for the last few years. We used the data generator from  to scale the datasets to arbitrary sizes while also ensuring that the relationships between attributes are maintained. By default, our experiments were run on datasets with 1 million tuples.
Deep Generative Models for AQP. In our experiments, we primarily focus on VAE for AQP as it is easy and efficient to train and generates realistic samples . By default, our VAE model consists of a 2 layer encoder and decoder that are parameterized by Normal and Bernoulli distributions respectively. We used binary encoding (Section IV-E) for converting tuples into a representation consumed by the encoder.
In order to generate high quality samples, we use rejection sampling during both VAE training and sample generation albeit at different granularities. During training, the value of threshold is set for each tuple so that the acceptance probability of samples generated from is roughly for most tuples. We use the procedure from  to generate a Monte Carlo estimate for satisfying acceptance probability constraints. While the trained model already produces realistic samples, we further ensure this by performing rejection sampling with a fixed threshold (for the entire dataset) during sample generation (as detailed in Section IV-B). There are many ways for choosing the value of . It could be provided by the user or chosen by cross validation such that it provides the best performance on query workload. By default, we compute the value of from the final epoch of training as follows. For each tuple , we have the Monte-Carlo estimate . We select the 90-th percentile of the distribution . Intuitively, this ensures that samples generated for 90% of the tuples would have acceptance probability of 0.9. Of course, it is possible to specify different values of for queries with stringent accuracy requirements. We used Wasserstein GAN as the architecture for generative adversarial networks . We used entropy based discretization  for continuous attributes when training discrete Bayesian networks. We used the default settings from  for training MSPN.
Query Workload. We used IDEBench  to generate aggregate queries involving filter and group-by conditions. We then selected a set of 1000 queries that are diverse in various facets such as number of predicates, selectivity, number of groups, attribute correlation etc.
Performance Measures. As detailed in Section IV-B, AQP using VAE introduces two sources of errors: sampling error and errors due to model bias. The accuracy of an estimate could be evaluated by relative error (see Equation 1). For each query in the workload, we compute the relative error over a fixed size sample (1% by default) obtained from the underlying dataset and the learned VAE model. For a given query, the relative error difference (RED) computed as the absolute difference between the two relative errors provides a meaningful way to compare them. Intuitively, RED will be close to 0 for a well trained VAE model. We repeat this process over 10 different samples and report the average results. Given that our query workload has 1000 queries, we use box plots to concisely visualize the distribution of the relative error difference. The middle line corresponds to the median value of the difference while the box boundaries correspond to the 25th and 75th percentiles. The top and bottom whiskers are set to show the 95th and 5th percentiles respectively.
Vi-B Experimental Results
Evaluating Model Quality. In our first experiment, we demonstrate that VAE could meaningfully learn the data distribution and generate realistic samples. Figure 4 shows the distribution of relative error differences for both datasets over the entire query workload for various sample sizes. We can see that the differences are less than 1% for almost all the cases for the Census dataset. The flights dataset has many attributes with large domain cardinalities which makes learning the data distribution very challenging. Nevertheless, our proposed approach is still within 3% of the relative error obtained from the samples of .
Impact of Selectivity. In this experiment, we group the queries based on their selectivity and compute the relative error difference for each group. As shown in Figure 4, the difference is vanishingly small for queries with large selectivities and slowly increases for decreasing selectivities. In general, generating estimates for low selectivity queries is challenging for any sampling based AQP. The capacity/model size constraints imposed on the VAE model could result in generating bad estimates for some queries with very low selectivities. However, this issue could be readily ameliorated by building multiple VAE models that learn the finer characteristics of data minimizing such errors in these cases.
Impact of Model Capacity and Depth. Figures 4 and 7 shows the impact of two important hyper parameters - the number of latent dimensions and depth of the encoder and decoder. We vary the latent dimension from 10% to 100% of the input dimension. Large latent dimension results in an expressive model that can learn complex data distributions at the cost of increased model size and training time. Increasing the depth results in a more accurate model but with larger model size and slower training time. Empirically, we found that setting latent dimension size to 50% (for binary encoding) and encoder/decoder network depth of 2 provides good results.
Effectiveness of Input Encoding and Output Decoding. It is our observation that the traditional approach of one-hot encoding coupled with generating a single sample tuple for each sample from the latent space does not provide realistic tuples. It may be suitable for image data but certainly not suitable for relational data. Figure 7 shows how different encodings affect the generated samples. For datasets such as Census where almost all attributes have small domain cardinality, all the three approaches provide similar results. However, for the flights dataset where some attributes have domain cardinality in tens of thousands, naive approaches such as one-hot encoding provides sub-optimal results. This is due to the fact that there are simply too many parameters to be learnt and even a large dataset of 1 Million tuples is insufficient. Similarly, Figure 7 shows that our proposed decoding approach dramatically decreases the relative error difference making the approach suitable for relational data. This is due to the fact that the naive decoding could produce unrealistic tuples that could violate common integrity constraints an effect that is minimized when using our proposed decoding.
Impact of Rejection Sampling. Figure 10 shows how varying the value of impacts the sample quality. Recall from Section IV-B that as , almost all samples from VAE are accepted, while when , samples are rejected unless they are likely to be from the true posterior distribution. As expected, decreasing the value of results in decreased value of relative error difference. However, this results in a larger number of samples being rejected. Our approach allows to be varied across queries such that queries with stringent accuracy requirements can use small for better estimates. We investigate the impact of rejection sampling on model building and sample generation later in the section.
One versus Multiple VAEs. In the next set of experiments, we consider the case where one uses multiple VAEs to learn the underlying data distribution. We partitioned the attributes based on marital-status for Census and origin-state for Flights. We evaluated partitioning data over other attributes and observed similar results. In order to compare the models fairly, we ensured that the cumulative model capacity for both scenarios were the same. For example, if we built VAE models with capacity each, then we compared it against a single VAE model with capacity . Figure 10 shows the results. As expected, the sample quality improves with larger number of VAE models enabling them to learn finer data characteristics. Interestingly, we observe that increasing the model capacity for the single VAE case has diminishing returns due to the fixed size of the training data. In other words, increasing the capacity does not improve the performance beyond certain model capacity. Figure 10 compares the performance of partitions selected by the dynamic programming algorithm for the scenario where an OLAP hierarchy is provided. We compare it against a greedy algorithm. As expected, our proposed approach that is cognizant of the R-ELBO metric provides better partitions - especially datasets such as Flight that have complex R-ELBO distributions.
Vi-C Comparison with DL Model for AQP.
While we primarily focused on VAE, it is possible to leverage other deep generative models for AQP. Figure 13 compares the performance of three common models : VAE, GAN and Bayesian Networks (BN). Generative Adversarial Networks (GANs) [20, 19] are a popular and powerful class of generative models that learn the distribution as a minimax game between two components - generator (that generates data) and discriminator (that identifies if the sample is from the true distribution or not). (Deep) Bayesian networks (BN) are another effective generative model that specifies the joint distribution as a directed graphical model where nodes correspond to random variable (for attribute ) and directed edges between nodes signify (direct) dependencies between the corresponding attributes. Please refer to  for more details. In order to ensure a fair comparison, we imposed a constraint that the model size for all three approaches are fixed. Furthermore, VAE provides the best results for a fixed model size. GANs provide reasonable performance but was heavily reliant on tuning. Training a GAN requires identifying an equilibria and tuning of many parameters such as the model architecture and learning rate . This renders the approach hard to use in practise for general data sets. Identifying appropriate mechanisms for training GANs over relational data for AQP is a promising avenue for future research. BNs provide the worst result among the three models. While BNs are easy to train for datasets involving discrete attributes, a hybrid dataset with discrete and continuous attributes, and attributes with large domain cardinalities are challenging. When the budget on model size is strict, BNs often learn a sub-optimal model.
We also evaluated VAE against the recently proposed MSPN  that has been utilized for AQP in . Similar to Bayesian Networks, MSPNs are acyclic graphs (albeit rooted graphs) with sum and product nodes as internal nodes. Intuitively, the sum nodes split the dataset into subsets while product nodes split the attributes. The leaf nodes define the probability distributions for an individual variable. MSPN could be used to represent an arbitrary probability distribution . We used the random sampling procedure from  for generating samples from a trained MSPN. We observed that MSPN often struggles to model distributions involving large number of attributes and/or tuples and that using a single MSPN for the entire model did not provide good results. As a comparison to train a VAE on 1M tuples of the Census data set on all attributes requires a few minutes versus almost 3.5 hours for MSPN. In addition the accuracy of queries with larger number of attributes for the case of MSPN was very poor and not close to any of the other models. Hence, we decided to provide an advantage to MSPN, building the model over subsets of attributes. That way we let the model focus only on specific queries and improve its accuracy. There were around 120 distinct combination of measure and filter attributes in our query workload. We built MSPN models for each combination of attributes, generate samples from it and evaluate our queries over it. For example, if a query involved an aggregate over and filter condition over , we built an MSPN over the projected dataset containing only . Unlike GAN and BN, we did not control the number of leaf nodes. However, the size of the MSPN models that were trained over attribute subsets were in the same ballpark as the other generative models. Figure 13 presents the performance of VAE and MSPN (build on specialized subsets of attributes) to be superior over GAN and BN. However, in the case of VAE the model was trained over the entire dataset being able to answer arbitrary queries while MSPN was trained over specific attribute subsets utilized by specific queries. Even in this case, providing full advantage to MSPN, the median relative error difference for VAE and MSPN were 0.060835 and 0.137699 respectively, more than two times better for VAE. This clearly demonstrates that a VAE model can learn a better approximation of the data, being able to answer arbitrary queries while it can be trained an order of magnitude faster than MSPN as detailed next.
Next, we compare our approach with DBEst  and NeuralCubes  that use ML models for answer AQP queries. Figure 13 compares the performance of our approach against these methods. In contrast to our approach that uses synthetic samples, DBEst and NeuralCubes use pre-built models to directly answer AQP queries. For simple aggregate queries, the performance of both these methods are comparable to that of our approach. However, our approach produces more accurate result for ad-hoc queries that are very common in data exploration. Furthermore, the ability of our approach to create arbitrary number of samples to achieve low error that is not possible with DBEst and NeuralCubes.
Performance Experiments. Our next set of experiments investigate the scalability of VAE for different dataset sizes and values of threshold . Figure 13 depicts the results for training over a single GPU. All results would be substantially better with the use of multiple GPUs. As expected, the training time increases with larger dataset size. However, due to batching and other memory optimizations, the increase is sublinear. Next, incorporating rejection sampling has an impact on the training time with stringent values of requiring more training time. The increased time is due to the larger number of training epochs needed for the model to learn the distribution. The validation procedure for evaluating the rejection rate uses a Monte Carlo approach  that also contributes to the increased training time. However overall it is evident from our results that very large data sets can be trained very efficiently even on a single GPU. This attests to the practical utility of the proposed approach. Figure 13 presents the cost of generating samples of different sizes and for various values of . Not surprisingly, lower values of require a larger sampling time due to the higher number of rejected samples. As becomes less stringent, sampling time dramatically decreases. Interestingly, the sampling time does not vary a lot for different sampling sizes. This is due to the efficient vectorized implementation of the sampling procedure in PyTorch and the availability of larger memory that could easily handle samples of large size. It is evident again that the proposed approach can generate large number of samples in fractions of a second making the approach highly suitable for fast query answering with increased accuracy.
Vii Related Work
Deep Learning for Databases. Recently, there has been increasing interest in applying deep learning techniques for solving fundamental problems in databases. SageDB  proposes a new database architecture that integrates deep learning techniques to model data distribution, workload and hardware and use it for indexing, join processing and query optimization. Deep learning has also been used for learning data distribution to support index structures , join cardinality estimation [26, 39], join order enumeration [30, 34], physical design , entity matching , workload management  and performance prediction .
Sampling based Approximate Query Processing. AQP has been extensively studied by the database community. A detailed surveys is available elsewhere [17, 36]. Non sampling based approaches involve synopses data structures such as histograms, wavelets and sketches. They are often designed for specific types of queries and could answer them efficiently. In our paper, we restrict ourselves to sampling based approaches [1, 2, 41, 25, 7]. Samples could either be pre-computed or obtained during runtime. Pre-computed samples often leverage prior knowledge about workloads to select samples that minimize the estimation error. However, if workload is not available or is inaccurate, the chosen samples could result in worse approximations. In this case, recomputing samples is often quite expensive. Our model based approach could easily avoid this issue by generating samples as much as needed on-demand. Online aggregation based approaches such as [24, 51] continuously refine the aggregate estimates during query execution. The execution can be stopped at any time if the user is satisfied with the estimate. Prior approaches often expect the data to be retrieved in a random order which could be challenging. Our model based approach could be easily retrofitted into online aggregation systems as they could generate random samples efficiently. Answering ad-hoc queries and aggregates over rare sub-populations is especially challenging  . Our approach offers a promising approach where as many samples as needed could be generated to answer such challenging queries without having to access the dataset.  uses mixed sum-product networks (MSPN) to generate aggregate estimates for interactive visualizations. While in the same spirit as our work, their proposed approach suffers from scalability issues that limits its widespread applicability. Even for a small dataset with 1 million tuples, it requires hours for training. This renders such an approach hard to apply for very large data sets. In contrast a VAE model can be trained in a matter of minutes making it ideal for very large data sets.
We proposed a model based approach for AQP and demonstrated experimentally that the generated samples are realistic and produce accurate aggregate estimates. We identify the issue of model bias and propose a rejection sampling based approach to mitigate it. We proposed dynamic programming based algorithms for identifying optimal partitions to train multiple generative models. Our approach could integrated easily into AQP systems and can satisfy arbitrary accuracy requirements by generating as many samples as needed without going back to the data. There are a number of interesting questions to consider in the future. Some of them include better mechanisms for generating conditional samples that satisfy certain constraints. Moreover, it would be interesting to study the applicability of generative models in other data management problems such as synthetic data generation for structured and graph databases extending ideas in .
The work of Gautam Das was supported in part by grants 1745925 and 1937143 from the National Science Foundation, and a grant from AT&T.
-  (1999) The aqua approximate query answering system. In ACM Sigmod Record, Vol. 28, pp. 574–576. Cited by: §VII.
-  (2013) BlinkDB: queries with bounded errors and bounded response times on very large data. In EuroSys, External Links: Cited by: §VII.
-  (2018) Tutorial - what is a variational autoencoder?. External Links: Cited by: §III.
-  (2015) Deep learning. Nature 521 (7553), pp. 436–444. Cited by: §III.
-  (2015) Importance weighted autoencoders. arXiv preprint arXiv:1509.00519. Cited by: §IV-B.
-  (2019) Bureau of transportation statistics. Flights Data Set . External Links: Cited by: §VI-A.
-  (2007) Optimized stratified sampling for approximate query processing. TODS 32 (2), pp. 9. Cited by: §VII.
-  (2017) Approximate query processing: no silver bullet. In SIGMOD, External Links: Cited by: §VII.
-  (2007) Sampling techniques. John Wiley & Sons. Cited by: §IV-B, §IV-B.
-  (2016) Tutorial on variational autoencoders. arXiv preprint arXiv:1606.05908. Cited by: §I-A, §III, §III, §VI-A.
-  (1995) Supervised and unsupervised discretization of continuous features. In MLR, Cited by: §VI-A.
-  (2018) Distributed representations of tuples for entity resolution. PVLDB 11 (11), pp. 1454–1467. Cited by: §VII.
-  (1965) Paths, trees, and flowers. Canadian Journal of mathematics 17, pp. 449–467. Cited by: §IV-C.
-  (1994) An introduction to the bootstrap. CRC press. Cited by: §IV-B, §IV-B.
-  (2018) IDEBench: a benchmark for interactive data exploration. arXiv:1804.02593. Cited by: §VI-A, §VI-A.
-  (2017) Revisiting reuse for approximate query processing. PVLDB. External Links: Cited by: §V-B.
-  (2001) Approximate query processing: taming the terabytes.. In VLDB, pp. 343–352. Cited by: §IV-B, §VII.
-  (2001) Selectivity estimation using probabilistic models. In ACM SIGMOD Record, Vol. 30. Cited by: §V-B.
-  (2016) Deep learning. MIT Press. Note: http://www.deeplearningbook.org Cited by: §I-A, §VI-A, §VI-C.
-  (2017) NIPS 2016 tutorial: generative adversarial networks. CoRR abs/1701.00160. External Links: Cited by: §VI-C.
-  (2018) Variational rejection sampling. In AISTATS, Cited by: §IV-B, §IV-B, §IV-B, §V-B, §VI-A, §VI-C.
-  (2002) Fast algorithms for hierarchical range histogram construction. In PODS, External Links: Cited by: §V-C.
-  (2011) Data mining: concepts and techniques. Elsevier. Cited by: §V-C.
-  (1997) Online aggregation. In Acm Sigmod Record, Vol. 26, pp. 171–182. Cited by: §VII.
-  (2016) Quickr: lazily approximating complex adhoc queries in bigdata clusters. In SIGMOD, pp. 631–646. Cited by: §VII.
-  (2019) Learned cardinalities: estimating correlated joins with deep learning. CIDR. Cited by: §VII.
-  (2019) Sagedb: a learned database system. Cited by: §VII.
-  (2018) The case for learned index structures. In SIGMOD, pp. 489–504. Cited by: §VII.
-  (2016) Inference and introspection in deep generative models of sparse data. Advances in Approximate Bayesian Inference Workshop at NIPS. Cited by: §IV-E.
-  (2018) Learning to optimize join queries with deep reinforcement learning. arXiv preprint arXiv:1808.03196. Cited by: §VII.
-  (2018) Model-based approximate query processing. arXiv:1811.06224. Cited by: §V-B, §VI-C, §VII.
-  (2019) DBEst: revisiting approximate query processing engines with machine learning models. In SIGMOD, . Cited by: §VI-C.
-  (2017) Releasing cloud databases for the chains of performance prediction models.. In CIDR, Cited by: §VII.
-  (2018) Deep reinforcement learning for join order enumeration. arXiv preprint arXiv:1803.00055. Cited by: §VII.
-  (2018) Mixed sum-product networks: a deep architecture for hybrid domains. In AAAI, Cited by: §VI-A, §VI-A, §VI-C.
-  (2015) A handbook for building an approximate query engine.. IEEE Data Eng. Bull. 38 (3), pp. 3–29. Cited by: §I-A, §IV-B, §VII.
-  (2017) Approximate query engines: commercial challenges and research opportunities. In SIGMOD, pp. 521–524. External Links: Cited by: §I-A.
-  (2001) Annealed importance sampling. Statistics and computing 11 (2), pp. 125–139. Cited by: §IV-B.
-  (2018) Learning state representations for query optimization with deep reinforcement learning. In DEEM Workshop, pp. 4. Cited by: §VII.
-  (2018) Data synthesis based on generative adversarial networks. PVLDB 11 (10), pp. 1071–1083. External Links: Cited by: §VIII.
-  (2018) VerdictDB: universalizing approximate query processing. In SIGMOD, Cited by: §VII.
-  (2017) Automatic differentiation in pytorch. Cited by: §VI-A.
-  (2017) Self-driving database management systems.. In CIDR, Cited by: §VII.
-  (2006) Compact histograms for hierarchical identifiers. In Proceedings of the 32nd international conference on Very large data bases, pp. 870–881. Cited by: §V-C.
-  (2005) An exact distribution-free test comparing two multivariate distributions based on adjacency. JRSS: Series B 67 (4), pp. 515–530. Cited by: §IV-C, §IV-C, §IV-C.
-  (2014) Bayesian networks with examples in R. Chapman and Hall, Boca Raton. Cited by: §VI-A.
-  (2019) UCI Machine Learning Repository. Adult Data Set . External Links: Cited by: §VI-A.
-  (2016) Ernest: efficient performance prediction for large-scale advanced analytics.. In NSDI, pp. 363–378. Cited by: §VII.
-  (2018) NeuralCubes: deep representations for visual data exploration. CoRR abs/1808.08983. Cited by: §VI-C.
-  (2012) Modern two-sample tests. External Links: Cited by: §IV-C, §IV-C, §IV-C.
-  (2010) Continuous sampling for online aggregation over multiple queries. In SIGMOD, Cited by: §VII.