From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | kp <pgsql(at)pobox(dot)gr> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Sequence scans on indexed row |
Date: | 2003-04-20 14:58:38 |
Message-ID: | 26876.1050850718@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
kp <pgsql(at)pobox(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | kp | 2003-04-20 15:17:43 | Re: Sequence scans on indexed row |
Previous Message | Tim Ellis | 2003-04-20 06:06:31 | Re: Sequence scans on indexed row |