From 7490522d484783cbeff5823236d6997e76c58ecf Mon Sep 17 00:00:00 2001 From: jiangML <1060319118@qq.com> Date: Thu, 19 Dec 2024 18:44:34 +0800 Subject: [PATCH] Fix query some system data error when there are multiple logical database --- .../executor/AbstractDatabaseMetaDataExecutor.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java index dbbe100f99650..95f16274eb8c6 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.row.MemoryQueryResultDataRow; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.user.Grantee; @@ -144,9 +145,13 @@ public static class DefaultDatabaseMetaDataExecutor extends AbstractDatabaseMeta @Override protected Collection getDatabaseNames(final ConnectionSession connectionSession) { - Optional database = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> isAuthorized(each, connectionSession.getConnectionContext().getGrantee())) - .filter(AbstractDatabaseMetaDataExecutor::hasDataSource).findFirst(); - return database.map(Collections::singletonList).orElse(Collections.emptyList()); + ShardingSphereDatabase database = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(connectionSession.getCurrentDatabaseName()); + if (null != database && isAuthorized(database.getName(), connectionSession.getConnectionContext().getGrantee()) && AbstractDatabaseMetaDataExecutor.hasDataSource(database.getName())) { + return Collections.singleton(database.getName()); + } + Collection databaseNames = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> isAuthorized(each, connectionSession.getConnectionContext().getGrantee())) + .filter(AbstractDatabaseMetaDataExecutor::hasDataSource).collect(Collectors.toList()); + return databaseNames.isEmpty() ? Collections.emptyList() : Collections.singletonList(databaseNames.iterator().next()); } @Override