Re: Optimizing sum() operations

From: "Dobes Vandermeer" <dobesv(at)gmail(dot)com>
To: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Optimizing sum() operations
Date: 2008-10-03 19:13:59
Message-ID: 7324d9a20810031213s53082483h72248315df794272@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Oct 3, 2008 at 4:51 AM, Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> wrote:
> On Fri, Oct 3, 2008 at 4:51 AM, Dobes Vandermeer <dobesv(at)gmail(dot)com> wrote:
>> I'm currently using sum() to compute historical values in reports;
>> basically select sum(amount) on records where date <= '...' and date
>>>= '...' who = X.
>>
>> Second, if this is a concern, is there a best practice for optimizing
>> these kinds of queries?
>
> You'll need to test to see what performance you get. That said,
> indexing is a good place to start. You can always run explain and
> explain analyze on the queries to double-check the planner.

Could I create an index that includes a sum() function - like:

create index sumidx on records (who, date, sum(amount)) ?

I'm sure that theoretically this is possible, but does postgres support it?

--

Dobes Vandermeer
Director, Habitsoft Inc.
dobesv(at)habitsoft(dot)com
778-891-2922

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Sean Davis 2008-10-03 19:23:42 Re: Optimizing sum() operations
Previous Message Harold A. Giménez Ch. 2008-10-03 17:41:28 Re: quiet restore