diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java index 00c6b9e86b317..417c002e6f94e 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviser.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData; -import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.index.IndexReviser; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sharding.rule.TableRule; @@ -36,13 +35,13 @@ public final class ShardingIndexReviser implements IndexReviser { @Override public Optional revise(final String tableName, final IndexMetaData originalMetaData, final ShardingRule rule) { - for (DataNode each : tableRule.getActualDataNodes()) { - IndexMetaData result = new IndexMetaData(getLogicIndex(originalMetaData.getName(), each.getTableName())); - result.getColumns().addAll(originalMetaData.getColumns()); - result.setUnique(originalMetaData.isUnique()); - return Optional.of(result); + if (tableRule.getActualDataNodes().isEmpty()) { + return Optional.empty(); } - return Optional.empty(); + IndexMetaData result = new IndexMetaData(getLogicIndex(originalMetaData.getName(), tableRule.getActualDataNodes().iterator().next().getTableName())); + result.getColumns().addAll(originalMetaData.getColumns()); + result.setUnique(originalMetaData.isUnique()); + return Optional.of(result); } private String getLogicIndex(final String actualIndexName, final String actualTableName) {