pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: rasmus@defero.se
To: pgsql-performance@postgresql.org
Subject: Re: Performance problems on a fairly big table with two key columns.
Date: Fri, 5 Sep 2003 09:34:52 +0100
Message-ID: <200309050934.52082.dev@archonet.com> (raw)
In-Reply-To: <1564.62.119.108.236.1062716026.squirrel@www.defero.se>
References: <1564.62.119.108.236.1062716026.squirrel@www.defero.se>

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



view thread (4+ messages)  latest in thread

Message-ID: <200309050934.52082.dev@archonet.com>
Permalink:  ../200309050934.52082.dev@archonet.com/
Also on:    postgresql.org/message-id/200309050934.52082.dev@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: dev@archonet.com, rasmus@defero.se
  Subject: Re: Performance problems on a fairly big table with two key columns.
  In-Reply-To: <200309050934.52082.dev@archonet.com>
  References: <1564.62.119.108.236.1062716026.squirrel@www.defero.se> <200309050934.52082.dev@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox