use of org.neo4j.internal.kernel.api.RelationshipValueIndexCursor 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.RelationshipValueIndexCursor 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));
}
}
use of org.neo4j.internal.kernel.api.RelationshipValueIndexCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseRelationshipIndexCursors.
@Test
void shouldReuseRelationshipIndexCursors() throws Exception {
// given
int connection;
int name;
String indexName = "myIndex";
IndexDescriptor index;
try (KernelTransaction tx = beginTransaction()) {
connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
index = tx.schemaWrite().indexCreate(prototype);
tx.commit();
}
Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
RelationshipValueIndexCursor c1 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
read.relationshipIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.fulltextSearch("hello"));
c1.close();
RelationshipValueIndexCursor c2 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.RelationshipValueIndexCursor in project neo4j by neo4j.
the class RecoveryIT method recoverDatabaseWithRelationshipIndex.
@Test
void recoverDatabaseWithRelationshipIndex() throws Throwable {
GraphDatabaseService database = createDatabase();
int numberOfRelationships = 10;
RelationshipType type = RelationshipType.withName("TYPE");
String property = "prop";
String indexName = "my index";
try (Transaction transaction = database.beginTx()) {
transaction.schema().indexFor(type).on(property).withIndexType(IndexType.FULLTEXT).withName(indexName).create();
transaction.commit();
}
awaitIndexesOnline(database);
try (Transaction transaction = database.beginTx()) {
Node start = transaction.createNode();
Node stop = transaction.createNode();
for (int i = 0; i < numberOfRelationships; i++) {
Relationship relationship = start.createRelationshipTo(stop, type);
relationship.setProperty(property, "value");
}
transaction.commit();
}
managementService.shutdown();
RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(databaseLayout, fileSystem);
recoverDatabase();
GraphDatabaseAPI recoveredDatabase = createDatabase();
awaitIndexesOnline(recoveredDatabase);
try (Transaction transaction = recoveredDatabase.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) transaction).kernelTransaction();
IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
IndexReadSession indexReadSession = ktx.dataRead().indexReadSession(index);
int relationshipsInIndex = 0;
try (RelationshipValueIndexCursor cursor = ktx.cursors().allocateRelationshipValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().relationshipIndexSeek(indexReadSession, cursor, unconstrained(), fulltextSearch("*"));
while (cursor.next()) {
relationshipsInIndex++;
}
}
assertEquals(numberOfRelationships, relationshipsInIndex);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.internal.kernel.api.RelationshipValueIndexCursor in project neo4j by neo4j.
the class KernelReadTracerTest method shouldTraceRelationshipIndexSeek.
@Test
void shouldTraceRelationshipIndexSeek() throws KernelException {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
try (RelationshipValueIndexCursor cursor = cursors.allocateRelationshipValueIndexCursor(NULL, INSTANCE)) {
int p1 = token.propertyKey("p1");
IndexReadSession session = read.indexReadSession(relIndex);
assertRelationshipIndexSeekTracing(tracer, cursor, session, IndexOrder.NONE, p1);
assertRelationshipIndexSeekTracing(tracer, cursor, session, IndexOrder.ASCENDING, p1);
}
}
Aggregations