Search in sources :

Example 1 with IndexQueryContext

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

the class H2TreeIndex method findFirstOrLast.

/**
 * {@inheritDoc}
 */
@Override
public Cursor findFirstOrLast(Session ses, boolean b) {
    try {
        QueryContext qctx = H2Utils.context(ses);
        IndexQueryContext qryCtx = idxQryContext(qctx);
        GridCursor<IndexRow> cursor = b ? queryIndex.findFirst(segment(qctx), qryCtx) : queryIndex.findLast(segment(qctx), qryCtx);
        return new H2Cursor(new IndexValueCursor<>(cursor, this::mapIndexRow));
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
}
Also used : IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) H2Cursor(org.apache.ignite.internal.processors.query.h2.H2Cursor) IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) QueryContext(org.apache.ignite.internal.processors.query.h2.opt.QueryContext)

Example 2 with IndexQueryContext

use of org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext 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)

Aggregations

IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)2 IndexQueryContext (org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 BPlusTree (org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree)1 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)1 QueryContext (org.apache.ignite.internal.processors.query.h2.opt.QueryContext)1 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)1