LUCENE-8152: Improve consumption of doc-value iterators.

This commit is contained in:
Adrien Grand 2018-02-12 14:49:49 +01:00
parent 7a38394765
commit aa157f1833
17 changed files with 38 additions and 152 deletions

View File

@ -144,6 +144,9 @@ Improvements
* LUCENE-8127: Speed up rewriteNoScoring when there are no MUST clauses. * LUCENE-8127: Speed up rewriteNoScoring when there are no MUST clauses.
(Michael Braun via Adrien Grand) (Michael Braun via Adrien Grand)
* LUCENE-8152: Improve consumption of doc-value iterators. (Horatiu Lazu via
Adrien Grand)
Bug Fixes Bug Fixes
* LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators. * LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators.

View File

@ -77,10 +77,7 @@ final class GlobalOrdinalsCollector implements Collector {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docTermOrds.docID()) { if (docTermOrds.advanceExact(doc)) {
docTermOrds.advance(doc);
}
if (doc == docTermOrds.docID()) {
long segmentOrd = docTermOrds.ordValue(); long segmentOrd = docTermOrds.ordValue();
long globalOrd = segmentOrdToGlobalOrdLookup.get(segmentOrd); long globalOrd = segmentOrdToGlobalOrdLookup.get(segmentOrd);
collectedOrds.set(globalOrd); collectedOrds.set(globalOrd);
@ -102,10 +99,7 @@ final class GlobalOrdinalsCollector implements Collector {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docTermOrds.docID()) { if (docTermOrds.advanceExact(doc)) {
docTermOrds.advance(doc);
}
if (doc == docTermOrds.docID()) {
collectedOrds.set(docTermOrds.ordValue()); collectedOrds.set(docTermOrds.ordValue());
} }
} }

View File

@ -182,11 +182,7 @@ final class GlobalOrdinalsQuery extends Query {
@Override @Override
public boolean matches() throws IOException { public boolean matches() throws IOException {
int docID = approximation.docID(); if (values.advanceExact(approximation.docID())) {
if (docID > values.docID()) {
values.advance(docID);
}
if (docID == values.docID()) {
final long segmentOrd = values.ordValue(); final long segmentOrd = values.ordValue();
final long globalOrd = segmentOrdToGlobalOrdLookup.get(segmentOrd); final long globalOrd = segmentOrdToGlobalOrdLookup.get(segmentOrd);
if (foundOrds.get(globalOrd)) { if (foundOrds.get(globalOrd)) {
@ -220,14 +216,8 @@ final class GlobalOrdinalsQuery extends Query {
@Override @Override
public boolean matches() throws IOException { public boolean matches() throws IOException {
int docID = approximation.docID(); if (values.advanceExact(approximation.docID()) && foundOrds.get(values.ordValue())) {
if (docID > values.docID()) { return true;
values.advance(docID);
}
if (docID == values.docID()) {
if (foundOrds.get(values.ordValue())) {
return true;
}
} }
return false; return false;
} }

View File

@ -113,10 +113,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docTermOrds.docID()) { if (docTermOrds.advanceExact(doc)) {
docTermOrds.advance(doc);
}
if (doc == docTermOrds.docID()) {
final int globalOrd = (int) segmentOrdToGlobalOrdLookup.get(docTermOrds.ordValue()); final int globalOrd = (int) segmentOrdToGlobalOrdLookup.get(docTermOrds.ordValue());
collectedOrds.set(globalOrd); collectedOrds.set(globalOrd);
float existingScore = scores.getScore(globalOrd); float existingScore = scores.getScore(globalOrd);
@ -145,10 +142,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docTermOrds.docID()) { if (docTermOrds.advanceExact(doc)) {
docTermOrds.advance(doc);
}
if (doc == docTermOrds.docID()) {
int segmentOrd = docTermOrds.ordValue(); int segmentOrd = docTermOrds.ordValue();
collectedOrds.set(segmentOrd); collectedOrds.set(segmentOrd);
float existingScore = scores.getScore(segmentOrd); float existingScore = scores.getScore(segmentOrd);
@ -258,10 +252,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docTermOrds.docID()) { if (docTermOrds.advanceExact(doc)) {
docTermOrds.advance(doc);
}
if (doc == docTermOrds.docID()) {
final int globalOrd = (int) segmentOrdToGlobalOrdLookup.get(docTermOrds.ordValue()); final int globalOrd = (int) segmentOrdToGlobalOrdLookup.get(docTermOrds.ordValue());
collectedOrds.set(globalOrd); collectedOrds.set(globalOrd);
occurrences.increment(globalOrd); occurrences.increment(globalOrd);
@ -276,10 +267,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docTermOrds.docID()) { if (docTermOrds.advanceExact(doc)) {
docTermOrds.advance(doc);
}
if (doc == docTermOrds.docID()) {
int segmentOrd = docTermOrds.ordValue(); int segmentOrd = docTermOrds.ordValue();
collectedOrds.set(segmentOrd); collectedOrds.set(segmentOrd);
occurrences.increment(segmentOrd); occurrences.increment(segmentOrd);

View File

@ -191,11 +191,7 @@ final class GlobalOrdinalsWithScoreQuery extends Query {
@Override @Override
public boolean matches() throws IOException { public boolean matches() throws IOException {
int docID = approximation.docID(); if (values.advanceExact(approximation.docID())) {
if (docID > values.docID()) {
values.advance(docID);
}
if (docID == values.docID()) {
final long segmentOrd = values.ordValue(); final long segmentOrd = values.ordValue();
final int globalOrd = (int) segmentOrdToGlobalOrdLookup.get(segmentOrd); final int globalOrd = (int) segmentOrdToGlobalOrdLookup.get(segmentOrd);
if (collector.match(globalOrd)) { if (collector.match(globalOrd)) {
@ -229,11 +225,7 @@ final class GlobalOrdinalsWithScoreQuery extends Query {
@Override @Override
public boolean matches() throws IOException { public boolean matches() throws IOException {
int docID = approximation.docID(); if (values.advanceExact(approximation.docID())) {
if (docID > values.docID()) {
values.advance(docID);
}
if (docID == values.docID()) {
final int segmentOrd = values.ordValue(); final int segmentOrd = values.ordValue();
if (collector.match(segmentOrd)) { if (collector.match(segmentOrd)) {
score = collector.score(segmentOrd); score = collector.score(segmentOrd);

View File

@ -199,10 +199,7 @@ public final class JoinUtil {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > sortedNumericDocValues.docID()) { if (sortedNumericDocValues.advanceExact(doc)) {
sortedNumericDocValues.advance(doc);
}
if (doc == sortedNumericDocValues.docID()) {
for (int i = 0; i < sortedNumericDocValues.docValueCount(); i++) { for (int i = 0; i < sortedNumericDocValues.docValueCount(); i++) {
long value = sortedNumericDocValues.nextValue(); long value = sortedNumericDocValues.nextValue();
joinValues.add(value); joinValues.add(value);
@ -246,15 +243,9 @@ public final class JoinUtil {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
assert docsInOrder(doc); assert docsInOrder(doc);
int dvDocID = numericDocValues.docID(); long value = 0;
if (dvDocID < doc) { if (numericDocValues.advanceExact(doc)) {
dvDocID = numericDocValues.advance(doc);
}
long value;
if (dvDocID == doc) {
value = numericDocValues.longValue(); value = numericDocValues.longValue();
} else {
value = 0;
} }
joinValues.add(value); joinValues.add(value);
if (needsScore) { if (needsScore) {

View File

@ -84,11 +84,8 @@ abstract class TermsCollector<DV> extends DocValuesTermsCollector<DV> {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (docValues.docID() < doc) {
docValues.advance(doc);
}
BytesRef term; BytesRef term;
if (docValues.docID() == doc) { if (docValues.advanceExact(doc)) {
term = docValues.binaryValue(); term = docValues.binaryValue();
} else { } else {
term = new BytesRef(BytesRef.EMPTY_BYTES); term = new BytesRef(BytesRef.EMPTY_BYTES);

View File

@ -96,11 +96,8 @@ abstract class TermsWithScoreCollector<DV> extends DocValuesTermsCollector<DV>
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (docValues.docID() < doc) {
docValues.advance(doc);
}
BytesRef value; BytesRef value;
if (docValues.docID() == doc) { if (docValues.advanceExact(doc)) {
value = docValues.binaryValue(); value = docValues.binaryValue();
} else { } else {
value = new BytesRef(BytesRef.EMPTY_BYTES); value = new BytesRef(BytesRef.EMPTY_BYTES);
@ -155,11 +152,8 @@ abstract class TermsWithScoreCollector<DV> extends DocValuesTermsCollector<DV>
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (docValues.docID() < doc) {
docValues.advance(doc);
}
BytesRef value; BytesRef value;
if (docValues.docID() == doc) { if (docValues.advanceExact(doc)) {
value = docValues.binaryValue(); value = docValues.binaryValue();
} else { } else {
value = new BytesRef(BytesRef.EMPTY_BYTES); value = new BytesRef(BytesRef.EMPTY_BYTES);
@ -207,10 +201,7 @@ abstract class TermsWithScoreCollector<DV> extends DocValuesTermsCollector<DV>
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docValues.docID()) { if (docValues.advanceExact(doc)) {
docValues.advance(doc);
}
if (doc == docValues.docID()) {
long ord; long ord;
while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
int termID = collectedTerms.add(docValues.lookupOrd(ord)); int termID = collectedTerms.add(docValues.lookupOrd(ord));
@ -255,10 +246,7 @@ abstract class TermsWithScoreCollector<DV> extends DocValuesTermsCollector<DV>
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > docValues.docID()) { if (docValues.advanceExact(doc)) {
docValues.advance(doc);
}
if (doc == docValues.docID()) {
long ord; long ord;
while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
int termID = collectedTerms.add(docValues.lookupOrd(ord)); int termID = collectedTerms.add(docValues.lookupOrd(ord));

View File

@ -1471,11 +1471,8 @@ public class TestJoinUtil extends LuceneTestCase {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > terms.docID()) {
terms.advance(doc);
}
final BytesRef joinValue; final BytesRef joinValue;
if (doc == terms.docID()) { if (terms.advanceExact(doc)) {
joinValue = terms.binaryValue(); joinValue = terms.binaryValue();
} else { } else {
// missing; // missing;
@ -1540,11 +1537,8 @@ public class TestJoinUtil extends LuceneTestCase {
@Override @Override
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
if (doc > terms.docID()) {
terms.advance(doc);
}
final BytesRef joinValue; final BytesRef joinValue;
if (doc == terms.docID()) { if (terms.advanceExact(doc)) {
joinValue = terms.binaryValue(); joinValue = terms.binaryValue();
} else { } else {
// missing; // missing;

View File

@ -591,10 +591,7 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
ord = -1; ord = -1;
} }
} else { } else {
if (globalDoc > docValues.docID()) { if (docValues.advanceExact(globalDoc)) {
docValues.advance(globalDoc);
}
if (globalDoc == docValues.docID()) {
ord = docValues.ordValue(); ord = docValues.ordValue();
} else { } else {
ord = -1; ord = -1;
@ -664,12 +661,8 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
@Override @Override
public void collect(int docId) throws IOException { public void collect(int docId) throws IOException {
int valuesDocID = docValues.docID();
if (valuesDocID < docId) {
valuesDocID = docValues.advance(docId);
}
long value; long value;
if (valuesDocID == docId) { if (docValues.advanceExact(docId)) {
value = docValues.longValue(); value = docValues.longValue();
} else { } else {
value = 0; value = 0;

View File

@ -560,20 +560,14 @@ public class CollapsingQParserPlugin extends QParserPlugin {
int ord = -1; int ord = -1;
if(this.ordinalMap != null) { if(this.ordinalMap != null) {
//Handle ordinalMapping case //Handle ordinalMapping case
if (contextDoc > segmentValues.docID()) { if (segmentValues.advanceExact(contextDoc)) {
segmentValues.advance(contextDoc);
}
if (contextDoc == segmentValues.docID()) {
ord = (int)segmentOrdinalMap.get(segmentValues.ordValue()); ord = (int)segmentOrdinalMap.get(segmentValues.ordValue());
} else { } else {
ord = -1; ord = -1;
} }
} else { } else {
//Handle top Level FieldCache or Single Segment Case //Handle top Level FieldCache or Single Segment Case
if (globalDoc > segmentValues.docID()) { if (segmentValues.advanceExact(globalDoc)) {
segmentValues.advance(globalDoc);
}
if (globalDoc == segmentValues.docID()) {
ord = segmentValues.ordValue(); ord = segmentValues.ordValue();
} else { } else {
ord = -1; ord = -1;
@ -786,14 +780,8 @@ public class CollapsingQParserPlugin extends QParserPlugin {
@Override @Override
public void collect(int contextDoc) throws IOException { public void collect(int contextDoc) throws IOException {
int collapseDocID = collapseValues.docID();
if (collapseDocID < contextDoc) {
collapseDocID = collapseValues.advance(contextDoc);
}
int collapseValue; int collapseValue;
if (collapseDocID == contextDoc) { if (collapseValues.advanceExact(contextDoc)) {
collapseValue = (int) collapseValues.longValue(); collapseValue = (int) collapseValues.longValue();
} else { } else {
collapseValue = 0; collapseValue = 0;
@ -1022,10 +1010,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
ord = (int)segmentOrdinalMap.get(segmentValues.ordValue()); ord = (int)segmentOrdinalMap.get(segmentValues.ordValue());
} }
} else { } else {
if (globalDoc > segmentValues.docID()) { if (segmentValues.advanceExact(globalDoc)) {
segmentValues.advance(globalDoc);
}
if (globalDoc == segmentValues.docID()) {
ord = segmentValues.ordValue(); ord = segmentValues.ordValue();
} }
} }
@ -1197,13 +1182,8 @@ public class CollapsingQParserPlugin extends QParserPlugin {
} }
public void collect(int contextDoc) throws IOException { public void collect(int contextDoc) throws IOException {
int collapseDocID = collapseValues.docID();
if (collapseDocID < contextDoc) {
collapseDocID = collapseValues.advance(contextDoc);
}
int collapseKey; int collapseKey;
if (collapseDocID == contextDoc) { if (collapseValues.advanceExact(contextDoc)) {
collapseKey = (int) collapseValues.longValue(); collapseKey = (int) collapseValues.longValue();
} else { } else {
collapseKey = 0; collapseKey = 0;

View File

@ -125,12 +125,8 @@ public class IGainTermsQParserPlugin extends QParserPlugin {
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
super.collect(doc); super.collect(doc);
++count; ++count;
int valuesDocID = leafOutcomeValue.docID();
if (valuesDocID < doc) {
valuesDocID = leafOutcomeValue.advance(doc);
}
int value; int value;
if (valuesDocID == doc) { if (leafOutcomeValue.advanceExact(doc)) {
value = (int) leafOutcomeValue.longValue(); value = (int) leafOutcomeValue.longValue();
} else { } else {
value = 0; value = 0;

View File

@ -150,12 +150,8 @@ public class TextLogisticRegressionQParserPlugin extends QParserPlugin {
} }
public void collect(int doc) throws IOException{ public void collect(int doc) throws IOException{
int valuesDocID = leafOutcomeValue.docID();
if (valuesDocID < doc) {
valuesDocID = leafOutcomeValue.advance(doc);
}
int outcome; int outcome;
if (valuesDocID == doc) { if (leafOutcomeValue.advanceExact(doc)) {
outcome = (int) leafOutcomeValue.longValue(); outcome = (int) leafOutcomeValue.longValue();
} else { } else {
outcome = 0; outcome = 0;

View File

@ -387,10 +387,7 @@ class FacetFieldProcessorByHashDV extends FacetFieldProcessor {
@Override @Override
public void collect(int segDoc) throws IOException { public void collect(int segDoc) throws IOException {
if (segDoc > values.docID()) { if (values.advanceExact(segDoc)) {
values.advance(segDoc);
}
if (segDoc == values.docID()) {
long l = values.nextValue(); // This document must have at least one value long l = values.nextValue(); // This document must have at least one value
collectValFirstPhase(segDoc, l); collectValFirstPhase(segDoc, l);
for (int i = 1; i < values.docValueCount(); i++) { for (int i = 1; i < values.docValueCount(); i++) {
@ -418,10 +415,7 @@ class FacetFieldProcessorByHashDV extends FacetFieldProcessor {
@Override @Override
public void collect(int segDoc) throws IOException { public void collect(int segDoc) throws IOException {
if (segDoc > values.docID()) { if (values.advanceExact(segDoc)) {
values.advance(segDoc);
}
if (segDoc == values.docID()) {
collectValFirstPhase(segDoc, values.longValue()); collectValFirstPhase(segDoc, values.longValue());
} }
} }

View File

@ -335,10 +335,7 @@ public class MinMaxAgg extends SimpleAggValueSource {
@Override @Override
public void collect(int doc, int slotNum) throws IOException { public void collect(int doc, int slotNum) throws IOException {
if (doc > subDv.docID()) { if (subDv.advanceExact(doc)) {
subDv.advance(doc);
}
if (doc == subDv.docID()) {
int segOrd = subDv.ordValue(); int segOrd = subDv.ordValue();
int ord = toGlobal==null ? segOrd : (int)toGlobal.get(segOrd); int ord = toGlobal==null ? segOrd : (int)toGlobal.get(segOrd);
if ((ord - slotOrd[slotNum]) * minmax < 0 || slotOrd[slotNum]==MISSING) { if ((ord - slotOrd[slotNum]) * minmax < 0 || slotOrd[slotNum]==MISSING) {

View File

@ -71,10 +71,7 @@ class UniqueMultiDvSlotAcc extends UniqueSlotAcc {
@Override @Override
public void collect(int doc, int slotNum) throws IOException { public void collect(int doc, int slotNum) throws IOException {
if (doc > subDv.docID()) { if (subDv.advanceExact(doc)) {
subDv.advance(doc);
}
if (doc == subDv.docID()) {
int segOrd = (int) subDv.nextOrd(); int segOrd = (int) subDv.nextOrd();
assert segOrd >= 0; assert segOrd >= 0;

View File

@ -693,12 +693,8 @@ public class TestRankQueryPlugin extends QParserPlugin {
public void setScorer(Scorer scorer) throws IOException {} public void setScorer(Scorer scorer) throws IOException {}
public void collect(int doc) throws IOException { public void collect(int doc) throws IOException {
int valuesDocID = values.docID();
if (valuesDocID < doc) {
valuesDocID = values.advance(doc);
}
long value; long value;
if (valuesDocID == doc) { if (values.advanceExact(doc)) {
value = values.longValue(); value = values.longValue();
} else { } else {
value = 0; value = 0;