private static List<String> propertyNames( TokenNameLookup tokens, IndexReference index ) { int[] propertyIds = index.properties(); List<String> propertyNames = new ArrayList<>( propertyIds.length ); for ( int propertyId : propertyIds ) { propertyNames.add( tokens.propertyKeyGetName( propertyId ) ); } return propertyNames; }
private static void assertValidIndex( IndexReference index ) throws NoSuchIndexException { if ( index == IndexReference.NO_INDEX ) { throw new NoSuchIndexException( index.schema() ); } } }
private static Map<String,String> indexProviderDescriptorMap( IndexReference indexReference ) { return MapUtil.stringMap( "key", indexReference.providerKey(), "version", indexReference.providerVersion() ); }
private static IndexType getIndexTypeOf( IndexReference index ) if ( index.isFulltextIndex() ) if ( index.schema().entityType() == EntityType.NODE ) if ( index.isUnique() ) if ( index.schema().entityType() == EntityType.NODE )
private IndexReference getIndexReference( int label, int prop ) { for ( IndexReference index : indexes ) { if ( index.schema().getEntityTokenIds()[0] == label && prop == index.properties()[0] ) { return index; } } for ( IndexReference index : uniqueIndexes ) { if ( index.schema().getEntityTokenIds()[0] == label && prop == index.properties()[0] ) { return index; } } throw new AssertionError( ); }
SchemaDescriptor schema = index.schema(); int[] entityTokenIds = schema.getEntityTokenIds(); boolean constraintIndex = index.isUnique(); String[] propertyNames = PropertyNameUtils.getPropertyKeys( tokenRead, index.properties() ); switch ( schema.entityType() )
indexes.sort( Comparator.comparing( a -> a.userDescription( tokens ) ) ); SchemaDescriptor schema = index.schema(); long indexId = getIndexId( indexingService, schema ); List<String> tokenNames = Arrays.asList( tokens.entityTokensGetNames( schema.entityType(), schema.getEntityTokenIds() ) ); result.add( new IndexResult( indexId, description, index.name(), tokenNames, propertyNames, "No index on ", index.userDescription( tokens ) );
if ( !index.isUnique() ) tokenNameLookup, index.properties() ); indexes.add( String.join( ",", propertyNames ) );
String labelName = tokens.labelGetName(indexReference.label()); List<String> properties = new ArrayList<>(); Arrays.stream(indexReference.properties()).forEach((i) -> properties.add(tokens.propertyKeyGetName(i))); try { return new IndexConstraintNodeInfo( properties, schemaRead.indexGetState(indexReference).toString(), !indexReference.isUnique() ? "INDEX" : "UNIQUENESS", schemaRead.indexGetState(indexReference).equals(InternalIndexState.FAILED) ? schemaRead.indexGetFailure(indexReference) : "NO FAILURE", schemaRead.indexGetPopulationProgress(indexReference).getCompleted() / schemaRead.indexGetPopulationProgress(indexReference).getTotal() * 100, schemaRead.indexSize(indexReference), schemaRead.indexUniqueValuesSelectivity(indexReference), indexReference.userDescription(tokens) ); } catch(IndexNotFoundKernelException e) { properties, "NOT_FOUND", !indexReference.isUnique() ? "INDEX" : "UNIQUENESS", "NOT_FOUND", 0,0,0, indexReference.userDescription(tokens) );
private void awaitOnline( IndexReference indexReference ) throws IndexNotFoundKernelException { // We do the isAdded check on the transaction state first, because indexGetState will grab a schema read-lock, which can deadlock on the write-lock // held by the index populator. Also, if we index was created in this transaction, then we will never see it come online in this transaction anyway. // Indexes don't come online until the transaction that creates them has committed. if ( !((KernelTransactionImplementation)tx).txState().indexDiffSetsBySchema( indexReference.schema() ).isAdded( (IndexDescriptor) indexReference ) ) { // If the index was not created in this transaction, then wait for it to come online before querying. Schema schema = db.schema(); IndexDefinition index = schema.getIndexByName( indexReference.name() ); schema.awaitIndexOnline( index, INDEX_ONLINE_QUERY_TIMEOUT_SECONDS, TimeUnit.SECONDS ); } // If the index was created in this transaction, then we skip this check entirely. // We will get an exception later, when we try to get an IndexReader, so this is fine. }
private void showIndices( DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup ) throws IndexNotFoundKernelException { SchemaRead schemaRead = ktx.schemaRead(); for ( IndexReference reference : loop( sortByType( schemaRead.indexesGetAll() ) ) ) { String userDescription = reference.schema().userDescription( nameLookup ); double uniqueValuesPercentage = schemaRead.indexUniqueValuesSelectivity( reference ); long size = schemaRead.indexSize( reference ); visitor.visitIndex( (IndexDescriptor) reference, userDescription, uniqueValuesPercentage, size ); } }
/** * Sorts indexes by type, returning first GENERAL indexes, followed by UNIQUE. Implementation is not suitable in * hot path. * * @param indexes Indexes to sort * @return sorted indexes */ static Iterator<IndexReference> sortByType( Iterator<IndexReference> indexes ) { List<IndexReference> materialized = Iterators.asList( indexes ); return Iterators.concat( Iterators.filter( i -> !i.isUnique(), materialized.iterator() ), Iterators.filter( IndexReference::isUnique, materialized.iterator() ) ); }
@Test public void shouldRespectOrderCapabilitiesForWildcard() throws Exception { // given boolean needsValues = false; int label = token.nodeLabel( "Node" ); int prop = token.propertyKey( "prop" ); IndexReference index = schemaRead.index( label, prop ); IndexOrder[] orderCapabilities = index.orderCapability( ValueCategory.UNKNOWN ); try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() ) { for ( IndexOrder orderCapability : orderCapabilities ) { // when read.nodeIndexSeek( index, node, orderCapability, needsValues, IndexQuery.exists( prop ) ); // then assertFoundNodesInOrder( node, orderCapability ); } } }
@Override public String getName() { return indexReference == null ? IndexReference.UNNAMED_INDEX : indexReference.name(); }
SchemaDescriptor schema = index.schema(); int[] entityTokenIds = schema.getEntityTokenIds(); boolean constraintIndex = index.isUnique(); String[] propertyNames = PropertyNameUtils.getPropertyKeys( tokenRead, index.properties() ); switch ( schema.entityType() )
private static IndexType getIndexTypeOf( IndexReference index ) if ( index.isFulltextIndex() ) if ( index.schema().entityType() == EntityType.NODE ) if ( index.isUnique() ) if ( index.schema().entityType() == EntityType.NODE )
indexes.sort( Comparator.comparing( a -> a.userDescription( tokens ) ) ); SchemaDescriptor schema = index.schema(); long indexId = getIndexId( indexingService, schema ); List<String> tokenNames = Arrays.asList( tokens.entityTokensGetNames( schema.entityType(), schema.getEntityTokenIds() ) ); result.add( new IndexResult( indexId, description, index.name(), tokenNames, propertyNames, "No index on ", index.userDescription( tokens ) );
if ( !index.isUnique() ) tokenNameLookup, index.properties() ); indexes.add( String.join( ",", propertyNames ) );
private void showIndices( DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup ) throws IndexNotFoundKernelException { SchemaRead schemaRead = ktx.schemaRead(); for ( IndexReference reference : loop( sortByType( schemaRead.indexesGetAll() ) ) ) { String userDescription = reference.schema().userDescription( nameLookup ); double uniqueValuesPercentage = schemaRead.indexUniqueValuesSelectivity( reference ); long size = schemaRead.indexSize( reference ); visitor.visitIndex( (IndexDescriptor) reference, userDescription, uniqueValuesPercentage, size ); } }
private IndexReference getOrCreateUniquenessConstraintIndex( SchemaRead schemaRead, TokenRead tokenRead, SchemaDescriptor schema, String provider ) throws SchemaKernelException, IndexNotFoundKernelException { IndexReference descriptor = schemaRead.index( schema ); if ( descriptor != IndexReference.NO_INDEX ) { if ( descriptor.isUnique() ) { // OK so we found a matching constraint index. We check whether or not it has an owner // because this may have been a left-over constraint index from a previously failed // constraint creation, due to crash or similar, hence the missing owner. if ( schemaRead.indexGetOwningUniquenessConstraintId( descriptor ) == null ) { return descriptor; } throw new AlreadyConstrainedException( ConstraintDescriptorFactory.uniqueForSchema( schema ), OperationContext.CONSTRAINT_CREATION, new SilentTokenNameLookup( tokenRead ) ); } // There's already an index for this schema descriptor, which isn't of the type we're after. throw new AlreadyIndexedException( schema, CONSTRAINT_CREATION ); } IndexDescriptor indexDescriptor = createConstraintIndex( schema, provider ); IndexProxy indexProxy = indexingService.getIndexProxy( indexDescriptor.schema() ); return indexProxy.getDescriptor(); }