Recursion in Datalog
Path( X, Y ) :- Edge( X, Y )
Path( X, Y ) :- Path( X, Z ), Path( Z, Y ).
Semantics: evaluate the rules until a fixedpoint:
Iteration #0: Edge: {(a,b), (a,c), (b,d), (c,d), (d,e)}
Iteration #1: Path: {(a,b), (a,c), (b,d), (c,d), (d,e)}
Iteration #2: Path gets the new tuples:
Iteration #3: Path gets the new tuple:
Iteration #4: Nothing changes -> We stop.
Note: number of iterations depends on the data. Cannot be
anticipated by only looking at the query!