use of org.h2.table.IndexColumn in project h2database by h2database.
the class NonUniqueHashIndex method remove.
@Override
public void remove(Session session, Row row) {
if (rowCount == 1) {
// last row in table
reset();
} else {
Value key = row.getValue(indexColumn);
ArrayList<Long> positions = rows.get(key);
if (positions.size() == 1) {
// last row with such key
rows.remove(key);
} else {
positions.remove(row.getKey());
}
rowCount--;
}
}
use of org.h2.table.IndexColumn in project h2database by h2database.
the class IndexCursor method canUseIndexFor.
private boolean canUseIndexFor(Column column) {
// The first column of the index must match this column,
// or it must be a VIEW index (where the column is null).
// Multiple IN conditions with views are not supported, see
// IndexCondition.getMask.
IndexColumn[] cols = index.getIndexColumns();
if (cols == null) {
return true;
}
IndexColumn idxCol = cols[0];
return idxCol == null || idxCol.column == column;
}
use of org.h2.table.IndexColumn 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;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class GridH2Table method indexesInformation.
/**
* @return Information about all indexes related to the table.
*/
@SuppressWarnings("ZeroLengthArrayAllocation")
public List<IndexInformation> indexesInformation() {
List<IndexInformation> res = new ArrayList<>();
IndexColumn keyCol = indexColumn(QueryUtils.KEY_COL, SortOrder.ASCENDING);
List<IndexColumn> wrappedKeyCols = H2Utils.treeIndexColumns(rowDescriptor(), new ArrayList<>(2), keyCol, affKeyCol);
// explicit add HASH index, due to we know all their parameters and it doesn't created on non afinity nodes.
res.add(new IndexInformation(false, true, PK_HASH_IDX_NAME, H2IndexType.HASH, H2Utils.indexColumnsSql(H2Utils.unwrapKeyColumns(this, wrappedKeyCols.toArray(new IndexColumn[0]))), null));
// explicit add SCAN index, due to we know all their parameters and it depends on affinity node or not.
res.add(new IndexInformation(false, false, SCAN_INDEX_NAME_SUFFIX, H2IndexType.SCAN, null, null));
for (Index idx : idxs) {
if (idx instanceof H2TreeIndexBase) {
res.add(new IndexInformation(idx.getIndexType().isPrimaryKey(), idx.getIndexType().isUnique(), idx.getName(), H2IndexType.BTREE, H2Utils.indexColumnsSql(H2Utils.unwrapKeyColumns(this, idx.getIndexColumns())), ((H2TreeIndexBase) idx).inlineSize()));
} else if (idx.getIndexType().isSpatial()) {
res.add(new IndexInformation(false, false, idx.getName(), H2IndexType.SPATIAL, H2Utils.indexColumnsSql(idx.getIndexColumns()), null));
}
}
return res;
}
use of org.h2.table.IndexColumn in project ignite by apache.
the class GridH2Table method createDuplicateIndexIfNeeded.
/**
* Creates proxy index for given target index.
* Proxy index refers to alternative key and val columns.
*
* @param target Index to clone.
* @return Proxy index.
*/
private Index createDuplicateIndexIfNeeded(Index target) {
if (!(target instanceof H2TreeIndexBase) && !(target instanceof SpatialIndex))
return null;
IndexColumn[] cols = target.getIndexColumns();
List<IndexColumn> proxyCols = new ArrayList<>(cols.length);
boolean modified = false;
for (IndexColumn col : cols) {
IndexColumn proxyCol = new IndexColumn();
proxyCol.columnName = col.columnName;
proxyCol.column = col.column;
proxyCol.sortType = col.sortType;
int altColId = desc.getAlternativeColumnId(proxyCol.column.getColumnId());
if (altColId != proxyCol.column.getColumnId()) {
proxyCol.column = getColumn(altColId);
proxyCol.columnName = proxyCol.column.getName();
modified = true;
}
proxyCols.add(proxyCol);
}
if (modified) {
String proxyName = target.getName() + "_proxy";
if (target.getIndexType().isSpatial())
return new GridH2ProxySpatialIndex(this, proxyName, proxyCols, target);
return new GridH2ProxyIndex(this, proxyName, proxyCols, target);
}
return null;
}
Aggregations