osirisdb 0.7.0

A SQL database engine built from scratch in Rust featuring a custom parser, binder, query planner, optimizer, catalog, and storage engine.
Documentation
  • Coverage
  • 61.97%
    955 out of 1541 items documented0 out of 341 items with examples
  • Size
  • Source code size: 828.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 11.97 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • musab05/osirisdb
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • musab05

OsirisDB

crates.io License Build Status

[!WARNING] Project Status: OsirisDB is currently under active development and is not yet ready for production use. APIs and interfaces are subject to change before the first stable release on crates.io.

A modular SQL database engine implemented in Rust, featuring a custom parser, binder, query planner, optimizer, catalog, and storage engine. It compiles raw SQL query strings into a fully typed Abstract Syntax Tree (AST) resembling PostgreSQL syntax.

This project is built from scratch to provide a clean, extensible foundation for SQL parsing, query analysis, and database engine implementation.

Features

  • Hand-written Lexer: Fast, zero-copy byte-level tokenizer with position tracking (line and column numbers) for precise error locations.
  • Pratt Parser for Expressions: Uses Top-Down Operator Precedence (Pratt parsing) for handling complex SQL expressions, nested operators, functions, and casts with correct precedence.
  • PostgreSQL Compatibility:
    • DDL: CREATE TABLE (including column constraints, default values, checks, generated columns, foreign keys, partition by, inherits, tablespaces), CREATE INDEX, CREATE VIEW, CREATE SCHEMA, CREATE SEQUENCE, DROP, TRUNCATE.
    • DML: SELECT (including joins, subqueries, group by, having, CTEs/with, order by, window functions, set operations like UNION/INTERSECT/EXCEPT).
    • Basic transaction control statements (BEGIN, COMMIT, ROLLBACK).
  • Trait-based Extensible Architecture: The parser is split into logical modules via extension traits, making it easy to add new statement parsers.

Architecture

See ARCHITECTURE.md for a detailed overview of the system architecture and the 11-stage query execution lifecycle.

Quick Start

Add osirisdb to your Cargo.toml:

[dependencies]
osirisdb = { git = "https://github.com/musab05/osirisdb.git" }

Usage Example

use osirisdb::parser::Parser;

fn main() {
    let sql = "SELECT id, name FROM users WHERE age >= 18 ORDER BY name ASC;";
    let mut parser = Parser::new(sql);

    match parser.parse() {
        Ok(statements) => {
            for stmt in statements {
                println!("{:#?}", stmt);
            }
        }
        Err(err) => {
            eprintln!("Parse error: {} at line {}, col {}", err.message, err.span.line, err.span.column);
        }
    }
}

Supported Statements & Syntax

Query Syntax (SELECT)

  • Column aliases and wildcards (SELECT a AS b, tbl.*)
  • Table Joins (INNER, LEFT/RIGHT/FULL OUTER, CROSS, NATURAL)
  • Filtering and Aggregation (WHERE, GROUP BY, HAVING)
  • CTEs / Subqueries (WITH active_users AS (SELECT ...) SELECT ...)
  • Ordering & Pagination (ORDER BY col DESC NULLS LAST LIMIT 10 OFFSET 5)
  • Set operations (UNION [ALL], INTERSECT [ALL], EXCEPT [ALL])

DDL Syntax

  • CREATE [TEMP] TABLE [IF NOT EXISTS] name (columns...)
  • CREATE [UNIQUE] INDEX [IF NOT EXISTS] name ON table (...)
  • CREATE [OR REPLACE] [TEMP] [RECURSIVE] VIEW name AS select
  • CREATE SCHEMA [IF NOT EXISTS] name
  • CREATE SEQUENCE [IF NOT EXISTS] name
  • DROP TABLE [IF EXISTS] names... [CASCADE | RESTRICT]
  • TRUNCATE [TABLE] names... [RESTART IDENTITY] [CASCADE | RESTRICT]

Project Structure

  • src/lexer/: Hand-written lexical analyzer (tokenizer).
    • lexer.rs: Core tokenizer loop and char readers.
    • token.rs: Token classifications and Span representation.
  • src/ast/: Struct and Enum definitions representing the SQL syntax trees.
  • src/parser/: Pratt & Recursive-descent parser implementation.
  • src/binder/: Name binding and query compilation. Maps the raw AST into a strongly typed, resolved AST.
  • src/catalog/: The system catalog metadata manager, tracking databases, schemas, tables, and roles.
  • src/executor/: Volcano-style iterator model execution engine, currently executing DDL statements.
  • src/storage/: The disk storage engine. Manages layout, file storage, database folders, and schemas on disk.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.