use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class AllStoreHolder method countsForRelationshipWithoutTxState.
@Override
public long countsForRelationshipWithoutTxState(int startLabelId, int typeId, int endLabelId) {
AccessMode mode = ktx.securityContext().mode();
CursorContext cursorContext = ktx.cursorContext();
if (mode.allowsTraverseRelType(typeId) && mode.allowsTraverseNode(startLabelId) && mode.allowsTraverseNode(endLabelId)) {
return storageReader.countsForRelationship(startLabelId, typeId, endLabelId, cursorContext);
}
if (mode.disallowsTraverseRelType(typeId) || mode.disallowsTraverseLabel(startLabelId) || mode.disallowsTraverseLabel(endLabelId)) {
// so the count will be 0.
return 0;
}
// token index scan can only scan for single relationship type
if (typeId != TokenRead.ANY_RELATIONSHIP_TYPE) {
try {
var index = findUsableTokenIndex(EntityType.RELATIONSHIP);
if (index != IndexDescriptor.NO_INDEX) {
long count = 0;
try (DefaultRelationshipTypeIndexCursor relationshipsWithType = cursors.allocateRelationshipTypeIndexCursor(cursorContext);
DefaultRelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(cursorContext);
DefaultNodeCursor sourceNode = cursors.allocateNodeCursor(cursorContext);
DefaultNodeCursor targetNode = cursors.allocateNodeCursor(cursorContext)) {
var session = tokenReadSession(index);
this.relationshipTypeScan(session, relationshipsWithType, unconstrained(), new TokenPredicate(typeId));
while (relationshipsWithType.next()) {
relationshipsWithType.relationship(relationship);
count += countRelationshipsWithEndLabels(relationship, sourceNode, targetNode, startLabelId, endLabelId);
}
}
return count - countsForRelationshipInTxState(startLabelId, typeId, endLabelId);
}
} catch (KernelException ignored) {
// ignore, fallback to allRelationshipsScan
}
}
long count;
try (DefaultRelationshipScanCursor rels = cursors.allocateRelationshipScanCursor(cursorContext);
DefaultNodeCursor sourceNode = cursors.allocateFullAccessNodeCursor(cursorContext);
DefaultNodeCursor targetNode = cursors.allocateFullAccessNodeCursor(cursorContext)) {
this.allRelationshipsScan(rels);
Predicate<RelationshipScanCursor> predicate = typeId == TokenRead.ANY_RELATIONSHIP_TYPE ? alwaysTrue() : CursorPredicates.hasType(typeId);
var filteredCursor = new FilteringRelationshipScanCursorWrapper(rels, predicate);
count = countRelationshipsWithEndLabels(filteredCursor, sourceNode, targetNode, startLabelId, endLabelId);
}
return count - countsForRelationshipInTxState(startLabelId, typeId, endLabelId);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class RelationshipTypeIndexOrderTest method tokenScan.
@Override
protected void tokenScan(IndexOrder indexOrder, KernelTransaction tx, int label, RelationshipTypeIndexCursor cursor) throws KernelException {
IndexDescriptor index = tx.schemaRead().index(SchemaDescriptor.forAnyEntityTokens(EntityType.RELATIONSHIP)).next();
TokenReadSession tokenReadSession = tx.dataRead().tokenReadSession(index);
tx.dataRead().relationshipTypeScan(tokenReadSession, cursor, IndexQueryConstraints.ordered(indexOrder), new TokenPredicate(label));
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class TransactionImpl method getRelationshipsByTypeAndPropertyWithoutPropertyIndex.
private ResourceIterator<Relationship> getRelationshipsByTypeAndPropertyWithoutPropertyIndex(KernelTransaction ktx, int typeId, PropertyIndexQuery... queries) {
var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.RELATIONSHIP));
if (index != IndexDescriptor.NO_INDEX) {
try {
var session = ktx.dataRead().tokenReadSession(index);
var cursor = ktx.cursors().allocateRelationshipTypeIndexCursor(ktx.cursorContext());
ktx.dataRead().relationshipTypeScan(session, cursor, unconstrained(), new TokenPredicate(typeId));
var relationshipScanCursor = ktx.cursors().allocateRelationshipScanCursor(ktx.cursorContext());
var propertyCursor = ktx.cursors().allocatePropertyCursor(ktx.cursorContext(), ktx.memoryTracker());
return new RelationshipTypePropertyIterator(ktx.dataRead(), cursor, relationshipScanCursor, propertyCursor, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker, queries);
} catch (KernelException e) {
// ignore, fallback to all node scan
}
}
return getRelationshipsByTypeAndPropertyViaAllRelsScan(ktx, typeId, queries);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class TransactionImpl method allRelationshipsWithType.
private ResourceIterator<Relationship> allRelationshipsWithType(final RelationshipType type) {
KernelTransaction ktx = kernelTransaction();
int typeId = ktx.tokenRead().relationshipType(type.name());
if (typeId == TokenRead.NO_TOKEN) {
return emptyResourceIterator();
}
var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.RELATIONSHIP));
if (index != IndexDescriptor.NO_INDEX) {
try {
var session = ktx.dataRead().tokenReadSession(index);
var cursor = ktx.cursors().allocateRelationshipTypeIndexCursor(ktx.cursorContext());
ktx.dataRead().relationshipTypeScan(session, cursor, unconstrained(), new TokenPredicate(typeId));
return new CursorIterator<>(cursor, RelationshipIndexCursor::relationshipReference, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker);
} catch (KernelException e) {
// ignore, fallback to all node scan
}
}
return allRelationshipsByTypeWithoutIndex(ktx, typeId);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class RelationshipTypeIndexCursorTestBase method relationshipTypeScan.
private void relationshipTypeScan(KernelTransaction tx, int label, RelationshipTypeIndexCursor cursor, IndexOrder indexOrder) throws KernelException {
IndexDescriptor index = tx.schemaRead().indexGetForName("rti");
TokenReadSession tokenReadSession = tx.dataRead().tokenReadSession(index);
tx.dataRead().relationshipTypeScan(tokenReadSession, cursor, IndexQueryConstraints.ordered(indexOrder), new TokenPredicate(label));
}
Aggregations