use of org.neo4j.storageengine.api.txstate.LongDiffSets in project neo4j by neo4j.
the class TxStateIndexChanges method indexUpdatesForRangeSeek.
// RANGE SEEK
static AddedAndRemoved indexUpdatesForRangeSeek(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, PropertyIndexQuery.RangePredicate<?> predicate, IndexOrder indexOrder) {
NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return EMPTY_ADDED_AND_REMOVED;
}
int size = descriptor.schema().getPropertyIds().length;
RangeFilterValues rangeFilter = predicate == null ? RangeFilterValues.fromExists(size, equalityPrefix) : RangeFilterValues.fromRange(size, equalityPrefix, predicate);
MutableLongList added = LongLists.mutable.empty();
MutableLongSet removed = LongSets.mutable.empty();
Map<ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(rangeFilter.lower, true, rangeFilter.upper, true);
for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : inRange.entrySet()) {
ValueTuple values = entry.getKey();
Value rangeKey = values.valueAt(equalityPrefix.length);
LongDiffSets diffForSpecificValue = entry.getValue();
// Needs to manually filter for if lower or upper should be included
// since we only wants to compare the first value of the key and not all of them for composite indexes
boolean allowed = rangeFilter.allowedEntry(rangeKey, equalityPrefix.length);
// The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
if (allowed && (predicate == null || predicate.isRegularOrder() || predicate.acceptsValue(rangeKey))) {
added.addAll(diffForSpecificValue.getAdded());
removed.addAll(diffForSpecificValue.getRemoved());
}
}
return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
use of org.neo4j.storageengine.api.txstate.LongDiffSets in project neo4j by neo4j.
the class TxStateIndexChanges method indexUpdatesWithValuesForRangeSeekByPrefix.
static AddedWithValuesAndRemoved indexUpdatesWithValuesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, TextValue prefix, IndexOrder indexOrder) {
NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
}
int keySize = descriptor.schema().getPropertyIds().length;
ValueTuple floor = getCompositeValueTuple(keySize, equalityPrefix, prefix, true);
ValueTuple maxString = getCompositeValueTuple(keySize, equalityPrefix, Values.MAX_STRING, false);
MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
MutableLongSet removed = LongSets.mutable.empty();
for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
ValueTuple key = entry.getKey();
Value prefixKey = key.valueAt(equalityPrefix.length);
// Needs to check type since the subMap might include non-TextValue for composite index
if (prefixKey.valueGroup() == ValueGroup.TEXT && ((TextValue) prefixKey).startsWith(prefix)) {
LongDiffSets diffSets = entry.getValue();
Value[] values = key.getValues();
diffSets.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, values)));
removed.addAll(diffSets.getRemoved());
} else {
break;
}
}
return new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
use of org.neo4j.storageengine.api.txstate.LongDiffSets in project neo4j by neo4j.
the class TxState method nodeDoDelete.
@Override
public void nodeDoDelete(long nodeId) {
nodes().remove(nodeId);
if (nodeStatesMap != null) {
// Previously this node state was removed completely and its state cleared. Was that to reduce memory footprint for large deletions?
// We have changed this so that it still keeps the removed relationships for this node so that they can be handed to command creation
// grouped by type and direction.
NodeStateImpl nodeState = nodeStatesMap.get(nodeId);
if (nodeState != null) {
final LongDiffSets diff = nodeState.labelDiffSets();
diff.getAdded().each(label -> getOrCreateLabelStateNodeDiffSets(label).remove(nodeId));
nodeState.markAsDeleted();
}
}
dataChanged();
}
Aggregations