pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
indexes are not working for
3+ messages / 3 participants
[nested] [flat]

* indexes are not working for
@ 2004-10-22 06:10  Anshaj <anshaj@in2m.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Anshaj @ 2004-10-22 06:10 UTC (permalink / raw)
  To: anshaj@in2m.com; +Cc: pgsql-admin

Dear group,

         I have a table foo
anshajdb=# \d foo
           Table "public.foo"
 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.


Thanks and Regards
Anshaj



 -- 
"Normal people believe that if it ain't broke, don't
fix it. Engineers believe that if it ain't broke, it
doesn't have enough features yet."




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: indexes are not working for
@ 2004-10-22 12:54  Robert Treat <xzilla@users.sourceforge.net>
  parent: Anshaj <anshaj@in2m.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Robert Treat @ 2004-10-22 12:54 UTC (permalink / raw)
  To: Anshaj <anshaj@in2m.com>; +Cc: 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 "public.foo"
>  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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: indexes are not working for
@ 2004-10-22 14:04  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Anshaj <anshaj@in2m.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2004-10-22 14:04 UTC (permalink / raw)
  To: Anshaj <anshaj@in2m.com>; +Cc: pgsql-admin

Anshaj <anshaj@in2m.com> writes:
> when I try to do a query like
> explain analyze select * from foo where snumber > 1000;
> It do a sequence scan on table.

One-sided inequalities are frequently not selective enough to justify an
indexscan.  A rule of thumb is that if the WHERE selects more than one
or two percent of the table, you will (and should) get a seqscan.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-10-22 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-22 06:10 indexes are not working for Anshaj <anshaj@in2m.com>
2004-10-22 12:54 ` Robert Treat <xzilla@users.sourceforge.net>
2004-10-22 14:04 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox