Re: BUG #6293: JDBC driver performance - Mailing list pgsql-bugs

From Kris Jurka
Subject Re: BUG #6293: JDBC driver performance
Date
Msg-id alpine.BSO.2.00.1111161621580.14447@leary.csoft.net
Whole thread Raw
In response to BUG #6293: JDBC driver performance  ("Teun Hoogendoorn" <th@atsc.nl>)
Responses Re: [JDBC] BUG #6293: JDBC driver performance  (Steven Schlansker <stevenschlansker@gmail.com>)
List pgsql-bugs

On Tue, 15 Nov 2011, Teun Hoogendoorn wrote:

>
> The following bug has been logged online:
>
> Bug reference:      6293
> PostgreSQL version: 9.1
> Description:        JDBC driver performance
> Details:
>
> Using the postgresql-9.1-901.jdbc3.jar driver instead of
> postgresql-9.0-801.jdbc3.jar drops performance dramatically.
>
> I think it has something to do with using ResultSetMetaData in Java. The
> postgres log shows me hundreds of identical query's when retrieving the
> ResultSetMetaData for a single query. I'm not using an ORM framework, just
> simple JDBC calls.

The 9.1 JDBC driver was changed to try and fetch all metadata for the
entire resultset in one query instead of potentially issuing multiple
queries for each column.  So this change was supposed to improve things.

Looking at the code, the caching pattern has changed slightly, so now it's
important to hold onto the same ResultSetMetaData instance.  That is you
need to do:

ResultSet rs = ...
ResultSetMetaData rsmd = rs.getMetaData();
for (int i=1; i<rsmd.getColumnCount(); i++) {
    // good
    System.out.println(rsmd.getAutoIncrement());
    // bad
    System.out.println(rs.getMetaData().getAutoIncrement());
}

The driver should probably be changed to hand back the same
ResultSetMetaData instance each time instead of a new one for each
MetaData call.

Does this explain your problem?  If not, can you provide more details on
how you access and use ResultSetMetaData?

Kris Jurka


pgsql-bugs by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Cannot dump 8.4.8 database using later versions
Next
From: Kris Jurka
Date:
Subject: Re: BUG #6292: java.sql.PreparedStatement.setNull() throws PSQLException