Skip to content
プロジェクト

概要

TinyDB is a zero-dependency C++23 embedded ACID relational database engine built from scratch. It features 4KB slotted pages with forwarding pointers, an RAII page-latched buffer pool, CRC32 WAL with ARIES-style crash recovery, disk-backed B+ Tree indexes, a Volcano SQL engine, and an interactive CLI.

データ・分析

この数値の測り方

できること

  • 4KB Paged Storage Engine: Slotted heap pages with in-place updates, tombstone deletion, and on-demand page compaction (SlottedPage, DiskManager).
  • Buffer Pool Manager: Fixed-size frame pool with Clock (Second-Chance) eviction, RAII ReadPageGuard / WritePageGuard latches, and strict WAL write-ahead enforcement.
  • ACID Transactions & ARIES Crash Recovery: CRC32-protected binary Write-Ahead Log (BEGIN, INSERT, UPDATE, DELETE, COMMIT, ABORT, CLR, CHECKPOINT), explicit BEGIN / COMMIT / ROLLBACK, and 3-phase Analysis / Redo / Undo startup recovery resilient to torn WAL tails.
  • Disk-Backed B+ Tree Indexes: Persistent internal and doubly-linked leaf pages supporting INT64, DOUBLE, and VARCHAR keys, recursive splits, underflow borrowing/merges, unique primary key indexes, non-unique secondary indexes, and range scans.

計測したスター増加

24時間
履歴を収集中
7日間
履歴を収集中
15日間
履歴を収集中
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

TinyDB

TinyDB is an embedded, ACID-compliant, SQLite-style relational CLI database engine written completely from scratch in C++23 with zero external runtime dependencies.

Features

  • 4KB Paged Storage Engine: Slotted heap pages with in-place updates, tombstone deletion, and on-demand page compaction (SlottedPage, DiskManager).
  • Buffer Pool Manager: Fixed-size frame pool with Clock (Second-Chance) eviction, RAII ReadPageGuard / WritePageGuard latches, and strict WAL write-ahead enforcement.
  • ACID Transactions & ARIES Crash Recovery: CRC32-protected binary Write-Ahead Log (BEGIN, INSERT, UPDATE, DELETE, COMMIT, ABORT, CLR, CHECKPOINT), explicit BEGIN / COMMIT / ROLLBACK, and 3-phase Analysis / Redo / Undo startup recovery resilient to torn WAL tails.
  • Disk-Backed B+ Tree Indexes: Persistent internal and doubly-linked leaf pages supporting INT64, DOUBLE, and VARCHAR keys, recursive splits, underflow borrowing/merges, unique primary key indexes, non-unique secondary indexes, and range scans.
  • SQL Engine & Volcano Pipeline: Case-insensitive SQL lexer/parser, persistent Page-0 catalog, automatic IndexScanExecutor selection for = and range WHERE predicates, and pull-based Volcano executors (SeqScan, IndexScan, Filter, Project, Sort, Limit, Insert, Update, Delete).
  • Interactive SQL CLI: Multi-line SQL REPL with Unicode box-drawn result tables, execution timing (µs/ms), one-shot --exec mode, and inspection dot-commands.

See docs/architecture.md for a deep dive into the engine internals.

Requirements

  • CMake 3.24+
  • A C++23 compiler (Clang 17+ / Apple Clang 16+ / GCC 13+)
  • Ninja or Make
  • GoogleTest (fetched automatically via FetchContent when BUILD_TESTING=ON)

Build & Test

cmake -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug
cmake --build cmake-build-debug -j
ctest --test-dir cmake-build-debug --output-on-failure

Using CMake presets:

cmake --preset dev
cmake --build --preset dev
ctest --preset dev

To build with AddressSanitizer + UndefinedBehaviorSanitizer:

cmake --preset sanitizers
cmake --build --preset sanitizers
ctest --preset sanitizers

CLI Usage

# Launch interactive REPL (default database: tinydb.db)
./cmake-build-debug/tinydb --db demo.db

# One-shot SQL execution
./cmake-build-debug/tinydb --db demo.db --exec "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(64) NOT NULL);"
./cmake-build-debug/tinydb --db demo.db --exec "INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob');"
./cmake-build-debug/tinydb --db demo.db --exec "SELECT * FROM users ORDER BY id ASC;"

# Run sample SQL script
./cmake-build-debug/tinydb --db sample.db < examples/sample.sql

# Print version or help
./cmake-build-debug/tinydb --version
./cmake-build-debug/tinydb --help

Interactive REPL Dot-Commands

Command Description
.tables List all tables in the database
.schema [table] Display CREATE TABLE and CREATE INDEX DDL for one or all tables
.checkpoint Flush dirty pages to disk and checkpoint the WAL
.stats Display page count, WAL size, buffer pool hit ratio, evictions, and disk I/O
.help Show REPL help
.exit / .quit Cleanly checkpoint and exit

Supported SQL Reference

Data Types

  • INT / INTEGER / BIGINT / INT64 (64-bit signed integer)
  • DOUBLE / FLOAT / REAL (64-bit IEEE-754 floating point)
  • VARCHAR / VARCHAR(N) / TEXT / STRING (UTF-8 variable-length string)
  • BOOL / BOOLEAN (true / false)
  • NULL

DDL

CREATE TABLE [IF NOT EXISTS] table_name (
    col1 INT PRIMARY KEY,
    col2 VARCHAR(64) NOT NULL,
    col3 DOUBLE,
    col4 BOOL
);
DROP TABLE [IF EXISTS] table_name;
CREATE [UNIQUE] INDEX idx_name ON table_name (col_name);

DML

INSERT INTO table_name [(col1, col2, ...)] VALUES (v1, v2, ...), (...);
SELECT * | expr [AS alias], ... FROM table_name
    [WHERE predicate]
    [ORDER BY col [ASC | DESC], ...]
    [LIMIT n];
UPDATE table_name SET col1 = expr1, ... [WHERE predicate];
DELETE FROM table_name [WHERE predicate];

Supported expressions: comparisons (=, !=, <>, <, <=, >, >=, IS NULL, IS NOT NULL), boolean logic (AND, OR, NOT with SQL 3-valued NULL semantics), and arithmetic (+, -, *, /, %, unary -).

Transactions (TCL)

BEGIN;
-- DML / DDL statements...
COMMIT;   -- Durable WAL flush
-- or:
ROLLBACK; -- Inverse undo chain with CLRs

Embedded C++23 API

See examples/quickstart.cpp (built as ./cmake-build-debug/tinydb_quickstart):

#include "tinydb/database.hpp"

auto db = tinydb::Database::open("app.db");
(*db)->execute("CREATE TABLE items (id INT PRIMARY KEY, name VARCHAR(64));");
(*db)->execute("INSERT INTO items VALUES (1, 'Widget');");
auto res = (*db)->execute("SELECT id, name FROM items WHERE id = 1;");

Benchmarks

Run ./cmake-build-debug/tinydb_bench (10,000 rows, 512-frame buffer pool, Apple Silicon):

Workload Ops Throughput (Debug) p50 Latency p99 Latency
Sequential Inserts (10k rows, batched) 10,000 979 ops/s 987.2 µs 1,586.4 µs
Indexed Point Lookups (PK B+ Tree) 5,000 4,217 ops/s 230.3 µs 359.5 µs
Indexed Range Scans (25-row windows) 1,000 2,523 ops/s 371.5 µs 574.0 µs
Transactional Point Updates 2,000 3,979 ops/s 244.2 µs 395.5 µs

Project Layout

include/tinydb/
  database.hpp, version.hpp
  common/       types.hpp, status.hpp, config.hpp, serializer.hpp
  storage/      disk_manager.hpp, slotted_page.hpp, buffer_pool.hpp
  transaction/  wal_manager.hpp, transaction_manager.hpp
  index/        bplus_tree.hpp
  query/        catalog.hpp, lexer.hpp, ast.hpp, parser.hpp, executor.hpp
src/            Corresponding C++23 implementations
main.cpp        CLI entrypoint and interactive REPL
tests/          unit/, integration/, recovery/ GoogleTest suites
benchmarks/     bench_main.cpp (10k+ row throughput & p50/p99 latency)
examples/       quickstart.cpp, sample.sql
docs/           architecture.md

関連プロジェクトを探す

読み込み中…