Query variable scalability and performance

I also liked how you used uid_in, however not always do we know the uid when doing the query. What would really solve this issue, would be the ability to use uid_in with variables, like so. I think this is the most efficient way to make this query.

query dentry($dict: string){
  DICT as var(func: eq(shortName, $dict))

  dentry(func: allofterms(content, "apple")) @filter(uid_in(dict, DICT)) {
    content
    meaning @filter(uid_in(dict, DICT)) {
      translation @filter(uid_in(dict, DICT)) {
        content
      }
    }
  }
}

I think, that @cascade could in theory optimize it this way. The docs say:

With the @cascade directive, nodes that don’t have all predicates specified in the query are removed.

Based on this definition, the cascade version of the query traverses all possible combinations, even nested ones, and then removes incomplete results at the end. But it could optimize the query, by removing them at query execution, basically working like uid_in.

1 Like