Fork me on GitHub
#xtdb
<
2021-10-30
>
introom07:10:01

HI Team, when do I use open-db compared with the noraml (xt/db node) call ?

refset10:10:18

For others who are curious - it's a performance thing, open-db avoids creating a bunch of low-level resources each time you want to execute a small query

introom03:10:07

My understanding is about lazy evaluation that not all query results are materialized.

introom03:10:41

As you have talked about performance, what exact underlying resources are relevant? And how it is shared with different (open-db) requests?

refset12:10:59

Lazy evaluation, whether through open-q or open-entity-history is mostly orthogonal, can be combined with either db or open-db

refset12:10:15

> not all query results are materialized that's definitely true of open-q, yep, but only when you don't use :order-by or a reducing aggregate in the :find

refset12:10:58

open-db will share a single KV-store snapshot between requests (which pools caching and underlying iterators), and also a temporal "entity-resolver" cache, see https://github.com/xtdb/xtdb/blob/e2f51ed99fc2716faa8ad254c0b18166c937b134/core/src/xtdb/query.clj#L1961-L1966

introom08:10:10

How can change the query to get a whole set #{[:cat #{“dog”, “mouse”}]} instead of #{[:cat “dog”] [:cat “mouse”]}. I am interested in the normal :find way.

(xt/submit-tx node [[::xt/put
                       {:xt/id :cat :meow-follows #{"dog" "mouse"}}]])
  (xt/q
   (xt/db node)
   '{:find [e z]
     :where [[e :meow-follows z]]})

Piotr Roterski09:10:16

I would try using https://docs.xtdb.com/language-reference/datalog-queries/#pull syntax for this

'{:find [(pull e [:meow-follows])]
  :where [[e :meow-follow z]]}

introom03:10:22

Yup. Pull was the only thing that came up to my mind.