Re: max time in a table query takes ages

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>
Cc: "Postgres General List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: max time in a table query takes ages
Date: 2008-10-23 13:47:57
Message-ID: 13737.1224769677@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"=?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?=" <gryzman(at)gmail(dot)com> writes:
> I have a simple query over a fairly simple query here, that scans for max
> date in a table that's fairly hudge (300M rows). there's index on that field
> that's being used, but for whatever reason, it takes ages. Ideas ?

> select date_trunc('day', max(data)) into dt from staticstats where
> processed = false

I suppose the problem is that rows with processed = false are very few
in the upper range of data. If so, and if you really need this to go
fast, a partial index might be worth its overhead:
create index foo on staticstats(data) where processed = false;

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Grzegorz Jaśkiewicz 2008-10-23 13:52:27 Re: max time in a table query takes ages
Previous Message Andrew Sullivan 2008-10-23 13:35:25 Re: Import db from 8.1.3 to 8.3.1