You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2023/03/23 13:40:57 UTC

[iotdb] 05/06: fix bug

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

hui pushed a commit to branch lmh/fixLimitPushDownBug1.1
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 1428c823b8dbf93287a837aa9b6bcb1afe308596
Author: liuminghui233 <54...@qq.com>
AuthorDate: Thu Mar 23 21:26:11 2023 +0800

    fix bug
---
 .../execution/operator/source/SeriesScanUtil.java  | 20 +++++++---------
 .../read/reader/series/PaginationController.java   | 28 ++++++----------------
 2 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java
index 635e7f873c..5e0f087945 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java
@@ -637,7 +637,10 @@ public class SeriesScanUtil {
         firstPageReader.setFilter(queryFilter);
       }
       firstPageReader.setLimitOffset(paginationController);
-      TsBlock tsBlock = firstPageReader.getAllSatisfiedPageData(orderUtils.getAscending(), true);
+      TsBlock tsBlock = firstPageReader.getAllSatisfiedPageData(orderUtils.getAscending());
+      if (!orderUtils.getAscending()) {
+        tsBlock = paginationController.applyTsBlock(tsBlock);
+      }
       firstPageReader = null;
 
       return tsBlock;
@@ -936,7 +939,7 @@ public class SeriesScanUtil {
 
   private void putPageReaderToMergeReader(VersionPageReader pageReader) throws IOException {
     mergeReader.addReader(
-        getPointReader(pageReader.getAllSatisfiedPageData(orderUtils.getAscending(), false)),
+        getPointReader(pageReader.getAllSatisfiedPageData(orderUtils.getAscending())),
         pageReader.version,
         orderUtils.getOverlapCheckTime(pageReader.getStatistics()),
         context);
@@ -1138,20 +1141,13 @@ public class SeriesScanUtil {
       return ((IAlignedPageReader) data).getTimeStatistics();
     }
 
-    TsBlock getAllSatisfiedPageData(boolean ascending, boolean isSeq) throws IOException {
+    TsBlock getAllSatisfiedPageData(boolean ascending) throws IOException {
       long startTime = System.nanoTime();
       try {
-        paginationController.setEnable(isSeq && ascending);
         TsBlock tsBlock = data.getAllSatisfiedData();
-
         if (!ascending) {
           tsBlock.reverse();
-
-          paginationController.setEnable(isSeq);
-          tsBlock = paginationController.applyTsBlock(tsBlock);
         }
-
-        paginationController.setEnable(true);
         return tsBlock;
       } finally {
         QUERY_METRICS.recordSeriesScanCost(
@@ -1179,7 +1175,9 @@ public class SeriesScanUtil {
     }
 
     public void setLimitOffset(PaginationController paginationController) {
-      data.setLimitOffset(paginationController);
+      if (orderUtils.getAscending()) {
+        data.setLimitOffset(paginationController);
+      }
     }
   }
 
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java
index 9b7b0e6435..88e9ab868a 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java
@@ -31,8 +31,6 @@ public class PaginationController {
   private long curLimit;
   private long curOffset;
 
-  private boolean enable = true;
-
   public PaginationController(long limit, long offset) {
     // row limit for result set. The default value is 0, which means no limit
     this.curLimit = limit;
@@ -42,51 +40,39 @@ public class PaginationController {
     this.curOffset = offset;
   }
 
-  public void setEnable(boolean enable) {
-    this.enable = enable;
-  }
-
   public boolean hasCurOffset() {
-    return enable && curOffset > 0;
+    return curOffset > 0;
   }
 
   public boolean hasCurOffset(long rowCount) {
-    return enable && curOffset >= rowCount;
+    return curOffset >= rowCount;
   }
 
   public boolean hasCurLimit() {
-    return !enable || (!hasLimit || curLimit > 0);
+    return !hasLimit || curLimit > 0;
   }
 
   public void consumeOffset(long rowCount) {
-    if (enable) {
-      curOffset -= rowCount;
-    }
+    curOffset -= rowCount;
   }
 
   public void consumeOffset() {
-    if (enable) {
-      curOffset--;
-    }
+    curOffset--;
   }
 
   public void consumeLimit() {
-    if (enable && hasLimit) {
+    if (hasLimit) {
       curLimit--;
     }
   }
 
   public void consumeLimit(long rowCount) {
-    if (enable && hasLimit) {
+    if (hasLimit) {
       curLimit -= rowCount;
     }
   }
 
   public TsBlock applyTsBlock(TsBlock resultTsBlock) {
-    if (!enable) {
-      return resultTsBlock;
-    }
-
     int fromIndex = 0, length = resultTsBlock.getPositionCount();
     if (curOffset > 0) {
       fromIndex = (int) Math.min(curOffset, length);