{"id":48260880,"url":"https://github.com/snigenigmatic/sql-engine","last_synced_at":"2026-04-04T21:33:45.234Z","repository":{"id":344865084,"uuid":"1139545089","full_name":"snigenigmatic/sql-engine","owner":"snigenigmatic","description":"An educational SQL database engine built from scratch in C++ to understand database internals.","archived":false,"fork":false,"pushed_at":"2026-03-16T19:14:50.000Z","size":75,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-17T04:16:19.280Z","etag":null,"topics":["cpp","db","sql"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snigenigmatic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-22T05:11:34.000Z","updated_at":"2026-03-16T19:19:14.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/snigenigmatic/sql-engine","commit_stats":null,"previous_names":["snigenigmatic/sql-engine"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/snigenigmatic/sql-engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snigenigmatic%2Fsql-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snigenigmatic%2Fsql-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snigenigmatic%2Fsql-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snigenigmatic%2Fsql-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snigenigmatic","download_url":"https://codeload.github.com/snigenigmatic/sql-engine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snigenigmatic%2Fsql-engine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31415110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","db","sql"],"created_at":"2026-04-04T21:33:44.604Z","updated_at":"2026-04-04T21:33:45.223Z","avatar_url":"https://github.com/snigenigmatic.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Engine\n\nAn educational SQL database engine built from scratch in C++ to understand database internals.\n\n## Features\n\n- Core data structures (Value, Schema, Tuple)\n- Type system: `INTEGER`, `FLOAT`, `VARCHAR`, `BOOLEAN`\n- Lexer and full SQL parser\n- Volcano/iterator query execution model\n- Full DML/DDL: `CREATE TABLE`, `DROP TABLE`, `INSERT`, `SELECT`, `UPDATE`, `DELETE`\n- `WHERE` clause with comparison and logical operators\n- Column projection (`SELECT col1, col2 ...`)\n- BTree index support: `CREATE INDEX`, point lookups (`=`), range scans (`\u003e`, `\u003e=`, `\u003c`, `\u003c=`)\n- Query planner: automatically uses index scan when an index exists on the filtered column\n- Disk-based persistence via `DiskManager`\n- Interactive REPL\n\n### Planned\n- JOIN operations\n- Transaction support (ACID)\n- Query optimizer\n\n## Building\n\n### Prerequisites\n- CMake 3.14 or higher\n- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)\n- Git (for fetching Google Test)\n\n### Build Instructions\n\n```bash\n# Clone the repository\ngit clone \u003crepository-url\u003e\ncd sql-engine\n\n# Configure and build (from repo root)\ncmake -B build\ncmake --build build\n\n# Run tests\nctest --test-dir build --output-on-failure\n\n# Run the REPL\n./build/src/sqlengine\n```\n\n### Build Options\n\n| Option | Default | Description |\n|---|---|---|\n| `CMAKE_BUILD_TYPE` | `Debug` | Build type (`Debug` / `Release`) |\n| `BUILD_TESTS` | `ON` | Build Google Test suites |\n| `ENABLE_LOGGING` | `ON` | Enable internal logging |\n\n```bash\n# Release build\ncmake -B build -DCMAKE_BUILD_TYPE=Release\ncmake --build build\n\n# Disable tests\ncmake -B build -DBUILD_TESTS=OFF\n\n# Disable logging\ncmake -B build -DENABLE_LOGGING=OFF\n```\n\n## Project Structure\n\n```\nsql-engine/\n├── src/\n│   ├── common/    # Value, Schema, Tuple\n│   ├── lexer/     # Tokenizer\n│   ├── parser/    # SQL parser + AST\n│   ├── catalog/   # Table and index registry\n│   ├── execution/ # Operators: SeqScan, Filter, Projection, IndexScan, Executor\n│   ├── storage/   # Table, BTree, DiskManager, BufferPool\n│   └── optimizer/ # (stub, planned)\n├── test/\n│   ├── integration/  # End-to-end SQL tests\n│   └── parser/       # Parser unit tests\n├── docs/\n└── third_party/\n```\n\n## Usage\n\n### REPL\n\n```bash\n./build/src/sqlengine\n```\n\n```sql\n-- DDL\nCREATE TABLE users (id INTEGER, name VARCHAR(50), age INTEGER);\nDROP TABLE users;\n\n-- DML\nINSERT INTO users VALUES (1, 'Alice', 25), (2, 'Bob', 30);\nSELECT * FROM users WHERE age \u003e 25;\nSELECT name, age FROM users;\nUPDATE users SET age = 99 WHERE id = 1;\nDELETE FROM users WHERE id = 2;\n\n-- Indexes\nCREATE INDEX idx_id ON users (id);\nSELECT * FROM users WHERE id = 1;    -- uses index point lookup\nSELECT * FROM users WHERE id \u003e 1;   -- uses index range scan\n```\n\n### REPL Commands\n\n| Command | Description |\n|---|---|\n| `tables` | List all tables and their columns |\n| `save` | Persist all tables to disk |\n| `help` | Show SQL syntax reference |\n| `quit` / `exit` | Save and exit |\n\n## Testing\n\n```bash\n# Build and run all tests\ncmake --build build \u0026\u0026 ctest --test-dir build --output-on-failure\n\n# Run a specific test binary\n./build/test/query_test\n./build/test/parser_test\n\n# Verbose output\nctest --test-dir build --output-on-failure --verbose\n```\n\n## Development Phases\n\n- [x] **Phase 0**: Project setup and core data structures\n- [x] **Phase 1**: Lexer and parser\n- [x] **Phase 2**: In-memory query execution (SeqScan, Filter, Projection)\n- [x] **Phase 3**: Disk-based storage with buffer pool\n- [x] **Phase 4**: BTree indexes with query planner integration\n- [x] **Phase 5**: JOIN operations\n  - [x] Parse `INNER JOIN ... ON ...` with qualified column references\n  - [x] Execute joins via `NestedLoopJoin`\n  - [x] Add rule-based join algorithm choice (`NestedLoopJoin` vs `HashJoin`)\n  - [x] Support `JOIN + WHERE` (single-table pushdown + post-join filter)\n  - [x] Add correctness checks (ambiguous columns, swapped `ON` sides, type-mismatch safety)\n  - [x] Add `EXPLAIN` command in REPL to print physical plan (`SeqScan`/`IndexScan`/`Join` path)\n  - [x] Add join-condition index matching (`IndexNestedLoopJoin` when index exists on join column)\n- [ ] **Phase 6**: Transactions\n\n## Architecture\n\nSee [docs/design.md](docs/design.md) for detailed architecture documentation.\n\n## Resources\n\n- [SQLite Architecture](https://www.sqlite.org/arch.html)\n- [CMU 15-445 Database Systems](https://15445.courses.cs.cmu.edu/)\n- [Database Internals by Alex Petrov](https://www.databass.dev/)\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnigenigmatic%2Fsql-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnigenigmatic%2Fsql-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnigenigmatic%2Fsql-engine/lists"}