Optimization with dates

Поиск
Список
Период
Сортировка
От Jean-Christophe Boggio
Тема Optimization with dates
Дата
Msg-id 72319017913.20011114005656@thefreecat.org
обсуждение исходный текст
Ответы Re: Optimization with dates  ("Josh Berkus" <josh@agliodbs.com>)
Re: Optimization with dates  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Re: Optimization with dates  (Jason Earl <jason.earl@simplot.com>)
Re: Optimization with dates  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hello,

I really have a problem dealing with dates :

I have a big table (~10M rows) like :

create table gains (      dategain    timestamp,      otherfields
);

There's an index on dategain and I want to use it to get the last
30 days records :

explain select count(*) from gains where dategain>=now()-30;

Aggregate  (cost=256546.78..256546.78 rows=1 width=0) ->  Seq Scan on gains  (cost=0.00..250627.68 rows=2367640
width=0)

whereas : 
explain select count(*) from gains where dategain>='now';

Aggregate  (cost=27338.47..27338.47 rows=1 width=0) ->  Index Scan using ix_gains_dategain on gains
(cost=0.00..27320.71rows=7103 width=0)
 

I have tried : where dategain>=(select now()-30); where dategain+30>='now' where date(dategain)>=date('now')-30 and
manyother, syntactically absurd :-)
 

Anyone can help me use this index ?

TIA, 
--
Jean-Christophe Boggio                       
cat@thefreecat.org                           -o)
Independant Consultant and Developer         /\\
Delphi, Linux, Perl, PostgreSQL, Debian     _\_V



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

Предыдущее
От: marc@oscar.eng.cv.net (Marc Spitzer)
Дата:
Сообщение: Re: how do I update or insert efficently in postgres
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Re: Optimization with dates