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()));
}
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;
}
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;
}
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);
});
}
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);
}
}
Aggregations