Attribute placeholder query


[: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.



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)



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

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


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!




This is a related issue to the attribute resolution limitation described here:

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.


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