Search in sources :

Example 6 with IndexKeyDefinition

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition in project ignite by apache.

the class IndexQueryProcessor method querySortedIndex.

/**
 * Runs an index query.
 *
 * @return Result cursor.
 */
private GridCursor<IndexRow> querySortedIndex(GridCacheContext<?, ?> cctx, SortedSegmentedIndex idx, IndexingQueryFilter cacheFilter, IndexRangeQuery qry) throws IgniteCheckedException {
    int segmentsCnt = cctx.isPartitioned() ? cctx.config().getQueryParallelism() : 1;
    BPlusTree.TreeRowClosure<IndexRow, IndexRow> treeFilter = null;
    // Also skips filtering if the current search is unbounded (both boundaries equal to null).
    if (qry.criteria.length > 1 && !(qry.lower == null && qry.upper == null)) {
        LinkedHashMap<String, IndexKeyDefinition> idxDef = idxProc.indexDefinition(idx.id()).indexKeyDefinitions();
        treeFilter = new IndexQueryCriteriaClosure(qry, idxDef, ((SortedIndexDefinition) idxProc.indexDefinition(idx.id())).rowComparator());
    }
    IndexQueryContext qryCtx = new IndexQueryContext(cacheFilter, treeFilter, null);
    if (segmentsCnt == 1)
        return treeIndexRange(idx, 0, qry, qryCtx);
    final GridCursor<IndexRow>[] segmentCursors = new GridCursor[segmentsCnt];
    // Actually it just traverses BPlusTree to find boundaries. It's too fast to parallelize this.
    for (int i = 0; i < segmentsCnt; i++) segmentCursors[i] = treeIndexRange(idx, i, qry, qryCtx);
    return new SegmentedIndexCursor(segmentCursors, (SortedIndexDefinition) idxProc.indexDefinition(idx.id()));
}
Also used : GridCursor(org.apache.ignite.internal.util.lang.GridCursor) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) BPlusTree(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree)

Example 7 with IndexKeyDefinition

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition in project ignite by apache.

the class IndexQueryProcessor method alignCriteriaWithIndex.

/**
 * Checks that specified index matches index query criteria.
 */
private IndexRangeQuery alignCriteriaWithIndex(InlineIndexImpl idx, Map<String, RangeIndexQueryCriterion> criteria, IndexDefinition idxDef) {
    // Size of bounds array has to be equal to count of indexed fields.
    IndexKey[] lowerBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
    IndexKey[] upperBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
    boolean lowerAllNulls = true;
    boolean upperAllNulls = true;
    IndexRangeQuery qry = new IndexRangeQuery(criteria.size());
    // Checks that users criteria matches a prefix subset of index fields.
    int i = 0;
    for (Map.Entry<String, IndexKeyDefinition> keyDef : idxDef.indexKeyDefinitions().entrySet()) {
        RangeIndexQueryCriterion criterion = criteria.remove(keyDef.getKey());
        if (keyDef.getValue().order().sortOrder() == DESC)
            criterion = criterion.swap();
        qry.criteria[i] = criterion;
        IndexKey l = (IndexKey) criterion.lower();
        IndexKey u = (IndexKey) criterion.upper();
        if (l != null)
            lowerAllNulls = false;
        if (u != null)
            upperAllNulls = false;
        lowerBounds[i] = l;
        upperBounds[i++] = u;
        if (criteria.isEmpty())
            break;
    }
    InlineIndexRowHandler hnd = idx.segment(0).rowHandler();
    qry.lower = lowerAllNulls ? null : new IndexSearchRowImpl(lowerBounds, hnd);
    qry.upper = upperAllNulls ? null : new IndexSearchRowImpl(upperBounds, hnd);
    return qry;
}
Also used : IndexSearchRowImpl(org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with IndexKeyDefinition

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition in project ignite by apache.

the class InlineObjectBytesDetector method objectMayBeInlined.

/**
 * Static analyze inline_size and inline columns set.
 * e.g.: indexed: (long, obj) and inline_size < 12.
 * In this case there is no space for inline object.
 *
 * @param keyDefs Index key definition.
 * @param inlineSize Inline size.
 *
 * @return {@code true} If the object may be inlined.
 */
public static boolean objectMayBeInlined(int inlineSize, Collection<IndexKeyDefinition> keyDefs) {
    int remainSize = inlineSize;
    // The settings does not affect on inline size.
    IndexKeyTypeSettings settings = new IndexKeyTypeSettings();
    for (IndexKeyDefinition def : keyDefs) {
        if (def.idxType() == IndexKeyTypes.JAVA_OBJECT)
            break;
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(def.idxType(), settings);
        if (keyType == null)
            return false;
        // Set size to 1 for variable length columns as that value can be set by user.
        remainSize -= keyType.inlineSize() > 0 ? 1 + keyType.inlineSize() : 1;
    }
    // For old versions JO type was inlined as byte array.
    return remainSize >= 4;
}
Also used : IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Example 9 with IndexKeyDefinition

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition in project ignite by apache.

the class IndexQueryReducer method pageComparator.

/**
 * {@inheritDoc}
 */
@Override
protected CompletableFuture<Comparator<NodePage<R>>> pageComparator() {
    return metaFut.thenApply(m -> {
        LinkedHashMap<String, IndexKeyDefinition> keyDefs = m.keyDefinitions();
        GridQueryTypeDescriptor typeDesc = cctx.kernalContext().query().typeDescriptor(cctx.name(), QueryUtils.typeName(valType));
        return new IndexedNodePageComparator(m, typeDesc, keyDefs);
    });
}
Also used : IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)

Example 10 with IndexKeyDefinition

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition in project ignite by apache.

the class GridH2Table method destroyIndex.

/**
 * Destroy index with GridIndexManager.
 */
private void destroyIndex(Index idx) {
    if (idx instanceof GridH2IndexBase) {
        GridH2IndexBase h2idx = (GridH2IndexBase) idx;
        // Destroy underlying Ignite index.
        IndexDefinition deleteDef = new IndexDefinition() {

            /**
             * {@inheritDoc}
             */
            @Override
            public IndexName idxName() {
                return new IndexName(cacheName(), getSchema().getName(), tableName, idx.getName());
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public LinkedHashMap<String, IndexKeyDefinition> indexKeyDefinitions() {
                throw new UnsupportedOperationException("Hasn't be invoked for destroyed index.");
            }
        };
        idxMgr.removeIndex(cacheContext(), deleteDef.idxName(), !rmIndex);
        // Call it too, if H2 index stores some state.
        h2idx.destroy(rmIndex);
    }
}
Also used : IndexName(org.apache.ignite.internal.cache.query.index.IndexName) IndexDefinition(org.apache.ignite.internal.cache.query.index.IndexDefinition) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)

Aggregations

IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)10 LinkedHashMap (java.util.LinkedHashMap)3 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)3 IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)3 IndexKey (org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey)3 HashMap (java.util.HashMap)2 IgniteException (org.apache.ignite.IgniteException)2 RangeIndexQueryCriterion (org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)2 IndexDefinition (org.apache.ignite.internal.cache.query.index.IndexDefinition)2 IndexName (org.apache.ignite.internal.cache.query.index.IndexName)2 Map (java.util.Map)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IndexQueryCriterion (org.apache.ignite.cache.query.IndexQueryCriterion)1 Index (org.apache.ignite.internal.cache.query.index.Index)1 IndexRowComparator (org.apache.ignite.internal.cache.query.index.sorted.IndexRowComparator)1 IndexSearchRowImpl (org.apache.ignite.internal.cache.query.index.sorted.IndexSearchRowImpl)1 InlineIndexRowHandler (org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 IndexQueryContext (org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext)1 InlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType)1