Re: Indexing timestamps - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Indexing timestamps
Date
Msg-id web-1501412@davinci.ethosmedia.com
Whole thread Raw
In response to Indexing timestamps  (Andre Schubert <andre.schubert@km3.de>)
Responses Re: Indexing timestamps  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-sql
Andre,

I'm not even going to try to deal with the seq_scan vs. index_scan
issues on now().  This has been brought up in the list archives.  Test
your actual response times as well as the query plan; you may find that
you don't have a real problem.

Something I can help you with:

> 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)

Try doing a:
CREATE INDEX idx_test_month ON test_table(extract(month FROM
time_stamp));

Which should help.

-Josh




pgsql-sql by date:

Previous
From: "Travis Hoyt"
Date:
Subject: Re: PostgreSQL on AIX
Next
From: Roberto Mello
Date:
Subject: Re: extract and variables in PL/pgSQL