DeepDB: Learn from Data, not from Queries!

Benjamin Hilprecht, Andreas Schmidt, Moritz Kulessa, Alejandro Molina, Kristian Kersting, Carsten Binnig

TL;DR

Most "learned" database components rely on workload-driven approaches that require executing tens of thousands of expensive training queries—only to break when data or workloads change. DeepDB flips this paradigm by learning directly from data via Relational Sum-Product Networks (RSPNs), a tractable deep probabilistic model. It supports ad-hoc joins, incremental updates without retraining, and outperforms state-of-the-art learned and classical baselines in both cardinality estimation and approximate query processing (AQP).

What Problem Does This Paper Address?

Modern database systems increasingly deploy machine learning for internal tasks like cardinality estimation and query cost modeling. However, the predominant paradigm is workload-driven: models are trained on observations collected by executing vast suites of queries against the database.

This introduces three critical bottlenecks:

  1. Excessive training costs: Gathering training data requires running tens to hundreds of thousands of query plans (taking hours or days on large databases).
  2. Poor generalization: Models fit the specific distributions of the query workload used during training, often failing on queries with unseen join paths or complex predicates.
  3. High maintenance overhead: When the underlying data undergoes inserts, updates, or deletes (as in OLTP systems), or when the query workload shifts, the training set must be regenerated and the model retrained from scratch.

DeepDB addresses this by learning a probabilistic representation directly from the underlying data offline, completely decoupled from past queries.

Methods

DeepDB models relational data using an ensemble of Relational Sum-Product Networks (RSPNs), extending classical Sum-Product Networks (SPNs):

  • Relational Sum-Product Networks (RSPNs): Standard SPNs recursively split data using sum nodes (clustering rows via algorithms like k-means) and product nodes (splitting independent columns via Randomized Dependency Coefficients, or RDC). DeepDB extends SPNs to relational settings by:
  • Supporting exact expectations to compute AVG and SUM aggregates in addition to probabilities (COUNT).
  • Handling SQL database specifics, such as three-valued NULL logic and non-key functional dependencies (stored in separate mapping dictionaries).
  • Direct updatability: updates and deletes recursively traverse the tree to adjust sum-node weights and leaf histograms in-place without rebuilding tree structure.
  • Handling Joins via Ensembles and Outer Joins:
  • RSPNs are trained over the full outer join of correlated tables (identified using pairwise RDC on random samples).
  • To avoid multi-counting rows when queries select only a subset of joined tables, DeepDB tracks tuple factors ($F$) and tuple-presence indicators ($N_T$), normalizing counts algebraically during inference.
  • An optimization algorithm automatically selects which multi-table RSPNs to build under a user-defined training budget factor.
  • Probabilistic Query Compilation: DeepDB compiles incoming SQL queries (with arbitrary conjunctions, disjunctions, acyclic equi-joins, GROUP BY, and numerical aggregations) into exact expectation and probability evaluations over the RSPN ensemble.
SQL Query  ──►  Probabilistic Compilation  ──►  Evaluate Expectations & Probabilities  ──►  Estimate / AQP Answer
                     (using Tuple Factors)            over RSPN Ensemble

Datasets

The authors evaluated DeepDB against multiple standard benchmarks:

  • IMDb Dataset: A real-world 3.7 GB relational dataset used with the JOB-light benchmark (70 queries) and an extended synthetic query set (200 queries spanning 3–6 tables and 1–5 selection predicates) for cardinality estimation.
  • Star Schema Benchmark (SSB): A synthetic analytical dataset evaluated at scale factor 500 (queries S1.1–S4.3) for AQP.
  • Flights Dataset: A real-world dataset scaled up to 1 billion records using IDEBench for AQP evaluations (queries F1.1–F5.2).
  • Synthetic IMDb Variations: Custom-generated datasets varying data skew (Zipf distributions) and attribute correlation degrees to test estimator robustness.

Key Insights and Ideas

  • Data-driven generalizes better than workload-driven: Workload-driven models (like Multi-Set Convolutional Networks, or MSCNs) fail when evaluated on queries larger than those seen during training (e.g., 4–6 table joins). Because RSPNs capture the true underlying joint probability distribution of the database rather than query-plan behavior, they naturally generalize to arbitrary ad-hoc queries.
  • Outer joins + tuple factors eliminate join pre-materialization: By augmenting outer joins with tuple factors, DeepDB uses a single unified model to answer queries on joined tables and queries on individual constituent tables without double-counting rows.
  • Tractable inference enables millisecond execution: SPNs allow exact inference in time linear with respect to network size, translating to query estimation latencies on the order of microseconds to a few milliseconds—fast enough for in-loop query optimization.

Key Results

  • Cardinality Estimation (JOB-light):
  • DeepDB achieved a median q-error of 1.34 and a 95th percentile q-error of 3.16, outperforming learned MSCN (median 3.22, 95th percentile 143) and native PostgreSQL 11.5 (median 6.84, 95th percentile 817).
  • Storage footprint was compact: 28.9 MB for DeepDB (and 1.32 median q-error with a 2.6 MB storage-optimized model) compared to 3.7 GB of raw database storage.
  • Training preparation took 48 minutes on CPU for DeepDB versus 34 hours of query execution on PostgreSQL to generate training labels for MSCN.
  • Handling Updates: Under incremental insertions up to 40.1% of the IMDb dataset, DeepDB’s median q-error only shifted from 1.22 to 1.41 without any full retraining.
  • Approximate Query Processing (AQP):
  • On SSB, DeepDB delivered relative errors < 6% across all queries, whereas sample-based tools (VerdictDB, Wander Join, PostgreSQL TABLESAMPLE) frequently suffered > 100% relative error or returned no results on highly selective predicates.
  • Query latency remained strictly under 31 ms on Flights and 293 ms on SSB, compared to multi-second execution times for sampling baselines.

Limitations and Future Work

  • Query and Schema Restrictions: DeepDB currently assumes acyclic equi-joins and standard numerical aggregates (COUNT, SUM, AVG); non-equi joins or cyclic queries are not supported.
  • Structural Degradation Under Massive Drift: In-place updates adapt node weights and leaf histograms, but they cannot dynamically create new sum or product splits. Substantial shifts in correlation structures require periodically rebuilding affected RSPNs in the background.
  • Confidence Interval Assumptions in Compound Aggregates: Deriving confidence intervals relies on independence assumptions between compiled terms; when evaluating arithmetic combinations of correlated aggregates (e.g., the difference between two SUM expressions), variance can be overestimated.
  • Query Compilation Overhead: While raw RSPN inference executes in microseconds, query translation currently takes up to a few milliseconds—an overhead the authors plan to optimize in future iterations.

Summary updated

BibTeX
@article{hilprecht2020deepdb,
  author = {Benjamin Hilprecht and Andreas Schmidt and Moritz Kulessa and Alejandro Molina and Kristian Kersting and Carsten Binnig},
  title = {{DeepDB: Learn from Data, not from Queries!}},
  journal = {Proc. VLDB Endow.},
  year = {2020},
  url = {https://openreview.net/forum?id=DeET0zwFO46},
}
Figure