Re: factorial
From: Serge Rielau <srielau_at_ca.ibm.com>
Date: Sun, 06 Jan 2002 13:36:26 -0500
Message-ID: <3C38992A.BF1A1FA9_at_ca.ibm.com>
Date: Sun, 06 Jan 2002 13:36:26 -0500
Message-ID: <3C38992A.BF1A1FA9_at_ca.ibm.com>
Hi Mikko,
I think the smallest version is:
DB2 today doesn't push the predicates into a recursion. From a algebraic point of
view it could.
Cheers
with factorial (n, f) as
( values(1, 1)
union all
select n+1, f*(n+1)
from factorial
where n<5
)
select * from factorial where n = 5;
however then it would need to push into both legs of the union (and then deduce
that 1 < 5 and kick that out).
However, in general the WITH clause is used to use the same result multiple times
in the following query. In this case pushing of the predicate would have to follow
a set of rules. In fact it couldn't be pushed. Rather the predicate describing the
superset needs to be added to the recursion.
Serge
-- Serge Rielau DB2 UDB SQL Compiler Development IBM Software Lab, CanadaReceived on Sun Jan 06 2002 - 19:36:26 CET