Skip to content

Commit

Permalink
Add flag for whether table index stats are supported (H2), and ignore if
Browse files Browse the repository at this point in the history
not. Fixes #444
  • Loading branch information
andyjefferson committed Jul 8, 2022
1 parent 74942f1 commit a08ed02
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ public interface DatastoreAdapter
*/
public static final String RAW_PREFIX_LIKE_STATEMENTS = "RawPrefixLikeStatements";

public static final String INCLUDE_TABLE_INDEX_STATISTICS = "IncludeTableIndexStatistics";

/**
* Initialise the datastore adapter.
* @param handler SchemaHandler that we initialise the types for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public H2Adapter(DatabaseMetaData metadata)
}
}

// H2 v2, at least, requires this
supportedOptions.add(INCLUDE_TABLE_INDEX_STATISTICS);

supportedOptions.add(PRIMARYKEY_IN_CREATE_STATEMENTS);
supportedOptions.add(LOCK_ROW_USING_SELECT_FOR_UPDATE);
supportedOptions.add(IDENTITY_COLUMNS);
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/org/datanucleus/store/rdbms/table/TableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,18 @@ private Map<DatastoreIdentifier, Index> getExistingIndices(Connection conn)
Iterator indexIter = tableIndexInfo.getChildren().iterator();
while (indexIter.hasNext())
{
// No idea of why this was being used, so commented out (H2 v2 fails if enabled)
// short idxType = ((Short)indexInfo.getProperty("type")).shortValue();
// if (idxType == DatabaseMetaData.tableIndexStatistic)
// {
// // Ignore
// continue;
// }

IndexInfo indexInfo = (IndexInfo)indexIter.next();
IndexInfo indexInfo = (IndexInfo)indexIter.next();

if (!dba.supportsOption(DatastoreAdapter.INCLUDE_TABLE_INDEX_STATISTICS))
{
short idxType = ((Short)indexInfo.getProperty("type")).shortValue();
if (idxType == DatabaseMetaData.tableIndexStatistic)
{
// Ignore
continue;
}
}

String indexName = (String)indexInfo.getProperty("index_name");
DatastoreIdentifier indexIdentifier = idFactory.newIdentifier(IdentifierType.CANDIDATE_KEY, indexName);
Index idx = indicesByName.get(indexIdentifier);
Expand Down

0 comments on commit a08ed02

Please sign in to comment.