Skip to content

Commit 9c8c1ed

Browse files
authored
Push down completely when group-by Aggregation with only one device entry
1 parent e022f22 commit 9c8c1ed

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/PushAggregationIntoTableScan.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ private PushDownLevel calculatePushDownLevel(
160160
}
161161

162162
// calculate DataSet part
163+
boolean singleDeviceEntry = tableScanNode.getDeviceEntries().size() < 2;
163164
if (groupingKeys.isEmpty()) {
164165
// GlobalAggregation
165-
if (tableScanNode.getDeviceEntries().size() < 2) {
166+
if (singleDeviceEntry) {
166167
return PushDownLevel.COMPLETE;
168+
} else {
169+
// We need to two-stage Aggregation to combine Aggregation result of different DeviceEntry
170+
return PushDownLevel.PARTIAL;
167171
}
168-
// We need to two-stage Aggregation to combine Aggregation result of different DeviceEntry
169-
return PushDownLevel.PARTIAL;
170172
}
171173

172174
List<FunctionCall> dateBinFunctionsOfTime = new ArrayList<>();
@@ -185,8 +187,9 @@ private PushDownLevel calculatePushDownLevel(
185187
// appear in groupingKeys.
186188

187189
return PushDownLevel.NOOP;
188-
} else if (ImmutableSet.copyOf(groupingKeys)
189-
.containsAll(tableScanNode.getIdColumnsInTableStore(metadata, session))) {
190+
} else if (singleDeviceEntry
191+
|| ImmutableSet.copyOf(groupingKeys)
192+
.containsAll(tableScanNode.getIdColumnsInTableStore(metadata, session))) {
190193
// If all ID columns appear in groupingKeys and no Measurement column appears, we can push
191194
// down completely.
192195
return PushDownLevel.COMPLETE;

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/AggregationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,35 @@ public void completePushDownTest() {
622622
"testdb.table1",
623623
ImmutableList.of("tag1", "tag2", "tag3", "attr1", "time", "count"),
624624
ImmutableSet.of("tag1", "tag2", "tag3", "attr1", "time", "s2")))));
625+
626+
// Global Aggregation or partialPushDown Aggregation with only one deviceEntry
627+
628+
// Output - AggTableScan
629+
assertPlan(
630+
planTester.createPlan("SELECT count(s2) FROM table1 where tag1='beijing' and tag2='A1'"),
631+
output(
632+
aggregationTableScan(
633+
singleGroupingSet(),
634+
ImmutableList.of(), // UnStreamable
635+
Optional.empty(),
636+
SINGLE,
637+
"testdb.table1",
638+
ImmutableList.of("count"),
639+
ImmutableSet.of("s2"))));
640+
641+
assertPlan(
642+
planTester.createPlan(
643+
"SELECT count(s2) FROM table1 where tag1='beijing' and tag2='A1' group by tag3"),
644+
output(
645+
project(
646+
aggregationTableScan(
647+
singleGroupingSet("tag3"),
648+
ImmutableList.of("tag3"),
649+
Optional.empty(),
650+
SINGLE,
651+
"testdb.table1",
652+
ImmutableList.of("tag3", "count"),
653+
ImmutableSet.of("s2", "tag3")))));
625654
}
626655

627656
@Test

0 commit comments

Comments
 (0)