A custom database engine implementation in Rust featuring B+ Tree indexing, persistent storage, and a SQL-like interface for basic database operations.
- B+ Tree Indexing: Efficient tree-based indexing for fast data retrieval
- Persistent Storage: Data persistence across application restarts
- Multi-type Support: Support for INTEGER, BIGINT, DOUBLE, FLOAT, and STRING data types
- Table Management: Create and manage multiple tables with schema validation
- CRUD Operations: Insert, select, and query operations
- Memory Management: LRU cache implementation for optimized memory usage
- Universal Key System: Generic key handling for different data types
src/
├── main.rs # Entry point and demo application
├── BPlusTree.rs # Core B+ Tree implementation
├── BTree.rs # Binary tree utilities
├── BTreePersistence.rs # B+ Tree serialization/deserialization
├── MetaEnum.rs # Data type definitions and metadata
├── TableCreationHandler.rs # Table schema creation and validation
├── TableQueryHandler.rs # Query execution and data manipulation
├── TableMetaHandler.rs # Table metadata management
├── TableBTreeManager.rs # Universal B+ Tree management system
├── UniversalBPlusTree.rs # Generic B+ Tree implementation
├── UniversalKey.rs # Universal key abstraction
├── FileWriter.rs # File I/O operations
├── RowData.rs # Row data structures and serialization
├── LruDict.rs # LRU cache implementation
└── Comparable.rs # Trait for comparable types
- Rust 1.70+ (2024 edition)
- Cargo package manager
# Clone the repository
git clone <your-repo-url>
cd OxideDB
# Build the project
cargo build
# Run the application
cargo run
On the first run, uncomment the table creation code in main.rs
:
// Uncomment this on first run to create tables
create_tables();
This will create the initial database schema with sample tables.
The database supports the following operations:
let user_columns = vec![
TableColumn::new("id".to_string(), Type::INTEGER, true),
TableColumn::new("name".to_string(), Type::STRING(100), false),
TableColumn::new("email".to_string(), Type::STRING(255), false),
];
handler.create_table_with_validation("users".to_string(), user_columns)?;
let user_data = vec![
DataArray::INTEGER(1),
DataArray::STRING("Test A".to_string(), 100),
DataArray::STRING("[email protected]".to_string(), 255),
];
let row = query_handler.create_row("users", user_data)?;
query_handler.insert("users".to_string(), 1, row)?;
match query_handler.select("users".to_string(), 1) {
Ok(Some(data)) => println!("User found: {}", data),
Ok(None) => println!("User not found"),
Err(e) => println!("Error: {}", e),
}
The included demo application showcases:
- Creating
users
andproducts
tables - Inserting sample data
- Querying records by primary key
- B+ Tree performance testing
- Persistence operations
- Storage Layer: File-based persistence with page management
- Index Layer: B+ Tree indexes for efficient data access
- Query Layer: SQL-like operations with type validation
- Schema Layer: Table metadata and schema management
INTEGER
(i32)BIGINT
(i64)FLOAT
(f32)DOUBLE
(f64)STRING(length)
(Variable length strings)
- Generic implementation supporting multiple key types
- Persistent storage with serialization
- Efficient range queries and point lookups
- Thread-safe operations with mutex protection
The database creates several files for persistence:
*.dat
- Table data files*_btree.idx
- B+ Tree index filestable_metadata.dat
- Table schema metadatameta_config.db
- System configuration
Key constants can be modified in main.rs
:
const PAGE_SIZE: usize = 4096; // Database page size
const HEADER_SIZE: usize = 64; // Page header size
- ✅ Table creation and schema validation
- ✅ Data insertion and retrieval
- ✅ B+ Tree indexing
- ✅ Data persistence
- ✅ Multi-type support
- 🔄 No DELETE or UPDATE operations yet
- 🔄 No complex queries (JOIN, WHERE clauses)
- 🔄 No transaction support
- 🔄 Limited error recovery
- 🔄 No concurrent access control
Run the included demo:
cargo run
The application will:
- Initialize the database system
- Create sample tables (if uncommented)
- Insert test data
- Perform queries
- Test B+ Tree functionality
- Save state to disk
This is an initial build of a custom database engine. Contributions are welcome!
- Implement DELETE and UPDATE operations
- Add query optimization
- Implement transaction support
- Add concurrent access control
- Improve error handling and recovery
- Add comprehensive test suite
- Implement query planner
This project is available under the MIT License.
This project has minimal dependencies and uses only Rust standard library features for maximum portability and learning value.
Note: This is an educational/experimental database engine.