Peer dies (CPU hangs) when querying for missing attribute


#1

This Datomic schema has a booking entity that has two states, open and closed. This is represented by two inst attributes, :example/opened-at and :example/closed-at. Each booking also has an owner, represented by :example/owner.

There can only be one booking that is open for any given owner.

Querying for a user’s open booking can be done with a query like this:

'[:find ?booking .
  :in $ ?userId
  :where
  [?b :example/owner ?userId]
  [(missing? $ ?b :example/closed-at)]]

But when executing that query, it hangs the CPU. Not sure why. I tried rewriting the query using not:

'[:find ?booking .
  :in $ ?userId
  :where
  [?b :example/owner ?userId]
  (not [?b :example/closed-at _])]

And with get-else:

'[:find ?booking .
  :in $ ?userId
  :where
  [?b :example/owner ?userId]
  [(get-else $ ?b :example/closed-at false) ?closed]
  [(false? ?closed)]]

But nothing helps. I don’t quite understand, since the number of datoms being searched for the missing :example/closed-at attribute is so small after the first query clause matches the owner.

Why would these queries kill the peer, and what’s the recommended way to query for entities missing an attribute? I realize I could add one more boolean attribute that stores whether the booking is open or closed, but that duplicates the state represented by :example/closed-at.