Search in sources :

Example 51 with IndexColumn

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--;
    }
}
Also used : Value(org.h2.value.Value)

Example 52 with IndexColumn

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;
}
Also used : IndexColumn(org.h2.table.IndexColumn)

Example 53 with IndexColumn

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;
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) Constraint(org.h2.constraint.Constraint) IndexColumn(org.h2.table.IndexColumn)

Example 54 with IndexColumn

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;
}
Also used : IndexInformation(org.apache.ignite.internal.processors.query.h2.database.IndexInformation) H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) ArrayList(java.util.ArrayList) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) SpatialIndex(org.h2.index.SpatialIndex) IndexColumn(org.h2.table.IndexColumn)

Example 55 with IndexColumn

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;
}
Also used : H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) SpatialIndex(org.h2.index.SpatialIndex) ArrayList(java.util.ArrayList) IndexColumn(org.h2.table.IndexColumn)

Aggregations

IndexColumn (org.h2.table.IndexColumn)53 Column (org.h2.table.Column)23 ArrayList (java.util.ArrayList)14 Index (org.h2.index.Index)12 Value (org.h2.value.Value)12 IndexType (org.h2.index.IndexType)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 Constraint (org.h2.constraint.Constraint)6 ExpressionColumn (org.h2.expression.ExpressionColumn)6 LinkedHashMap (java.util.LinkedHashMap)5 CacheException (javax.cache.CacheException)5 TableFilter (org.h2.table.TableFilter)5 StatementBuilder (org.h2.util.StatementBuilder)5 ValueString (org.h2.value.ValueString)5 HashMap (java.util.HashMap)4 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)4 H2TreeIndexBase (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase)4 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 Row (org.h2.result.Row)4 ResultSet (java.sql.ResultSet)3