中文文档 | English
This is a comprehensive database management system developed for the CS307 Database Systems course at SUSTech. The project is built upon the foundation of CS307-Database/engine-project and significantly extends it with advanced features including B+ tree indexing, query optimization, web interface, and full CRUD operations support.
- 🗄️ Complete Database Engine: Extended from the base framework with comprehensive RDBMS functionality
- 📝 Full SQL Support: Complete SQL parsing and execution using JSqlParser
- 🔍 Query Optimization: Advanced logical and physical query optimization with cost-based planning
- 💾 Storage Management: Enhanced page-based storage with buffer pool and LRU replacement
- 🌳 B+ Tree Indexing: Efficient indexing system with automatic index management
- 🌐 Web Interface: Modern, responsive web UI for database interaction
- 🔗 REST API: HTTP server for programmatic database access
- 📊 Aggregation Functions: Support for SUM, MAX, MIN, COUNT, AVG operations
- 🔢 Extended Data Types: Full support for single-precision FLOAT and double-precision DOUBLE
- 📋 Advanced Queries: Implemented ORDER BY sorting and GROUP BY grouping
- 🔗 Multi-table Joins: Support for LEFT JOIN, INNER JOIN, RIGHT JOIN, CROSS JOIN operations
Our implementation significantly extends the original engine-project with:
- Enhanced SQL Operations: Added DELETE, complex WHERE clauses, JOIN operations, aggregation functions
- Advanced Indexing: Implemented B+ tree indexing with automatic index management and optimization
- Query Optimization: Built comprehensive logical and physical query planners
- Web Interface: Developed a modern web-based interface for database interaction
- Performance Improvements: Added buffer pool optimizations
- Extended Data Types: Support for FLOAT, DOUBLE, and enhanced CHAR handling
- System Management: Added table metadata management, index synchronization, and persistence
-
Storage Layer (Enhanced from base)
DiskManager: File I/O and page managementBufferPool: Memory management with LRU replacement policyPage: Fixed-size page abstraction (4KB default)
-
Record Management (Extended)
RecordManager: Record lifecycle managementRecordFileHandle: File-level operationsRecord: Individual record representation
-
Metadata Management (New)
MetaManager: Schema and table metadata persistenceTableMeta: Table structure definitionsColumnMeta: Column specifications and constraints
-
Indexing System (New)
IndexManager: Index lifecycle and operationsBPlusTreeIndex: B+ tree implementationIndex: Generic index interface
-
Query Processing (Significantly Enhanced)
PhysicalPlanner: Query execution plan generationLogicalOperator: Abstract query operationsPhysicalOperator: Concrete execution operators
-
System Interface (New)
DBManager: Central database coordinationHttpServer: REST API endpoint- Web UI: Modern frontend interface
- Language: Java 17
- SQL Parser: JSqlParser 5.1
- Network: Netty 4.1 (HTTP server & zero-copy buffers)
- Serialization: Jackson 2.17
- Logging: TinyLog 1.3
- Testing: JUnit 5 & AssertJ
- Frontend: HTML5/CSS3/JavaScript with Flask server
- Build Tool: Maven
- Java 17 or higher
- Maven 3.6+
- Python 3.7+ (for web interface)
# Clone the repository
git clone <repository-url>
cd SUSTech_CS307_DB_Proj2
# Build with Maven
mvn clean compile
# Run tests
mvn test# Method 1: Using Maven
mvn exec:java -Dexec.mainClass="edu.sustech.cs307.DBEntry"
# Method 2: Direct execution
java -cp "target/classes:target/dependency/*" edu.sustech.cs307.DBEntryThe database server will start on port 8080 with the following services:
- Console interface for direct SQL interaction
- HTTP API for programmatic access
- Automatic metadata persistence
# Navigate to frontend directory
cd front-end
# Install Flask (if not already installed)
pip install flask
# Start the web server
python server.pyAccess the web interface at: http://localhost:3000
The database provides an interactive console supporting comprehensive SQL operations:
-- Table operations
SHOW TABLES;
DESC table_name;
CREATE TABLE students (id INT, name CHAR, age INT);
DROP TABLE students;
-- Data operations
INSERT INTO students VALUES (1, 'Alice', 20);
SELECT * FROM students WHERE age > 18;
UPDATE students SET age = 21 WHERE name = 'Alice';
DELETE FROM students WHERE age < 18;
-- Advanced queries
SELECT s.name, c.course_name
FROM students s
JOIN courses c ON s.course_id = c.id
WHERE s.age > 20;
-- Index operations
CREATE INDEX idx_name ON students(name);
SHOW BTREE students name;
DROP INDEX idx_name ON students;The system exposes REST endpoints for external integration:
# Execute SQL queries
curl "http://localhost:8080/?sql=SELECT * FROM students"
# Get table list
curl "http://localhost:8080/?sql=SHOW TABLES"
# Post SQL commands
curl -X POST "http://localhost:8080" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "sql=SELECT * FROM students"- Interactive SQL Editor: Real-time SQL editing with template support
- Real-time Results: Immediate query execution and result display
- Table Browser: Visual table structure and data exploration
- Performance Metrics: Query execution time and statistics
- Responsive Design: Works on desktop and mobile devices
src/main/java/edu/sustech/cs307/
├── DBEntry.java # Main application entry point
├── exception/ # Custom exception types
├── http/ # HTTP server implementation
├── index/ # B+ tree and indexing system
├── logicalOperator/ # Query logical operators
├── meta/ # Metadata management
├── optimizer/ # Query optimization engine
├── physicalOperator/ # Physical execution operators
├── record/ # Record and page management
├── storage/ # Storage engine components
├── system/ # Core system managers
├── tuple/ # Tuple representation
└── value/ # Data type system
This project is built upon the foundation provided by CS307-Database/engine-project. We extend our gratitude to the original framework contributors for providing the solid base infrastructure.