pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Childs <peterachilds@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Planner statistics, correlations
Date: Fri, 12 Jan 2007 08:56:54 +0000
Message-ID: <a2de01dd0701120056p37f1906excd71068468e5769a@mail.gmail.com> (raw)
In-Reply-To: <20070112081631.GA10636@oppetid.no>
References: <20070112081631.GA10636@oppetid.no>

On 12/01/07, Tobias Brox <tobias@nordicbet.com> wrote:
> We have a table with a timestamp attribute (event_time) and a state flag
> which usually changes value around the event_time (it goes to 4).  Now
> we have more than two years of events in the database, and around 5k of
> future events.
>
> It is important to frequently pick out "overdue events", say:
>
>   select * from events where state<>4 and event_time<now()
>
> This query would usually yield between 0 and 100 rows - however, the
> planner doesn't see the correlation betewen state and event_time - since
> most of the events have event_time<now, the planner also assumes most of
> the events with state<>4 has event_time<now, so the expected number of
> rows is closer to 5k.  This matters, because I have a query with joins,
> and I would really benefit from nested loops.
>
> (I've tried replacing "now()" above with different timestamps from the
> future and the past.  I'm using pg 8.2)
>
> Any suggestions?
>

Can you say what state might be rather than what it is not. I'm guess
that state is an int but there is only a limited list of possible
states, if you can say what it might be rather than what it is the
index is more liklly to be used.

Peter.



view thread (8+ messages)  latest in thread

Message-ID: <a2de01dd0701120056p37f1906excd71068468e5769a@mail.gmail.com>
Permalink:  ../a2de01dd0701120056p37f1906excd71068468e5769a@mail.gmail.com/
Also on:    postgresql.org/message-id/a2de01dd0701120056p37f1906excd71068468e5769a@mail.gmail.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: peterachilds@gmail.com
  Subject: Re: Planner statistics, correlations
  In-Reply-To: <a2de01dd0701120056p37f1906excd71068468e5769a@mail.gmail.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