Skip to content

Commit

Permalink
improved performance of database meta data access
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@1207 3dd849cd-670e-4645-a7cd-dd197c8d0e81
  • Loading branch information
rwisser committed Apr 19, 2017
1 parent 5692c13 commit b125520
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
32 changes: 30 additions & 2 deletions src/main/net/sf/jailer/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,36 @@ public class Configuration {
public boolean useInlineViewsInDataBrowser = true;
public String virtualColumnsQuery = null;
public String userDefinedColumnsQuery = null;
public String importedKeysQuery = null;
public String primaryKeysQuery = null;

public String importedKeysQuery =
"SELECT null, PKCU.TABLE_SCHEMA, PKCU.TABLE_NAME, PKCU.COLUMN_NAME,"
+ " null, KCU.TABLE_SCHEMA, KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.ORDINAL_POSITION,"
+ " null, null, RC.CONSTRAINT_NAME, RC.UNIQUE_CONSTRAINT_NAME, null"
+ " FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC"
+ " JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU"
+ " ON KCU.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG"
+ " AND KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA"
+ " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME"
+ " JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PKCU"
+ " ON PKCU.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG"
+ " AND PKCU.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA"
+ " AND PKCU.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME"
+ " AND PKCU.ORDINAL_POSITION = KCU.ORDINAL_POSITION"
+ " WHERE PKCU.TABLE_SCHEMA = '${SCHEMA}'"
+ " ORDER BY KCU.ORDINAL_POSITION";

public String primaryKeysQuery =
"SELECT null, KCU.TABLE_SCHEMA, KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.ORDINAL_POSITION, C.CONSTRAINT_NAME"
+ " FROM"
+ " INFORMATION_SCHEMA.TABLE_CONSTRAINTS C"
+ " JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU"
+ " ON KCU.CONSTRAINT_CATALOG = C.CONSTRAINT_CATALOG"
+ " AND KCU.CONSTRAINT_SCHEMA = C.CONSTRAINT_SCHEMA"
+ " AND KCU.CONSTRAINT_NAME = C.CONSTRAINT_NAME"
+ " WHERE C.CONSTRAINT_TYPE = 'PRIMARY KEY'"
+ " AND KCU.TABLE_SCHEMA = '${SCHEMA}'"
+ " ORDER BY KCU.ORDINAL_POSITION";

public String indexInfoQuery = null;
public String identifierQuoteString = "\"";
public DBMS dbms = DBMS.UNKNOWN;
Expand Down
44 changes: 25 additions & 19 deletions src/main/net/sf/jailer/modelbuilder/MetaDataCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,33 @@ public ResultSet forTable(String tableName) {
*/
private static void readMetaData(final MetaDataCache metaDataCache, Session session, String query, final Set<Integer> intIndex) throws SQLException {
metaDataCache.cache = new HashMap<String, List<Object[]>>();
session.executeQuery(query, new Session.AbstractResultSetReader() {
@Override
public void readCurrentRow(ResultSet resultSet) throws SQLException {
int numCol = getMetaData(resultSet).getColumnCount();
Object[] row = new Object[numCol];
for (int i = 1; i < numCol; ++i) {
if (intIndex.contains(i)) {
row[i - 1] = resultSet.getInt(i);
} else {
row[i - 1] = resultSet.getString(i);
boolean wasSilent = session.getSilent();
session.setSilent(true);
try {
session.executeQuery(query, new Session.AbstractResultSetReader() {
@Override
public void readCurrentRow(ResultSet resultSet) throws SQLException {
int numCol = getMetaData(resultSet).getColumnCount();
Object[] row = new Object[numCol];
for (int i = 1; i < numCol; ++i) {
if (intIndex.contains(i)) {
row[i - 1] = resultSet.getInt(i);
} else {
row[i - 1] = resultSet.getString(i);
}
}
String table = (String) row[2];
List<Object[]> rowList = metaDataCache.cache.get(table);
if (rowList == null) {
rowList = new ArrayList<Object[]>();
metaDataCache.cache.put(table, rowList);
}
rowList.add(row);
}
String table = (String) row[2];
List<Object[]> rowList = metaDataCache.cache.get(table);
if (rowList == null) {
rowList = new ArrayList<Object[]>();
metaDataCache.cache.put(table, rowList);
}
rowList.add(row);
}
});
});
} finally {
session.setSilent(wasSilent);
}
}

/**
Expand Down

0 comments on commit b125520

Please sign in to comment.