You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2023/02/27 16:39:05 UTC

[lucene] branch main updated: Lazily resolve ordinals when merging. (#12170)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 38d253fb53d Lazily resolve ordinals when merging. (#12170)
38d253fb53d is described below

commit 38d253fb53d33104a6b64e5fed56e79a14a4189b
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Mon Feb 27 17:38:59 2023 +0100

    Lazily resolve ordinals when merging. (#12170)
    
    The default implementation of merging doc values resolves the ordinal of a
    document in `nextDoc()`. But sometimes, doc values iterators are consumed
    without retrieving ordinals, e.g. to write the set of documents that have a
    value, so this may be wasteful.
    
    With this change, ordinals get resolved lazily upon `ordValue()`.
---
 .../org/apache/lucene/codecs/DocValuesConsumer.java  | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java
index 0d55915acc0..13ad32cf696 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java
@@ -709,7 +709,7 @@ public abstract class DocValuesConsumer implements Closeable {
 
     return new SortedDocValues() {
       private int docID = -1;
-      private int ord;
+      private SortedDocValuesSub current;
 
       @Override
       public int docID() {
@@ -718,20 +718,20 @@ public abstract class DocValuesConsumer implements Closeable {
 
       @Override
       public int nextDoc() throws IOException {
-        SortedDocValuesSub sub = docIDMerger.next();
-        if (sub == null) {
-          return docID = NO_MORE_DOCS;
+        current = docIDMerger.next();
+        if (current == null) {
+          docID = NO_MORE_DOCS;
+        } else {
+          docID = current.mappedDocID;
         }
-        int subOrd = sub.values.ordValue();
-        assert subOrd != -1;
-        ord = (int) sub.map.get(subOrd);
-        docID = sub.mappedDocID;
         return docID;
       }
 
       @Override
-      public int ordValue() {
-        return ord;
+      public int ordValue() throws IOException {
+        int subOrd = current.values.ordValue();
+        assert subOrd != -1;
+        return (int) current.map.get(subOrd);
       }
 
       @Override