use of org.h2.index.IndexType in project h2database by h2database.
the class MVTable method addIndex.
@Override
public Index addIndex(Session session, String indexName, int indexId, IndexColumn[] cols, IndexType indexType, boolean create, String indexComment) {
if (indexType.isPrimaryKey()) {
for (IndexColumn c : cols) {
Column column = c.column;
if (column.isNullable()) {
throw DbException.get(ErrorCode.COLUMN_MUST_NOT_BE_NULLABLE_1, column.getName());
}
column.setPrimaryKey(true);
}
}
boolean isSessionTemporary = isTemporary() && !isGlobalTemporary();
if (!isSessionTemporary) {
database.lockMeta(session);
}
MVIndex index;
int mainIndexColumn;
mainIndexColumn = getMainIndexColumn(indexType, cols);
if (database.isStarting()) {
if (transactionStore.store.hasMap("index." + indexId)) {
mainIndexColumn = -1;
}
} else if (primaryIndex.getRowCountMax() != 0) {
mainIndexColumn = -1;
}
if (mainIndexColumn != -1) {
primaryIndex.setMainIndexColumn(mainIndexColumn);
index = new MVDelegateIndex(this, indexId, indexName, primaryIndex, indexType);
} else if (indexType.isSpatial()) {
index = new MVSpatialIndex(session.getDatabase(), this, indexId, indexName, cols, indexType);
} else {
index = new MVSecondaryIndex(session.getDatabase(), this, indexId, indexName, cols, indexType);
}
if (index.needRebuild()) {
rebuildIndex(session, index, indexName);
}
index.setTemporary(isTemporary());
if (index.getCreateSQL() != null) {
index.setComment(indexComment);
if (isSessionTemporary) {
session.addLocalTempTableIndex(index);
} else {
database.addSchemaObject(session, index);
}
}
indexes.add(index);
setModified();
return index;
}
Aggregations