Fork me on GitHub
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.


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


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


> 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


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


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


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)]?


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

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.


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


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