Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: factorial

Re: factorial

From: Serge Rielau <srielau_at_ca.ibm.com>
Date: Sun, 06 Jan 2002 13:36:26 -0500
Message-ID: <3C38992A.BF1A1FA9@ca.ibm.com>

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, Canada
Received on Sun Jan 06 2002 - 12:36:26 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US