This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 5b26dfa620b [IOTDB-6335] Redundant rows when using GROUP BY TIME with
LIMIT
5b26dfa620b is described below
commit 5b26dfa620b75f06e264fbac5b0d3ee38940ac9b
Author: YangCaiyin <[email protected]>
AuthorDate: Wed Jun 5 15:10:02 2024 +0800
[IOTDB-6335] Redundant rows when using GROUP BY TIME with LIMIT
---
.../plan/optimization/LimitOffsetPushDown.java | 3 ++-
.../plan/optimization/LimitOffsetPushDownTest.java | 28 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDown.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDown.java
index 36cc13254c7..df73a23dd18 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDown.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDown.java
@@ -335,7 +335,8 @@ public class LimitOffsetPushDown implements PlanOptimizer {
if (queryStatement.getResultTimeOrder() == Ordering.ASC) {
startTime = startTime + offsetSize * step;
} else {
- startTime = startTime + (size - offsetSize - limitSize) * step;
+ long startTimeInterval = size - offsetSize - limitSize;
+ startTime = startTime + (startTimeInterval < 0 ? 0 :
startTimeInterval) * step;
}
endTime =
limitSize == 0
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDownTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDownTest.java
index f550fde25fb..d4646994484 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDownTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/optimization/LimitOffsetPushDownTest.java
@@ -322,6 +322,34 @@ public class LimitOffsetPushDownTest {
checkGroupByTimePushDown(sql, 154, 354, 0, 0);
}
+ @Test
+ public void testGroupByTimePushDown12() {
+ String sql =
+ "select avg(s1),sum(s2) from root.** group by ([4, 899), 200ms) order
by time desc limit 3";
+ checkGroupByTimePushDown(sql, 404, 899, 0, 0);
+ }
+
+ @Test
+ public void testGroupByTimePushDown13() {
+ String sql =
+ "select avg(s1),sum(s2) from root.** group by ([4, 899), 200ms) order
by time desc limit 5";
+ checkGroupByTimePushDown(sql, 4, 899, 0, 0);
+ }
+
+ @Test
+ public void testGroupByTimePushDown14() {
+ String sql =
+ "select avg(s1),sum(s2) from root.** group by ([4, 899), 200ms) order
by time desc offset 2 limit 5";
+ checkGroupByTimePushDown(sql, 4, 899, 0, 0);
+ }
+
+ @Test
+ public void testGroupByTimePushDown15() {
+ String sql =
+ "select avg(s1),sum(s2) from root.** group by ([4, 899), 200ms) order
by time desc limit 6";
+ checkGroupByTimePushDown(sql, 4, 899, 0, 0);
+ }
+
private void checkGroupByTimePushDown(
String sql, long startTime, long endTime, long rowLimit, long rowOffset)
{
QueryStatement queryStatement =