On Mon, 15 Jun 2015 11:03:17 +1000
<david at andl.org> wrote:

> >>>Unless the recursion is circular, I don't see how an SQL query
> >>>over a finite database could fail to terminate.  
> 
> What does this mean? It is trivial to write a recursive CTE that does
> not terminate, and the property of "circularity" is not what makes the
> difference.

Hmm, for a correctly written recursive query not to terminate, is it not
a requirement that the data contain a cycle?  I can't prove it, but no
counterexample springs to mind.  

In the positive: a correct recursive query always terminates if the
data represent a directed acyclic graph.  

By "correct" I mean the CTE expresses a recursive relation.  If you
recurse over

        with R (a, b) as (select 1 as a, 1 as b)

you have no right to expect termination.  But you might be able to fry
an egg on the processor.  

--jkl

Reply via email to