| От | CSN |
|---|---|
| Тема | selecting rows older than X, ensuring index is used |
| Дата | |
| Msg-id | 20050820223301.34430.qmail@web52902.mail.yahoo.com обсуждение |
| Ответы |
Re: selecting rows older than X, ensuring index is used
|
| Список | pgsql-general |
Hi,
I want to select records that haven't had an error
(logged to last_error) in the last 24 hours. My query
is:
select * from table1
where last_error is null
or extract(epoch from now()-last_error) > 86400;
I've created an index on last_error (timestamp with
time zone - can be NULL), then used EXPLAIN:
Seq Scan on table1 (cost=0.00..20.86 rows=217
width=72)
Filter: ((last_error IS NULL) OR
(date_part('epoch'::text, (now() - last_error)) >
86400::double precision))
There are over 550 rows in table1, so it doesn't look
the index is being used. Is there a way to rewrite
this query so the index is used?
Thanks,
CSN
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера