|
279 | 279 | import java.io.File; |
280 | 280 | import java.util.AbstractMap; |
281 | 281 | import java.util.ArrayList; |
| 282 | +import java.util.Arrays; |
282 | 283 | import java.util.Collections; |
283 | 284 | import java.util.Comparator; |
284 | 285 | import java.util.HashMap; |
@@ -3126,18 +3127,19 @@ private LastQueryAggTableScanOperator constructLastQueryAggTableScanOperator( |
3126 | 3127 | // LAST_VALUES optimize |
3127 | 3128 | lastValuesCacheResults = new ArrayList<>(); |
3128 | 3129 | 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()); |
3129 | 3138 | // When we need last cache of Time column if: |
3130 | 3139 | // 1. query is group by (we need last cache of Time to help judge if there is no data in |
3131 | 3140 | // device) |
3132 | 3141 | // 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; |
3141 | 3143 | String[] targetColumns; |
3142 | 3144 |
|
3143 | 3145 | if (needTime) { |
@@ -3198,7 +3200,9 @@ private LastQueryAggTableScanOperator constructLastQueryAggTableScanOperator( |
3198 | 3200 | .initOrInvalidateLastCache( |
3199 | 3201 | node.getQualifiedObjectName().getDatabaseName(), |
3200 | 3202 | deviceEntry.getDeviceID(), |
3201 | | - targetColumns, |
| 3203 | + needInitTime |
| 3204 | + ? targetColumns |
| 3205 | + : Arrays.copyOfRange(targetColumns, 0, targetColumns.length - 1), |
3202 | 3206 | false); |
3203 | 3207 | } else { |
3204 | 3208 | hitCachesIndexes.add(i); |
|
0 commit comments