Mercurial > hg > monetdb-java
comparison 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 |
comparison
equal
deleted
inserted
replaced
415:50e43af49d47 | 416:b3c876a0d61f |
---|---|
62 * The current state of this connection is that it nearly implements the | 62 * The current state of this connection is that it nearly implements the |
63 * whole Connection interface. | 63 * whole Connection interface. |
64 * | 64 * |
65 * @author Fabian Groffen | 65 * @author Fabian Groffen |
66 * @author Martin van Dinther | 66 * @author Martin van Dinther |
67 * @version 1.5 | 67 * @version 1.6 |
68 */ | 68 */ |
69 public class MonetConnection | 69 public class MonetConnection |
70 extends MonetWrapper | 70 extends MonetWrapper |
71 implements Connection, AutoCloseable | 71 implements Connection, AutoCloseable |
72 { | 72 { |
2098 private String[] type; | 2098 private String[] type; |
2099 /** The max string length for each column in this result */ | 2099 /** The max string length for each column in this result */ |
2100 private int[] columnLengths; | 2100 private int[] columnLengths; |
2101 /** The table for each column in this result */ | 2101 /** The table for each column in this result */ |
2102 private String[] tableNames; | 2102 private String[] tableNames; |
2103 /** The schema for each column in this result */ | |
2104 private String[] schemaNames; | |
2103 /** The query sequence number */ | 2105 /** The query sequence number */ |
2104 private final int seqnr; | 2106 private final int seqnr; |
2105 /** A List of result blocks (chunks of size fetchSize/cacheSize) */ | 2107 /** A List of result blocks (chunks of size fetchSize/cacheSize) */ |
2106 private DataBlockResponse[] resultBlocks; | 2108 private DataBlockResponse[] resultBlocks; |
2107 | 2109 |
2220 case HeaderLineParser.TYPE: | 2222 case HeaderLineParser.TYPE: |
2221 type = hlp.values.clone(); | 2223 type = hlp.values.clone(); |
2222 isSet[TYPES] = true; | 2224 isSet[TYPES] = true; |
2223 break; | 2225 break; |
2224 case HeaderLineParser.TABLE: | 2226 case HeaderLineParser.TABLE: |
2227 { | |
2225 tableNames = hlp.values.clone(); | 2228 tableNames = hlp.values.clone(); |
2229 final int array_size = tableNames.length; | |
2230 schemaNames = new String[array_size]; | |
2231 // split the schema and table names from the cloned values array | |
2232 for (int i = 0; i < array_size; i++) { | |
2233 String qtable = tableNames[i]; | |
2234 if (qtable != null) { | |
2235 int dot = qtable.indexOf('.'); | |
2236 if (dot >= 0) { | |
2237 schemaNames[i] = qtable.substring(0, dot); | |
2238 tableNames[i] = qtable.substring(dot +1); | |
2239 } else { | |
2240 schemaNames[i] = ""; | |
2241 } | |
2242 } else { | |
2243 schemaNames[i] = ""; | |
2244 tableNames[i] = ""; | |
2245 } | |
2246 } | |
2226 isSet[TABLES] = true; | 2247 isSet[TABLES] = true; |
2248 } | |
2227 break; | 2249 break; |
2228 } | 2250 } |
2229 } catch (MCLParseException e) { | 2251 } catch (MCLParseException e) { |
2230 return e.getMessage(); | 2252 return e.getMessage(); |
2231 } | 2253 } |
2330 * | 2352 * |
2331 * @return the tables of the columns | 2353 * @return the tables of the columns |
2332 */ | 2354 */ |
2333 String[] getTableNames() { | 2355 String[] getTableNames() { |
2334 return tableNames; | 2356 return tableNames; |
2357 } | |
2358 | |
2359 /** | |
2360 * Returns the schemas of the columns | |
2361 * | |
2362 * @return the schemas of the columns | |
2363 */ | |
2364 String[] getSchemaNames() { | |
2365 return schemaNames; | |
2335 } | 2366 } |
2336 | 2367 |
2337 /** | 2368 /** |
2338 * Returns the lengths of the columns | 2369 * Returns the lengths of the columns |
2339 * | 2370 * |