Indexing timestamps

Поиск
Список
Период
Сортировка
От Andre Schubert
Тема Indexing timestamps
Дата
Msg-id 20020606104521.3b3f1b06.andre.schubert@km3.de
обсуждение исходный текст
Ответы Re: Indexing timestamps  ("Josh Berkus" <josh@agliodbs.com>)
Список pgsql-sql
Hi all,

i have some questions on indexing a timestamp column of a table.

i have the following structure:

create table test_table( time_stamp datetime, id int8);
create index test_index on test_table using btree(time_stamp);

select count(*) from tbl_traffic;count  
--------116894

I have questions on the following explains:

explain select * from test_table where time_stamp = datetime('2002-01-01');
NOTICE:  QUERY PLAN:

Index Scan using test_index on test_table  (cost=0.00..1651.78 rows=584 width=16)

explain select * from test_table where time_stamp = datetime(now());
NOTICE:  QUERY PLAN:

Seq Scan on test_table  (cost=0.00..2733.64 rows=584 width=16)

Why is the index test_index not used with the now() function?
If it is possible, how should i create i index that is used with now()?



explain select * from test_table where date_trunc('month',time_stamp) = date_trunc('month',datetime('2002-01-01'));
NOTICE:  QUERY PLAN:

Seq Scan on test_table  (cost=0.00..2441.41 rows=584 width=16)

explain select * from test_table where date_trunc('month',time_stamp) = date_trunc('month',datetime(now()));
NOTICE:  QUERY PLAN:

Seq Scan on test_table  (cost=0.00..3318.12 rows=584 width=16)

I need to select all data from this table monthly by select data of the last month.
Can anyone explain me why the second Seq scan takes longer than the first one and
is there i whay to define a index that is used if i do such a select, or better
is there a better select statement that uses some indexes??

Thanks in advance, hope someone could answer my questions :)


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

Предыдущее
От: Ludwig Lim
Дата:
Сообщение: Re: simple select statement inquiry
Следующее
От: "D'Arcy J.M. Cain"
Дата:
Сообщение: Re: PostgreSQL on AIX