Skip to content

Commit

Permalink
Use NEUTRAL inclusion for exact match queries in GenericNativeIndexRe…
Browse files Browse the repository at this point in the history
…ader

Because there is no notion of inclusion or exclusion for exact matches
and it would make the decision whether or not to include a composite key
by only looking at the first slot instead of taking all slots into
consideration.

Also fix CompositeIndexPopulatorCompatibility test to catch
IndexEntryConflictException during population.
  • Loading branch information
burqen committed Jul 27, 2018
1 parent 33af284 commit 83ac836
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public void shouldEnforceUniqueConstraintsDirectly() throws Exception
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() );
withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p ->
{
p.add( Arrays.asList(
IndexEntryUpdate.add( nodeId1, descriptor.schema(), value1, value2 ),
IndexEntryUpdate.add( nodeId2, descriptor.schema(), value1, value2 ) ) );
try
{
p.add( Arrays.asList(
IndexEntryUpdate.add( nodeId1, descriptor.schema(), value1, value2 ),
IndexEntryUpdate.add( nodeId2, descriptor.schema(), value1, value2 ) ) );
TestNodePropertyAccessor propertyAccessor =
new TestNodePropertyAccessor( nodeId1, descriptor.schema(), value1, value2 );
propertyAccessor.addNode( nodeId2, descriptor.schema(), value1, value2 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Value asValue()
}
}

// todo is this simple lowest approach viable?
void initValueAsLowest( ValueGroup valueGroup )
{
type = valueGroup == ValueGroup.UNKNOWN ? LOWEST_TYPE_BY_VALUE_GROUP : GenericLayout.TYPE_BY_GROUP[valueGroup.ordinal()];
Expand All @@ -142,6 +143,7 @@ void initValueAsLowest( ValueGroup valueGroup )
inclusion = LOW;
}

// todo is this simple highest approach viable?
void initValueAsHighest( ValueGroup valueGroup )
{
type = valueGroup == ValueGroup.UNKNOWN ? HIGHEST_TYPE_BY_VALUE_GROUP : GenericLayout.TYPE_BY_GROUP[valueGroup.ordinal()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.HIGH;
import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.LOW;
import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.NEUTRAL;

class GenericNativeIndexReader extends NativeIndexReader<CompositeGenericKey,NativeIndexValue>
{
Expand Down Expand Up @@ -76,8 +77,8 @@ boolean initializeRangeForQuery( CompositeGenericKey treeKeyFrom, CompositeGener
break;
case exact:
ExactPredicate exactPredicate = (ExactPredicate) predicate;
treeKeyFrom.initFromValue( i, exactPredicate.value(), LOW );
treeKeyTo.initFromValue( i, exactPredicate.value(), HIGH );
treeKeyFrom.initFromValue( i, exactPredicate.value(), NEUTRAL );
treeKeyTo.initFromValue( i, exactPredicate.value(), NEUTRAL );
break;
case range:
RangePredicate<?> rangePredicate = (RangePredicate<?>) predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
import org.neo4j.storageengine.api.schema.IndexSampler;
import org.neo4j.values.storable.Value;

import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.HIGH;
import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.LOW;
import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.NEUTRAL;

abstract class NativeIndexReader<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
implements IndexReader
Expand Down Expand Up @@ -93,8 +92,8 @@ public long countIndexedNodes( long nodeId, Value... propertyValues )
treeKeyTo.initialize( nodeId );
for ( int i = 0; i < propertyValues.length; i++ )
{
treeKeyFrom.initFromValue( i, propertyValues[i], LOW );
treeKeyTo.initFromValue( i, propertyValues[i], HIGH );
treeKeyFrom.initFromValue( i, propertyValues[i], NEUTRAL );
treeKeyTo.initFromValue( i, propertyValues[i], NEUTRAL );
}
try ( RawCursor<Hit<KEY,VALUE>,IOException> seeker = tree.seek( treeKeyFrom, treeKeyTo ) )
{
Expand Down

0 comments on commit 83ac836

Please sign in to comment.