I've always been curious about how SQL engines actually work.<p>So I built a minimum viable SQL engine in Go.<p>- Supports CSV files as tables<p>- Supports SELECT, FROM, WHERE, LIMIT<p>It's very simple:<p>1. Parses query string<p>2. Converts it into an AST representation<p>3. Executes the query against the CSV<p>4. Returns the results
Nice job.<p>You can see this post for the start of a guide in implementing something very similar "Writing a SQL database from scratch in Go":<p><a href="https://notes.eatonphil.com/database-basics.html" rel="nofollow">https://notes.eatonphil.com/database-basics.html</a><p>(Use the tag "sql" to find the later parts. Sadly not linked directly from that first one.)
Nice. I also wanted to know the details behind database engine and ACID compliance. So, decided to follow Database Design and Implementation by Edward Sciore, and re-implemented the database in Python: <a href="https://github.com/quazi-irfan/pySimpleDB">https://github.com/quazi-irfan/pySimpleDB</a><p>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.
Try this talk about sqlite!<p><a href="https://www.youtube.com/watch?v=ZSKLA81tBis" rel="nofollow">https://www.youtube.com/watch?v=ZSKLA81tBis</a>