Re: BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop

From: Richard Neill <rn214(at)cam(dot)ac(dot)uk>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop
Date: 2010-01-20 16:56:16
Message-ID: 4B5735B0.7050106@cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Kevin Grittner wrote:
> "Richard Neill" <rn214(at)cam(dot)ac(dot)uk> wrote:
>
>> date_trunc('day', timestamp '2010-01-20 10:16:55')
>
> What happens with a "timestamp with time zone" literal?
>
> -Kevin
>

Good call!

This query is fast:

SELECT count(1) FROM tbl_tracker WHERE ((srep_timestamp >=
date_trunc('day', timestamp with time zone '2010-01-20 10:16:55') AND
srep_timestamp < date_trunc('day', timestamp with time zone '2010-01-20
10:16:55') + INTERVAL '24 hour' )) ;

In other words:

#fast
WHERE column < '2010-010-20 00:00:00'

#fast
WHERE column < date_trunc('day', timestamp with time zone
'2010-01-20 10:16:55')

#slow
WHERE column < date_trunc('day', timestamp
'2010-01-20 10:16:55')

Why is that, I wonder?

Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2010-01-20 17:04:09 Re: BUG #5293: constant function (date_trunc) is repeatedly evaluated inside loop
Previous Message Kevin Grittner 2010-01-20 15:21:46 Re: BUG #5292: Corrupted installer