optimizer ignoring primary key and doing sequence scan

From: "Chris Hoy" <chris(dot)hoy(at)hoyc(dot)fsnet(dot)co(dot)uk>
To: <pgsql-general(at)postgresql(dot)org>
Subject: optimizer ignoring primary key and doing sequence scan
Date: 2008-07-14 19:54:31
Message-ID: D6B6367850304938B1280AF8F0D4AD73@Yellowstone
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi

I have a number of tables in my database where the queries appear to
ignoring the primary key and doing a seq scan instead, however other tables
appear to be fine. I can see any difference between them.

Is their any way of determination why the otimizer isn't picking up the
primary key?

Version 8.3.3 windows

An example of a non working table is:

select * from industries where industryid = 1;
"Seq Scan on industries (cost=0.00..1.02 rows=1 width=116) (actual
time=0.011..0.013 rows=1 loops=1)"

CREATE TABLE industries
(
industryid serial NOT NULL,
industryname character varying(45) NOT NULL,
prn_key integer,
CONSTRAINT pk_industry PRIMARY KEY (industryid),
CONSTRAINT un_industry UNIQUE (industryname)
)

A example of woring one

explain select * from currencies where currencyid = 1
"Index Scan using pk_currencyid on currencies (cost=0.00..8.27 rows=1
width=196)"
CREATE TABLE currencies
(
currencyid serial NOT NULL,
currencyname character varying(85) NOT NULL,
prn_key integer,
CONSTRAINT pk_currencyid PRIMARY KEY (currencyid)
)

Chris

No virus found in this outgoing message.
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.4.10/1551 - Release Date: 14/07/2008
06:49

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-07-14 20:08:53 Re: optimizer ignoring primary key and doing sequence scan
Previous Message Scott Marlowe 2008-07-14 19:17:39 Re: statement timeout and pg_dump