X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6612C529F3 for ; Thu, 7 Jul 2005 05:13:32 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41190-09 for ; Thu, 7 Jul 2005 08:13:27 +0000 (GMT) Received: from dns.texnet.it (dns.texnet.it [217.19.150.6]) by svr1.postgresql.org (Postfix) with ESMTP id 97F8C529BE for ; Thu, 7 Jul 2005 05:13:27 -0300 (ADT) Received: from pool-a-150.texnet.it ([217.19.150.150] helo=paros.rigacci.org) by dns.texnet.it with esmtp (Exim 3.35 #1 (Debian)) id 1DqRVg-00042R-00 for ; Thu, 07 Jul 2005 10:13:28 +0200 Received: from niccolo by paros.rigacci.org with local (Exim 4.50) id 1DqRVf-0004TL-VP for pgsql-performance@postgresql.org; Thu, 07 Jul 2005 10:13:27 +0200 Date: Thu, 7 Jul 2005 10:13:27 +0200 To: pgsql-performance@postgresql.org Subject: Re: CURSOR slowes down a WHERE clause 100 times? Message-ID: <20050707081327.GA17054@rigacci.org> References: <20050706211946.GA3460@rigacci.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050706211946.GA3460@rigacci.org> User-Agent: Mutt/1.5.9i From: Niccolo Rigacci X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.102 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/59 X-Sequence-Number: 13300 On Wed, Jul 06, 2005 at 11:19:46PM +0200, Niccolo Rigacci wrote: > > I have a performace problem with the following query: > > BEGIN; > DECLARE mycursor BINARY CURSOR FOR > SELECT > toponimo, > wpt > FROM wpt_comuni_view > WHERE ( > wpt && > setSRID('BOX3D(4.83 36, 20.16 47.5)'::BOX3D, 4326) > ); > FETCH ALL IN mycursor; > END; > > I get the results in about 108 seconds (8060 rows). > > If I issue the SELECT alone (without the CURSOR) I get the > same results in less than 1 second. By trial and error I discovered that adding an "ORDER BY toponimo" clause to the SELECT, boosts the CURSOR performances so that they are now equiparable to the SELECT alone. Is there some documentation on how an ORDER can affect the CURSOR in a different way than the SELECT? -- Niccolo Rigacci Firenze - Italy War against Iraq? Not in my name!