Re: Speeding up Aggregates - Mailing list pgsql-performance

From Dror Matalon
Subject Re: Speeding up Aggregates
Date
Msg-id 20031003215347.GQ87525@rlx11.zapatec.com
Whole thread Raw
In response to Re: Speeding up Aggregates  (Rod Taylor <rbt@rbt.ca>)
Responses Re: Speeding up Aggregates
Re: Speeding up Aggregates
List pgsql-performance
On Fri, Oct 03, 2003 at 05:44:49PM -0400, Rod Taylor wrote:
> > item_max_date() looks like this:
> >    select max(dtstamp) from items where channel = $1 and link = $2;
>
> It is too bad the (channel, link) index doesn't have dtstamp at the end
> of it, otherwise the below query would be a gain (might be a small one
> anyway).
>
>   select dtstamp
>     from items
>    where channel = $1
>      and link = $2
> ORDER BY dtstamp DESC
>    LIMIT 1;

Similar idea to what Josh suggested. I did create an additional index
with dtstamp at the end and it doesn't look like the planner used it.
Using the above query instead of max() didn't improve things either.

>
>
> Could you show us the exact specification of the function?  In
> particular, did you mark it VOLATILE, IMMUTABLE, or STABLE?
>
> I hope it isn't the first or second one ;)

CREATE or REPLACE FUNCTION item_max_date (int4, varchar) RETURNS
timestamptz AS '
select max(dtstamp) from items where channel = $1 and link = $2;
' LANGUAGE 'sql';




--
Dror Matalon
Zapatec Inc
1700 MLK Way
Berkeley, CA 94709
http://www.zapatec.com

pgsql-performance by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: reindex/vacuum locking/performance?
Next
From: Dror Matalon
Date:
Subject: Re: Speeding up Aggregates