Re: Bind message - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: Bind message
Date
Msg-id 24245.1159276238@sss.pgh.pa.us
Whole thread Raw
In response to Re: Bind message  (Markus Schaber <schabi@logix-tt.com>)
Responses Re: Bind message
List pgsql-jdbc
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

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: Bind message
Next
From: till toenges
Date:
Subject: Re: bytea memory improvement