pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Markus Schaber <schabi@logix-tt.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bind message
Date: Tue, 26 Sep 2006 09:10:38 -0400
Message-ID: <24245.1159276238@sss.pgh.pa.us> (raw)
In-Reply-To: <4519166D.9040705@logix-tt.com>
References: <D4D1632DC736E74AB95FE78CD609007923B0F7@mtxexch01.add0.masergy.com>
	<Pine.BSO.4.63.0609251417310.4350@leary2.csoft.net>
	<451846B0.6070906@logix-tt.com>
	<45184D61.3010007@opencloud.com>
	<4518E986.3030801@logix-tt.com>
	<4518FF16.3050804@opencloud.com>
	<4519166D.9040705@logix-tt.com>

Markus Schaber <schabi@logix-tt.com> 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



view thread (18+ messages)  latest in thread

Message-ID: <24245.1159276238@sss.pgh.pa.us>
Permalink:  ../24245.1159276238@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24245.1159276238@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tgl@sss.pgh.pa.us, schabi@logix-tt.com
  Subject: Re: Bind message
  In-Reply-To: <24245.1159276238@sss.pgh.pa.us>
  References: <D4D1632DC736E74AB95FE78CD609007923B0F7@mtxexch01.add0.masergy.com> <Pine.BSO.4.63.0609251417310.4350@leary2.csoft.net> <451846B0.6070906@logix-tt.com> <45184D61.3010007@opencloud.com> <4518E986.3030801@logix-tt.com> <4518FF16.3050804@opencloud.com> <4519166D.9040705@logix-tt.com> <24245.1159276238@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox