3

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 Answer 1

3

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?

2
  • 1
    Thanks Nikita, so at the least I should be able to modify the query to bind all entity ids and then query datomic for all transactions that added? to those entities right? It's less efficient but should result in all relevant datoms? Jul 13, 2017 at 15:52
  • If your query has no predicates, rules and always queries the same DB, I think it can be done, sure Jul 13, 2017 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.