Datomic - Get all datoms relevant to an arbitrary query

419 Views Asked by At

Given an arbitrary datomic query q on database d, is it possible to derive a query x from q that when run against d would return all relevant datums r required to produce the result of q on d? The results of q on d should equal the results of q on r.

I'm trying to sync datomic with a datascript client. I know all the queries in advance, and Id like to create a subset of my datomic database in datascript restricted to datums relevant for the clientside queries. For simplicity assume no parameterized queries, although Id expect with placeholders one might achieve the same effect for arbitrary query input parameters, and a solution that allowed for them would be preferred.

I know I can get all the entity ids returned by a query by modifying it and running it against the db, and then touching all those entities, but I'm hoping for something more efficient that only returns the subset of entity datums related to a query, and that can be derived from the query q ALONE without having to run q on d first.

Thanks.

1

There are 1 best solutions below

2
On

I don’t think so — queries don’t work on datoms directly. They start with datoms, if you query the database, but are converted to sets and all subsequent operations are done on sets. This lets queries to run on arbitrary collections the same way they run on Datomic indexes.

I believe https://github.com/mpdairy/posh tried to do query analysis to figure out which datoms it touches. Maybe give it a look?