A foundational project to build a lightweight, relational database engine from scratch in Java. The primary goal is to gain a deep, systems-level understanding of database internals, including storage, indexing, concurrency, and recovery.
This repository also contains a detailed developer log that chronicles the design decisions, challenges, and learning process throughout the project's development.
The engine is designed with a classic, layered database architecture.
Client -> Parser -> Planner -> Executor -> Transaction & Storage Manager
- SQL Parser: Converts SQL strings into an Abstract Syntax Tree (using ANTLR).
- Query Planner: Translates the AST into a logical plan of operators.
- Execution Engine: Executes the plan (e.g.,
SeqScan
,IndexScan
). - Transaction Manager: Ensures ACID properties using locking and logging.
- Storage Manager: Manages data on disk through a buffer pool.
- Buffer Manager: Caches disk pages in memory using an LRU policy.
- Disk Manager: Handles the physical I/O of reading/writing pages to table files.
- Index Manager: Manages B+-Tree indexes for fast lookups.
- Phase 1: The Storage Layer
- Initial Project Setup
-
Page
Class and On-Disk Representation -
DiskManager
for Raw Page I/O -
BufferPoolManager
with LRU Caching - Heap File and Tuple Storage
- Phase 2: Basic Query Execution
- SQL Parser (ANTLR)
-
SeqScan
(Sequential Scan) Executor
- Phase 3: Indexing
- B+-Tree Implementation
-
IndexScan
Executor
- Phase 4: Concurrency & Recovery
- Transaction Manager
- Write-Ahead Logging (WAL)
- Strict Two-Phase Locking (2PL)
This project is built using Java 21 and Maven.
# Clone the repository
git clone https://github.com/lokiT26/java-sql-engine.git
# Navigate into the project directory
cd java-sql-engine
# Build the project and run tests
mvn clean install