Is there any performance degradation from moving a filter to the @filter
instead of the function?
Let’s say I have a type of Contact
that has 30K nodes. I want to get all of them that have the Contact.firstName predicate equal to Anthony (8 Contacts). Here are two different ways to do that:
query {
wType(func: type(Contact)) @filter(eq(Contact.firstName, "Anthony")) { uid }
wOutType(func: eq(Contact.firstName, "Anthony")) { uid }
}
They will both provide the same results, but is either one better performance over the other?
As you may be aware, I am using the graphql endpoint but doing some advance filter logic through a DQL custom query. These filters will be built progmatically by user provided data in the UI. It is actually easier for me progmatically to use the example above wType
way of doing it because then I can just insert the filter part wherever it may be needed and leave the type(Contact)
code bit mostly the same. For instance I may be wanting to do a nested filter where I then need to add cascade and another nested bit of graph and then add the filter(s) onto that part. Here is a little more advance example that gets Contacts with (the firstName: Anthony and lastName: Master) or located in city Timbukto:
query {
var1 as var(func: type(Contact)) @filter(eq(Contact.firstName, "Anthony"))
var2 as var(func: type(Contact)) @filter(eq(Contact.lastName, "Master"))
var3 as var(func: type(Contact)) @cascade {
Contact.hasAddresses {
HasAddress.address {
Addr.city @filter(eq(City.name, "Timbuktu")) {
City.name
}
}
}
}
node(func: type(Contact)) @filter((uid(var1) AND uid(var2)) OR uid(var3)) {
uid
}
}