Index not used on simple select - Mailing list pgsql-hackers

From Ole Gjerde
Subject Index not used on simple select
Date
Msg-id Pine.LNX.4.05.9907221310400.27596-100000@snowman.icebox.org
Whole thread Raw
In response to Re: [HACKERS] Interesting index/LIKE/join slowness problems  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Index not used on simple select
List pgsql-hackers
Hey,
I've been having this bizarre problem with some index on this one table.
The table has in the past had more than 9 indexes, but today I redid the
table and it still has the same problem.
I just did a dump of the schema, COPY'd the data out.  Deleted all
postgres files, and installed 6.5.1.
The table has 3,969,935 rows in it.

Any ideas?

Here is the explain reports after both vacuum and vacuum analyze on the
table:
---------------------------------------------
parts=> explain select * from av_parts where partnumber = '123456';
NOTICE:  QUERY PLAN:

Index Scan using av_parts_partnumber_index on av_parts  (cost=3.55 rows=32
width=124)

EXPLAIN
parts=> explain select * from av_parts where nsn = '123456';
NOTICE:  QUERY PLAN:

Seq Scan on av_parts  (cost=194841.86 rows=3206927 width=124)

EXPLAIN
-------------------------------------------------

This is how I create the 2 indexes:
-------------------------------------------------
CREATE  INDEX "av_parts_partnumber_index" on "av_parts" using btree             ( "partnumber" "varchar_ops" );
CREATE  INDEX "av_parts_nsn_index" on "av_parts" using btree             ( "nsn" "varchar_ops" );
-------------------------------------------------

Table    = av_parts
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                |Length|
+----------------------------------+----------------------------------+-------+
| itemid                           | int4 not null default nextval (  |4 |
| vendorid                         | int4                             |4 |
| partnumber                       | varchar()                        |25 |
| alternatepartnumber              | varchar()                        |25 |
| nsn                              | varchar()                        |15 |
| description                      | varchar()                        |50 |
| condition                        | varchar()                        |10 |
| quantity                         | int4                             |4 |
| rawpartnumber                    | varchar()                        |25 |
| rawalternatenumber               | varchar()                        |25 |
| rawnsnnumber                     | varchar()                        |15 |
| date                             | int4                             |4 |
| cagecode                         | varchar()                        |10 |
+----------------------------------+----------------------------------+-------+
Indices:  av_parts_itemid_key         av_parts_nsn_index         av_parts_partnumber_index

Thanks,
Ole Gjerde



pgsql-hackers by date:

Previous
From: "F.J.Cuberos"
Date:
Subject:
Next
From: The Hermit Hacker
Date:
Subject: Fortune 500 ...