Re: Timestamps and performances problems

From: "Gaetano Mendola" <mendola(at)bigfoot(dot)com>
To: "Jean-Christophe ARNU (JX)" <jc(dot)arnu(at)free(dot)fr>, <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Timestamps and performances problems
Date: 2002-04-10 09:51:28
Message-ID: 004101c1e075$49103940$5ce8fea9@GMENDOLA2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"Jean-Christophe ARNU (JX)" <jc(dot)arnu(at)free(dot)fr> wrote:
> Hello all.
> I've a performance problem on specific requests :
>
> When I use timestamps + interval in where clauses, query performance is
> slowed down by a factor of 20 or 30!!!! For exemple :
> select timestamp,value
> from measure
> where timestamp<now() and timestamp>(now() - '1 hour'::interval)
>
> is 20 to 30 times longer than
>
> select timestamp,value
> from measure
> where timestamp<'2002-04-10 10:00' and timestamp>='2002-04-10 9:00';
>
> So where is the bottleneck?
> A paradigm seems that now() and (now() - '1hour'::interval) is evaluated
for
> each row comparison... Am I right? Thus is there a way to make SQL
> interpreter evaluate this by rewriting them before launching any
comparisons?
>
> Or do I have to rewrite all my application queries and calculate each
time
> now() and interval predicates?

I have the same problem, but in my case I use this query in a view so I
can't store the value now()
in a variable temp, I hope that this problem have another solution.

May be I can create a function that return a data set and I do the select
inside
with a temp variable for store now() but I don't know if is just a
quick & dirty solution.

Ciao
Gaetano.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Raphael Bauduin 2002-04-10 13:00:46 performance "tests"
Previous Message Jean-Christophe ARNU (JX) 2002-04-10 08:55:17 Timestamps and performances problems