pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: kp <pgsql@pobox.gr>
Cc: pgsql-admin@postgresql.org
Subject: Re: Sequence scans on indexed row
Date: Sun, 20 Apr 2003 10:58:38 -0400
Message-ID: <26876.1050850718@sss.pgh.pa.us> (raw)
In-Reply-To: <3EA231D2.2040305@pobox.gr>
References: <3EA231D2.2040305@pobox.gr>

kp <pgsql@pobox.gr> writes:
> 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 think it's doing what it's supposed to, then.  Using an indexscan to
select 1/14th of a table is a loser --- the seqscan will be faster.
(If you disbelieve this, try timing it both ways.  You can set
enable_seqscan to off to force the planner to do it the other way.)

> 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.

The only way it's wrong is if the particular value being searched for is
much less than 1/14th of the table.  IIRC Postgres 7.1 does not have
statistics about anything beyond the most common value of the column,
and so it's easily misled by nonuniform data distributions.  If that's
your situation then an update to 7.2.* or 7.3.* seems called for.

			regards, tom lane




view thread (5+ messages)  latest in thread

Message-ID: <26876.1050850718@sss.pgh.pa.us>
Permalink:  ../26876.1050850718@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26876.1050850718@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, pgsql@pobox.gr
  Subject: Re: Sequence scans on indexed row
  In-Reply-To: <26876.1050850718@sss.pgh.pa.us>
  References: <3EA231D2.2040305@pobox.gr> <26876.1050850718@sss.pgh.pa.us>

* 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