From: | Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: short-cutting if sum()>constant |
Date: | 2009-12-23 01:46:35 |
Message-ID: | 20091223024635.48d66554@dawn.webthatworks.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 23 Dec 2009 01:09:40 +0100
Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> wrote:
> On Wed, 23 Dec 2009 00:00:31 +0100
> Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> wrote:
>
> > On Tue, 22 Dec 2009 20:47:18 +0100
> > Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> >
> > > Hello
> > >
> > > I found one ugly trick. You can multiply lines and SUM > cons
> > > could be replaced limit clause:
> >
> > The trick is really smart (and fun), kudos, really, it's always a
> > pleasure to read your solutions, thanks.
> >
> > But as expected:
>
> as unexpected...
As even more unexpected... when all row are >0 and most of them are
equal to 1 the generate_series performs appreciably better (roughly
15% faster).
And I think your version can be further optimised:
select count(*) from (select (generate_series(1,a))::int from
data limit 90000000) s;
This perform 30% faster.
So what's so slow in the plpgsql version?
Fortunately as expected when "enough" rows are >1 the for loop
solution perform much better.
--
Ivan Sergio Borgonovo
http://www.webthatworks.it
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2009-12-23 07:38:52 | Re: short-cutting if sum()>constant |
Previous Message | Ivan Sergio Borgonovo | 2009-12-23 00:09:40 | Re: short-cutting if sum()>constant |