Re: Select on timestamp-day slower than timestamp alone

From: Reiner Dassing <dassing(at)wettzell(dot)ifag(dot)de>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Select on timestamp-day slower than timestamp alone
Date: 2003-05-06 14:00:32
Message-ID: 3EB7C000.9030206@wettzell.ifag.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello Richard!

Your proposal to use an explicit cast to "with time zone" helps:

explain
select * from wetter where epoche between
'2003-05-06 06:50:54+00'::timestamp with time zone-'1 days'::interval
AND '2003-05-06 04:45:36';


QUERY PLAN

---------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using wetter_epoche_idx on wetter (cost=0.00..5.45 rows=1
width=16)
Index Cond: ((epoche >= '2003-05-05 06:50:54+00'::timestamp with
time zone) AND (epoche <= '2003-05-06 04:45:36+00'::timestamp with time
zone))
(2 rows)

The result now is like expected.

Thanks for the help.
But for your question "why we get "timestamp without time zone"."
I have no answer.

Reiner

>
>>Select not using index:
>>-----------------------
>>wetter=# explain select * from wetter where epoche between
>>'2003-05-06 06:50:54+00'::timestamp-'1 days'::interval
>>AND '2003-05-06 04:45:36';
>>
>> QUERY PLAN
>>
>>---------------------------------------------------------------------------
>>----------------------------------------------------------------------------
>>-------------------- Seq Scan on wetter (cost=0.00..768644.57 rows=10253528
>>width=16) Filter: ((epoche >= ('2003-05-05 06:50:54'::timestamp without
>>time zone)::timestamp with time zone) AND (epoche <= '2003-05-06
>>04:45:36+00'::timestamp with time zone))
>>(2 rows)
>
>
> Well, the "why" is because the number of rows recommended is so big
> (rows=10253528) - I'm also puzzled why we get "timestamp without time zone".
> Does an explicit cast to "with time zone" help?
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Christopher Kings-Lynne 2003-05-06 14:04:39 Re: [PERFORM] Hypothetical suggestions for planner, indexing
Previous Message Tom Lane 2003-05-06 13:59:08 Re: Select on timestamp-day slower than timestamp alone