Mercurial > hg > monetdb-java
diff src/main/java/org/monetdb/jdbc/MonetConnection.java @ 416:b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Previously getSchemaName() and getTableName() would extract the schema name or the table name from a single string containing both, separated by a dot.
Now this is done once at a higher level (ResultSetResponse) and the values can be accessed directly.
The methods getPrecision(), getScale(), isNullable() and isAutoIncrement() used to call fetchColumnInfo() which created a MonetDatabaseMetaData object and next call MonetDatabaseMetaData.getColumns() method.
However this getColumns() method queries and returns much more info than really needed for the methods in ResultSetMetaData. It is a costly (and slow) method.
Hence it is now replaced with a smaller and faster custom query (based on the query from getColumns()) which runs much faster.
Also the creation of a MonetDatabaseMetaData object is no longer needed and has been removed.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 20 Jan 2021 23:54:03 +0100 (2021-01-20) |
parents | 1e278695fe54 |
children | 8368cbc670bf |
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java @@ -64,7 +64,7 @@ import org.monetdb.mcl.parser.StartOfHea * * @author Fabian Groffen * @author Martin van Dinther - * @version 1.5 + * @version 1.6 */ public class MonetConnection extends MonetWrapper @@ -2100,6 +2100,8 @@ public class MonetConnection private int[] columnLengths; /** The table for each column in this result */ private String[] tableNames; + /** The schema for each column in this result */ + private String[] schemaNames; /** The query sequence number */ private final int seqnr; /** A List of result blocks (chunks of size fetchSize/cacheSize) */ @@ -2222,8 +2224,28 @@ public class MonetConnection isSet[TYPES] = true; break; case HeaderLineParser.TABLE: + { tableNames = hlp.values.clone(); + final int array_size = tableNames.length; + schemaNames = new String[array_size]; + // split the schema and table names from the cloned values array + for (int i = 0; i < array_size; i++) { + String qtable = tableNames[i]; + if (qtable != null) { + int dot = qtable.indexOf('.'); + if (dot >= 0) { + schemaNames[i] = qtable.substring(0, dot); + tableNames[i] = qtable.substring(dot +1); + } else { + schemaNames[i] = ""; + } + } else { + schemaNames[i] = ""; + tableNames[i] = ""; + } + } isSet[TABLES] = true; + } break; } } catch (MCLParseException e) { @@ -2335,6 +2357,15 @@ public class MonetConnection } /** + * Returns the schemas of the columns + * + * @return the schemas of the columns + */ + String[] getSchemaNames() { + return schemaNames; + } + + /** * Returns the lengths of the columns * * @return the lengths of the columns