Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id DF6422E005B for ; Tue, 1 Apr 2008 12:50:11 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 79911-05 for ; Tue, 1 Apr 2008 12:50:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from fabaglexfr.fabasoft.com (fabaglexfr.fabasoft.com [192.84.221.196]) by developer.postgresql.org (Postfix) with ESMTP id 7AF2B2E0055 for ; Tue, 1 Apr 2008 12:50:07 -0300 (ADT) Received: from FABAMAIL.fabagl.fabasoft.com ([10.10.5.137]) by fabaglexfr.fabasoft.com with InterScan Messaging Security Suite; Tue, 01 Apr 2008 17:49:18 +0200 Content-class: urn:content-classes:message Subject: Re: Cursors and different settings for default_statistics_target MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Tue, 1 Apr 2008 17:48:04 +0200 x-mimeole: Produced By Microsoft Exchange V6.5 Message-ID: In-Reply-To: <2798.1207063805@sss.pgh.pa.us> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Cursors and different settings for default_statistics_target Thread-Index: AciUDQBYMQtnp9s1Q8+Q/c4qN7H0CwAAfxFQ References: <2798.1207063805@sss.pgh.pa.us> From: "Hell, Robert" To: "Tom Lane" Cc: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200804/9 X-Sequence-Number: 29502 That's it - I found a more simple statement which has the same problem (0.02 seconds vs. 6 seconds): With cursor (6 seconds): appcooelakdb2=3D> explain DECLARE curs_1 CURSOR FOR SELECT DISTINCT t2.objid FROM atobjval t2 WHERE t2.aggrid =3D 0 AND t2.attrid =3D 281479288455385 ORDER BY t2.objid; QUERY PLAN ------------------------------------------------------------------------ ---------------------- Unique (cost=3D0.00..1404823.63 rows=3D538 width=3D8) -> Index Scan using atobjvalix on atobjval t2 (cost=3D0.00..1404751.32 rows=3D28925 width=3D8) Index Cond: ((attrid =3D 281479288455385::bigint) AND (aggrid = =3D 0)) Without cursor (0.02 seconds) appcooelakdb2=3D> explain SELECT DISTINCT t2.objid FROM atobjval t2 = WHERE t2.aggrid =3D 0 AND t2.attrid =3D 281479288455385 ORDER BY t2.objid; QUERY PLAN ------------------------------------------------------------------------ ---------------------- Unique (cost=3D151717.85..151862.48 rows=3D538 width=3D8) -> Sort (cost=3D151717.85..151790.17 rows=3D28925 width=3D8) Sort Key: objid -> Bitmap Heap Scan on atobjval t2 (cost=3D1692.40..149574.51 rows=3D28925 width=3D8) Recheck Cond: (attrid =3D 281479288455385::bigint) Filter: (aggrid =3D 0) -> Bitmap Index Scan on ind_atobjval (cost=3D0.00..1685.16 rows=3D59402 width=3D0) Index Cond: (attrid =3D 281479288455385::bigint) What's the difference between plan calculation for cursors and straight queries? Kind regards, Robert -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 Sent: Dienstag, 01. April 2008 17:30 To: Hell, Robert Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] Cursors and different settings for default_statistics_target=20 "Hell, Robert" writes: > When we use 20 as default_statistics_target the retrieval of the data > takes 7.5 seconds - with 25 as default_statistics_target (with restart > and analyze) it takes 0.6 seconds. > The query plan is identical in both situations (row estimation differs a > little bit) - the query is always fast when it is executed without a > cursor. A cursor doesn't necessarily use the same plan as a straight query does. Try "EXPLAIN DECLARE curs_285058224 CURSOR FOR ..." and see if you aren't getting different plans in these two cases. regards, tom lane