Re: Index not used with prepared statement - Mailing list pgsql-performance

From Guido Neitzer
Subject Re: Index not used with prepared statement
Date
Msg-id 9FDFDA1B-5A2B-465F-A4BA-ED70D1BCE62A@pharmaline.de
Whole thread Raw
In response to Re: Index not used with prepared statement  (Andreas Seltenreich <andreas+pg@gate450.dyndns.org>)
List pgsql-performance
On 11.09.2005, at 11:03 Uhr, Andreas Seltenreich wrote:

> I'm not perfectly sure, but since the index could only be used with a
> subset of all possible parameters (the pattern for like has to be
> left-anchored), I could imagine the planner has to avoid the index in
> order to produce an universal plan (the thing behind a prepared
> statement).

Hmm. Now I get it. So I have to look that my framework doesn't
produce a preparedStatement, instead build a complete statement
string. Weird.

> Is there a reason you are using the like operator at all? IMO using
> the =-operator instead in your example should produce an "index-using
> prepared statement".

Yes, you are right, but then I can't pass anything like '45%' to the
query. It will just return nothing.

I use the "like" because I build the queries on the fly and add a %
at the end where necessary.

And, to be clear: this is a minimal example, most of my queries are
generated by a framework. This was an example to test the behaviour.

Okay, I had problems with the understanding of prepared statements on
the client and the server side. What I thought was, that I get a
preparedStatement by JDBC which also inserts the values into the
string and this is executed on the server side.

cug

pgsql-performance by date:

Previous
From: Andreas Seltenreich
Date:
Subject: Re: Index not used with prepared statement
Next
From: John A Meinel
Date:
Subject: Re: shared buffers