Fork me on GitHub
#xtdb
<
2022-05-10
>
Martynas Maciulevičius07:05:47

Is there a good way to filter based on an attribute if I don't save it? Or is it better to store a false value instead? I have a boolean attribute in DB which I don't save but when I set it to true I add it. Is it better to save false or is there a good way to obtain it with one query? I expect to have many entries there.

tatut07:05:47

[:find ?e :where [?e :has-attr ?v] (not-join [?e] [?e :does-not-have])]

Martynas Maciulevičius07:05:53

Nice. I'll try it, thanks!

tatut07:05:14

that works, idk how "good" it is, might not be the fastest

refset11:05:34

> Or is it better to store a false value instead? Queries will generally be much faster if you store explicit false/`nil` values and search for those, rather than the absence of an attribute, but whether it's significant for your application greatly depends on the relative cardinalities involved

tatut11:05:34

could a native missing? implementation be made that is faster than the suggested not-join workaround?

refset11:05:18

A native missing? would probably help a little, as subqueries like not-join aren't free, but it still wouldn't be able to get close to the speed of storing the explicit null values

refset11:05:38

That's my guess, anyway :)

Martynas Maciulevičius11:05:24

Hm. So what is better then? Storing nil or storing false? Should the query check via predicate funcion in that case? [(nil? :my-attr)]? [(false? :my-attr)]?

tatut11:05:49

[?e :my-attr false] EAV pattern?

1
Martynas Maciulevičius11:05:00

I don't know how it's wired but those three could either be equivalent or EAV best for performance...? It's my guess.

refset12:05:02

The EAV pattern should be fastest there. I would personally try storing false or perhaps even a domain-specific keyword sentinel like :my.orders/no-shipping-date-specified as using nil might get confusing. Although a keyword will inevitably use more disk space

2
tatut12:05:53

as there's no schema registry, I guess there's no interning of keywords possible

✔️ 1
Martynas Maciulevičius12:05:01

The value that I'll have is something that I calculate for each entry and it's always a boolean. And I know that I shouldn't need anything else there (it won't become an enum/kw). So no worries 😄

👌 1