Abstract
NeuroCard is a single, compact neural density estimator that learns the correlations across an entire database schema without making any independence assumptions. By combining unbiased join sampling with deep autoregressive models, it achieves orders-of-magnitude better accuracy than traditional methods and previous machine learning approaches, even on complex queries involving dozens of tables.
Introduction
Query optimizers are the "brains" of a database, deciding the most efficient way to execute SQL queries. To do this effectively, they require accurate cardinality estimates—predictions of how many rows a query or join will return. Historically, this has been a significant challenge. Traditional estimators rely on simple histograms and assume independence between columns or tables. However, real-world data is highly correlated, and these assumptions lead to exponential error growth in complex queries. While recent machine learning models showed promise, they were largely limited to single tables and struggled to scale to the multi-table joins common in production.
Methods
NeuroCard introduces a "one model for all" approach, treating the entire database as a single joint probability distribution. The system architecture integrates several components to achieve this.
The architecture relies on four key pillars:
- Unbiased Join Sampling: NeuroCard uses the Exact Weight algorithm to draw uniform, independent samples from the "full outer join" of all tables in linear time. This avoids the impossible task of materializing trillions of rows.
- Deep Autoregressive (AR) Models: Using models like ResMADE or Transformers, NeuroCard learns the probability of each column value conditioned on previous columns, capturing complex high-dimensional correlations.
- Lossless Column Factorization: To handle high-cardinality columns (e.g., unique IDs with millions of values), NeuroCard factorizes values into sub-columns. This keeps the model small while retaining full precision.
- Virtual Columns for Schema Subsetting: Indicator columns mark table presence in a join, and fanout columns account for row duplication, allowing the model to handle queries touching only a subset of tables.
Evaluation and Results
The authors evaluated NeuroCard using the IMDB dataset across three workloads: JOB-light (standard benchmark), JOB-light-ranges (adds range filters), and JOB-M (16 tables and multi-key joins).
Key findings include:
- State-of-the-Art Accuracy: On JOB-light, NeuroCard achieved an 8.5× maximum error, compared to ~40× for previous best methods.
- Superior Scaling: On complex JOB-light-ranges and JOB-M benchmarks, NeuroCard outperformed prior methods (DeepDB, MSCN) by 15–34×.
- Efficiency: The models are remarkably compact, requiring only 4 MB for a 6-table schema and 27 MB for a 16-table schema.
- Fast Construction: Models can be built or updated in minutes, making them practical for dynamic production environments.
Conclusion
NeuroCard demonstrates that a single model trained on a full join distribution can provide highly accurate cardinality estimates for any sub-query. By leveraging sampling and autoregressive modeling, it overcomes the limitations of traditional independence assumptions and the scalability issues of previous ML approaches. Future work includes extending support to cyclic joins and reducing inference latency for real-time optimization.
Summary updated