Query root and filtering

Suppose I have User and Post types in my Dgraph schema, and I’m writing an API that receives a uid and returns the User with that uid.

Naturally I want this API to ensure that the uid is actually that of a User and not a Post. I can think of two queries that achieve this:

queryA(func: uid($uid)) @filter(type(User)) {
  ...
}

queryB(func: type(User)) @filter(uid($uid)) {
  ...
}

Are these two queries equally efficient?

Using the UID is always n-Times efficient than any other function.

1 Like

Thank you. I suspected as much, but I wouldn’t have been surprised if Dgraph was doing some clever query planning for cases like this.

On a side note, I’m really enjoying working with Dgraph! Keep up the good work.

1 Like