Attribute placeholder query


#1

If
[:find ?e :where [?e :ns/int 2]]
gives me an entity id, then why does
[:find ?e :where [?e _ 2]]
give me an empty result?

Could it be related to some index not having been synced yet? Tried to sync with conn.sync().get()before querying but the empty query result remains.

Thanks,
Marc


#2

Found a hack (?) where I can tie an attr variable to an :db/ident value and get the desired result:

[:find ?e :where [?e ?attr 2][?attr :db/ident _]]

Is this a reasonable way to find the entity ids of any attributes having the value 2 asserted? (I know it’s an expensive query)

Thanks,
Marc


#3

Hey Marc, I think you might be interested in accessing the VAET index directly.

https://docs.datomic.com/on-prem/indexes.html#VAET

It’s indexed by value, then attribute, then entity.


#4

Thanks, jplane, but I can’t use the VAET index since it only contains datoms whose attribute has a :db/valueType of :db.type/ref. And I’m looking for all values of attributes of any type. I found a way around it - maybe a bit hacky, I don’t know. But thanks for your suggestion anyway!

Cheers,
Marc


#5

Marc,

This is a related issue to the attribute resolution limitation described here:
https://docs.datomic.com/on-prem/query.html#idents-vs-entity-ids

Briefly, dynamic (or ignored with _) variable in the attribute position make it difficult for the query engine to determine how to perform an index lookup. As you found, one way around this issue is to force resolution of the attribute variable via an additional clause.


#6

Thanks for the explanation and reference, Marshal - that all makes sense! Good to know I can use my workaround.