add hasSingleArrayBackingStorage

allow for optimization only when there really is a single array, and not when there is a multi dimensional one
This commit is contained in:
Shay Banon 2013-01-23 10:24:33 +01:00
parent bbfd3957eb
commit 20f43bf54c
7 changed files with 38 additions and 7 deletions

View File

@ -387,12 +387,14 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
Object ordsStorage = docToOrd.ordinals().getBackingStorage(); Object ordsStorage = docToOrd.ordinals().getBackingStorage();
FieldComparator<BytesRef> perSegComp = null; FieldComparator<BytesRef> perSegComp = null;
if (ordsStorage instanceof byte[]) { if (docToOrd.ordinals().hasSingleArrayBackingStorage()) {
perSegComp = new ByteOrdComparator((byte[]) ordsStorage, termsIndex, docBase); if (ordsStorage instanceof byte[]) {
} else if (ordsStorage instanceof short[]) { perSegComp = new ByteOrdComparator((byte[]) ordsStorage, termsIndex, docBase);
perSegComp = new ShortOrdComparator((short[]) ordsStorage, termsIndex, docBase); } else if (ordsStorage instanceof short[]) {
} else if (ordsStorage instanceof int[]) { perSegComp = new ShortOrdComparator((short[]) ordsStorage, termsIndex, docBase);
perSegComp = new IntOrdComparator((int[]) ordsStorage, termsIndex, docBase); } else if (ordsStorage instanceof int[]) {
perSegComp = new IntOrdComparator((int[]) ordsStorage, termsIndex, docBase);
}
} }
// Don't specialize the long[] case since it's not // Don't specialize the long[] case since it's not
// possible, ie, worse case is MAX_INT-1 docs with // possible, ie, worse case is MAX_INT-1 docs with

View File

@ -38,6 +38,11 @@ public class DocIdOrdinals implements Ordinals {
this.numDocs = numDocs; this.numDocs = numDocs;
} }
@Override
public boolean hasSingleArrayBackingStorage() {
return false;
}
@Override @Override
public Object getBackingStorage() { public Object getBackingStorage() {
return null; return null;

View File

@ -36,6 +36,11 @@ public class EmptyOrdinals implements Ordinals {
return 0; return 0;
} }
@Override
public boolean hasSingleArrayBackingStorage() {
return false;
}
@Override @Override
public Object getBackingStorage() { public Object getBackingStorage() {
return null; return null;

View File

@ -50,6 +50,11 @@ public class MultiFlatArrayOrdinals implements Ordinals {
this.numOrds = numOrds; this.numOrds = numOrds;
} }
@Override
public boolean hasSingleArrayBackingStorage() {
return false;
}
@Override @Override
public Object getBackingStorage() { public Object getBackingStorage() {
return ordinals; return ordinals;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.fielddata.ordinals; package org.elasticsearch.index.fielddata.ordinals;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.util.IntArrayRef; import org.elasticsearch.index.fielddata.util.IntArrayRef;
/** /**
@ -27,6 +26,11 @@ import org.elasticsearch.index.fielddata.util.IntArrayRef;
*/ */
public interface Ordinals { public interface Ordinals {
/**
* Are the ordinals backed by a single ordinals array?
*/
boolean hasSingleArrayBackingStorage();
/** /**
* Returns the backing storage for this ordinals. * Returns the backing storage for this ordinals.
*/ */

View File

@ -37,6 +37,11 @@ public class SingleArrayOrdinals implements Ordinals {
this.numOrds = numOrds; this.numOrds = numOrds;
} }
@Override
public boolean hasSingleArrayBackingStorage() {
return true;
}
@Override @Override
public Object getBackingStorage() { public Object getBackingStorage() {
return ordinals; return ordinals;

View File

@ -38,6 +38,11 @@ public class SinglePackedOrdinals implements Ordinals {
this.numOrds = numOrds; this.numOrds = numOrds;
} }
@Override
public boolean hasSingleArrayBackingStorage() {
return reader.hasArray();
}
@Override @Override
public Object getBackingStorage() { public Object getBackingStorage() {
if (reader.hasArray()) { if (reader.hasArray()) {