Yesterday I found this and ported it to Python: <a href="https://github.com/tekknolagi/db.py">https://github.com/tekknolagi/db.py</a><p>It's ~150LOC but doesn't have aggregates (yet)
It’s like a ray tracer: every programmer should write a toy sql engine!<p>A very long time ago I started writing a game in a weekend a for Ludum dare competition and ended up writing a toy sql engine of my own <a href="https://williame.github.io/post/59997353762.html" rel="nofollow">https://williame.github.io/post/59997353762.html</a><p>I still get the urge to make a proper one one day. With the sql features that I wish sql engines had. Hmmm. Need-sniping myself now… :)
Great toy but it's a bit misleading not to touch on the query planner. All real SQL implementations will plan how to most efficiently run a query so the order of operations can be wildly different to expected based on the data and indexes available. This kind of tutorial makes it look like joins are very inefficient whereas a real database may make them highly efficient for a given query.
I had fun over the last day implementing this two ways in Elixir: <a href="https://github.com/halostatue/sqltoy_elixir">https://github.com/halostatue/sqltoy_elixir</a>.
I hoped this had a toy implementation of sql indices, but it looks like that's not the case: it just sorts the whole table on the fly on an ORDER BY.