pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: kp <pgsql@pobox.gr>
To: pgsql-admin@postgresql.org
Subject: Sequence scans on indexed row
Date: Sun, 20 Apr 2003 07:36:18 +0200
Message-ID: <3EA231D2.2040305@pobox.gr> (raw)

Hello all.

I am doing a straight forward update on a table with over 1.6 million 
records based on a where clause that only uses one of its indexed 
columns (btree on a varchar). However postgres instists on not using the 
index and instead does a sequence scan that takes ages to complete.

The weird thing is that the same table has another column indexed in 
exactly the same way (btree on a varchar) which postgres correctly uses 
the index on.

One difference between the two columns is that on one I have fixed the 
maximum size of the varchar to 80 while the other is free to grow as 
much as it wants.

The other difference between these two columns (or rather the kind of 
data they contain) is that the column for which postgres *uses* the 
index on contains around 32000 distinct values while the other only 
contains 14 distinct values.

I have a suspicion that postgres (i'm using 7.1.3) incorrectly assumes 
that a sequence scan is cheaper for the column with the 14 distinct 
values in it and ends up scanning 1.6 million rows.

Bug? If so, has it been fixed on later versions?

TIA for any replies,
kp




view thread (5+ messages)  latest in thread

Message-ID: <3EA231D2.2040305@pobox.gr>
Permalink:  ../3EA231D2.2040305@pobox.gr/
Also on:    postgresql.org/message-id/3EA231D2.2040305@pobox.gr

 · 

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-admin@postgresql.org
  Cc: pgsql@pobox.gr
  Subject: Re: Sequence scans on indexed row
  In-Reply-To: <3EA231D2.2040305@pobox.gr>
  References: <3EA231D2.2040305@pobox.gr>

* 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