Received: from mel-rto4.wanadoo.fr (smtp-out-4.wanadoo.fr [193.252.19.23]) by postgresql.org (Postfix) with ESMTP id 863A0475452 for ; Wed, 10 Apr 2002 04:31:10 -0400 (EDT) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto4.wanadoo.fr; 10 Apr 2002 10:31:11 +0200 Received: from ez (217.128.2.234) by mel-rta7.wanadoo.fr; 10 Apr 2002 10:31:09 +0200 Date: Wed, 10 Apr 2002 04:22:15 -0400 From: Jean-Christophe ARNU (JX) To: pgsql-admin@postgresql.org Subject: Timestamps and performances problems Message-Id: <20020410042215.38c9f863.arnu@paratronic.fr> Organization: Paratronic X-Mailer: Sylpheed version 0.7.3 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Archive-Number: 200204/117 X-Sequence-Number: 4005 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? Thanks by advance -- Jean-Christophe ARNU s/w developer Paratronic France > Notre devoir, pour leur bien et pour le bien de Linux, est de te > flinguer avant que tu ne les sacrifies (fût-ce avec les meilleures > intentions du monde). -+- TP In: Guide du linuxien pervers : "De la pédagogie par l'Exemple"