Skip to content

Commit 90c540c

Browse files
authored
Fast schema partition fetch for single device query (#17493)
1 parent 89c2af8 commit 90c540c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import java.util.Collections;
6161
import java.util.HashMap;
6262
import java.util.HashSet;
63-
import java.util.LinkedHashMap;
6463
import java.util.List;
6564
import java.util.Map;
6665
import java.util.Objects;
@@ -520,19 +519,30 @@ private SchemaPartition parseSchemaPartitionTableResp(
520519
String database = entry1.getKey();
521520
final Map<TSeriesPartitionSlot, TRegionReplicaSet> result1 =
522521
regionReplicaMap.computeIfAbsent(database, k -> new HashMap<>());
522+
Map<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionTable = entry1.getValue();
523+
524+
if (seriesPartitionTable.size() == 1) {
525+
// Fast collection in case of query for single device
526+
Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionEntry =
527+
seriesPartitionTable.entrySet().iterator().next();
528+
List<TRegionReplicaSet> regionReplicaSets =
529+
partitionCache.getRegionReplicaSet(
530+
Collections.singletonList(seriesPartitionEntry.getValue()));
531+
result1.put(seriesPartitionEntry.getKey(), regionReplicaSets.get(0));
532+
continue;
533+
}
523534

524-
Map<TSeriesPartitionSlot, TConsensusGroupId> orderedMap =
525-
new LinkedHashMap<>(entry1.getValue());
526-
List<TConsensusGroupId> orderedGroupIds =
527-
orderedMap.values().stream().distinct().collect(Collectors.toList());
535+
List<TConsensusGroupId> distinctRegionGroupIds =
536+
new ArrayList<>(new HashSet<>(seriesPartitionTable.values()));
528537
List<TRegionReplicaSet> regionReplicaSets =
529-
partitionCache.getRegionReplicaSet(orderedGroupIds);
538+
partitionCache.getRegionReplicaSet(distinctRegionGroupIds);
530539
Map<TConsensusGroupId, TRegionReplicaSet> groupIdToReplicaSet = new HashMap<>();
531-
for (int index = 0; index < orderedGroupIds.size(); index++) {
532-
groupIdToReplicaSet.put(orderedGroupIds.get(index), regionReplicaSets.get(index));
540+
for (int index = 0; index < distinctRegionGroupIds.size(); index++) {
541+
groupIdToReplicaSet.put(distinctRegionGroupIds.get(index), regionReplicaSets.get(index));
533542
}
534543

535-
for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : orderedMap.entrySet()) {
544+
for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 :
545+
seriesPartitionTable.entrySet()) {
536546
result1.put(entry2.getKey(), groupIdToReplicaSet.get(entry2.getValue()));
537547
}
538548
}

0 commit comments

Comments
 (0)