pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alex Stapleton <alexs@advfn.com>
To: pgsql-performance@postgresql.org
Subject: PostgreSQL using the wrong Index
Date: Mon, 13 Jun 2005 14:02:30 +0100
Message-ID: <2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.com> (raw)

We have two index's like so

l1_historical=# \d "N_intra_time_idx"
        Index "N_intra_time_idx"
Column |            Type
--------+-----------------------------
time   | timestamp without time zone
btree


l1_historical=# \d "N_intra_pkey"
          Index "N_intra_pkey"
Column |            Type
--------+-----------------------------
symbol | text
time   | timestamp without time zone
unique btree (primary key)

and on queries like this

select * from "N_intra" where symbol='SOMETHING WHICH DOESNT EXIST'  
order by time desc limit 1;

PostgreSQL takes a very long time to complete, as it effectively  
scans the entire table, backwards. And the table is huge, about 450  
million rows. (btw, there are no triggers or any other exciting  
things like that on our tables in this db.)

but on things where the symbol does exist in the table, it's more or  
less fine, and nice and fast.

Whilst the option the planner has taken might be faster most of the  
time, the worst case scenario is unacceptable for obvious reasons.  
I've googled for trying to force the use of a specific index, but  
can't find anything relevant. Does anyone have any suggestions on  
getting it to use an index which hopefully will have better worst  
case performance?



view thread (6+ messages)  latest in thread

Message-ID: <2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.com>
Permalink:  ../2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.com/
Also on:    postgresql.org/message-id/2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.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: alexs@advfn.com
  Subject: Re: PostgreSQL using the wrong Index
  In-Reply-To: <2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.com>
  References: <2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.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