Fork me on GitHub
#datomic
<
2023-12-28
>
Saket10:12:31

Hey folks, the following query is extremely slow. I'd expect it to be fast as it's getting all the entities that has ?v as value, and the attribute's ident. Can be done, just by using vaet for getting entities and then aevt for the next.

(d/q '[:find [?e ?ident] 
       :in $ ?v
       :where [?e ?a ?v]
       [?a :db/ident ?ident]] 
     (d/db db/datomic-conn) my-val)
;; Runs for more than half a min on a 9 Gigs db. (Result only contains 10 entries)
Whereas if we use pull expression, we get it pretty fast:
(d/q '[:find ?e (pull ?a [:db/ident])
       :in $ ?v
       :where [?e ?a ?v]] 
     (d/db db/datomic-conn) my-val)
Am I missing something here?

favila13:12:36

Because it doesn’t know that ?a is a reference attribute and ?v is a ref it is using aevt not vaet

favila13:12:01

I don’t know a not-tricky way to do this with query; I would just use d/datoms

Saket13:12:55

> Because it doesn’t know that ?a is a reference attribute and ?v is a ref it is using aevt not vaet Isn't this the known order of conditions in where clauses: [entity attr value txn deleted?] ?

favila13:12:27

Yes but vaet only contains entries where a is a ref attr

favila13:12:12

Suppose ?v is a scalar value

Saket13:12:44

I think I need to read more on the indices, clearly my knowledge is incomplete on this topic. Thanks @U09R86PA4 for the response. I am going to read https://docs.datomic.com/pro/query/indexes.html

favila13:12:12

:where [?a :db/valueType db.type/ref][?e ?a ?v] might do what you want, but I wouldn’t trust it to always use vaet without testing. :where [(datomic.api/datoms $ :vaet ?v) [[?e ?a]]] gives you explicit control

Saket21:12:36

This makes sense. Thanks a lot @U09R86PA4

cch123:12:04

As a matter of hygiene, we fail deploys that have dependency conflicts with the Ion runtime. These conflicts are nicely reported when pushing a revision, but it’s frustrating to merge a branch with a hidden conflict that can only be exposed on push (we don’t deploy every branch in our CI/CD pipeline). It would be really useful to catch these conflicts without requiring a push (99% of which will never get deployed). Has anybody else bumped into this issue? Any suggestions?

👀 1