Apache Lucene open-source search software
LUCENE-4283: check next skip point to see if it's worth invoking skipper
Michael McCandlesseab777c3d3c9
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListReader.java b/lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListReader.javaindex 597d9a0404b..b136c2ad318 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListReader.java@@ -59,7 +59,7 @@ public abstract class MultiLevelSkipListReader {private int skipInterval[]; // skipInterval of each levelprivate int[] numSkipped; // number of docs skipped per level- private int[] skipDoc; // doc id of current skip entry per level+ protected int[] skipDoc; // doc id of current skip entry per levelprivate int lastDoc; // doc id of last read skip entry with docId <= targetprivate long[] childPointer; // child pointer of current skip entry per levelprivate long lastChildPointer; // childPointer of last read skip entry with docId <= targetdiff --git a/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.javaindex da69a321781..15a22a2fc16 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java@@ -355,6 +355,10 @@ public final class BlockPostingsReader extends PostingsReaderBase {// no skip data for this term):private int skipOffset;+ // docID for next skip point, we won't use skipper if+ // target docID is not larger than this+ private int nextSkipDoc;+private Bits liveDocs;public BlockDocsEnum(FieldInfo fieldInfo) throws IOException {@@ -391,6 +395,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {}accum = 0;docUpto = 0;+ nextSkipDoc = BLOCK_SIZE - 1; // we won't skip if target is found in first blockdocBufferUpto = BLOCK_SIZE;skipped = false;return this;@@ -475,10 +480,13 @@ public final class BlockPostingsReader extends PostingsReaderBase {@Overridepublic int advance(int target) throws IOException {// nocommit make frq block load lazy/skippable+ if (DEBUG) {+ System.out.println(" FPR.advance target=" + target);+ }- // nocommit use skipper!!! it has next last doc id!!-- if (docFreq > BLOCK_SIZE && target - accum > BLOCK_SIZE) {+ // current skip docID < docIDs generated from current buffer <= next skip docID+ // we don't need to skip if target is buffered already+ if (docFreq > BLOCK_SIZE && target > nextSkipDoc) {if (DEBUG) {System.out.println("load skipper");@@ -517,6 +525,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {accum = skipper.getDoc(); // actually, this is just lastSkipEntrydocIn.seek(skipper.getDocPointer()); // now point to the block we want to search}+ nextSkipDoc = skipper.getNextSkipDoc();}// Now scan... this is an inlined/pared down version@@ -622,6 +631,8 @@ public final class BlockPostingsReader extends PostingsReaderBase {// no skip data for this term):private int skipOffset;+ private int nextSkipDoc;+private Bits liveDocs;public BlockDocsAndPositionsEnum(FieldInfo fieldInfo) throws IOException {@@ -664,6 +675,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {doc = -1;accum = 0;docUpto = 0;+ nextSkipDoc = BLOCK_SIZE - 1;docBufferUpto = BLOCK_SIZE;skipped = false;return this;@@ -783,11 +795,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {System.out.println(" FPR.advance target=" + target);}- // nocommit 2 is heuristic guess!!- // nocommit put cheating back! does it help?- // nocommit use skipper!!! it has next last doc id!!- //if (docFreq > BLOCK_SIZE && target - (BLOCK_SIZE - docBufferUpto) - 2*BLOCK_SIZE > accum) {- if (docFreq > BLOCK_SIZE && target - accum > BLOCK_SIZE) {+ if (docFreq > BLOCK_SIZE && target > nextSkipDoc) {if (DEBUG) {System.out.println(" try skipper");}@@ -833,6 +841,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {posPendingFP = skipper.getPosPointer();posPendingCount = skipper.getPosBufferUpto();}+ nextSkipDoc = skipper.getNextSkipDoc();}// Now scan... this is an inlined/pared down version@@ -1047,6 +1056,8 @@ public final class BlockPostingsReader extends PostingsReaderBase {// no skip data for this term):private int skipOffset;+ private int nextSkipDoc;+private Bits liveDocs;public EverythingEnum(FieldInfo fieldInfo) throws IOException {@@ -1110,6 +1121,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {doc = -1;accum = 0;docUpto = 0;+ nextSkipDoc = BLOCK_SIZE - 1;docBufferUpto = BLOCK_SIZE;skipped = false;return this;@@ -1278,11 +1290,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {System.out.println(" FPR.advance target=" + target);}- // nocommit 2 is heuristic guess!!- // nocommit put cheating back! does it help?- // nocommit use skipper!!! it has next last doc id!!- //if (docFreq > BLOCK_SIZE && target - (BLOCK_SIZE - docBufferUpto) - 2*BLOCK_SIZE > accum) {- if (docFreq > BLOCK_SIZE && target - accum > BLOCK_SIZE) {+ if (docFreq > BLOCK_SIZE && target > nextSkipDoc) {if (DEBUG) {System.out.println(" try skipper");@@ -1332,6 +1340,7 @@ public final class BlockPostingsReader extends PostingsReaderBase {lastStartOffset = skipper.getStartOffset();payloadByteUpto = skipper.getPayloadByteUpto();}+ nextSkipDoc = skipper.getNextSkipDoc();}// nocommit inline nextDoc herediff --git a/lucene/core/src/java/org/apache/lucene/codecs/block/BlockSkipReader.java b/lucene/core/src/java/org/apache/lucene/codecs/block/BlockSkipReader.javaindex b06b941ab55..f2dc7e7caee 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/block/BlockSkipReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/block/BlockSkipReader.java@@ -152,6 +152,10 @@ final class BlockSkipReader extends MultiLevelSkipListReader {return lastPayloadByteUpto;}+ public int getNextSkipDoc() {+ return skipDoc[0];+ }+@Overrideprotected void seekChild(int level) throws IOException {super.seekChild(level);diff --git a/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java b/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.javaindex ac55322edf8..84985278d73 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java@@ -37,7 +37,7 @@ public final class ForUtil {** @param data uncompressed data* @param intBuffer integer buffer to hold compressed data- * @return the number of frame bits for current block+ * @return the header for the current block*/static int compress(final int[] data, IntBuffer intBuffer) {int numBits = getNumBits(data);@@ -54,7 +54,8 @@ public final class ForUtil {}/**- * Save only one int when the whole block equals to 1+ * Save only one int when the whole block equals to a+ * single value.*/static int compressDuplicateBlock(final int[] data, IntBuffer intBuffer) {intBuffer.put(0, data[0]);