Yet another question about not use on indexes

From: Xevi Serrats <tomcatbsd(at)yahoo(dot)es>
To: pgsql-performance(at)postgresql(dot)org
Subject: Yet another question about not use on indexes
Date: 2003-05-11 13:16:00
Message-ID: 20030511131600.47686.qmail@web13001.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi,

I have created a table whit some indexes. I analize
the query of this table and never use index.

After this, I create a more simplistic table with two
columns and one index and the query uses the index.

Look at this:

pfc=# \d document
Table
"public.document"
Column | Type |
Modifiers
------------+--------------------------+----------------------------------------------------
codi | integer | not null
default nextval('seq_document'::text)
nom | character varying(32) | not null
descripcio | text |
formulari | integer |
fitxer | character varying(32) |
tamany | integer | default -1
data | timestamp with time zone | default
('now'::text)::timestamp(6) with time zone
Indexes: document_pkey primary key btree (codi),
ind_doc1 btree (codi),
ind_document btree (formulari)
Triggers: RI_ConstraintTrigger_19414,
RI_ConstraintTrigger_19418,
RI_ConstraintTrigger_19419,
actualitzaritemcercadocument,
altaitemcercadocument,
baixaitemcercadocument,
eliminaracldocument,
eliminaravaluaciodocument

pfc=# explain select * from document where codi=2;
QUERY PLAN
----------------------------------------------------------
Seq Scan on document (cost=0.00..1.19 rows=1
width=120)
Filter: (codi = 2)
(2 rows)

This query must use index document_pkey but explain
tells us that the query does a Sequencial scan on
table document.

Look at this simplistic case:

pfc=# \d prova
Table "public.prova"
Column | Type | Modifiers
--------+-----------------------+-----------
codi | integer | not null
nom | character varying(30) |
Indexes: prova_pkey primary key btree (codi)

pfc=# explain select * from prova where codi=1234;
QUERY PLAN
-------------------------------------------------------------------------
Index Scan using prova_pkey on prova
(cost=0.00..5.99 rows=1 width=37)
Index Cond: (codi = 1234)
(2 rows)

Now the query uses index, explain tell something about
index scan using index prova_pkey.

What is the diference with two cases? What must I do?
It is a bug? I need do something else?

Thanks a lot for helping me.

Regards,

Xevi.

_______________________________________________________________
Yahoo! Messenger
Nueva versión: Webcam, voz, y mucho más ¡Gratis!
Descárgalo ya desde http://messenger.yahoo.es

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Richard Huxton 2003-05-11 14:08:34 Re: Yet another question about not use on indexes
Previous Message Tom Lane 2003-05-11 02:46:25 Re: realtime data inserts