From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Mitch Vincent" <mitch(at)venux(dot)net> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Timestamp indexes |
Date: | 2000-07-21 15:15:04 |
Message-ID: | 13354.964192504@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Mitch Vincent" <mitch(at)venux(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Mitch Vincent | 2000-07-21 15:53:25 | Re: Timestamp indexes |
Previous Message | DalTech - CTE | 2000-07-21 15:06:27 | Re: problem with view and case - please help |