pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mitch Vincent <mitch@venux.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Timestamp indexes
Date: Fri, 21 Jul 2000 11:15:04 -0400
Message-ID: <13354.964192504@sss.pgh.pa.us> (raw)
In-Reply-To: <001d01bff323$39cdb250$4100000a@doot>
References: <001d01bff323$39cdb250$4100000a@doot>

"Mitch Vincent" <mitch@venux.net> writes:
> A while back I as told (by Tom Lane I *think*) that timestamp (previously
> datetime) fields couldn't be indexed as such

That's certainly not true now, if it ever was...

regression=# create table applicants(resubmitted timestamp);
CREATE
regression=# create index applicants_i on applicants(resubmitted);
CREATE
regression=# explain select * from applicants where resubmitted = 'today';
NOTICE:  QUERY PLAN:

Index Scan using applicants_i on applicants  (cost=0.00..8.14 rows=10 width=8)

EXPLAIN

> and that I should index them
> using this method :

> CREATE  INDEX "applicants_resubmitted" on "applicants" using btree ( date
> ("resubmitted") "date_ops" );

> Since almost all the queries that search that field  search it casting the
> field to date, I thought that would be OK.. It was for a while (in the 6.5.X
> days) but it seems that 7.0.2 is treating this different. I can't get an
> index scan on that field no matter what I do.

Dunno, it works for me ...

regression=# CREATE  INDEX "applicants_resubmitted" on "applicants"
regression-# (date("resubmitted") "date_ops" );
CREATE
regression=# explain select * from applicants where date(resubmitted) = 'today';
NOTICE:  QUERY PLAN:

Index Scan using applicants_resubmitted on applicants  (cost=0.00..8.16 rows=10
width=8)

EXPLAIN
regression=# explain select * from applicants where resubmitted::date = 'today';
NOTICE:  QUERY PLAN:

Index Scan using applicants_resubmitted on applicants  (cost=0.00..8.16 rows=10
width=8)

EXPLAIN

You would want an index on date() of the field if this is what most of
your queries look like --- a straight index on the timestamp isn't
useful for such a query.  But I don't know why you're not getting
index scans.  More details please?

			regards, tom lane



view thread (6+ messages)  latest in thread

Message-ID: <13354.964192504@sss.pgh.pa.us>
Permalink:  ../13354.964192504@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13354.964192504@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mitch@venux.net
  Subject: Re: Timestamp indexes
  In-Reply-To: <13354.964192504@sss.pgh.pa.us>
  References: <001d01bff323$39cdb250$4100000a@doot> <13354.964192504@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox