postgresql-jdbc.git / summary / log / commit / refs
commit 567e26842095be327ff03b60bb55884be2ecf960
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Date: Thu Oct 29 19:10:37 2015 +0000
perf: optimize ResultSet.getObject
This change improves performance by eliminating TypeCache lookup on a per-row basis.
The first lookup is cached inside Field
org/postgresql/core/Field.java | 29 ++++++++++++++++++++++++
org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 27 ++++++++++++++++++----
2 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/org/postgresql/core/Field.java b/org/postgresql/core/Field.java
index 40a34b7c..23e534f9 100644
--- a/org/postgresql/core/Field.java
+++ b/org/postgresql/core/Field.java
@@ -38,6 +38,11 @@ public class Field
private String schemaName = "";
private int nullable = ResultSetMetaData.columnNullableUnknown;
private boolean autoIncrement = false;
+ private int sqlType;
+ private String pgType = NOT_YET_LOADED;
+
+ // New string to avoid clashes with other strings
+ private static final String NOT_YET_LOADED = new String("pgType is not yet loaded");
/*
* Construct a field based on the information fed to it.
@@ -200,4 +205,28 @@ public class Field
Oid.toString(oid) + "," + length + "," +
(format == TEXT_FORMAT ? 'T' : 'B') + ")";
}
+
+ public void setSQLType(int sqlType)
+ {
+ this.sqlType = sqlType;
+ }
+
+ public int getSQLType()
+ {
+ return sqlType;
+ }
+
+ public void setPGType(String pgType)
+ {
+ this.pgType = pgType;
+ }
+
+ public String getPGType()
+ {
+ return pgType;
+ }
+
+ public boolean isTypeInitialized() {
+ return pgType != NOT_YET_LOADED;
+ }
}
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index f98fd9c4..20105609 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -49,6 +49,7 @@ import org.postgresql.core.Query;
import org.postgresql.core.ResultCursor;
import org.postgresql.core.ResultHandler;
import org.postgresql.core.ServerVersion;
+import org.postgresql.core.TypeInfo;
import org.postgresql.core.Utils;
import org.postgresql.largeobject.LargeObject;
import org.postgresql.largeobject.LargeObjectManager;
@@ -1275,7 +1276,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
throws SQLException
{
checkColumnIndex(columnIndex);
- String columnTypeName = connection.getTypeInfo().getPGType(fields[columnIndex - 1].getOID());
+ String columnTypeName = getPGType(columnIndex);
updateValue(columnIndex, new NullObject(columnTypeName));
}
@@ -2880,14 +2881,30 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
return s;
}
- protected String getPGType( int column ) throws SQLException
+ protected String getPGType(int column) throws SQLException
{
- return connection.getTypeInfo().getPGType(fields[column - 1].getOID());
+ Field field = fields[column - 1];
+ initSqlType(field);
+ return field.getPGType();
}
- protected int getSQLType( int column ) throws SQLException
+ protected int getSQLType(int column) throws SQLException
{
- return connection.getTypeInfo().getSQLType(fields[column - 1].getOID());
+ Field field = fields[column - 1];
+ initSqlType(field);
+ return field.getSQLType();
+ }
+
+ private void initSqlType(Field field) throws SQLException
+ {
+ if (field.isTypeInitialized())
+ return;
+ TypeInfo typeInfo = connection.getTypeInfo();
+ int oid = field.getOID();
+ String pgType = typeInfo.getPGType(oid);
+ int sqlType = typeInfo.getSQLType(pgType);
+ field.setSQLType(sqlType);
+ field.setPGType(pgType);
}
private void checkUpdateable() throws SQLException
[parent: 6dc418356030]