Search in sources :

Example 1 with GridH2ProxyIndex

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ProxyIndex in project ignite by apache.

the class GridH2Table method removeIndex.

/**
 * Remove the given index from the list.
 *
 * @param h2Idx the index to remove
 */
public void removeIndex(Session session, Index h2Idx) {
    lock(true);
    try {
        ensureNotDestroyed();
        ArrayList<Index> idxs = new ArrayList<>(this.idxs);
        Index targetIdx = (h2Idx instanceof GridH2ProxyIndex) ? ((GridH2ProxyIndex) h2Idx).underlyingIndex() : h2Idx;
        for (int i = pkIndexPos; i < idxs.size(); ) {
            Index idx = idxs.get(i);
            if (idx == targetIdx || (idx instanceof GridH2ProxyIndex && ((GridH2ProxyIndex) idx).underlyingIndex() == targetIdx)) {
                idxs.remove(i);
                if (idx instanceof GridH2ProxyIndex && idx.getSchema().findIndex(session, idx.getName()) != null)
                    database.removeSchemaObject(session, idx);
                if (idx instanceof GridH2IndexBase)
                    destroyIndex(idx);
                continue;
            }
            i++;
        }
        this.idxs = idxs;
    } finally {
        unlock(true);
    }
}
Also used : ArrayList(java.util.ArrayList) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) SpatialIndex(org.h2.index.SpatialIndex)

Example 2 with GridH2ProxyIndex

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2ProxyIndex 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

ArrayList (java.util.ArrayList)2 SpatialIndex (org.h2.index.SpatialIndex)2 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)1 H2TreeIndexBase (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase)1 Index (org.h2.index.Index)1 IndexColumn (org.h2.table.IndexColumn)1