index does not improve performance - Mailing list pgsql-general

From Milos Prudek
Subject index does not improve performance
Date
Msg-id 3C599A17.884C0F35@tiscali.cz
Whole thread Raw
Responses Re: index does not improve performance  (Jason Earl <jason.earl@simplot.com>)
Re: index does not improve performance  (Neil Conway <nconway@klamath.dyndns.org>)
List pgsql-general
Hi all,

I have a table with 253.380 records. It's a firewall log. I thought that
creating an index will improve queries but results so far were
disappointing.

The table has about 20 columns, most of them of type "text". There's a
text field "ip_type" that has one of three values: TCP, UDP,  ICMP. I
tried to do two selects with and without an index on "ip_type".


Without index:

"select count(*) from log where ip_type='udp';" takes 3.0 seconds (this
query evaluates to zero rows).

"select count(*) from log where ip_type='UDP';" takes 4.5 seconds (this
query evaluates to 245.182 rows).



With index:

"select count(*) from log where ip_type='udp';" takes 0.0 seconds.

"select count(*) from log where ip_type='UDP';" takes 5.0 seconds.


It looks like creating an index degrades performance if the result set
is similar to the size of the whole table (I had much better results
when the condition was met by only two thousand records). Is this
normal?
--
Milos Prudek

pgsql-general by date:

Previous
From: "Gregory Wood"
Date:
Subject: Drop Foreign Key
Next
From: Doug McNaught
Date:
Subject: Re: unique & update