Extensible Database Simulator for Fast Prototyping In-Database Algorithms

Yifan Wang, Daisy Zhe Wang · DOI

Abstract

In-database analytics and machine learning are critical for reducing the latency between data management and analysis. However, implementing new algorithms within mainstream database kernels is notoriously difficult due to their complexity and low-level implementations. We present DBSim, an extensible relational database simulator built in pure Python. DBSim allows researchers to prototype and verify in-database algorithms—including new SQL syntax, operators, and optimization rules—with minimal effort by leveraging a flexible registry-based architecture that bypasses the need for kernel modifications.

Introduction

Modern data science often involves a costly data exchange loop between databases and external analytic tools. Integrating analytics directly into the Relational Database Management System (RDBMS) is a promising solution, but the barrier to entry for researchers is high. Mainstream kernels like PostgreSQL or MySQL are massive C++ codebases where even minor changes to the query optimizer or relational algebra can take months to implement. DBSim addresses this by providing a "sandbox" environment that mimics a full RDBMS pipeline while remaining highly modular and easy to extend.

System Architecture

DBSim is designed to simulate the entire lifecycle of a SQL query. It integrates all major components found in a standard RDBMS, providing a realistic environment for testing new database logic.

The overall architecture of DBSim, showing the flow from the GUI/APIs through the Kernel components and the pluggable Extension modules.

The pipeline consists of:

  1. Parser: Translates SQL queries into an Abstract Syntax Tree (AST).
  2. Operators: Resolves schema information and converts the AST into a logical query plan.
  3. Optimizer: A rule-based engine that applies transformations to find an efficient execution plan.
  4. Compiler & Executor: Translates the optimized plan into physical actions and executes them.

The Extension Mechanism

The core strength of DBSim lies in its Registry-based mechanism, which enables "plug-and-play" functionality for new features. Instead of modifying the core kernel code, users define extensions as separate modules.

The Registry mechanism in DBSim, which maps extended syntax and custom implementations to the core Kernel without requiring direct code modification.

As shown in the registry diagram, users can register new keywords, operators, or optimization rules. At runtime, the simulator checks the registry and dynamically "overwrites" standard behaviors with these custom implementations. This allows researchers to toggle experimental features on and off without restarting the system, significantly speeding up the iteration cycle.

Prototyping and Evaluation

DBSim is implemented in pure Python, which aligns with the language of choice for most data science and machine learning algorithms. This allows for seamless integration of complex logic, such as similarity search using vector embeddings.

To evaluate new algorithms, DBSim provides multiple metrics:

  • Internal Cost Models: A built-in heuristic estimator.
  • External RDBMS Interoperability: The ability to export plans to real-world systems like SQLite to obtain professional-grade cost estimates.
  • Execution Profiling: Measuring the actual wall-clock time of the Python-based execution.

Furthermore, DBSim includes a GUI for interactive debugging. The visualizer allows users to see query plans transform in real-time as different optimization rules are applied or removed, providing deep insight into the impact of specific algorithmic changes.

Conclusion and Future Work

DBSim provides a low-cost, high-agility environment for prototyping in-database algorithms. By abstracting the complexities of a database kernel into a modular Python framework, it empowers researchers to focus on algorithmic innovation rather than system plumbing. Future work includes expanding support for cost-based (Volcano-style) optimization, broader RDBMS interoperability for cost estimation, and the implementation of advanced indexing structures.

Summary updated

BibTeX
@misc{wang2022extensible,
  author = {Yifan Wang and Daisy Zhe Wang},
  title = {{Extensible Database Simulator for Fast Prototyping In-Database Algorithms}},
  year = {2022},
  eprint = {2204.09819},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2204.09819},
}
Figure