ByteCard: Enhancing ByteDance's Data Warehouse with Learned Cardinality Estimation

Yuxing Han, H. Wang, Lixiang Chen, Yifeng Dong, Xing Chen, Benquan Yu, Chengcheng Yang, Weining Qian

TL;DR

This paper introduces ByteCard, a novel framework for integrating learned cardinality estimation models into ByteDance's exabyte-scale data warehouse, ByteHouse. By carefully selecting and integrating lightweight, accurate models, ByteCard significantly improves query optimization performance and reduces latency, addressing a critical bottleneck in modern data warehouses.

What Problem Does This Paper Address?

Cardinality estimation, the process of predicting the number of rows an operation will produce, is fundamental to query optimization in data warehouses. Inaccurate estimates lead to suboptimal query plans, impacting performance. ByteHouse, ByteDance's massive data warehouse, previously relied on traditional, error-prone cardinality estimators. These traditional methods struggle with the inherent data skewness and rapid updates common in real-world datasets, leading to substantial estimation errors. This paper tackles the challenge of improving cardinality estimation accuracy in ByteHouse while ensuring practical performance, addressing the bottleneck that hinders efficient query processing.

Methods

ByteCard is a framework designed for seamless integration of learned cardinality estimation models. Its core components include:

  • Model Selection: The authors meticulously evaluated various learned models based on accuracy, inference latency, model size, and training overhead. They prioritized models that strike a balance between these factors for practical deployment.
  • Inference Engine: This component provides a high-level abstraction for integrating learned models into ByteHouse's query processing. It handles model loading, validation, and context initialization, enabling lock-free, high-concurrency inference.
  • ModelForge Service: A standalone service responsible for the training and management of learned models. It isolates training from online query processing to prevent disruption and supports routine training for COUNT estimation and occasional fine-tuning for COUNT-DISTINCT estimation.
  • Learned Models:
    • For single-table COUNT estimation, they use tree-based Bayesian Networks (BNs), which capture column dependencies effectively.
  • For multi-table COUNT (join) estimation, they employ FactorJoin, which leverages single-table BNs and a factor graph approach to estimate join sizes efficiently.
  • For COUNT-DISTINCT (NDV) estimation, they utilize RBX, a workload-independent neural network model known for its robustness and adaptability.

Datasets

The paper evaluated ByteCard using the following datasets:

  • IMDB: A benchmark dataset, scaled to 1TB.
  • STATS: A benchmark dataset, scaled to 1TB.
  • AEOLUS: An internal business workload from ByteHouse, comprising 200 complex queries.

Key Insights and Ideas

  • The "Accuracy vs. Practicality" Trade-off is Crucial: Simply choosing the most accurate learned model isn't enough. ByteCard's success hinges on selecting models that are also efficient in terms of inference latency, model size, and training overhead, making them suitable for production environments.
  • A Modular Framework is Key: ByteCard's architecture, with its distinct Inference Engine and ModelForge Service, allows for flexible integration of various learned models without disrupting the existing data warehouse operations.
  • Learned Models Excel Where Traditional Ones Fail: The paper highlights how learned models, particularly those capturing cross-column correlations (like BNs and FactorJoin), significantly outperform traditional methods in scenarios with data skewness and complex relationships, which are common in real-world business data.
  • Workload-Independent Models Offer Scalability: RBX's ability to estimate NDVs without requiring workload-specific training simplifies deployment and maintenance, making it a valuable component for a large-scale system like ByteHouse.

Key Results

  • Significant Query Processing Speed-up: ByteCard led to substantial query processing speed-ups in ByteHouse across various optimization scenarios.
  • Latency Improvement: Integration of ByteCard resulted in up to a 30% improvement in the 99th quantile of query latency on real-world datasets.
  • Reduced Reading I/Os: ByteCard's accurate cardinality estimates helped optimize materialization strategies, leading to reduced reading I/Os.
  • Reduced Hash Table Resizing: For aggregation processing, ByteCard's NDV estimation (RBX) significantly reduced the frequency of hash table resizing, improving memory management.
  • Lower Q-Errors: ByteCard consistently achieved lower Q-Errors (a metric for estimation accuracy) compared to traditional sketch-based and sample-based methods across all evaluated workloads.

Limitations and Future Work

  • Model Selection Complexity: Identifying the "best" learned model for specific scenarios remains a challenge, as no single model performs optimally across all situations.
  • Cost Estimation: While cardinality estimation is improved, accurate cost modeling of query plans remains difficult due to the fluctuating nature of cloud environments. Future work will explore ML for enhancing query processing in this area.
  • Integration of More ML-Enhanced Components: The authors plan to integrate more ML-enhanced components, such as learned cost estimators, into ByteHouse. This will involve adapting training algorithms and ensuring efficient inference within the system kernel.
  • Meta-Learning for Robustness: To address the limitations of current estimators in handling diverse data distributions and workloads, the authors plan to explore meta-learning approaches.
  • Synergy with Cascades Framework: Future research will focus on synergizing ML with the Cascades framework, a common architecture in modern query optimizers, to improve query plan exploration.

Summary updated

Abstract

Cardinality estimation is a critical component and a longstanding challenge in modern data warehouses. ByteHouse, ByteDance's cloud-native engine for extensive data analysis in exabyte-scale environments, serves numerous internal decision-making business scenarios. With the increasing demand for ByteHouse, cardinality estimation becomes the bottleneck for efficiently processing queries. Specifically, the existing query optimizer of ByteHouse uses the traditional Selinger-like cardinality estimator, which can produce substantial estimation errors, resulting in suboptimal query plans.
BibTeX
@misc{han2024bytecard,
  author = {Yuxing Han and H. Wang and Lixiang Chen and Yifeng Dong and Xing Chen and Benquan Yu and Chengcheng Yang and Weining Qian},
  title = {{ByteCard: Enhancing ByteDance's Data Warehouse with Learned Cardinality Estimation}},
  year = {2024},
  eprint = {2403.16110},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.16110},
}
Figure