somandal commented on code in PR #11200:
URL: https://github.com/apache/pinot/pull/11200#discussion_r1278059576


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/docidsets/AndDocIdSet.java:
##########
@@ -75,13 +77,21 @@ public BlockDocIdIterator iterator() {
     List<BitmapBasedDocIdIterator> bitmapBasedDocIdIterators = new 
ArrayList<>();
     List<ScanBasedDocIdIterator> scanBasedDocIdIterators = new ArrayList<>();
     List<BlockDocIdIterator> remainingDocIdIterators = new ArrayList<>();
-    for (int i = 0; i < numDocIdSets; i++) {
-      BlockDocIdIterator docIdIterator = _docIdSets.get(i).iterator();
+
+    Iterator<BlockDocIdSet> iterator = _docIdSets.iterator();
+    for (int i = 0; iterator.hasNext(); i++) {
+      BlockDocIdSet blockDocIdSet = iterator.next();
+      BlockDocIdIterator docIdIterator = blockDocIdSet.iterator();
       allDocIdIterators[i] = docIdIterator;
       if (docIdIterator instanceof SortedDocIdIterator) {
         sortedDocIdIterators.add((SortedDocIdIterator) docIdIterator);
+        // do not keep holding on to the _docIdRanges since they will occupy 
heap space during the query execution
+        iterator.remove();
       } else if (docIdIterator instanceof BitmapBasedDocIdIterator) {
         bitmapBasedDocIdIterators.add((BitmapBasedDocIdIterator) 
docIdIterator);
+        // do not keep holding on to the bitmaps since they will occupy heap 
space during the query execution
+        _numEntriesScannedInFilter += 
blockDocIdSet.getNumEntriesScannedInFilter();

Review Comment:
   it is quite confusing when you update the `getNumEntriesScannedInFilter` 
here but not for the `SortedDocIdIterator` case where also you remove the 
iterator. From the code (please double check) it looks like the 
`SortedDocIdSet` returns 0:
   
   ```
     @Override
     public long getNumEntriesScannedInFilter() {
       return 0L;
     }
   ```
   
   Can we also call this API for that case to ensure that if ever the 
implementation changes in the future this doesn't result in a bug here since we 
don't update for all cases where we remove?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to