Received: from nts-03.mm.eutelsat.org (nts-03.mm.eutelsat.org [194.214.173.15]) by postgresql.org (Postfix) with ESMTP id 6D796475951 for ; Wed, 10 Apr 2002 05:51:41 -0400 (EDT) Received: from dell-01.mm.eutelsat.org (IDENT:root@dell-01.mm.eutelsat.org [194.214.173.17]) by nts-03.mm.eutelsat.org (8.9.3/8.8.7) with ESMTP id LAA00817; Wed, 10 Apr 2002 11:49:35 +0200 Received: from GMENDOLA2 (gmendola2.mm.eutelsat.org [194.214.173.26]) by dell-01.mm.eutelsat.org (8.11.2/8.8.7) with SMTP id g3A9pSF30149; Wed, 10 Apr 2002 11:51:28 +0200 Message-ID: <004101c1e075$49103940$5ce8fea9@GMENDOLA2> From: "Gaetano Mendola" To: "Jean-Christophe ARNU (JX)" , References: <20020410045517.57c89e27.jc.arnu@free.fr> Subject: Re: Timestamps and performances problems Date: Wed, 10 Apr 2002 11:51:28 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200204/79 X-Sequence-Number: 3967 "Jean-Christophe ARNU (JX)" 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() - '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.