Skip to content

Commit 1cd4bc3

Browse files
authored
NonAlignedTreeDeviceViewScan may return limit + offset lines result when the offset is pushed down
1 parent e31ebae commit 1cd4bc3

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,13 @@ private void calculateSeriesScanOptionsList() {
547547
boolean canPushDownLimitToAllSeriesScanOptions =
548548
canPushDownLimit && pushDownConjunctsForEachMeasurement.isEmpty();
549549
// the left child of LeftOuterTimeJoinOperator is SeriesScanOperator
550-
boolean pushDownLimitToLeftChildSeriesScanOperator =
550+
boolean pushDownOffsetAndLimitToLeftChildSeriesScanOperator =
551551
canPushDownLimit && pushDownConjunctsForEachMeasurement.size() == 1;
552552
// the left child of LeftOuterTimeJoinOperator is InnerTimeJoinOperator
553553
boolean pushDownOffsetAndLimitAfterInnerJoinOperator =
554554
canPushDownLimit && pushDownConjunctsForEachMeasurement.size() > 1;
555555
removeUpperOffsetAndLimitOperator =
556-
pushDownLimitToLeftChildSeriesScanOperator
556+
pushDownOffsetAndLimitToLeftChildSeriesScanOperator
557557
|| pushDownOffsetAndLimitAfterInnerJoinOperator
558558
|| isSingleColumn;
559559
for (int i = 0; i < measurementSchemas.size(); i++) {
@@ -580,16 +580,19 @@ private void calculateSeriesScanOptionsList() {
580580
commonParameter.timeColumnName));
581581
}
582582
if (isSingleColumn
583-
|| (pushDownLimitToLeftChildSeriesScanOperator
583+
|| (pushDownOffsetAndLimitToLeftChildSeriesScanOperator
584584
&& pushDownPredicateForCurrentMeasurement != null)) {
585585
builder.withPushDownLimit(node.getPushDownLimit());
586586
builder.withPushLimitToEachDevice(node.isPushLimitToEachDevice());
587587
}
588-
if (canPushDownLimitToAllSeriesScanOptions) {
588+
589+
// In the case of single column, both offset and limit are pushed down to the
590+
// SeriesScanOperator
591+
if (!isSingleColumn && canPushDownLimitToAllSeriesScanOptions) {
589592
builder.withPushDownLimit(node.getPushDownLimit() + node.getPushDownOffset());
590593
}
591594
if (isSingleColumn
592-
|| (pushDownLimitToLeftChildSeriesScanOperator
595+
|| (pushDownOffsetAndLimitToLeftChildSeriesScanOperator
593596
&& pushDownPredicateForCurrentMeasurement != null)) {
594597
builder.withPushDownOffset(
595598
node.isPushLimitToEachDevice() ? 0 : node.getPushDownOffset());

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/NonAlignedTreeDeviceViewScanOperatorTreeTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,29 @@ public void testScanWithCanPushDownPredicateAndCannotPushDownPredicateAndPushLim
273273
}
274274
}
275275

276+
@Test
277+
public void testScanSingleFieldColumnWithPushLimitToEachDevice1() throws Exception {
278+
List<String> outputColumnList = Arrays.asList("sensor0");
279+
TreeNonAlignedDeviceViewScanNode node =
280+
getTreeNonAlignedDeviceViewScanNode(outputColumnList, Arrays.asList("sensor0"));
281+
node.setPushLimitToEachDevice(false);
282+
node.setPushDownLimit(1);
283+
node.setPushDownOffset(1);
284+
ExecutorService instanceNotificationExecutor =
285+
IoTDBThreadPoolFactory.newFixedThreadPool(1, "test-instance-notification");
286+
Operator operator = getOperator(node, instanceNotificationExecutor);
287+
assertTrue(operator instanceof DeviceIteratorScanOperator);
288+
try {
289+
checkResult(operator, outputColumnList, 1);
290+
} catch (Exception e) {
291+
e.printStackTrace();
292+
fail(e.getMessage());
293+
} finally {
294+
operator.close();
295+
instanceNotificationExecutor.shutdown();
296+
}
297+
}
298+
276299
@Test
277300
public void testScanWithPushDownPredicateAndPushLimitToEachDevice1() throws Exception {
278301
List<String> outputColumnList = Arrays.asList("sensor0", "sensor1", "sensor2", "time", "tag1");

0 commit comments

Comments
 (0)