Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 383299FB31A for ; Tue, 26 Sep 2006 10:10:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 85623-02 for ; Tue, 26 Sep 2006 13:10:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 91ACC9FB24B for ; Tue, 26 Sep 2006 10:10:41 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k8QDAcii024246; Tue, 26 Sep 2006 09:10:38 -0400 (EDT) To: Markus Schaber cc: pgsql-jdbc@postgresql.org Subject: Re: Bind message In-reply-to: <4519166D.9040705@logix-tt.com> References: <451846B0.6070906@logix-tt.com> <45184D61.3010007@opencloud.com> <4518E986.3030801@logix-tt.com> <4518FF16.3050804@opencloud.com> <4519166D.9040705@logix-tt.com> Comments: In-reply-to Markus Schaber message dated "Tue, 26 Sep 2006 14:00:45 +0200" Date: Tue, 26 Sep 2006 09:10:38 -0400 Message-ID: <24245.1159276238@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200609/119 X-Sequence-Number: 15837 Markus Schaber writes: > Don't forget that, in the current implementation, the query planner has > no choice but planning the query without any actual parameter values, > which is likely to give equal or worse results in most cases. No, I think you are oversimplifying. What the planner is supposed to do when given a parameterized query (and no parameter value info) is to generate a plan that won't be too terribly awful regardless of the parameter values. With a set of sample values, it may generate a plan that is great for those values and utterly unusable for anything else. Here's a simple example: select ... from a join b on (a.key = b.key) where a.val = ? Given a parameter value that looks like it will match only one A row, you will likely get a plan like this: Nest Loop Index Scan on A Index Cond: val = ? Index Scan on B Index Cond: b.key = a.key which is about as fast as you can get if indeed there's only one match. However if the parameter value matches very many A rows, this plan is horrid. With no value for the parameter, the planner should pick a compromise plan (perhaps a mergejoin) that may not be as fast for the single-match case, but will finish before doomsday in the other case. regards, tom lane