Lists: | pgsql-ru-general |
---|
From: | apm <korjavin(at)gmail(dot)com> |
---|---|
To: | pgsql-ru-general(at)postgresql(dot)org |
Subject: | Не используется индекс в запросе. |
Date: | 2008-05-31 05:38:53 |
Message-ID: | g1qo9f$jm8g1qo9f$jm8$1@ger.gmane.org@ger.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-ru-general |
Не пойму логики в простейшем случае.
Есть таблица
CREATE TABLE log
(
ip inet NOT NULL,
regdt timestamp NOT NULL DEFAULT now()
)
CREATE INDEX ix_log_ip
ON log
USING btree
(ip, regdt);
Делаю explain запроса
select count(*) from log
where ip='127.0.0.1' and regdt>cast (now() as timestamp);
Использует индекс ix_log_ip
но стоит изменить так
select count(*) from log
where ip='127.0.0.1'
and regdt>cast (now()-interval '1 day' as timestamp);
как получаю sec scan
тоже самое если использовать cast('20080101' as timestamp).
Как побороть?
From: | Alex Gorbachenko <agent_007(at)immo(dot)ru> |
---|---|
To: | pgsql-ru-general(at)postgresql(dot)org |
Subject: | Re: Не используется индекс в запросе. |
Date: | 2008-06-06 11:27:09 |
Message-ID: | 20080606152709.5709d7f5@satellite.immo |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-ru-general |
On Sat, 31 May 2008 11:38:53 +0600
apm wrote:
>как получаю sec scan
>тоже самое если использовать cast('20080101' as timestamp).
>
>Как побороть?
set enable_seqscan to off, но не думаю, что вы будете этому рады.
--
np: Dream Theater - Voices