Back to all work

CMU Database Systems

BusTub Database Internals

I implemented the core of CMU's teaching database in C++, from the buffer pool to transactions. Then I tuned its index and query paths to 18th and 17th on the course leaderboards.

Jan to Apr 2026C++17

What I built inside the database

Disk-based DBMS internals

Query pathAsync background I/OImplemented component
BusTub database system architectureA SQL client sends queries through the parser, binder, planner, and optimizer into the execution engine, where custom rewrite rules run in the optimizer. The engine coordinates with the multi-version transaction manager, which writes version metadata into the table heap, and reads data through a B+Tree index and the table heap. All page access flows through the buffer pool manager and an asynchronous disk scheduler to the disk manager and the database file. Highlighted components are implemented coursework and link to details below.BusTub DBMSSQL front endExecution +TransactionsAccess methodsBuffer + I/ODiskSQL clientshell, testsParserBinderPlannerQuery execution and plan optimizationOptimizermy rewrite rulesQuery execution and plan optimizationExecution enginebatch pull model, joins, sort, windowMulti-version concurrency controlTransaction managerMVCC, OCC validation, GCConcurrent B+Tree index and access-path tuningB+Tree indexlatch crabbing, range scansTable heapslotted tuple storageBuffer pool and page infrastructureBuffer pool managerARC replacement, page guardsBuffer pool and page infrastructureDisk schedulerasync request queueDisk managerpage reads, writesDatabase filepages
SQL clientshell, tests
SQL front end
Parser
Binder
Planner
Optimizermy rewrite rules
Execution + Transactions
Execution enginebatch pull model, joins, sort, window
Transaction managerMVCC, OCC validation, GC
Access methods
B+Tree indexlatch crabbing, range scans
Table heapslotted tuple storage
Buffer + I/O
Buffer pool managerARC replacement, page guards
Disk schedulerasync request queue
Disk
Async background I/O
Disk managerpage reads, writes
Database filepages
Neutral components are the course-provided scaffold. Highlighted components are the parts I implemented, and each links to its record below. Per the course academic integrity policy, solution code is not public.

The course provides the SQL front end, catalog, table heap, and test harness. Highlighted boxes are the parts I wrote.

More on the buffer pool and transactions

Buffer pool and page infrastructure

Implemented the buffer pool manager, an ARC page-replacement policy, an asynchronous disk scheduler, and RAII page guards that give every upper layer safe concurrent page access.

Problem
Every component above storage shares one fixed pool of in-memory frames. Correctness depends on pages staying pinned while in use, being evicted in a useful order, and never being touched after eviction under concurrent access.
Implementation
Built the frame lifecycle around an adaptive replacement cache that balances recency against frequency, moved disk I/O behind a scheduler that services read and write requests from a shared queue, and wrapped page access in read and write guards that release latches and pins deterministically.
Reasoning
Centralizing latch and pin lifetime inside guards removes a whole class of leak and ordering bugs from the layers above. An adaptive replacement policy avoids hand-tuning between recency-heavy and frequency-heavy workloads.
Outcome
The pool became the concurrency foundation for the index, execution, and transaction projects, and its access path is where the later index tuning work landed.

Multi-version concurrency control

Added optimistic multi-version concurrency control to the engine, with tuple version chains and undo logs, snapshot visibility, atomic write-write conflict detection, serializable commit validation, and garbage collection.

Problem
Concurrent transactions must read consistent snapshots while writers race on the same tuples. A naive read-then-check-then-write sequence lets two writers pass the same check and silently lose one update.
Implementation
Reconstructed tuple versions from undo chains, tracked the oldest active read timestamp through a watermark, routed every write path through the compare-and-set helper so the conflict check runs under the page write latch instead of a read-then-check-then-write sequence, validated serializable transactions against committed writes at commit time, and reclaimed undo logs below the watermark.
Reasoning
Commit validation has to sit inside the commit critical section. Two serializable transactions can otherwise both validate before either publishes its commit timestamp, letting write skew through. Serial commit ordering is the textbook OCC trade for that correctness.
Outcome
The implementation passed the course's concurrent and serializable test suites, and profiling the validation and garbage-collection paths raised benchmark throughput in leaderboard runs.

BusTub is Carnegie Mellon's teaching database system. The SQL front end, catalog, table heap, disk manager, optimizer framework, executor interfaces, and test harness are provided by the course, and the records above are the components I implemented on that scaffold.

Solution code stays private under the course academic integrity policy, so this page describes the work at the level of the public project specifications.

C++17, Concurrent systems programming, Query optimization, Performance engineering. Single-node disk-based relational DBMS, Four core components from storage to transactions, Performance work on the index and query paths.

Where the time went

Rewrite rules did most of the work on the query path. On the index, moving cache hits off the global latch raised throughput about 1.6x in local runs, and binary search was the other large gain.

More on the query and index work

Query execution and plan optimization

Implemented the executor suite for the batch pull-based engine, then wrote the optimizer rewrite rules and hash-join fast path that finished 17th on the course query-execution leaderboard.

Problem
Declarative plans must run through composable operators that respect bounded memory and stay correct when data exceeds the buffer pool. The benchmark queries were then slow for a reason no executor could fix on its own: the plans carried columns, projection layers, and duplicate aggregates that nothing downstream needed.
Implementation
Built each executor against the batched pull contract, where one call returns up to twenty tuples, covering hash aggregation, nested-loop, hash, and index joins, an external merge sort that sorts fixed-size runs in memory, spills each run to buffer-pool pages, and merges two runs per pass, and window functions over sorted partitions. Then added rewrite rules for column pruning, projection merging, predicate pushdown, aggregate deduplication, and always-false filter elimination, converted qualifying nested-loop joins into hash joins that build on the left child and probe with the right, and gave the join an integer-key fast path that skips building a key vector on every probe.
Reasoning
Work removed from the plan is work no operator has to do, so the rewrite rules were worth more than tuning the executors. The execution-level change came last and deliberately: the integer fast path only pays off once the plan is already minimal, and it falls back to the generic key for non-integer and outer joins rather than narrowing what the join can accept.
Outcome
In local runs the heaviest benchmark query dropped by about an order of magnitude and a query that previously timed out completed in under a second. The graded run finished the three benchmark queries in 1000, 471, and 245 milliseconds, ranking 17th in the course.

Concurrent B+Tree index and access-path tuning

Built a concurrent B+Tree index with latch crabbing, then tuned the read and write paths by removing per-traversal buffer-pool reads, comparison cost, and global-latch contention, finishing 18th on the course throughput leaderboard.

Problem
Many threads traverse a shared tree whose shape changes through splits and merges, so the index needs a strict latch discipline that still avoids serializing every operation. Once correct, throughput was limited less by the tree algorithm than by fixed costs paid on every traversal.
Implementation
Implemented the leaf and internal page layouts, split and merge logic, and a range-scan iterator. Traversal takes read latches downward and write-latches only the leaf, then retries with pessimistic top-down write latching and safe-node release when a structural change is required. Profiling the benchmark then drove four changes: binary search inside pages, an atomic root page-id cache, replacing the buffer pool's page table and the replacer's frame map with arrays indexed by page id and frame id, and moving replacement bookkeeping out from under the global latch behind a shared mutex.
Reasoning
Structural changes are rare compared with ordinary lookups and updates, so an optimistic-first protocol keeps the common path cheap while the pessimistic fallback keeps splits and merges safe. The tuning work followed the same principle one level down: the contended global latch and the per-traversal header read were costs paid by every thread, so removing them mattered more than micro-optimizing the tree logic.
Outcome
The index passed the course's concurrent contention tests and backs the index scan and index join executors in the later projects. The graded run sustained 668,382 read and 159,371 write queries per second on the concurrent benchmark, ranking 18th in the course.

Rewrite rules did most of the work. Pruning columns and collapsing projection layers ahead of the aggregation was worth roughly an order of magnitude on the heaviest query in local runs, while the execution-level changes contributed the final fraction. The graded run finished the three benchmark queries in 1000, 471, and 245 milliseconds, ranking 17th in the course.

Binary search and moving the cache-hit path off the global latch were the two largest gains on the index, worth roughly 2x and 1.6x in local runs. The graded run reached 668,382 read and 159,371 write queries per second on the concurrent 100K-key benchmark, ranking 18th in the course. The index work earned the course leaderboard bonus.