Index not used with prepared statement

Поиск
Список
Период
Сортировка
От Guido Neitzer
Тема Index not used with prepared statement
Дата
Msg-id 33A6D7B7-FDF3-456E-9154-402E9C5BC5D9@pharmaline.de
обсуждение исходный текст
Ответы Re: Index not used with prepared statement  (Andreas Seltenreich <andreas+pg@gate450.dyndns.org>)
Список 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 по дате отправления:

Предыдущее
От: Gavin Sherry
Дата:
Сообщение: Re: performance discrepancy indexing one column versus
Следующее
От: Andreas Seltenreich
Дата:
Сообщение: Re: Index not used with prepared statement