Overview
Obsidian Chess Studio uses SQLite as its embedded database, managed through Diesel ORM. The database stores chess games, player information, puzzles, and analysis results with optimized indexes for fast searches.Technology Stack
Database Engine
- SQLite 3 - Embedded SQL database
- Diesel 2.3 - ORM and query builder
- r2d2 - Connection pooling (16 connections)
- Rusqlite - Low-level SQLite bindings
Optimizations
- Custom indexes on frequently queried columns
- Move encoding (8 bytes per move)
- Position hashing for fast lookups
- Connection pooling for concurrency
Database Schema
The database consists of several interconnected tables:Core Tables
- Games
- Players
- Events
- Sites
Stores chess games with encoded moves and metadata.Key fields:
Moves- BLOB storing encoded moves (8 bytes per move)PawnHome- Pawn structure signature for filteringECO- Opening classification codeWhiteMaterial/BlackMaterial- Material balance
Additional Tables
- Comments
- Puzzles
- Analysis Cache
- Variant Positions
Stores game annotations.
Move Encoding
Moves are stored as binary blobs to save space and improve performance.Encoding Format
- Space efficient: 8 bytes per move vs 4-6 bytes for SAN string
- Fast parsing: Bit manipulation faster than string parsing
- Portable: Binary format independent of notation style
Example Storage
Position Search
Exact Position Search
Searches for games matching an exact FEN position.Partial Position Search
Searches for positions with similar piece configurations.Indexing Strategy
Primary Indexes
Indexes on frequently queried columns:Composite Indexes
For common multi-column queries:Performance Impact
Query Performance with Indexes:
- Player games search: < 10ms (indexed vs 500ms+ unindexed)
- ECO code filtering: < 5ms (indexed vs 200ms+ unindexed)
- Rating range queries: < 15ms (indexed vs 1000ms+ unindexed)
Query Optimization
Bulk Inserts
- With transaction: ~10,000 games/second
- Without transaction: ~100 games/second
Prepared Statements
Diesel uses prepared statements automatically:Connection Pooling
Database Migrations
Migrations are managed by Diesel:Statistics Queries
Player Statistics
Opening Performance
Backup and Maintenance
Database Backup
Vacuum (Defragment)
Integrity Check
Performance Tips
Use Transactions
Batch Queries
Limit Results
Use Indexes
Always create indexes on:
- Foreign keys
- Filter columns
- Join columns
- ORDER BY columns
Next Steps
Backend Architecture
Learn about the Rust backend
Frontend Architecture
Explore the React frontend
