Has(pred) VS eq(pred, true)

Hi. I’m using the “has(pred)” as a pattern on many queries as a way to limite things by type.

What form is more performant?

{
  q(func: has(__is_some_type)) {
   ...

or

{
  q(func: eq(__is_some_type, true)) {
   ...

and why?

Thanks!

I’m not sure about the performance. But the difference of the two approaches is that the first is a wideopen search. And the second is index-based search.

Both have their pros and cons:
Indexing takes up more space over time. Without indexing the search it may take a little longer if you do not set a boundary parameter. You must evaluate the cost benefit. I would recommend using the two combined.

By logic what is indexed has a specific indexing table, so it should be faster. However, it would not be ideal for Labels. For the Dgraph could in theory lose miliseconds by analyzing value by value (even if theres is only two values). So it is better that you use the predicate itself than an indexed value in some cases. Filters get faster through the first approach. But it can in theory be less performatic if used in a Root search. But I do not think so much. Never seen problems with Labels/Kinds.

More about the first approach: https://docs.dgraph.io/howto/#giving-nodes-a-type

PS. We will also soon see improvements in the HAS function.

1 Like