Skip to content

Commit

Permalink
FusionIndexReader validate index order on queries
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Nov 16, 2017
1 parent 367293e commit b6c6e4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Expand Up @@ -161,12 +161,8 @@ private void validateQuery( IndexOrder indexOrder, IndexQuery[] predicates )

if ( indexOrder != null )
{
ValueGroup[] valueGroups = new ValueGroup[predicates.length];
for ( int i = 0; i < predicates.length; i++ )
{
valueGroups[i] = predicates[i].valueGroup();
}
IndexOrder[] capability = NativeSchemaNumberIndexProvider.CAPABILITY.orderCapability( valueGroups );
ValueGroup valueGroup = predicates[0].valueGroup();;
IndexOrder[] capability = NativeSchemaNumberIndexProvider.CAPABILITY.orderCapability( valueGroup );
if ( !ArrayUtil.contains( capability, indexOrder ) )
{
throw new UnsupportedOperationException(
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.kernel.impl.index.schema.fusion;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
Expand All @@ -36,6 +37,8 @@
import org.neo4j.storageengine.api.schema.IndexSampler;
import org.neo4j.values.storable.Value;

import static java.lang.String.format;

class FusionIndexReader implements IndexReader
{
private final IndexReader nativeReader;
Expand Down Expand Up @@ -132,6 +135,12 @@ public void query( IndexProgressor.NodeValueClient cursor, IndexOrder indexOrder
// todo: There will be no ordering of the node ids here. Is this a problem?
if ( predicates[0] instanceof ExistsPredicate )
{
if ( indexOrder != IndexOrder.UNORDERED )
{
throw new UnsupportedOperationException(
format( "Tried to query index with unsupported order %s. Supported orders for query %s are %s.",
indexOrder, Arrays.toString( predicates ), Arrays.toString( new IndexOrder[]{IndexOrder.UNORDERED} ) ) );
}
BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor( cursor, propertyKeys );
cursor.initialize( multiProgressor, propertyKeys );
nativeReader.query( multiProgressor, indexOrder, predicates[0] );
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;

import org.neo4j.internal.kernel.api.IndexCapability;
import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.index.IndexAccessor;
Expand All @@ -35,6 +36,7 @@
import org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant;
import org.neo4j.storageengine.api.schema.IndexSample;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.ValueGroup;

/**
* This {@link SchemaIndexProvider index provider} act as one logical index but is backed by two physical
Expand Down Expand Up @@ -132,7 +134,20 @@ public IndexCapability getCapability( IndexDescriptor indexDescriptor )
{
IndexCapability nativeCapability = nativeProvider.getCapability( indexDescriptor );
IndexCapability luceneCapability = luceneProvider.getCapability( indexDescriptor );
return new UnionIndexCapability( nativeCapability, luceneCapability );
return new UnionIndexCapability( nativeCapability, luceneCapability )
{
@Override
public IndexOrder[] orderCapability( ValueGroup... valueGroups )
{
// No order capability when combining results from different indexes
if ( valueGroups.length == 1 && valueGroups[0] == null )
{
return new IndexOrder[]{IndexOrder.UNORDERED};
}
// Otherwise union of capabilities
return super.orderCapability( valueGroups );
}
};
}

@Override
Expand Down

0 comments on commit b6c6e4f

Please sign in to comment.