private ResourceIterator<Node> nodesByLabelAndProperties( KernelTransaction transaction, int labelId, IndexQuery.ExactPredicate... queries ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( isInvalidQuery( labelId, queries ) ) { statement.close(); return emptyResourceIterator(); } int[] propertyIds = getPropertyIds( queries ); IndexReference index = findMatchingIndex( transaction, labelId, propertyIds ); if ( index != IndexReference.NO_INDEX ) { try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, getReorderedIndexQueries( index.properties(), queries ) ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, queries ); }
@Override long fetchNext() { if ( cursor.next() ) { return cursor.nodeReference(); } else { close(); return NO_ID; } }
private ResourceIterator<Node> nodesByLabelAndProperty( KernelTransaction transaction, int labelId, IndexQuery query ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( query.propertyKeyId() == TokenRead.NO_TOKEN || labelId == TokenRead.NO_TOKEN ) { statement.close(); return emptyResourceIterator(); } IndexReference index = transaction.schemaRead().index( labelId, query.propertyKeyId() ); if ( index != IndexReference.NO_INDEX ) { // Ha! We found an index - let's use it to find matching nodes try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, query ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, query ); }
private ResourceIterator<Node> allNodesWithLabel( final Label myLabel ) { KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); Statement statement = ktx.acquireStatement(); int labelId = ktx.tokenRead().nodeLabel( myLabel.name() ); if ( labelId == TokenRead.NO_TOKEN ) { statement.close(); return Iterators.emptyResourceIterator(); } NodeLabelIndexCursor cursor = ktx.cursors().allocateNodeLabelIndexCursor(); ktx.dataRead().nodeLabelScan( labelId, cursor ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); }
private ResourceIterator<Node> nodesByLabelAndProperty( KernelTransaction transaction, int labelId, IndexQuery query ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( query.propertyKeyId() == TokenRead.NO_TOKEN || labelId == TokenRead.NO_TOKEN ) { statement.close(); return emptyResourceIterator(); } IndexReference index = transaction.schemaRead().index( labelId, query.propertyKeyId() ); if ( index != IndexReference.NO_INDEX ) { // Ha! We found an index - let's use it to find matching nodes try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, query ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, query ); }
private ResourceIterator<Node> nodesByLabelAndProperties( KernelTransaction transaction, int labelId, IndexQuery.ExactPredicate... queries ) { Statement statement = transaction.acquireStatement(); Read read = transaction.dataRead(); if ( isInvalidQuery( labelId, queries ) ) { statement.close(); return emptyResourceIterator(); } int[] propertyIds = getPropertyIds( queries ); IndexReference index = findMatchingIndex( transaction, labelId, propertyIds ); if ( index != IndexReference.NO_INDEX ) { try { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, getReorderedIndexQueries( index.properties(), queries ) ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); } catch ( KernelException e ) { // weird at this point but ignore and fallback to a label scan } } return getNodesByLabelAndPropertyWithoutIndex( statement, labelId, queries ); }
private ResourceIterator<Node> allNodesWithLabel( final Label myLabel ) { KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); Statement statement = ktx.acquireStatement(); int labelId = ktx.tokenRead().nodeLabel( myLabel.name() ); if ( labelId == TokenRead.NO_TOKEN ) { statement.close(); return Iterators.emptyResourceIterator(); } NodeLabelIndexCursor cursor = ktx.cursors().allocateNodeLabelIndexCursor(); ktx.dataRead().nodeLabelScan( labelId, cursor ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); }
@Override long fetchNext() { if ( cursor.next() ) { return cursor.nodeReference(); } else { close(); return NO_ID; } }