by archiewood on 10/7/24, 12:39 PM with 9 comments
So I built a minimum viable SQL engine in Go.
- Supports CSV files as tables
- Supports SELECT, FROM, WHERE, LIMIT
It's very simple:
1. Parses query string
2. Converts it into an AST representation
3. Executes the query against the CSV
4. Returns the results
by stevekemp on 10/7/24, 5:03 PM
You can see this post for the start of a guide in implementing something very similar "Writing a SQL database from scratch in Go":
https://notes.eatonphil.com/database-basics.html
(Use the tag "sql" to find the later parts. Sadly not linked directly from that first one.)
by iamcreasy on 10/7/24, 5:44 PM
This db treats file as raw disk and reads and writes in blocks. In the book, your step 3 and 4 will be a start of a transaction that uses recovery manager to log changes introduced by the query, and buffer manager to page in and out file blocks in memory. This book uses serializable isolation, so if buffer pool is full and can't page in new block or if another transactions are writing to that same block - the newer transaction will be rolled back after a brief wait.
by lainga on 10/7/24, 4:57 PM
by zh2408 on 10/7/24, 7:36 PM
by coredog64 on 10/7/24, 3:41 PM
by ddmf on 10/8/24, 7:50 AM