Index - Mailing list pgsql-general

From Dmitry Andrianov
Subject Index
Date
Msg-id D25012D499D87C4B8A03AF727E624195022BDE@exchange2000.universe.dart.spb
Whole thread Raw
List pgsql-general
Hi.

I just installed PG 7.1.2, created a table, consisting of single
varchar(32) column 'name' and filled it with ~3M records (real last name
from our user database). After that i have created index on this column
and VACUUM ANALYZEd the table.

test=# \d lnames
                Table "lnames"
 Attribute |         Type          | Modifier
-----------+-----------------------+----------
 name      | character varying(32) |
Index: idx_main

test=# \d idx_main
         Index "idx_main"
 Attribute |         Type
-----------+-----------------------
 name      | character varying(32)
btree



test=# EXPLAIN SELECT * FROM lnames WHERE name='ivanov';
NOTICE:  QUERY PLAN:

Index Scan using idx_main on lnames  (cost=0.00..4847.52 rows=1271
width=12)

EXPLAIN


I think, PG should respond instantly on queries like "SELECT * FROM
lnames WHERE name='ivanov'". And it does unless there are many records
with the same value. But in case when there are about 3000 records with
name='ivanov', it takes about a half a minute for Postgres before I can
even see a first row.

Why is that?

Also interesting:

SELECT COUNT(*) FROM lnames WHERE name='ivanov';

this query takes about 20 seconds on table without an index
(sequentional scan) and 40 seconds (2 times more!) after index has been
built and analyzed.

Could anybody explain me what i'm doing wrong, please?

Thanks in advance.

Regards,
Dmitry Andrianov




pgsql-general by date:

Previous
From: "Kapil Tilwani"
Date:
Subject: OIDs overflow
Next
From: "Lucky"
Date:
Subject: libpq++ PgDatabase and PgConnection