Re: Performance problems on a fairly big table with two key columns. - Mailing list pgsql-performance

From Richard Huxton
Subject Re: Performance problems on a fairly big table with two key columns.
Date
Msg-id 200309050934.52082.dev@archonet.com
Whole thread Raw
In response to Performance problems on a fairly big table with two key columns.  ("Rasmus Aveskogh" <rasmus@defero.se>)
Responses Re: Performance problems on a fairly big table with two
List pgsql-performance
On Thursday 04 September 2003 23:53, Rasmus Aveskogh wrote:
> Hi,
>
> I have a table that looks like this:
>
>   DATA   ID   TIME
>
> |------|----|------|
>
> The table holds app. 14M rows now and grows by app. 350k rows a day.
>
> The ID-column holds about 1500 unique values (integer).
> The TIME-columns is of type timestamp without timezone.
>
> I have one index (b-tree) on the ID-column and one index (b-tree) on the
> time-column.
>
> My queries most often look like this:
>
> SELECT DATA FROM <tbl> WHERE ID = 1 AND TIME > now() - '1 day'::interval;
[snip]
> I tried applying a multicolumn index on ID and TIME, but that one won't
> even be used (after ANALYZE).

The problem is likely to be that the parser isn't spotting that now()-'1 day'
is constant. Try an explicit time and see if the index is used. If so, you
can write a wrapper function for your expression (mark it STABLE so the
planner knows it won't change during the statement).

Alternatively, you can do the calculation in the application and use an
explicit time.

HTH
--
  Richard Huxton
  Archonet Ltd

pgsql-performance by date:

Previous
From: Eirik Oeverby
Date:
Subject: Re: SELECT's take a long time compared to other DBMS
Next
From: "Bjorn T Johansen"
Date:
Subject: Re: [GENERAL] Seq scan of table?