Skip to content

Commit c183b92

Browse files
authored
Fast path for reading single doc with ordinals (#102902)
This optimization is added for enrich lookups, which are likely to match a single document. The change decreases the latency of the enrich operation in the nyc_taxis benchmark from 100ms to 70ms. When combined with #102901, it further reduces the latency to below 40ms, better than the previous performance before the regression. Relates #102625
1 parent 5c3d118 commit c183b92

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

docs/changelog/102902.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 102902
2+
summary: Fast path for reading single doc with ordinals
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/index/mapper/BlockDocValuesReader.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,20 @@ private static class SingletonOrdinals extends BlockDocValuesReader {
555555
this.ordinals = ordinals;
556556
}
557557

558+
private BlockLoader.Block readSingleDoc(BlockFactory factory, int docId) throws IOException {
559+
if (ordinals.advanceExact(docId)) {
560+
BytesRef v = ordinals.lookupOrd(ordinals.ordValue());
561+
return factory.constantBytes(v);
562+
} else {
563+
return factory.constantNulls();
564+
}
565+
}
566+
558567
@Override
559568
public BlockLoader.Block read(BlockFactory factory, Docs docs) throws IOException {
569+
if (docs.count() == 1) {
570+
return readSingleDoc(factory, docs.get(0));
571+
}
560572
try (BlockLoader.SingletonOrdinalsBuilder builder = factory.singletonOrdinalsBuilder(ordinals, docs.count())) {
561573
for (int i = 0; i < docs.count(); i++) {
562574
int doc = docs.get(i);

0 commit comments

Comments
 (0)