I think I'm beginning to understand now the intricacies of or-join; and I'd like to check my understanding.
Using the same terminology from https://v1-docs.xtdb.com/language-reference/1.24.3/datalog-queries/#clause-or-join:
1. the query in an or-join must be thought of as an independent query, with absolutely no relation or connection to the clauses outside of it - EXCEPT for the unifying logic vars
2. the unifying logic vars unify not just with "the rest of the query", but also with the values from :in
This is based on my observation from the situation below:
[;; users
{:xt/id :petr :owner/name "Petr" :owner/store :abc}
{:xt/id :ivan :owner/name "Ivan" :owner/store :abc-branch}
{:xt/id :sergei :ower/name "Sergei" :owner/store :abc-branch}
{:xt/id :boris :owner/name "Boris" :owner/store :abc-branch2}
;; stores
{:xt/id :abc :store/address "addr1"}
{:xt/id :abc-branch :store/address "addr2" :store/parent :abc}
{:xt/id :abc-branch2 :store/address "addr3" :store/parent :abc}
;; books
{:xt/id :b1 :book/store :abc ...}
{;xt/id :b2 :book/store :abc-branch ...}
{:xt/id :b3 :book/store :abc-branch2 ...}]
;; given an owner id, find all store ids and addresses for owner or branches of owner's
(let [{:keys [biff/db] :as ctx} (get-context)]
(q db
'{:find [store store-addr]
:where [[store :store/address store-addr]
(or-join [owner]
[owner :owner/store store]
(and [owner :owner/store parent-store]
[store :store/parent parent-store]))]
:in [owner]}
:ivan))
With this query, when the queried owner is the owner of a branch (`:ivan`), I need to or-join [owner store]: both owner and store need to be part of the unifying logic vars for this to work; or else all stores are returned.
Is my understanding correct?hey @jf.slack-clojurians yes that interpretation looks right to me. Welcome to the club 🙂
thanks, Jeremy! gratitude-thank-you