Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BC4246338B9 for ; Fri, 3 Jul 2009 11:24:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 24079-04 for ; Fri, 3 Jul 2009 11:24:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id C8E316331CA for ; Fri, 3 Jul 2009 11:24:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n63EOZmP000750; Fri, 3 Jul 2009 10:24:35 -0400 (EDT) To: Oliver Jowett cc: Robin Houston , PostgreSQL - JDBC Subject: Re: Cursor-based results: bafflingly slow In-reply-to: <4A4E11EB.4040809@opencloud.com> References: <1b795e7b0907030546o7e44ebcdteb1168c9d6680380@mail.gmail.com> <1b795e7b0907030601x53ad69efk5412acc1a2595c61@mail.gmail.com> <4A4E04D1.5010905@opencloud.com> <1b795e7b0907030639r562a9006g4c3b286bce3e5d7b@mail.gmail.com> <4A4E11EB.4040809@opencloud.com> Comments: In-reply-to Oliver Jowett message dated "Sat, 04 Jul 2009 02:12:59 +1200" Date: Fri, 03 Jul 2009 10:24:35 -0400 Message-ID: <749.1246631075@sss.pgh.pa.us> From: Tom Lane 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: 200907/8 X-Sequence-Number: 19776 Oliver Jowett writes: > If you want to stream results promptly, you may be stuck with removing > that ORDER BY. I'm not sure if there's any way to say to the planner > "give me a plan with a low startup cost, even if it has a higher total > cost" which seems to be what you want here. You need to use a cursor for that. The problem with the fetchsize mechanism is that it doesn't give the planner any clue that the user might not intend to fetch the whole result, or might prefer low startup cost to low total cost anyway. > I came across some (very old) posts in the archives that suggested that > DECLARE CURSOR has a fudge where it ranks plan costs assuming that only > some rows (10%?) will actually be fetched. I'm not sure if that's true > of the current planner. Exactly. As of 8.4 you can control the percentage, too. regards, tom lane