I'm surprised at the differences in runtime.

As a general rule, HAVING is costly, but I don't see how it'd be any
costlier than the CTE.

Are you running the HAVING by itself?
select rpan8, count(*) as theCount
from f0311
group by rpan8
having count(*) > 10000
order by rpan8


Or are you still doing it in a CTE?
with tbl as (
select rpan8, count(*) as theCount
from f0311
group by rpan8
having count(*) > 10000
order by rpan8
) select * from tbl


Also Rob might be onto something, what happens if you run HAVING
version of the statement after the other?

If the HAVING version is still slower, it'd be interesting to see what
visual explain says about both statements.

Charles

On Wed, Aug 19, 2009 at 6:52 AM, Jonathan
Mason<jonathan.mason@xxxxxxxxxxxxxxxx> wrote:
Many thanks to everyone who responded to my question, it really is
appreciated.

I totally missed the HAVING clause in the SQL book I was looking at, and
the AS clause wasn't listed.  Time to get a more up to date book I
guess.

I tried both methods and noticed that over a file with 4,000,000+
records the HAVING returned the first page of results in approximately
24 seconds whilst the AS only took around 2 seconds.

All the best and thanks again

Jonathan




This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].