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

From Guido Neitzer
Subject Index not used with prepared statement
Date
Msg-id 33A6D7B7-FDF3-456E-9154-402E9C5BC5D9@pharmaline.de
Whole thread Raw
Responses Re: Index not used with prepared statement
List pgsql-performance
Hi.

I have a performance problem with prepared statements (JDBC prepared
statement).

This query:

PreparedStatement st = conn.prepareStatement("SELECT id FROM
dga_dienstleister WHERE plz like '45257'");

does use an index.

This query:

         String plz = "45257";
         PreparedStatement st = conn.prepareStatement("SELECT id FROM
dga_dienstleister WHERE plz like ?");
         st.setString(1, plz);

does NOT use an index.

As it should in the end result in absolutely the same statement, the
index should be used all the time. I have to set the
protocolVersion=2 and use the JDBC2 driver to get it working (but
then the statements are created like in the first query, so no
solution, only a workaround).

I'm not sure whether this is a bug (I think it is) or a problem of
understanding.

Known problem?

I have tried PG 8.0.1, 8.0.3, 8.1beta with the JDBC-drivers

- postgresql-8.0-312.jdbc2.jar --> okay with protocolVersion=2 in the
URL
- postgresql-8.0-312.jdbc3.jar --> not okay whatever I do

I'm on Mac OS X, if that matters.

cug

pgsql-performance by date:

Previous
From: Gavin Sherry
Date:
Subject: Re: performance discrepancy indexing one column versus
Next
From: Andreas Seltenreich
Date:
Subject: Re: Index not used with prepared statement