Skip site navigation (1) Skip section navigation (2)

Re: indexes are not working for

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Anshaj <anshaj(at)in2m(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: indexes are not working for
Date: 2004-10-22 12:54:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
Please do not post new topic as reply's to unrelated threads!!

On Friday 22 October 2004 02:10, Anshaj wrote:
> Dear group,
>          I have a table foo
> anshajdb=# \d foo
>            Table ""
>  Column  |       Type        | Modifiers
> ---------+-------------------+-----------
>  snumber | numeric(18,0)     |
>  test    | character varying |
> Indexes:
>     "snum_idx" btree (snumber)
> when I try to do a query like
> explain analyze select * from foo where snumber > 1000;
> Seq Scan on foo  (cost=0.00..69.00 rows=320 width=391) (actual
> time=0.011..0.721 rows=323 loops=1)
>    Filter: (snumber > 1000::numeric)
>  Total runtime: 0.979 ms
> (3 rows)
> It do a sequence scan on table. Why it is not using the snum_idx in this
> query. Do I need to change some setting or indexes don't work on this
> types of query.

You query is not selective enough for the database to use an index. ie. your 
retrieving 323 rows from at best 1323 rows in the table, so the database 
figures it can grab all of the records much faster by just doing a seq scan 
on the table.   Try adding some more data to the table and/or selecting a 
specific value and you'll see your index get used.     

Robert Treat
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

In response to

pgsql-admin by date

Next:From: Joe MaldonadoDate: 2004-10-22 13:12:49
Subject: Re: REVOKE not working...
Previous:From: Simon RiggsDate: 2004-10-22 09:22:54
Subject: Re: replication using WAL archives

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group