Index problem

Поиск
Список
Период
Сортировка
От David Mitchell
Тема Index problem
Дата
Msg-id 42ADEE92.8020107@telogis.com
обсуждение исходный текст
Ответы Re: Index problem
Список pgsql-general
I'm totally baffled as to why postgres won't use this index. I have a
table "point" with an index on it as so:

CREATE INDEX unit_point
   ON point
   USING btree
   (unit_id, time);

When I try the following query, it insists on using a seqscan:

SELECT time FROM point
WHERE unit_id = 95501 and flags & 64 = 64
ORDER BY time DESC LIMIT 1;

If I enable_seqscan to off, then it uses the index. I have timed both
options and using the index is about 3 times faster. I have run vacuum
analyze on this table.  Here is the explain output:

seqscan = on:
Limit  (cost=12883.87..12883.87 rows=1 width=8)
   ->  Sort  (cost=12883.87..12883.99 rows=46 width=8)
         Sort Key: "time"
         ->  Seq Scan on point  (cost=0.00..12882.60 rows=46 width=8)
               Filter: ((unit_id = 95501::oid) AND (((flags)::integer &
64) = 64))

seqscan = off:
Limit  (cost=19710.90..19710.90 rows=1 width=8)
   ->  Sort  (cost=19710.90..19711.01 rows=46 width=8)
         Sort Key: "time"
         ->  Index Scan using unit_point on point  (cost=0.00..19709.63
rows=46 width=8)
               Index Cond: (unit_id = 95501::oid)
               Filter: (((flags)::integer & 64) = 64)

Can somebody please help?
--
David Mitchell
Software Engineer
Telogis

NOTICE:
This message (including any attachments) contains CONFIDENTIAL
INFORMATION intended for a specific individual and purpose, and
is protected by law.  If you are not the intended recipient,
you should delete this message and are hereby notified that any
disclosure, copying, or distribution of this message, or the
taking of any action based on it, is strictly prohibited.

В списке pgsql-general по дате отправления:

Предыдущее
От: Együd Csaba
Дата:
Сообщение: PG 8.0.1 is getting slow in 24 hours. Only daily VACUUM FULL helps
Следующее
От: Tom Lane
Дата:
Сообщение: Re: PG 8.0.1 is getting slow in 24 hours. Only daily VACUUM FULL helps