diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexReader.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexReader.java index c15c404c40208..611365ddd541a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexReader.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexReader.java @@ -70,8 +70,8 @@ public void close() @Override public IndexSampler createSampler() { - // For an unique index there's an optimization, knowing that all values in it are unique, to simply count - // the number of indexes values and create a sample for that count. The GBPTree doesn't have an O(1) + // For a unique index there's an optimization, knowing that all values in it are unique, to simply count + // the number of indexed values and create a sample for that count. The GBPTree doesn't have an O(1) // count mechanism, it will have to manually count the indexed values in it to get it. // For that reason this implementation opts for keeping complexity down by just using the existing // non-unique sampler which scans the index and counts (potentially duplicates, of which there will diff --git a/community/neo4j/src/test/java/org/neo4j/index/IndexSamplingIntegrationTest.java b/community/neo4j/src/test/java/org/neo4j/index/IndexSamplingIntegrationTest.java index c5b1849e6bfbf..60f5e46802023 100644 --- a/community/neo4j/src/test/java/org/neo4j/index/IndexSamplingIntegrationTest.java +++ b/community/neo4j/src/test/java/org/neo4j/index/IndexSamplingIntegrationTest.java @@ -51,7 +51,11 @@ import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.rule.TestDirectory; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; public class IndexSamplingIntegrationTest { @@ -60,7 +64,7 @@ public class IndexSamplingIntegrationTest private final Label label = Label.label( "Person" ); private final String property = "name"; - private final int nodes = 1000; + private final long nodes = 1000; private final String[] names = {"Neo4j", "Neo", "Graph", "Apa"}; @Test @@ -121,12 +125,12 @@ public void shouldSampleNotUniqueIndex() throws Throwable // Then - // sampling will consider also the delete nodes till the next lucene compaction + // lucene will consider also the delete nodes, native won't DoubleLongRegister register = fetchIndexSamplingValues( db ); assertEquals( names.length, register.readFirst() ); - assertEquals( nodes, register.readSecond() ); + assertThat( register.readSecond(), allOf( greaterThanOrEqualTo( nodes - deletedNodes ), lessThanOrEqualTo( nodes ) ) ); - // but the deleted nodes should not be considered in the index size value + // but regardless, the deleted nodes should not be considered in the index size value DoubleLongRegister indexSizeRegister = fetchIndexSizeValues( db ); assertEquals( 0, indexSizeRegister.readFirst() ); assertEquals( nodes - deletedNodes, indexSizeRegister.readSecond() );