NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

NeuroCard: One Cardinality Estimator for All Tables

Zongheng Yang, Amog Kamsetty, Sifei Luan, Eric Liang, Yan Duan, Xi Chen, Ion Stoica

TL;DR

NeuroCard is a learned data-driven cardinality estimator that captures correlations across all tables in a database using a single deep autoregressive model. By combining efficient on-the-fly join sampling with lossless column factorization, it avoids making any inter-table or inter-column independence assumptions. This allows NeuroCard to deliver orders-of-magnitude higher accuracy than previous state-of-the-art methods while maintaining a compact footprint of just a few megabytes.

What Problem Does This Paper Address?

Query optimizers are the brain of any relational database system; they determine the most efficient way to execute a SQL query. To do this effectively, they rely on cardinality estimation—predicting how many rows a query or sub-query will return.

Traditional database systems use simple 1D histograms and make "lossy" independence assumptions (e.g., assuming that a person's eye color is independent of their hair color, or that data across different tables is uncorrelated). When queries involve complex joins and filters, these assumptions break down, causing estimation errors to multiply exponentially.

While recent machine learning approaches have attempted to solve this, they face severe limitations:

  1. Query-driven models (supervised learning) fail when users issue unexpected queries outside the training distribution.
  2. Data-driven models (density estimators) have historically been restricted to single tables. Building a model for every possible join combination is impossible because the number of combinations grows exponentially with the number of tables.
Figure 1: NeuroCard uses a single probabilistic model, which learns all possible correlations among all tables in a database, to estimate join queries on any subset of tables.

Methods

NeuroCard overcomes these challenges by training a single neural density estimator over the full outer join of the entire database schema. Its architecture relies on four key innovations:

  • On-the-Fly Join Sampling: Materializing a full outer join for a database can result in trillions of rows, making it computationally impossible to compute directly. NeuroCard uses an exact-weight join sampling algorithm that precomputes join count tables via dynamic programming in linear time. This allows the system to stream uniform, independent samples directly to the neural network without ever materializing the full join.
  • Schema Subsetting via Virtual Columns: To handle queries that only look at a subset of tables, NeuroCard appends virtual indicator columns ($1_T$) and fanout columns ($F$) to the training samples. The model learns these values, enabling the inference engine to correctly downscale probabilities when tables are omitted from a query.
  • Lossless Column Factorization: High-cardinality columns (like unique IDs with millions of values) cause neural network embedding matrices to explode in size. NeuroCard slices these values into smaller bit chunks (subcolumns). Because it uses an autoregressive model, it can learn the conditional probabilities between these chunks, reducing space requirements by over 500$\times$ with zero loss of information.
Figure 2: Overview of NeuroCard. The Join Sampler (§4) provides correct training data (sampled tuples from join) by using unbi- ased join counts. Sampled tuples are streamed to an autoregressive model for maximum likelihood training (§3). Inference algorithms (§6) use the learned distribution to estimate query cardinalities.

Datasets

The authors evaluated NeuroCard using the real-world IMDB dataset, which is widely recognized for its rich, complex real-world correlations. They tested three distinct workloads:

  • JOB-light: A standard 70-query star-schema benchmark focusing on single-key joins.
  • JOB-light-ranges: A new benchmark introduced by the authors containing 1,000 queries with a much wider variety of range and equality filters.
  • JOB-M: A new, highly complex 16-table benchmark featuring multi-key joins and up to 11 joins per query to test scalability.

Key Insights and Ideas

  • The Full Outer Join is a Universal Space: The authors realized that a full outer join contains all the necessary information to answer queries on any subset of tables, provided you mathematically account for the "fanout" effects of the missing tables.
  • Autoregressive Slicing is Lossless: Slicing a column into bits would normally destroy correlation data if you used standard histograms. However, because deep autoregressive models evaluate exact conditional product rules ($P(A, B) = P(A)P(B|A)$), bit-slicing becomes completely lossless.
  • High Statistical Efficiency: NeuroCard doesn't need to see the whole database to understand it. Training on just 0.001% of the total data space is enough for the neural network to generalize effectively to unseen queries.
Figure 4: End-to-end example. (a) A join schema of three tables and their join key columns. Content columns are omitted. (b) Join counts (blue) enable uniform sampling of the full outer join and are computed in linear time by dynamic programming. Here, edges connect join partners. (c) Learning target: the full outer join of the schema, with virtual columns in blue. We show the fanouts F, the number of times a join key value appears in the corresponding base table, for keys 𝐵.𝑥and 𝐶.𝑦. The fanouts for 𝐴.𝑥and 𝐵.𝑦are all 1 and omitted. Each indicator 1𝑇denotes whether a tuple has a match in table 𝑇. (d) Examples of schema subsetting, i.e., queries that touch a subset of the full join (§6).

Key Results

  • New State-of-the-Art: On the standard JOB-light benchmark, NeuroCard achieved a maximum Q-error of just 8.51$\times$ using a tiny 3.8 MB model. This represents a 4.6$\times$ to 8$\times$ improvement in tail-error over the previous best methods (like DeepDB).
  • Robustness to Complex Filters: On the new JOB-light-ranges dataset, NeuroCard outperformed prior methods by 15–34$\times$ at the tail quantiles, proving its ability to handle complex range predicates.
  • Scales to Large Schemas: On the 16-table JOB-M benchmark, NeuroCard maintained high accuracy with a 27.3 MB model, whereas its closest competitor, DeepDB, ran out of memory.
  • Fast Training: NeuroCard can be fully constructed or updated in seconds to minutes (e.g., ~1.25 minutes for 3 million tuples), making it highly practical.

Limitations and Future Work

  • Acyclic Schema Assumption: NeuroCard currently assumes acyclic join graphs (trees). While the authors mention mathematical relaxations to handle cycles, fully integrating cyclic graphs remains future work.
  • Inference Latency Overhead: Computing cardnalities via neural network forward passes takes around 17 ms per query. While highly predictable, this is slower than traditional 1D histograms (~1 ms). The authors suggest model compression and weight quantization as next steps to reduce this overhead.
  • Unseen Join Paths: If a user requests an exotic join path not captured in the predefined schema graph, NeuroCard must fall back to classical database heuristics.

Summary updated

BibTeX
@article{yang2020neurocard,
  author = {Zongheng Yang and Amog Kamsetty and Sifei Luan and Eric Liang and Yan Duan and Xi Chen and Ion Stoica},
  title = {{NeuroCard: One Cardinality Estimator for All Tables}},
  journal = {Proc. VLDB Endow.},
  year = {2020},
  doi = {10.14778/3421424.3421432},
}
Figure