BFS and DFS
Choose the order a walk reaches records in.
Syntax
Write BFS or DFS after the edge collection.
FOR v IN 1..3 OUTBOUND "gid://namespace/resource/id" name_edge BFS
FOR v IN 1..3 OUTBOUND "gid://namespace/resource/id" name_edge DFSParameters and arguments
BFSNearest first, one level at a time. This is the default order
Required: NoDFSOne branch to its end before the next
Required: No
Examples
A breadth-first walk. The content store holds no edges, so the answer shows the shape with no results.
Return type and behaviour
BFS returns the records nearest to the start first, ordered by depth and then by record. DFS follows one branch to its end, taking the records in order, before it moves to the next. Results are capped at 10,000 rows, so with a cap the two orders can return different sets.
Errors and exceptions
| Error | What happened | How to recover |
|---|---|---|
HTQL-1003 | The traversal is not written in HTQL's grammar | Check the range, the direction, the start and the edge collection |
HTQL-2012 | The edge collection's name is not in lower snake case | Write a name such as placed_by_edge |
Placement and context
The order keyword follows the edge collection and comes before PRUNE.
Best practices
- Use BFS when you want the nearest records first.
- Use DFS to follow a chain to its end.
- Leave the keyword out when you want the default, BFS.