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 9EB88529A4 for ; Wed, 6 Jul 2005 18:19:51 -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 82655-04 for ; Wed, 6 Jul 2005 21:19:49 +0000 (GMT) Received: from dns.texnet.it (dns.texnet.it [217.19.150.6]) by svr1.postgresql.org (Postfix) with ESMTP id BD3B452998 for ; Wed, 6 Jul 2005 18:19:47 -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 1DqHJ4-000541-00 for ; Wed, 06 Jul 2005 23:19:47 +0200 Received: from niccolo by paros.rigacci.org with local (Exim 4.50) id 1DqHJ4-0000tt-8b for pgsql-performance@postgresql.org; Wed, 06 Jul 2005 23:19:46 +0200 Date: Wed, 6 Jul 2005 23:19:46 +0200 To: pgsql-performance@postgresql.org Subject: CURSOR slowes down a WHERE clause 100 times? Message-ID: <20050706211946.GA3460@rigacci.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i From: Niccolo Rigacci X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/52 X-Sequence-Number: 13293 Hi to all, 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. The wpt_comuni_view is a VIEW of a 3 tables JOIN, and the "wpt" field is a PostGIS geometry column. The "&&" is the PostGIS "overlaps" operator. If I CURSOR SELECT from a temp table instead of the JOIN VIEW the query time 1 second. If I omit the WHERE clause the CURSOR fetches results in 1 second. Can the CURSOR on JOIN affects so heavly the WHERE clause? I suspect that - with the CURSOR - a sequential scan is performed on the entire data set for each fetched record... Any idea? This is the definition of the VIEW: CREATE VIEW wpt_comuni_view AS SELECT istat_wpt.oid, istat_wpt.id, istat_wpt.toponimo, istat_comuni.residenti, istat_wpt.wpt FROM istat_comuni JOIN istat_comuni2wpt USING (idprovincia, idcomune) JOIN istat_wpt ON (idwpt = id); Thank you for any hint. -- Niccolo Rigacci Firenze - Italy War against Iraq? Not in my name!