@Override public NodeValueIndexCursor allocateNodeValueIndexCursor() { NodeValueIndexCursor n = cursors.allocateNodeValueIndexCursor(); allCursors.add( n ); return n; }
NodeValueIndexCursor indexQuery( KernelTransaction ktx, IndexDescriptor indexDescriptor, IndexQuery... indexQueries ) throws KernelException { NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(); ktx.dataRead().nodeIndexSeek( indexDescriptor, cursor, IndexOrder.NONE, false, indexQueries ); return cursor; } }
/** * Performs an index seek. * * @param read The Read instance to use for seeking * @param cursors Used for cursor allocation * @param index A reference to an index * @param value The value to seek for * @return A cursor positioned at the data found in index. */ public static NodeValueIndexCursor indexSeek( Read read, CursorFactory cursors, IndexReference index, Object value ) throws KernelException { assert index.properties().length == 1; if ( value == Values.NO_VALUE || value == null ) { return NodeValueIndexCursor.EMPTY; } else { NodeValueIndexCursor cursor = cursors.allocateNodeValueIndexCursor(); IndexQuery.ExactPredicate query = exact( index.properties()[0], makeValueNeoSafe( value ) ); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, query ); return cursor; } } }
private NodeValueIndexCursor seek( KernelTransaction transaction ) throws KernelException { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); transaction.dataRead().nodeIndexSeek( index, cursor, IndexOrder.NONE, false, exactQuery() ); return cursor; }
/** * Perform an index scan and assert that the correct nodes and values were found. * * Since this method modifies TX state for the test it is not safe to call this method more than once in the same transaction. * * @param expected the expected nodes and values * @param tx the transaction * @param index the index * @param needsValues if the index is expected to provide values * @param anotherValueFoundByQuery a values that would be found by, if a node with that value existed. This method * will create a node with that value, after initializing the cursor and assert that the new node is not found. */ private void assertNodeAndValueForScan( Set<Pair<Long,Value>> expected, Transaction tx, IndexReference index, boolean needsValues, Object anotherValueFoundByQuery ) throws Exception { try ( NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor() ) { tx.dataRead().nodeIndexScan( index, nodes, IndexOrder.NONE, needsValues ); assertNodeAndValue( expected, tx, needsValues, anotherValueFoundByQuery, nodes ); } }
/** * Perform an index seek and assert that the correct nodes and values were found. * * Since this method modifies TX state for the test it is not safe to call this method more than once in the same transaction. * * @param expected the expected nodes and values * @param tx the transaction * @param index the index * @param needsValues if the index is expected to provide values * @param anotherValueFoundByQuery a values that would be found by the index queries, if a node with that value existed. This method * will create a node with that value, after initializing the cursor and assert that the new node is not found. * @param queries the index queries */ private void assertNodeAndValueForSeek( Set<Pair<Long,Value>> expected, Transaction tx, IndexReference index, boolean needsValues, Object anotherValueFoundByQuery, IndexQuery... queries ) throws Exception { try ( NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor() ) { tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, needsValues, queries ); assertNodeAndValue( expected, tx, needsValues, anotherValueFoundByQuery, nodes ); } }
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 ); }
IndexReference index = tx.schemaRead().index( label, prop ); try ( NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor() )
IndexReference index = tx.schemaRead().index( label, prop ); try ( NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor() )
int propertyKeyId = ktx.tokenRead().propertyKey( NAME_PROPERTY ); IndexReference index = ktx.schemaRead().index( labelId, propertyKeyId ); try ( NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor() )
NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(); ktx.dataRead().nodeIndexSeek( index, cursor, IndexOrder.NONE, false, predicates ); int count = 0;
IndexDescriptor index = TestIndexDescriptorFactory.uniqueForLabel( labelId, propertyKeyId ); Read read = ktx.dataRead(); try ( NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor() )
ThreadToStatementContextBridge.class ).getKernelTransactionBoundToThisThread( true ); IndexReference index = ktx.schemaRead().index( ktx.tokenRead().nodeLabel( LABEL ), ktx.tokenRead().propertyKey( KEY ) ); NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(); ktx.dataRead().nodeIndexSeek( index, cursor, IndexOrder.NONE, false, IndexQuery.exact( 1, VALUE ) ); assertTrue( cursor.next() );
/** * Performs an index seek. * * @param read The Read instance to use for seeking * @param cursors Used for cursor allocation * @param index A reference to an index * @param value The value to seek for * @return A cursor positioned at the data found in index. */ public static NodeValueIndexCursor indexSeek( Read read, CursorFactory cursors, IndexReference index, Object value ) throws KernelException { assert index.properties().length == 1; if ( value == Values.NO_VALUE || value == null ) { return NodeValueIndexCursor.EMPTY; } else { NodeValueIndexCursor cursor = cursors.allocateNodeValueIndexCursor(); IndexQuery.ExactPredicate query = exact( index.properties()[0], makeValueNeoSafe( value ) ); read.nodeIndexSeek( index, cursor, IndexOrder.NONE, false, query ); return cursor; } } }
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 ); }