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 4C46552996 for ; Thu, 7 Jul 2005 07:07:05 -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 62964-03 for ; Thu, 7 Jul 2005 10:06:57 +0000 (GMT) Received: from dns.texnet.it (dns.texnet.it [217.19.150.6]) by svr1.postgresql.org (Postfix) with ESMTP id 5C1F352816 for ; Thu, 7 Jul 2005 07:06:56 -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 1DqTHX-0005yK-00 for ; Thu, 07 Jul 2005 12:06:59 +0200 Received: from niccolo by paros.rigacci.org with local (Exim 4.50) id 1DqTHW-00056m-G5 for pgsql-performance@postgresql.org; Thu, 07 Jul 2005 12:06:58 +0200 Date: Thu, 7 Jul 2005 12:06:58 +0200 To: pgsql-performance@postgresql.org Subject: Re: CURSOR slowes down a WHERE clause 100 times? Message-ID: <20050707100658.GA19237@rigacci.org> References: <20050706211946.GA3460@rigacci.org> <20050707081327.GA17054@rigacci.org> <42CCF28A.3010403@archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42CCF28A.3010403@archonet.com> User-Agent: Mutt/1.5.9i From: Niccolo Rigacci X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.084 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/61 X-Sequence-Number: 13302 On Thu, Jul 07, 2005 at 10:14:50AM +0100, Richard Huxton wrote: > >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. > I think you're misunderstanding exactly what's happening here. If you > ask for a cursor, PG assumes you aren't going to want all the results > (or at least not straight away). After all, most people use them to work > through results in comparatively small chunks, perhaps only ever > fetching 1% of the total results. This make finally sense! > In your case, since you're immediately issuing FETCH ALL, > you're not really using the cursor at all, but PG doesn't know > that. In fact, fetching only the first rows from the cursor, is rather quick! This demonstrates that the PG planner is smart. Not so smart are the MapServer and QGIS query builders, which use a CURSOR to FETCH ALL. I will investigate in this direction now. Thank you very much, your help was excellent! -- Niccolo Rigacci Firenze - Italy War against Iraq? Not in my name!