How is sorting done under the hood in DQL?

I Want to Do

Implement an advanced sorting where parents are sorted by nested children

What I Did

Figured out it is impossible currently…

What I need to Do

I need to learn how sorting is done underneath the DQL language. Find the limitations to it and think of a way to resolve around it. We can’t do better sorting in GraphQL unless it is possible in DQL without breaking the overfetching principal.

Any examples

SQL can sort results based upon joined tables. I am not sure how this happens actually either without first joining all results which would be equivalent to Dgraph traversing all the edges from a type.

Use cases

Need to sort by counts
Need to sort by one to one relationships
Want to sort by one to many relationships

We use GraphQL too so our sort should in the end respect rules, but before we worry about that the sort needs to be possible in DQL

If you read Go code, this should be enough to get you started.

LMK if you need additional help. I’ll jump on a call with you if you need to

Thank you! I will try that late tonight. I understand algorithms but not Go syntax so I will try to read it and the comments to understand the logic.