pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Neill <rn214@cam.ac.uk>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5293: constant function (date_trunc) is	 repeatedly evaluated inside loop
Date: Wed, 20 Jan 2010 16:56:16 +0000
Message-ID: <4B5735B0.7050106@cam.ac.uk> (raw)
In-Reply-To: <4B56CA85020000250002E85A@gw.wicourts.gov>
References: <201001201423.o0KENXDR099157@wwwmaster.postgresql.org>
	<4B56CA85020000250002E85A@gw.wicourts.gov>



Kevin Grittner wrote:
> "Richard Neill" <rn214@cam.ac.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



view thread (6+ messages)  latest in thread

Message-ID: <4B5735B0.7050106@cam.ac.uk>
Permalink:  ../4B5735B0.7050106@cam.ac.uk/
Also on:    postgresql.org/message-id/4B5735B0.7050106@cam.ac.uk

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: rn214@cam.ac.uk, Kevin.Grittner@wicourts.gov
  Subject: Re: BUG #5293: constant function (date_trunc) is	 repeatedly evaluated inside loop
  In-Reply-To: <4B5735B0.7050106@cam.ac.uk>

* 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