Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 83B5F2E027F for ; Thu, 13 Dec 2007 19:31:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 67775-06 for ; Thu, 13 Dec 2007 19:31:10 -0400 (AST) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1F8A32E003D for ; Thu, 13 Dec 2007 19:31:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id lBDNV5xn022414; Thu, 13 Dec 2007 18:31:06 -0500 (EST) To: Oliver Jowett cc: Tom Duffey , pgsql-jdbc@postgresql.org Subject: Re: Slow query after upgrades In-reply-to: <4761BACA.4020008@opencloud.com> References: <3EB52707-C945-43D6-9B3F-15F3B228D6F6@techbydesign.com> <4761A221.80604@opencloud.com> <1d4e0c10712131358m4bbc3f57t7e33c6c8ad2b3710@mail.gmail.com> <435EC9B4-F3DD-4136-9070-93E0DBB94B3F@techbydesign.com> <1d4e0c10712131452l65841793r449eb3c7cffbf3a5@mail.gmail.com> <0116C2A9-8DB5-4EBE-A66B-BE7F2A11651C@techbydesign.com> <4761BACA.4020008@opencloud.com> Comments: In-reply-to Oliver Jowett message dated "Fri, 14 Dec 2007 12:05:46 +1300" Date: Thu, 13 Dec 2007 18:31:05 -0500 Message-ID: <22413.1197588665@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/103 X-Sequence-Number: 17958 Oliver Jowett writes: > Tom Duffey wrote: >> This makes a huge difference, thanks. However, is there anything I can >> do to help improve the performance of that query when using a newer >> protocol? > We need to work out what is going wrong under the newer protocol first, It looks pretty obvious from the peanut gallery: in the parameterized query, the planner daren't choose an indexscan, because for the vast majority of the possible values of the parameter an indexscan would suck. Tom's apparently only interested in the case where the parameter is close to the end of the range, so that only a few rows need to be retrieved. In this case the indexscan wins big, but the planner can't count on that. A possible hack is to put a reasonably small LIMIT on the query. regards, tom lane