use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseNodeValueIndexCursor.
@Test
void shouldReuseNodeValueIndexCursor() throws Exception {
int prop = token.propertyKey("prop");
IndexDescriptor indexDescriptor = tx.schemaRead().indexGetForName(NODE_PROP_INDEX_NAME);
Predicates.awaitEx(() -> tx.schemaRead().indexGetState(indexDescriptor) == ONLINE, 1, MINUTES);
IndexReadSession indexSession = tx.dataRead().indexReadSession(indexDescriptor);
NodeValueIndexCursor c1 = cursors.allocateNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
read.nodeIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
c1.close();
NodeValueIndexCursor c2 = cursors.allocateNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor 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);
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor 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);
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup.
@Test
void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception {
// given
ConstraintDescriptor constraint = createConstraint("Person", "id");
long ourNode;
{
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
ourNode = createLabeledNode(transaction, "Person", "id", 1);
commit();
}
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
TokenRead tokenRead = transaction.tokenRead();
int propId = tokenRead.propertyKey("id");
IndexDescriptor idx = transaction.schemaRead().indexGetForName(constraint.getName());
// when
createLabeledNode(transaction, "Person", "id", 2);
// then I should find the original node
try (NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker())) {
assertThat(transaction.dataRead().lockingNodeUniqueIndexSeek(idx, cursor, exact(propId, Values.of(1)))).isEqualTo(ourNode);
}
commit();
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck.
@Test
void unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck() throws Exception {
// given
ConstraintDescriptor constraint = createConstraint("Person", "id");
long ourNode;
{
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
ourNode = createLabeledNode(transaction, "Person", "id", 1);
createLabeledNode(transaction, "Item", "id", 2);
commit();
}
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
TokenRead tokenRead = transaction.tokenRead();
int propId = tokenRead.propertyKey("id");
IndexDescriptor idx = transaction.schemaRead().indexGetForName(constraint.getName());
// when
createLabeledNode(transaction, "Item", "id", 2);
// then I should find the original node
try (NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker())) {
assertThat(transaction.dataRead().lockingNodeUniqueIndexSeek(idx, cursor, exact(propId, Values.of(1)))).isEqualTo(ourNode);
}
commit();
}
Aggregations