Skip to content

Commit e60408c

Browse files
authored
Fix last cache bugs because init the time last cache but not updated in later process
1 parent 14ade2b commit e60408c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
import java.io.File;
280280
import java.util.AbstractMap;
281281
import java.util.ArrayList;
282+
import java.util.Arrays;
282283
import java.util.Collections;
283284
import java.util.Comparator;
284285
import java.util.HashMap;
@@ -3126,18 +3127,19 @@ private LastQueryAggTableScanOperator constructLastQueryAggTableScanOperator(
31263127
// LAST_VALUES optimize
31273128
lastValuesCacheResults = new ArrayList<>();
31283129
int measurementSize = parameter.getMeasurementColumnNames().size();
3130+
// We don't init time if the last cache will not be updated in process of operator
3131+
boolean needInitTime =
3132+
parameter.getTableAggregators().stream()
3133+
.anyMatch(
3134+
aggregator ->
3135+
aggregator.getAccumulator() instanceof LastDescAccumulator
3136+
&& !((LastDescAccumulator) aggregator.getAccumulator())
3137+
.isMeasurementColumn());
31293138
// When we need last cache of Time column if:
31303139
// 1. query is group by (we need last cache of Time to help judge if there is no data in
31313140
// device)
31323141
// 2. last(time), last(device) or last(attribute) occurs
3133-
boolean needTime =
3134-
!node.getGroupingKeys().isEmpty()
3135-
|| parameter.getTableAggregators().stream()
3136-
.anyMatch(
3137-
aggregator ->
3138-
aggregator.getAccumulator() instanceof LastDescAccumulator
3139-
&& !((LastDescAccumulator) aggregator.getAccumulator())
3140-
.isMeasurementColumn());
3142+
boolean needTime = !node.getGroupingKeys().isEmpty() || needInitTime;
31413143
String[] targetColumns;
31423144

31433145
if (needTime) {
@@ -3198,7 +3200,9 @@ private LastQueryAggTableScanOperator constructLastQueryAggTableScanOperator(
31983200
.initOrInvalidateLastCache(
31993201
node.getQualifiedObjectName().getDatabaseName(),
32003202
deviceEntry.getDeviceID(),
3201-
targetColumns,
3203+
needInitTime
3204+
? targetColumns
3205+
: Arrays.copyOfRange(targetColumns, 0, targetColumns.length - 1),
32023206
false);
32033207
} else {
32043208
hitCachesIndexes.add(i);

0 commit comments

Comments
 (0)