From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: David Olbersen <DOlbersen@stbernard.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Type casting and indexes
Date: Thu, 8 May 2003 09:13:29 -0700 (PDT)
Message-ID: <20030508090101.K43697-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <E7E213858379814A9AE48CA6754F5ECB0D6DDE@mail01.stbernard.com>
On Thu, 8 May 2003, David Olbersen wrote:
> Anyway, I've found a (bug|feature|standard?) with type casting and index usage.
>
> I've got a table with a column that's a timestamp with time zone. This
> column is indexed. If I issue the "normal" query of:
>
> SELECT count(*) FROM foo WHERE bar > '2003-05-05':;timestamp
>
> I get the following EXPLAIN ANALYZE output:
>
> urldb=> explain select count(*) from foo where bar > '2003-05-05'::timestamp;
> QUERY PLAN
> ------------------------------------------------------------------------
> Aggregate (cost=89960.75..89960.75 rows=1 width=0) (actual time=
> 56706.58..56706.58 rows=1 loops=1)
> -> Seq Scan on urlinfo (cost=0.00..87229.45 rows=1092521 width=0) (actual
> time=25.37..56537.86 rows=27490 loops=1)
> Filter: (ratedon > ('2003-05-05 00:00:00'::timestamp without time
> zone)::timestamp with time zone)
> Total runtime: 56706.67 msec
>
> So it seems that the type conversion is killing the use of the index,
> even though the type conversion has to happen for the condition to be
> tested.
IIRC, timestamp->timestamptz is not considered to give a constant value
(ie, is not stable) probably since it depends on timezone settings which
could be changed (for example by a function) during the query, so for each
row the conversion from '2003-05-05 00:00:00'::timestamp without time zone
to a timestamp with time zone can potentially give a different answer.
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-performance@postgresql.org
Cc: sszabo@megazone23.bigpanda.com, DOlbersen@stbernard.com
Subject: Re: Type casting and indexes
In-Reply-To: <20030508090101.K43697-100000@megazone23.bigpanda.com>
References: <E7E213858379814A9AE48CA6754F5ECB0D6DDE@mail01.stbernard.com> <20030508090101.K43697-100000@megazone23.bigpanda.com>
* 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