Recursive Queries and Working Relations

Evaluate reachability by repeatedly extending a working relation and see how row identity determines whether cyclic paths terminate.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. An anchor supplies the initial rows
  2. Adding columns can change what counts as a repeat

An anchor supplies the initial rows

For a graph reachability query, start with the source and repeatedly join the current frontier to edges leaving it. With set-style duplicate elimination on the vertex identity, add and continue only from new vertices. A path with three hops can require three extension rounds. In a finite graph eventually no further vertices remain.

Adding columns can change what counts as a repeat

If a result row includes path length, revisiting a vertex at a new length gives a different row. Deduplicating the whole row may then fail to stop cycling. A bounded-depth query or explicit path-visited rule has a different contract from set reachability. Breadth-first search explains why visiting vertices once is sufficient for basic reachability. Incremental view maintenance addresses efficient changes to derived relations.[1][2]

References

  1. PostgreSQL Global Development Group, PostgreSQL Documentation ↩
  2. CMU 15-445/645, Introduction to Database Systems: Lectures ↩