Skip to content

Commit

Permalink
Fast path for reading single doc with ordinals (#102902)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dnhatn authored Dec 6, 2023
1 parent 5c3d118 commit c183b92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/102902.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 102902
summary: Fast path for reading single doc with ordinals
area: ES|QL
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,20 @@ private static class SingletonOrdinals extends BlockDocValuesReader {
this.ordinals = ordinals;
}

private BlockLoader.Block readSingleDoc(BlockFactory factory, int docId) throws IOException {
if (ordinals.advanceExact(docId)) {
BytesRef v = ordinals.lookupOrd(ordinals.ordValue());
return factory.constantBytes(v);
} else {
return factory.constantNulls();
}
}

@Override
public BlockLoader.Block read(BlockFactory factory, Docs docs) throws IOException {
if (docs.count() == 1) {
return readSingleDoc(factory, docs.get(0));
}
try (BlockLoader.SingletonOrdinalsBuilder builder = factory.singletonOrdinalsBuilder(ordinals, docs.count())) {
for (int i = 0; i < docs.count(); i++) {
int doc = docs.get(i);
Expand Down

0 comments on commit c183b92

Please sign in to comment.