pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Why is my index not used
3+ messages / 3 participants
[nested] [flat]

* Why is my index not used
@ 2002-02-18 18:54  Kristian Eide <kreide@online.no>
  0 siblings, 2 replies; 3+ messages in thread

From: Kristian Eide @ 2002-02-18 18:54 UTC (permalink / raw)
  To: pgsql-sql

I have a table, currently at about 150.000 rows, with a btree index on a
field named 'misscnt'. ~138k of the rows have this fields set as null, ~12k
as 0, ~350 as 1, ~200 as 2 and ~150 as 3 (these are the only values used).

Still, I get the following:

# explain select * from cam where misscnt>=1;
NOTICE:  QUERY PLAN:

Seq Scan on cam  (cost=0.00..3609.59 rows=46896 width=66)

Why do postgre think it will get over 46k rows from this query? If I try a
VACUUM ANALYZE on the table, I get:

# explain select * from cam where misscnt>=1;
NOTICE:  QUERY PLAN:

Seq Scan on cam  (cost=0.00..3874.01 rows=50347 width=66)

So now it actually thinks it will get _more_ rows:

# select count(*) from cam where misscnt>=1;
 count 
-------
   692

If I use "set enable_seqscan=false;" and try "select * from cam where
misscnt>=1;" the index is used, and the query executes quite a bit faster.
However, shouldn't Postgre be able to do this automatically?

This is using PostgreSQL 7.1.2.


Thanks.

---
Kristian Eide





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

* Re: Why is my index not used
@ 2002-02-18 20:59  Chris Ruprecht <chrup999@yahoo.com>
  parent: Kristian Eide <kreide@online.no>
  1 sibling, 0 replies; 3+ messages in thread

From: Chris Ruprecht @ 2002-02-18 20:59 UTC (permalink / raw)
  To: Kristian Eide <kreide@online.no>; +Cc: pgsql-sql

try to cast your argument, for example, if misscnt is of type bigint, try:

explain select * from cam where misscnt>=1::int8;


Best regards,
Chris

At 19:54 +0100 02/18/2002, Kristian Eide wrote:
>I have a table, currently at about 150.000 rows, with a btree index on a
>field named 'misscnt'. ~138k of the rows have this fields set as null, ~12k
>as 0, ~350 as 1, ~200 as 2 and ~150 as 3 (these are the only values used).
>
>Still, I get the following:
>
># explain select * from cam where misscnt>=1;
>NOTICE:  QUERY PLAN:
>
>Seq Scan on cam  (cost=0.00..3609.59 rows=46896 width=66)
>
>Why do postgre think it will get over 46k rows from this query? If I try a
>VACUUM ANALYZE on the table, I get:
>
># explain select * from cam where misscnt>=1;
>NOTICE:  QUERY PLAN:
>
>Seq Scan on cam  (cost=0.00..3874.01 rows=50347 width=66)
>
>So now it actually thinks it will get _more_ rows:
>
># select count(*) from cam where misscnt>=1;
>  count
>-------
>    692
>
>If I use "set enable_seqscan=false;" and try "select * from cam where
>misscnt>=1;" the index is used, and the query executes quite a bit faster.
>However, shouldn't Postgre be able to do this automatically?
>
>This is using PostgreSQL 7.1.2.
>
>
>Thanks.
>
>---
>Kristian Eide
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


-- 
Chris Ruprecht
Network grunt and bit pusher extraordinaíre

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




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

* Re: Why is my index not used
@ 2002-02-18 21:04  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Kristian Eide <kreide@online.no>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2002-02-18 21:04 UTC (permalink / raw)
  To: Kristian Eide <kreide@online.no>; +Cc: pgsql-sql

"Kristian Eide" <kreide@online.no> writes:
> Why do postgre think it will get over 46k rows from this query?

Not sure (and you didn't give the pg_statistic data that might tell us
why).  But it's no longer a very interesting question; we will not be
fixing 7.1 optimizer bugs anymore.  Please try it in 7.2 and see if you
get better results.

			regards, tom lane



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


end of thread, other threads:[~2002-02-18 21:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-18 18:54 Why is my index not used Kristian Eide <kreide@online.no>
2002-02-18 20:59 ` Chris Ruprecht <chrup999@yahoo.com>
2002-02-18 21: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