| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: factorial
Hi Mikko,
I think the smallest version is:
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;
DB2 today doesn't push the predicates into a recursion. From a algebraic point of
view it could.
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.
Cheers
Serge
-- Serge Rielau DB2 UDB SQL Compiler Development IBM Software Lab, CanadaReceived on Sun Jan 06 2002 - 12:36:26 CST
![]() |
![]() |