Skip to content

Valino123/Minisql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniSQL

A lightweight database management system implementation based on CMU-15445 BusTub framework, adapted for educational purposes and MiniSQL experiment requirements.

Overview

MiniSQL is a simplified database system that implements core database components including buffer pool management, indexing, record management, and query execution.

Key Features

  • Buffer Pool Management: LRU replacement policy and buffer pool manager
  • Index Management: B+ Tree indexing with support for various data types
  • Record Management: Row-based storage with schema management
  • Query Execution: SQL parser and executor with support for basic operations
  • Concurrency Control: Transaction management and locking mechanisms
  • Storage Management: Disk-based storage with page management

Architecture

The system is organized into several key modules:

Core Components

  • Buffer Manager: Manages memory pages and implements LRU replacement
  • Storage Manager: Handles disk I/O and file management
  • Index Manager: Implements B+ Tree indexes for efficient data access
  • Record Manager: Manages table records and schemas
  • Catalog Manager: Maintains database metadata and schema information
  • Query Executor: Executes SQL queries with various execution plans

Supported Operations

  • Data Definition: CREATE TABLE, DROP TABLE, CREATE INDEX, DROP INDEX
  • Data Manipulation: INSERT, DELETE, UPDATE, SELECT
  • Query Types: Sequential scan, index scan, nested loop joins

Development Environment

Requirements

  • Compiler:
    • Apple clang 11.0+ (macOS)
    • GCC/G++ 8.0+ (Linux)
  • Build System: CMake 3.20+
  • Debugger: GDB 7.0+ (optional)
  • Parser Tools: Flex & Bison (for SQL grammar modifications)

Platform Support

  • ✅ macOS (native)
  • ✅ Linux (native)
  • ✅ Windows (via WSL - Ubuntu 20+ recommended)

Building the Project

Quick Start

# Clone the repository
git clone <repository-url>
cd minisql-master

# Create build directory
mkdir build
cd build

# Configure and build
cmake ..
make -j$(nproc)

Build Options

Debug Build (default):

cmake ..
make -j

Release Build:

cmake -DCMAKE_BUILD_TYPE=Release ..
make -j

Clean Build:

# Use the provided clean script
./clean.sh

# Or manually
rm -rf build
mkdir build
cd build
cmake ..
make -j

Windows (WSL)

For Windows users, install WSL with Ubuntu 20+ and follow the Linux build instructions. For IDE integration, see CLion with WSL.

Running Tests

All Tests

cd build/test
./minisql_test

Individual Tests

# Build specific test
make lru_replacer_test
make buffer_pool_manager_test
make b_plus_tree_test

# Run from build directory
./test/lru_replacer_test
./test/buffer_pool_manager_test

Available Test Suites

  • Buffer Management: lru_replacer_test, buffer_pool_manager_test
  • Index Management: b_plus_tree_test, b_plus_tree_index_test, index_iterator_test
  • Storage: disk_manager_test, table_heap_test
  • Catalog: catalog_test
  • Concurrency: lock_manager_test
  • Recovery: recovery_manager_test
  • Execution: executor_test

Project Structure

minisql-master/
├── src/                    # Source code
│   ├── buffer/            # Buffer pool management
│   ├── catalog/           # Database catalog
│   ├── concurrency/       # Transaction and locking
│   ├── executor/          # Query execution
│   ├── index/             # B+ Tree indexing
│   ├── page/              # Page management
│   ├── parser/            # SQL parsing
│   ├── planner/           # Query planning
│   ├── record/            # Record management
│   ├── storage/           # Storage management
│   └── main.cpp           # Entry point
├── test/                  # Test suites
├── thirdparty/            # Third-party dependencies
│   ├── googletest/        # Google Test framework
│   └── glog/              # Google Logging
├── CMakeLists.txt         # Build configuration
├── LICENSE                # MIT License
└── README.md              # This file

Key Modifications from BusTub

This implementation includes several enhancements over the original BusTub framework:

  • Enhanced Disk Manager: Extended with bitmap pages and disk file metadata pages for persistent page allocation tracking
  • Serialization Support: Memory object serialization/deserialization for data persistence in Record Manager, Index Manager, and Catalog Manager
  • Refactored Record Manager: Restructured data structures (Row, Field, Schema, Column) and implementations
  • Persistent Catalog Manager: Redesigned to support persistence and provide interfaces for the Executor layer
  • Extended Parser: Enhanced to output syntax trees for Executor layer consumption

Usage Example

-- Create a table
CREATE TABLE students (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    age INT
);

-- Create an index
CREATE INDEX idx_name ON students(name);

-- Insert data
INSERT INTO students VALUES (1, 'Alice', 20);
INSERT INTO students VALUES (2, 'Bob', 22);

-- Query data
SELECT * FROM students WHERE age > 21;

-- Update data
UPDATE students SET age = 23 WHERE id = 1;

-- Delete data
DELETE FROM students WHERE id = 2;

Development Notes

  • The project uses C++17 standard
  • Debug builds include comprehensive logging and error checking
  • Memory leak detection is available on supported platforms
  • Code formatting follows clang-format standards

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Based on CMU-15445 BusTub framework
  • Uses Google Test for unit testing
  • Uses Google Logging for debug output

Contributing

This is an educational project. Please ensure any modifications maintain the academic integrity of the codebase and follow the existing code style and architecture patterns.

About

Single User SQL Engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors