|
9 | 9 |
|
10 | 10 | package org.elasticsearch.index.engine;
|
11 | 11 |
|
| 12 | +import com.carrotsearch.hppc.IntArrayList; |
| 13 | + |
12 | 14 | import org.apache.lucene.index.LeafReaderContext;
|
13 | 15 | import org.apache.lucene.search.FieldDoc;
|
14 | 16 | import org.apache.lucene.search.ScoreDoc;
|
@@ -191,8 +193,28 @@ private Translog.Operation[] loadDocuments(List<SearchRecord> documentRecords) t
|
191 | 193 | maxDoc = leafReaderContext.reader().maxDoc();
|
192 | 194 | } while (docRecord.docID() >= docBase + maxDoc);
|
193 | 195 |
|
194 |
| - leafFieldLoader = storedFieldLoader.getLoader(leafReaderContext, null); |
195 |
| - leafSourceLoader = sourceLoader.leaf(leafReaderContext.reader(), null); |
| 196 | + // TODO: instead of building an array, consider just checking whether doc ids are dense. |
| 197 | + // Note, field loaders then would lose the ability to optionally eagerly loading values. |
| 198 | + IntArrayList nextDocIds = new IntArrayList(); |
| 199 | + for (int j = i; j < documentRecords.size(); j++) { |
| 200 | + var record = documentRecords.get(j); |
| 201 | + if (record.isTombstone()) { |
| 202 | + continue; |
| 203 | + } |
| 204 | + int docID = record.docID(); |
| 205 | + if (docID >= docBase + maxDoc) { |
| 206 | + break; |
| 207 | + } |
| 208 | + int segmentDocID = docID - docBase; |
| 209 | + nextDocIds.add(segmentDocID); |
| 210 | + } |
| 211 | + |
| 212 | + // This computed doc ids arrays us used by stored field loader as a heuristic to determine whether to use a sequential |
| 213 | + // stored field reader (which bulk loads stored fields and avoids decompressing the same blocks multiple times). For |
| 214 | + // source loader, it is also used as a heuristic for bulk reading doc values (E.g. SingletonDocValuesLoader). |
| 215 | + int[] nextDocIdArray = nextDocIds.toArray(); |
| 216 | + leafFieldLoader = storedFieldLoader.getLoader(leafReaderContext, nextDocIdArray); |
| 217 | + leafSourceLoader = sourceLoader.leaf(leafReaderContext.reader(), nextDocIdArray); |
196 | 218 | setNextSourceMetadataReader(leafReaderContext);
|
197 | 219 | }
|
198 | 220 | int segmentDocID = docRecord.docID() - docBase;
|
|
0 commit comments