A Lightweight Learned Cardinality Estimation Model

Yaoyu Zhu, Jintao Zhang, Guoliang Li, Jianhua Feng

Abstract

Cardinality estimation—the process of predicting the number of rows returned by a query—is a fundamental component of query optimization in Database Management Systems (DBMS). Traditional methods often force a trade-off between the high accuracy of data-driven deep learning models and the low-latency performance of workload-driven approaches. This paper introduces CoDe (Covering with Decompositions), a novel model that bridges this gap. By utilizing mathematical covering designs to manage dimensionality and Canonical Polyadic (CP) tensor decomposition for efficient data representation, CoDe achieves state-of-the-art accuracy with inference speeds up to 16x faster than existing data-driven methods. Notably, CoDe demonstrates superior performance on discrete datasets and "zero-queries," which are traditionally challenging for learned estimators.

1. Introduction

In modern DBMS, the query optimizer relies on cardinality estimates to select the most efficient execution plan. Inaccurate estimates can lead to suboptimal plan selection, potentially increasing query execution time from milliseconds to minutes. Existing solutions typically fall into two categories: workload-driven methods, which are fast but struggle with unseen query patterns, and data-driven methods, which offer high accuracy but require significant computational resources (often GPUs) and introduce high latency during optimization. CoDe is designed to provide the "best of both worlds": the accuracy of data-centric modeling with the lightweight footprint required for production environments.

2. Problem Statement

Cardinality estimation faces three primary hurdles:

  1. The Curse of Dimensionality: Modeling a table with dozens of columns creates an exponential state space that is difficult to capture in a single model.
  2. Inference Latency: Data-driven models using deep neural networks often require expensive forward passes that can slow down the optimization phase.
  3. Data Characteristics: Many models struggle with discrete, nominal data and "zero-queries" (queries returning no results), as they often rely on continuous approximations that fail to capture the sparsity of real-world data.

3. Methodology

CoDe addresses these challenges through a two-pillar architecture consisting of Covering Designs and Tensor Decomposition.

3.1 Covering Design

To avoid the complexity of modeling all columns simultaneously, CoDe decomposes a table into multiple overlapping subsets of columns, referred to as blocks. This is guided by a $C(v, k, t)$ covering design, a mathematical framework ensuring that any query involving up to $t$ columns is guaranteed to be covered by at least one block. This approach keeps the dimensionality of each individual model manageable while maintaining comprehensive coverage of the schema.

3.2 Tensor Decomposition (CP)

Each block’s data distribution is represented as a multi-dimensional tensor. CoDe employs Canonical Polyadic (CP) decomposition to factorize these tensors into a sum of rank-1 tensors (vectors).

This method offers a significant speed advantage: during query time, estimation is reduced to simple vector lookups and basic arithmetic (multiplications and additions). This process is highly parallelizable and avoids the overhead of neural network inference. Furthermore, because tensor decomposition treats every value as a distinct entry, it is naturally suited for discrete data where smooth, continuous approximations are inappropriate.

3.3 Block Fusion

When a query spans more columns than are contained in a single block, CoDe utilizes a Block Fusion algorithm. Based on Bayes' theorem and the principle of conditional independence, this algorithm stitches together estimates from multiple overlapping blocks to provide a global cardinality estimate.

4. Evaluation

The researchers evaluated CoDe against state-of-the-art models (including Naru and DeepDB) using three standard benchmarks:

  • DMV Dataset: 11.6 million rows of real-world New York vehicle registration data.
  • Forest Dataset: 581k rows of forest cover type data with 45 categorical attributes.
  • Poker Hand Dataset: 1 million rows used for predicting poker hands.

4.1 Key Results

  • Accuracy: CoDe achieved a median q-error of 1.0 across all datasets, indicating perfect accuracy for over 50% of tested queries.
  • Inference Speed: The model demonstrated latencies as low as 0.04ms, making it at least 16x faster than competing data-driven techniques.
  • Zero-Query Handling: On the DMV dataset, CoDe correctly identified queries with zero results with 99.1% accuracy, a significant improvement over competitors which ranged from 5% to 48%.

5. Discussion and Limitations

CoDe’s success stems from its data-centric approach, which allows it to recognize "empty" regions of the data space more effectively than workload-biased models. However, several areas for future work remain:

  • Hyper-parameter Sensitivity: The "rank" ($R$) of the tensor decomposition is a critical factor; an incorrect $R$ can lead to either overfitting or poor accuracy.
  • Dynamic Updates: While minor updates can be handled via weight-scaling, major shifts in data distribution currently require retraining the decomposition matrices, which may take several minutes.
  • Joins: Current evaluations focus on single tables or pre-joined wide tables. Extending the model to handle dynamic multi-table joins is a primary objective for future iterations.

6. Conclusion

CoDe represents a significant step forward in learned cardinality estimation. By combining the structural rigor of covering designs with the computational efficiency of tensor decomposition, it provides a lightweight, highly accurate solution that meets the stringent latency requirements of modern database optimizers.

Summary updated

BibTeX
@article{zhu2025lightweight,
  author = {Yaoyu Zhu and Jintao Zhang and Guoliang Li and Jianhua Feng},
  title = {{A Lightweight Learned Cardinality Estimation Model}},
  journal = {IEEE Trans. Knowl. Data Eng.},
  year = {2025},
  doi = {10.1109/tkde.2025.3591025},
}
Figure