Re: Select on timestamp-day slower than timestamp alone - Mailing list pgsql-performance

From Richard Huxton
Subject Re: Select on timestamp-day slower than timestamp alone
Date
Msg-id 200305061404.24194.dev@archonet.com
Whole thread Raw
In response to Select on timestamp-day slower than timestamp alone  (Reiner Dassing <dassing@wettzell.ifag.de>)
Responses Re: Select on timestamp-day slower than timestamp alone
List pgsql-performance
On Tuesday 06 May 2003 7:59 am, Reiner Dassing wrote:
> Hello all!
>
> On PostgreSQL V7.3.2 on TRU64 I recognized the following phenomena
> that a SELECT using a difference of a timestamp and an interval
> in the WHERE clause does not use the index
> but using a timestamp without a difference does use the index.
> The semantic of both SELECT's is equal, i.e., the result is equal.
>
> Therefore, the second way is much faster.
>
> Any ideas?

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

--
  Richard Huxton


pgsql-performance by date:

Previous
From: Ron Johnson
Date:
Subject: Re: [HACKERS] Hypothetical suggestions for planner,
Next
From: "Jim C. Nasby"
Date:
Subject: Re: [HACKERS] Hypothetical suggestions for planner, indexing improvement