Skip to content

Commit

Permalink
Cache a copy of ResultSetMetaData in the ResultSet.
Browse files Browse the repository at this point in the history
This solves a major performance problem for ResultSetMetaData users
which did not cache the ResultSetMetaData object.  One of the users
is the driver's own implementation of updatable ResultSets, so this
can't be worked around solely in end user code.

In the 9.0 and earlier releases, the Field objects were used to hold
database lookup results and these were longer lived than the
ResultSetMetaData object.  Now that ResultSetMetaData is holding
these database lookups we must hold onto the object to avoid
repeating the database queries.

Reported as bug #6293, fix by Steven Schlansker.
  • Loading branch information
kjurka committed Feb 10, 2012
1 parent 86b9794 commit 1934bf1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
12 changes: 11 additions & 1 deletion org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,18 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg

private HashMap columnNameIndexMap; // Speed up findColumn by caching lookups

public abstract ResultSetMetaData getMetaData() throws SQLException;
private ResultSetMetaData rsMetaData;

protected abstract ResultSetMetaData createMetaData() throws SQLException;

public ResultSetMetaData getMetaData() throws SQLException
{
checkClosed();
if (rsMetaData == null) {
rsMetaData = createMetaData();
}
return rsMetaData;
}

public AbstractJdbc2ResultSet(Query originalQuery, BaseStatement statement, Field[] fields, Vector tuples,
ResultCursor cursor, int maxRows, int maxFieldSize,
Expand Down
3 changes: 1 addition & 2 deletions org/postgresql/jdbc3/Jdbc3ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public class Jdbc3ResultSet extends org.postgresql.jdbc3.AbstractJdbc3ResultSet
super(originalQuery, statement, fields, tuples, cursor, maxRows, maxFieldSize, rsType, rsConcurrency, rsHoldability);
}

public java.sql.ResultSetMetaData getMetaData() throws SQLException
protected java.sql.ResultSetMetaData createMetaData() throws SQLException
{
checkClosed();
return new Jdbc3ResultSetMetaData(connection, fields);
}

Expand Down
3 changes: 1 addition & 2 deletions org/postgresql/jdbc3g/Jdbc3gResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public class Jdbc3gResultSet extends org.postgresql.jdbc3g.AbstractJdbc3gResultS
super(originalQuery, statement, fields, tuples, cursor, maxRows, maxFieldSize, rsType, rsConcurrency, rsHoldability);
}

public java.sql.ResultSetMetaData getMetaData() throws SQLException
protected java.sql.ResultSetMetaData createMetaData() throws SQLException
{
checkClosed();
return new Jdbc3gResultSetMetaData(connection, fields);
}

Expand Down
3 changes: 1 addition & 2 deletions org/postgresql/jdbc4/Jdbc4ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public class Jdbc4ResultSet extends AbstractJdbc4ResultSet implements java.sql.R
super(originalQuery, statement, fields, tuples, cursor, maxRows, maxFieldSize, rsType, rsConcurrency, rsHoldability);
}

public java.sql.ResultSetMetaData getMetaData() throws SQLException
protected java.sql.ResultSetMetaData createMetaData() throws SQLException
{
checkClosed();
return new Jdbc4ResultSetMetaData(connection, fields);
}

Expand Down

0 comments on commit 1934bf1

Please sign in to comment.