by nathell · 4y ago · 0 comments
Looking into SQLite’s innards is a great source of inspiration. Thanks for this post.
Edit: I'm prototyping in Python and implementing in Rust with intent to create a C API and embedding a Scheme runtime for "server"-side query and constraint parsing.
The hard part is getting all of that consistent with concurrent writes. Can rows change while you scan? can indexes? How do you check that your write is valid immediately before committing, etc. things like that.
I think SQL makes that pretty hard already, but in a "database-as-a-bag-of-data-structures" mode I think that's going to get even harder.
To have good query optimization, you need to implement, at the very least, some form of dynamic programming, otherwise you will not be able to optimize queries that have more than half a dozen tables in selects. Then you have to implement selection of the best plan or approximation to it, which would make you implement beam search through space of all solutions you generated, and that's simplest case. For guaranteed optimization, you need to implement or utilize pseudoboolean optimization engine.
I am a database engine developer right now. ;)
Until the day you load a bunch of new data and it gets skewed, or you delete a bunch of data without shrinking and oops, your join order and method is not efficient anymore.
You can have this today by running XTDB[1] on top of SQLite via JDBC.
> Written in something like C, Rust, or Zig.
And then compiling your application into native executables with GraalVM Native Image[2].
Embeddable, check. Datomic data model and Datalog query, check. Storage written in C, check.
Edit: it's written in Clojure, so JVM. Extra bleh
No longer actively maintained, but maybe a nice starting point for hacking on your dream!
qpdb/mentat [2] seems to be the largest (+131 commits) and most recently modified (May this year) fork of mozilla/mentat.
[0]: https://github.com/mozilla/mentat/network/members - Seriously, how am I supposed to use this? Hundreds of entries, but no counts for stars, contributors, or commits, no details about recent commits. Just click every one?
The obvious issue is that they're fairly deeply embedded in the Clojure(Script) ecosystem.
You can see me prototype here: https://git.sr.ht/~chiefnoah/quark
I think I gave up when trying to implement one-many relationships because the SQL was getting too gnarly.