Search in sources :

Example 1 with NodeIndexCursor

use of org.neo4j.internal.kernel.api.NodeIndexCursor in project neo4j by neo4j.

the class TransactionImpl method nodesByLabelAndProperties.

private ResourceIterator<Node> nodesByLabelAndProperties(KernelTransaction transaction, int labelId, PropertyIndexQuery.ExactPredicate... queries) {
    Read read = transaction.dataRead();
    if (isInvalidQuery(labelId, queries)) {
        return emptyResourceIterator();
    }
    int[] propertyIds = getPropertyIds(queries);
    IndexDescriptor index = findUsableMatchingCompositeIndex(transaction, SchemaDescriptor.forLabel(labelId, propertyIds), propertyIds, () -> transaction.schemaRead().indexesGetForLabel(labelId));
    if (index != IndexDescriptor.NO_INDEX) {
        try {
            NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker());
            IndexReadSession indexSession = read.indexReadSession(index);
            read.nodeIndexSeek(indexSession, cursor, unconstrained(), getReorderedIndexQueries(index.schema().getPropertyIds(), queries));
            return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // weird at this point but ignore and fallback to a label scan
        }
    }
    return getNodesByLabelAndPropertyWithoutPropertyIndex(transaction, labelId, queries);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) NodeIndexCursor(org.neo4j.internal.kernel.api.NodeIndexCursor) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 2 with NodeIndexCursor

use of org.neo4j.internal.kernel.api.NodeIndexCursor in project neo4j by neo4j.

the class TransactionImpl method nodesByLabelAndProperty.

private ResourceIterator<Node> nodesByLabelAndProperty(KernelTransaction transaction, int labelId, PropertyIndexQuery query) {
    Read read = transaction.dataRead();
    if (query.propertyKeyId() == TokenRead.NO_TOKEN || labelId == TokenRead.NO_TOKEN) {
        return emptyResourceIterator();
    }
    var index = findUsableMatchingIndex(transaction, SchemaDescriptor.forLabel(labelId, query.propertyKeyId()));
    if (index != IndexDescriptor.NO_INDEX) {
        // Ha! We found an index - let's use it to find matching nodes
        try {
            NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker());
            IndexReadSession indexSession = read.indexReadSession(index);
            read.nodeIndexSeek(indexSession, cursor, unconstrained(), query);
            return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // weird at this point but ignore and fallback to a label scan
        }
    }
    return getNodesByLabelAndPropertyWithoutPropertyIndex(transaction, labelId, query);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) NodeIndexCursor(org.neo4j.internal.kernel.api.NodeIndexCursor) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 3 with NodeIndexCursor

use of org.neo4j.internal.kernel.api.NodeIndexCursor in project neo4j by neo4j.

the class TransactionImpl method allNodesWithLabel.

private ResourceIterator<Node> allNodesWithLabel(final Label myLabel) {
    KernelTransaction ktx = kernelTransaction();
    int labelId = ktx.tokenRead().nodeLabel(myLabel.name());
    if (labelId == TokenRead.NO_TOKEN) {
        return emptyResourceIterator();
    }
    var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.NODE));
    if (index != IndexDescriptor.NO_INDEX) {
        try {
            var session = ktx.dataRead().tokenReadSession(index);
            var cursor = ktx.cursors().allocateNodeLabelIndexCursor(ktx.cursorContext());
            ktx.dataRead().nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(labelId));
            return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // ignore, fallback to all node scan
        }
    }
    return allNodesByLabelWithoutIndex(ktx, labelId);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeIndexCursor(org.neo4j.internal.kernel.api.NodeIndexCursor) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

KernelException (org.neo4j.exceptions.KernelException)3 NodeIndexCursor (org.neo4j.internal.kernel.api.NodeIndexCursor)3 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)3 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)3 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)3 CursorIterator (org.neo4j.kernel.impl.coreapi.internal.CursorIterator)3 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)3 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)2 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)2 Read (org.neo4j.internal.kernel.api.Read)2 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)2 TokenRead (org.neo4j.internal.kernel.api.TokenRead)2 TokenPredicate (org.neo4j.internal.kernel.api.TokenPredicate)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1