use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class TransactionImpl method relationshipsByTypeAndProperty.
private ResourceIterator<Relationship> relationshipsByTypeAndProperty(KernelTransaction transaction, int typeId, PropertyIndexQuery query) {
Read read = transaction.dataRead();
if (query.propertyKeyId() == TokenRead.NO_TOKEN || typeId == TokenRead.NO_TOKEN) {
return emptyResourceIterator();
}
var index = findUsableMatchingIndex(transaction, SchemaDescriptor.forRelType(typeId, query.propertyKeyId()));
if (index != IndexDescriptor.NO_INDEX) {
// Ha! We found an index - let's use it to find matching relationships
try {
var cursor = transaction.cursors().allocateRelationshipValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker());
IndexReadSession indexSession = read.indexReadSession(index);
read.relationshipIndexSeek(indexSession, cursor, unconstrained(), query);
return new CursorIterator<>(cursor, RelationshipIndexCursor::relationshipReference, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker);
} catch (KernelException e) {
// weird at this point but ignore and fallback to a type scan
}
}
return getRelationshipsByTypeAndPropertyWithoutPropertyIndex(transaction, typeId, query);
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class TransactionImpl method relationshipsByTypeAndProperties.
private ResourceIterator<Relationship> relationshipsByTypeAndProperties(KernelTransaction tx, int typeId, PropertyIndexQuery.ExactPredicate... queries) {
Read read = tx.dataRead();
if (isInvalidQuery(typeId, queries)) {
return emptyResourceIterator();
}
int[] propertyIds = getPropertyIds(queries);
IndexDescriptor index = findUsableMatchingCompositeIndex(tx, SchemaDescriptor.forRelType(typeId, propertyIds), propertyIds, () -> tx.schemaRead().indexesGetForRelationshipType(typeId));
if (index != IndexDescriptor.NO_INDEX) {
try {
RelationshipValueIndexCursor cursor = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
IndexReadSession indexSession = read.indexReadSession(index);
read.relationshipIndexSeek(indexSession, cursor, unconstrained(), getReorderedIndexQueries(index.schema().getPropertyIds(), queries));
return new CursorIterator<>(cursor, RelationshipIndexCursor::relationshipReference, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker);
} catch (KernelException e) {
// weird at this point but ignore and fallback to a label scan
}
}
return getRelationshipsByTypeAndPropertyWithoutPropertyIndex(tx, typeId, queries);
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method countIndexedNodes.
private static int countIndexedNodes(GraphDatabaseAPI db, Label label, String... keys) throws Exception {
try (InternalTransaction tx = (InternalTransaction) db.beginTx()) {
KernelTransaction ktx = tx.kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int labelId = tokenRead.nodeLabel(label.name());
int[] propertyKeyIds = new int[keys.length];
for (int i = 0; i < propertyKeyIds.length; i++) {
propertyKeyIds[i] = tokenRead.propertyKey(keys[i]);
}
PropertyIndexQuery[] predicates = new PropertyIndexQuery[propertyKeyIds.length];
for (int i = 0; i < propertyKeyIds.length; i++) {
predicates[i] = PropertyIndexQuery.exists(propertyKeyIds[i]);
}
IndexDescriptor index = single(ktx.schemaRead().index(SchemaDescriptor.forLabel(labelId, propertyKeyIds)));
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
int count = 0;
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), predicates);
while (cursor.next()) {
count++;
}
}
tx.commit();
return count;
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class ReadTracingIT method noPageCacheTracingAvailableOnRelationshipIndexSeek.
@Test
void noPageCacheTracingAvailableOnRelationshipIndexSeek() throws KernelException {
createRelationshipIndex();
try (Transaction tx = database.beginTx()) {
var source = tx.createNode(label);
var target = tx.createNode(label);
var relationship = source.createRelationshipTo(target, type);
relationship.setProperty(property, testPropertyValue);
tx.commit();
}
try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
var kernelTransaction = transaction.kernelTransaction();
var dataRead = kernelTransaction.dataRead();
var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(indexName);
IndexReadSession indexReadSession = kernelTransaction.dataRead().indexReadSession(indexDescriptor);
var cursorContext = kernelTransaction.cursorContext();
assertZeroCursor(cursorContext);
try (var cursor = kernelTransaction.cursors().allocateRelationshipValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
dataRead.relationshipIndexSeek(indexReadSession, cursor, unconstrained(), fulltextSearch(testPropertyValue));
consumeCursor(cursor);
}
assertZeroCursor(cursorContext);
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class RelationshipIndexTransactionStateTest method assertEntityAndValueForSeek.
@Override
void assertEntityAndValueForSeek(Set<Pair<Long, Value>> expected, KernelTransaction tx, IndexDescriptor index, boolean needsValues, Object anotherValueFoundByQuery, PropertyIndexQuery... queries) throws Exception {
try (RelationshipValueIndexCursor relationships = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
tx.dataRead().relationshipIndexSeek(indexSession, relationships, unordered(needsValues), queries);
assertEntityAndValue(expected, tx, needsValues, anotherValueFoundByQuery, new RelationshipCursorAdapter(relationships));
}
}
Aggregations