mozilla / mentat

UNMAINTAINED A persistent, relational store inspired by Datomic and DataScript.
https://mozilla.github.io/mentat/
Apache License 2.0
1.65k stars 115 forks source link

[views] Cache the (:db/tx, :db/txInstant) relation #707

Open ncalexan opened 6 years ago

ncalexan commented 6 years ago

One thing I'm finding as a consumer of Mentat is that I need to turn transaction IDs (:db/tx) into (local) transaction instants (:db/txInstant) a good deal. In the future, I'll need to index into transaction IDs by local (and, with potential for confusion, incomparable remote) transaction instants. In the same way that we cache the (:db/id, :db/ident) relation for translating entids and idents locally, perhaps we should cache the (:db/tx, :db/txInstant) relation.

There are a lot of ways to achieve this. It's pretty easy to just "wire it in" to the transactor as another special table in the SQL store. It's also easy to materialize it each time the store is opened, and update it like we do the rest of the schema. There's existing work to cache attributes that we might leverage.

There are things we might be able to do with this. For example, we might make it easy to turn a tx ref into a txInstant coming out of a query, say like:

[:find (tx-instant ?tx)
 :where [_ _ _ ?tx]]

(That's really what I'm tired of doing -- manually inserting [?tx :db/txInstant ?txI] clauses to convert in the query body.) Although post-processing functions like this need care, because it's not clear what should happen when tx-instant: Ref -> Option<Instant> returns None.

In any case, something to think about. Just being able to binary search a big list of the relation wouldn't be a bad outcome for me.