This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1bc9e932599 For #32527, fix duplicate results when querying
information_schema.SCHEMATA (#32528)
1bc9e932599 is described below
commit 1bc9e9325999cde55c3a255fa70b819feac4cc2c
Author: Raigor <[email protected]>
AuthorDate: Thu Aug 15 17:07:31 2024 +0800
For #32527, fix duplicate results when querying information_schema.SCHEMATA
(#32528)
---
.../information/SelectInformationSchemataExecutor.java | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
index 09a1043251c..0f463b38210 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java
@@ -31,13 +31,12 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectS
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -154,12 +153,12 @@ public final class SelectInformationSchemataExecutor
extends DefaultDatabaseMeta
}
private Collection<String> getCatalogs(final ResourceMetaData
resourceMetaData) throws SQLException {
- Collection<String> result = new
HashSet<>(resourceMetaData.getStorageUnits().size(), 1F);
- for (Entry<String, StorageUnit> entry :
resourceMetaData.getStorageUnits().entrySet()) {
- try (Connection connection =
entry.getValue().getDataSource().getConnection()) {
- result.add(connection.getCatalog());
- }
+ Optional<StorageUnit> storageUnit =
resourceMetaData.getStorageUnits().values().stream().findFirst();
+ if (!storageUnit.isPresent()) {
+ return Collections.emptySet();
+ }
+ try (Connection connection =
storageUnit.get().getDataSource().getConnection()) {
+ return Collections.singleton(connection.getCatalog());
}
- return result;
}
}