Re: Query with date where clause is very slow

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Query with date where clause is very slow
Date: 2009-02-20 10:53:28
Message-ID: gnm238$cm3$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2009-02-20, Mike Christensen <imaudi(at)comcast(dot)net> wrote:
> Hi all -
>
> I have a fairly simple query:
>
> select * from subscriptions s
> inner join notifications n on n.userid = s.userid
> inner join users u on u.userid = s.userid
> where s.subscriberid='affaa328-5b53-430e-991a-22674ede6faf'
> and n.date > (CURRENT_TIMESTAMP - INTERVAL '14 day')::date;

converting timestamp to date is moderately complex (lots of integer division)
try this instead of (CURRENT_TIMESTAMP - INTERVAL '14 day')::date;

('today'::date -14)

indexing notifications on (userid,date) may help significantly too,

bye.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Akinde 2009-02-20 11:24:49 Re: Large object loading stalls
Previous Message Torsten Bronger 2009-02-20 10:35:02 Getting time-dependent load statistics