Baihe: SysML Framework for AI-driven Databases

Andreas Pfadler, Rong Zhu, Wei Chen, Botong Huang, Tianjing Zeng, Bolin Ding, Jingren ZhouarXiv 2021

Abstract

In recent years, "learned" database components have shown significant promise in academic settings, yet their deployment in production environments remains limited. This paper introduces Baihe, a SysML framework designed to bridge this gap. Baihe provides a robust, decoupled architecture for integrating machine learning (ML) models into existing database systems like PostgreSQL. By separating model inference from core database processes and providing a "shadow" planning environment, Baihe enables the safe and extensible adoption of AI-driven optimizations without compromising system stability or requiring heavy external dependencies.

Introduction

The field of "AI4DB" has proposed numerous learned components, ranging from cardinality estimators to learned indices. However, a significant "deployment gap" exists. Databases require deterministic reliability, whereas ML models are inherently stochastic and often rely on complex, heavy-weight libraries (e.g., TensorFlow, PyTorch) that are difficult to manage in mission-critical environments. Directly integrating these into a database core poses risks of system crashes and performance instability.

Baihe addresses these challenges by providing a standardized, safe, and extensible way to retrofit existing relational databases with AI. It adheres to four core principles: separation from the core system, minimal third-party dependencies, robustness, and configurability.

System Architecture

The Baihe framework is designed to decouple the database's core logic from the ML models it utilizes. This separation ensures that model failures do not impact the overall availability of the database.

High-level view of the Baihe architecture showing the separation between the DB host, background workers, and the training environment.

Core Components

  1. Baihe Extension: A plugin for the host database (implemented for PostgreSQL) that intercepts query planning and execution using standard hooks.
  2. Shadow Planner: To avoid intrusive modifications to the database's core source code, Baihe utilizes a "shadow" version of the system's planner. This allows researchers to inject ML hooks—such as cardinality estimation for specific joins—while keeping the main engine pristine.
  3. Background Service Workers: Model inference is offloaded to separate background processes. Each model runs in its own worker; if a worker hangs or crashes, the database automatically falls back to its traditional deterministic logic.
  4. IPC Module: High-speed communication between the extension and background workers is managed via shared memory, minimizing latency overhead during query execution.
Detailed architecture of Baihe for PostgreSQL, highlighting the Shadow Planner and the flow of inference messages.

Implementation and Deployment

Baihe supports two distinct modes of operation to balance flexibility and performance:

  • Development Mode: Supports Python-based models, allowing researchers to iterate quickly using standard ML frameworks.
  • Production Mode: Uses a custom LLVM-based compiler to transform models into self-contained, highly efficient binary libraries. These binaries have zero external ML dependencies and are C-ABI compatible, simplifying deployment for database administrators.

Data Collection

Unlike standard database logs, Baihe’s data collection module is "dataset-centric." It allows users to define specific filters and version the resulting data. This ensures that training data is reproducible and precisely tailored for specific ML tasks, such as cost modeling or join-order selection.

Key Insights

  • The Shadow Planner: This architectural choice is a game-changer for extensibility. It allows for deep integration (e.g., replacing join-order selection) without the maintenance burden of a forked database engine.
  • Safety via Decoupling: Treating ML as an "untrusted" component ensures that a single segmentation fault in a model does not take down the entire data warehouse.
  • Seamless Fallback: The framework's design guarantees that if model inference fails or exceeds a time budget, the system reverts to standard behavior, maintaining high availability.

Evaluation and Use Cases

The utility of Baihe has been demonstrated through two primary use cases:

  1. Component-wise Optimization: Replacing individual optimizer components, such as cardinality estimators, with ML models.
  2. End-to-End Learned Query Optimization: Integrating state-of-the-art learned optimizers like NEO (Tree Convolution Networks) and BAO (hint-set steering) into PostgreSQL.

Conclusion and Future Work

Baihe provides a robust foundation for the next generation of AI-driven databases. While currently focused on offline training and query optimization, future work aims to expand the framework's scope to include online training, learned indices, and automatic knob tuning. By open-sourcing the framework, the authors hope to establish a standardized testbed for the database research community.

Summary updated

BibTeX
@misc{pfadler2021baihe,
  author = {Andreas Pfadler and Rong Zhu and Wei Chen and Botong Huang and Tianjing Zeng and Bolin Ding and Jingren Zhou},
  title = {{Baihe: SysML Framework for AI-driven Databases}},
  year = {2021},
  eprint = {2112.14460},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.14460},
}
Figure