X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E85A532A14F; Wed, 29 Sep 2004 09:40:42 +0100 (BST) 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 37453-09; Wed, 29 Sep 2004 08:40:33 +0000 (GMT) Received: from anchor-post-36.mail.demon.net (anchor-post-36.mail.demon.net [194.217.242.86]) by svr1.postgresql.org (Postfix) with ESMTP id A94E932A15F; Wed, 29 Sep 2004 09:40:25 +0100 (BST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-36.mail.demon.net with esmtp (Exim 4.42) id 1CCa0S-000JEe-KA; Wed, 29 Sep 2004 08:40:12 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id BDE34167EE; Wed, 29 Sep 2004 09:40:10 +0100 (BST) Message-ID: <415A74EB.9040308@archonet.com> Date: Wed, 29 Sep 2004 09:40:11 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) X-Accept-Language: en-us, en MIME-Version: 1.0 To: John Meinel Cc: pgsql-hackers-win32 , pgsql-performance@postgresql.org Subject: Re: [PERFORM] Poor Performance for large queries References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> <22682.1096434647@sss.pgh.pa.us> <415A575F.2060802@johnmeinel.com> In-Reply-To: <415A575F.2060802@johnmeinel.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/158 X-Sequence-Number: 2288 John Meinel wrote: > > So notice that when doing the actual select it is able to do the index > query. But for some reason with a prepared statement, it is not able to > do it. > > Any ideas? In the index-using example, PG knows the value you are comparing to. So, it can make a better estimate of how many rows will be returned. With the prepared/compiled version it has to come up with a plan that makes sense for any value. If you look back at the explain output you'll see PG is guessing 181,923 rows will match with the prepared query but only 1 for the second query. If in fact you returned that many rows, you wouldn't want to use the index - it would mean fetching values twice. The only work-around if you are using plpgsql functions is to use EXECUTE to make sure your queries are planned for each value provided. -- Richard Huxton Archonet Ltd