Re: Perl Binding affects speed? - Mailing list pgsql-performance

From Marti Raudsepp
Subject Re: Perl Binding affects speed?
Date
Msg-id AANLkTi=ZUN+T3h+QT1ff1krbaxj62qVpQda4ECEjo1Ou@mail.gmail.com
Whole thread Raw
In response to Perl Binding affects speed?  ("Sam Wong" <sam@hellosam.net>)
Responses Re: Perl Binding affects speed?  (Martin Kjeldsen <martin@martinkjeldsen.dk>)
List pgsql-performance
On Fri, Feb 25, 2011 at 05:02, Sam Wong <sam@hellosam.net> wrote:
> * But if I do this - using binding:
> $dbh->selectall_arrayref("SELECT * from shipment_lookup WHERE (UPPER(lookup)
> LIKE ?)", undef, '0GURG5YGVQA9%');
> It took 10 seconds to finish the query, just like it was using full table
> scan instead! Even though the 'explain' shows the same query plan.

This is a pretty common shortcoming with placeholders. Since planning
of parameterized queries is done *before* binding parameters, the
planner has no knowledge of what the "?" placeholder actually is. Thus
it often gets the selectivity statistics wrong and produces worse
plans for your values.

AFAIK the only workaround is to not use variable binding in these
cases, but escape and insert your variables straight it into the SQL
query.

Regards,
Marti

pgsql-performance by date:

Previous
From: "Sam Wong"
Date:
Subject: Perl Binding affects speed?
Next
From: Martin Kjeldsen
Date:
Subject: Re: Perl Binding affects speed?