Skip to content

Learning low-level systems by building a mini SQL database in Java. From disk pages and B-Trees to transactions and locking. πŸš€

License

Notifications You must be signed in to change notification settings

lokiT26/java-sql-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Java SQL Engine

Language Build Status

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.

πŸ›οΈ Architecture Overview

The engine is designed with a classic, layered database architecture.

Architecture Diagram

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.

βœ… Project Roadmap

  • 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)

πŸš€ Getting Started

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

About

Learning low-level systems by building a mini SQL database in Java. From disk pages and B-Trees to transactions and locking. πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Languages