Re: Is relational theory irrelevant? (was Re: Dreaming About Redesigning SQL)

From: Mikito Harakiri <mikharakiri_at_iahu.com>
Date: Tue, 11 Nov 2003 10:12:48 -0800
Message-ID: <5O9sb.21$Up4.73_at_news.oracle.com>


"Lauri Pietarinen" <lauri.pietarinen_at_atbusiness.com> wrote in message news:3FB0A52C.2050105_at_atbusiness.com...
> Mikito Harakiri wrote:
> >select EX.EMP#
> >from EMP EX
> >where (select count(1)
> > from EMP EY
> > where EY.HEIGHT < EX.HEIGHT) < 5
> >
> >
> >
> Wow! That is BEAUTIFUL! And I bet it will be easy to teach an
> optimiser how to handle it best ;-)

I doubt your exclamation is unmistaken here, because all I did was copying and pasting from the first Date's "Quota Queries" article. Date also quotes equivalent self-join query, which is admittedly less intuitive. Query unnesting should be able to transform one form into another (the question might be if any product on the market can do that). Then, it is still a selfjoin, so that it have to be transformed into single table scan with stopcount.

> BTW, what if you had to order on more than one column (as is often
> the case)?

select EX.EMP#
from EMP EX
where (select count(1)

        from EMP EY
        where EY.HEIGHT < EX.HEIGHT or EY.HEIGHT = EX.HEIGHT  and EY.SAL <
EX.SAL ) < 5

or something more physical like this

select EX.EMP#
from EMP EX
where (select count(1)

        from EMP EY
        where padding(EY.HEIGHT)||padding(EY.SAL)  <
padding(EX.HEIGHT)||padding(EX.SAL) ) < 5 Received on Tue Nov 11 2003 - 19:12:48 CET

Original text of this message