This is an automated email from the ASF dual-hosted git repository.
yx9o 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 b80dbeac2ae Optimize DialectDatabaseStatisticsCollector (#34621)
b80dbeac2ae is described below
commit b80dbeac2ae20f34f17d5783f838b938f97ba2cf
Author: jiangML <[email protected]>
AuthorDate: Wed Feb 12 10:09:38 2025 +0800
Optimize DialectDatabaseStatisticsCollector (#34621)
---
.../DialectDatabaseStatisticsCollector.java | 15 ++++++-----
.../opengauss/OpenGaussStatisticsCollector.java | 10 ++++----
.../postgresql/PostgreSQLStatisticsCollector.java | 30 +++++++++++++++-------
.../ShardingSphereStatisticsCollector.java | 30 +++++++++++++++-------
.../statistics/StatisticsRefreshEngine.java | 24 +++++++++++++++--
.../admin/OpenGaussAdminExecutorCreator.java | 17 +-----------
.../admin/OpenGaussAdminExecutorCreatorTest.java | 13 ++++++----
.../admin/OpenGaussAdminExecutorFactoryTest.java | 6 ++++-
.../admin/PostgreSQLAdminExecutorCreator.java | 17 +-----------
9 files changed, 92 insertions(+), 70 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/DialectDatabaseStatisticsCollector.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/DialectDatabaseStatisticsCollector.java
index 997d8ecda35..ef0f31c3943 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/DialectDatabaseStatisticsCollector.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/DialectDatabaseStatisticsCollector.java
@@ -32,13 +32,6 @@ import java.util.Optional;
@SingletonSPI
public interface DialectDatabaseStatisticsCollector extends DatabaseTypedSPI {
- /**
- * Get statistics schema tables.
- *
- * @return schema and tables
- */
- Map<String, Collection<String>> getStatisticsSchemaTables();
-
/**
* Collect row column values.
*
@@ -50,4 +43,12 @@ public interface DialectDatabaseStatisticsCollector extends
DatabaseTypedSPI {
* @throws SQLException SQL exception
*/
Optional<Collection<Map<String, Object>>> collectRowColumnValues(String
databaseName, String schemaName, String tableName, ShardingSphereMetaData
metaData) throws SQLException;
+
+ /**
+ * Is statistics tables.
+ *
+ * @param schemaTables schema tables
+ * @return returns true if all are statistics tables
+ */
+ boolean isStatisticsTables(Map<String, Collection<String>> schemaTables);
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/opengauss/OpenGaussStatisticsCollector.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/opengauss/OpenGaussStatisticsCollector.java
index 461c6bdebc7..e8368e58f06 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/opengauss/OpenGaussStatisticsCollector.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/opengauss/OpenGaussStatisticsCollector.java
@@ -33,17 +33,17 @@ public final class OpenGaussStatisticsCollector implements
DialectDatabaseStatis
private final PostgreSQLStatisticsCollector delegated = new
PostgreSQLStatisticsCollector();
- @Override
- public Map<String, Collection<String>> getStatisticsSchemaTables() {
- return delegated.getStatisticsSchemaTables();
- }
-
@Override
public Optional<Collection<Map<String, Object>>>
collectRowColumnValues(final String databaseName, final String schemaName,
final String tableName,
final ShardingSphereMetaData metaData) throws SQLException {
return delegated.collectRowColumnValues(databaseName, schemaName,
tableName, metaData);
}
+ @Override
+ public boolean isStatisticsTables(final Map<String, Collection<String>>
schemaTables) {
+ return delegated.isStatisticsTables(schemaTables);
+ }
+
@Override
public String getDatabaseType() {
return "openGauss";
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/postgresql/PostgreSQLStatisticsCollector.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/postgresql/PostgreSQLStatisticsCollector.java
index a2eb37cfe6f..e0d895cd854 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/postgresql/PostgreSQLStatisticsCollector.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/postgresql/PostgreSQLStatisticsCollector.java
@@ -17,6 +17,8 @@
package
org.apache.shardingsphere.infra.metadata.statistics.collector.postgresql;
+import com.cedarsoftware.util.CaseInsensitiveMap;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.statistics.collector.DialectDatabaseStatisticsCollector;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -24,32 +26,26 @@ import
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
/**
* Statistics collector for PostgreSQL.
*/
public final class PostgreSQLStatisticsCollector implements
DialectDatabaseStatisticsCollector {
- private static final Map<String, Collection<String>>
STATISTICS_SCHEMA_TABLES = new ConcurrentHashMap<>();
+ private static final Map<String, Collection<String>>
STATISTICS_SCHEMA_TABLES = new CaseInsensitiveMap<>();
static {
for (PostgreSQLTableStatisticsCollector each :
ShardingSphereServiceLoader.getServiceInstances(PostgreSQLTableStatisticsCollector.class))
{
if (!STATISTICS_SCHEMA_TABLES.containsKey(each.getSchemaName())) {
- STATISTICS_SCHEMA_TABLES.put(each.getSchemaName(), new
LinkedList<>());
+ STATISTICS_SCHEMA_TABLES.put(each.getSchemaName(), new
CaseInsensitiveSet<>());
}
STATISTICS_SCHEMA_TABLES.get(each.getSchemaName()).add(each.getTableName());
}
}
- @Override
- public Map<String, Collection<String>> getStatisticsSchemaTables() {
- return STATISTICS_SCHEMA_TABLES;
- }
-
@Override
public Optional<Collection<Map<String, Object>>>
collectRowColumnValues(final String databaseName, final String schemaName,
final String tableName,
final ShardingSphereMetaData metaData) throws SQLException {
@@ -57,6 +53,22 @@ public final class PostgreSQLStatisticsCollector implements
DialectDatabaseStati
return tableStatisticsCollector.isPresent() ?
Optional.of(tableStatisticsCollector.get().collect(databaseName, schemaName,
tableName, metaData)) : Optional.empty();
}
+ @Override
+ public boolean isStatisticsTables(final Map<String, Collection<String>>
schemaTables) {
+ if (schemaTables.isEmpty()) {
+ return false;
+ }
+ for (Entry<String, Collection<String>> entry :
schemaTables.entrySet()) {
+ if (!STATISTICS_SCHEMA_TABLES.containsKey(entry.getKey())) {
+ return false;
+ }
+ if
(!STATISTICS_SCHEMA_TABLES.get(entry.getKey()).containsAll(entry.getValue())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public String getDatabaseType() {
return "PostgreSQL";
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
index 08bc41963cb..8637c81cb97 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/shardingsphere/ShardingSphereStatisticsCollector.java
@@ -17,6 +17,8 @@
package
org.apache.shardingsphere.infra.metadata.statistics.collector.shardingsphere;
+import com.cedarsoftware.util.CaseInsensitiveMap;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.statistics.collector.DialectDatabaseStatisticsCollector;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -24,32 +26,26 @@ import
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
/**
* Statistics collector for ShardingSphere.
*/
public final class ShardingSphereStatisticsCollector implements
DialectDatabaseStatisticsCollector {
- private static final Map<String, Collection<String>>
STATISTICS_SCHEMA_TABLES = new ConcurrentHashMap<>();
+ private static final Map<String, Collection<String>>
STATISTICS_SCHEMA_TABLES = new CaseInsensitiveMap<>();
static {
for (ShardingSphereTableStatisticsCollector each :
ShardingSphereServiceLoader.getServiceInstances(ShardingSphereTableStatisticsCollector.class))
{
if (!STATISTICS_SCHEMA_TABLES.containsKey(each.getSchemaName())) {
- STATISTICS_SCHEMA_TABLES.put(each.getSchemaName(), new
LinkedList<>());
+ STATISTICS_SCHEMA_TABLES.put(each.getSchemaName(), new
CaseInsensitiveSet<>());
}
STATISTICS_SCHEMA_TABLES.get(each.getSchemaName()).add(each.getTableName());
}
}
- @Override
- public Map<String, Collection<String>> getStatisticsSchemaTables() {
- return STATISTICS_SCHEMA_TABLES;
- }
-
@Override
public Optional<Collection<Map<String, Object>>>
collectRowColumnValues(final String databaseName, final String schemaName,
final String tableName,
final ShardingSphereMetaData metaData) throws SQLException {
@@ -58,6 +54,22 @@ public final class ShardingSphereStatisticsCollector
implements DialectDatabaseS
return tableStatisticsCollector.isPresent() ?
Optional.of(tableStatisticsCollector.get().collect(databaseName, schemaName,
tableName, metaData)) : Optional.empty();
}
+ @Override
+ public boolean isStatisticsTables(final Map<String, Collection<String>>
schemaTables) {
+ if (schemaTables.isEmpty()) {
+ return false;
+ }
+ for (Entry<String, Collection<String>> entry :
schemaTables.entrySet()) {
+ if (!STATISTICS_SCHEMA_TABLES.containsKey(entry.getKey())) {
+ return false;
+ }
+ if
(!STATISTICS_SCHEMA_TABLES.get(entry.getKey()).containsAll(entry.getValue())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public String getDatabaseType() {
return "ShardingSphere";
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/statistics/StatisticsRefreshEngine.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/statistics/StatisticsRefreshEngine.java
index 00f7f478577..3cba5683898 100644
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/statistics/StatisticsRefreshEngine.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/statistics/StatisticsRefreshEngine.java
@@ -28,6 +28,8 @@ import
org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.metadata.statistics.DatabaseStatistics;
+import
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics;
import
org.apache.shardingsphere.infra.metadata.statistics.collector.DialectDatabaseStatisticsCollector;
import
org.apache.shardingsphere.infra.metadata.statistics.collector.shardingsphere.ShardingSphereStatisticsCollector;
import org.apache.shardingsphere.mode.lock.global.GlobalLockDefinition;
@@ -35,6 +37,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import java.util.Collection;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -75,10 +78,11 @@ public final class StatisticsRefreshEngine {
}
}
}
+ cleanStatisticsData();
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
- log.error("Refresh statistics error.", ex);
+ log.warn("Refresh statistics error.", ex);
}
}
@@ -113,7 +117,23 @@ public final class StatisticsRefreshEngine {
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
- log.error("Refresh {}.{}.{} statistics failed.", databaseName,
schemaName, table.getName(), ex);
+ log.warn("Refresh {}.{}.{} statistics failed.", databaseName,
schemaName, table.getName(), ex);
+ }
+ }
+
+ private void cleanStatisticsData() {
+ try {
+ ShardingSphereMetaData metaData =
contextManager.getMetaDataContexts().getMetaData();
+ ShardingSphereStatistics statistics =
contextManager.getMetaDataContexts().getStatistics();
+ for (Entry<String, DatabaseStatistics> entry :
statistics.getDatabaseStatisticsMap().entrySet()) {
+ if (!metaData.containsDatabase(entry.getKey())) {
+
contextManager.getPersistServiceFacade().getMetaDataPersistFacade().getStatisticsService().delete(entry.getKey());
+ }
+ }
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ log.warn("Clean up useless statistics data failed.", ex);
}
}
}
diff --git
a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
index 45db5398953..c730eb69f78 100644
---
a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
+++
b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
@@ -128,24 +128,9 @@ public final class OpenGaussAdminExecutorCreator
implements DatabaseAdminExecuto
}
private boolean isSelectedStatisticsSystemTable(final Map<String,
Collection<String>> selectedSchemaTables) {
- if (selectedSchemaTables.isEmpty()) {
- return false;
- }
DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "openGauss");
Optional<DialectDatabaseStatisticsCollector>
dialectStatisticsCollector =
DatabaseTypedSPILoader.findService(DialectDatabaseStatisticsCollector.class,
databaseType);
- if (!dialectStatisticsCollector.isPresent()) {
- return false;
- }
- Map<String, Collection<String>> statisticalSchemaTables =
dialectStatisticsCollector.get().getStatisticsSchemaTables();
- for (Entry<String, Collection<String>> each :
selectedSchemaTables.entrySet()) {
- if (!statisticalSchemaTables.containsKey(each.getKey())) {
- return false;
- }
- if
(!statisticalSchemaTables.get(each.getKey()).containsAll(each.getValue())) {
- return false;
- }
- }
- return true;
+ return dialectStatisticsCollector.map(optional ->
optional.isStatisticsTables(selectedSchemaTables)).orElse(false);
}
private boolean isSQLFederationSystemCatalogQueryExpressions(final
SQLStatementContext sqlStatementContext) {
diff --git
a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
index 2b67d868c02..847b8834002 100644
---
a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
+++
b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
@@ -40,6 +40,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,7 +52,7 @@ class OpenGaussAdminExecutorCreatorTest {
@Test
void assertCreateExecutorForSelectDatabase() {
- setUp("pg_database");
+ initDialectDatabaseStatisticsCollector(true);
SelectStatementContext selectStatementContext =
mockSelectStatementContext("pg_database");
Optional<DatabaseAdminExecutor> actual = new
OpenGaussAdminExecutorCreator()
.create(selectStatementContext, "select datname,
datcompatibility from pg_database where datname = 'sharding_db'", "postgres",
Collections.emptyList());
@@ -61,7 +62,7 @@ class OpenGaussAdminExecutorCreatorTest {
@Test
void assertCreateExecutorForSelectTables() {
- setUp("pg_tables");
+ initDialectDatabaseStatisticsCollector(true);
SelectStatementContext selectStatementContext =
mockSelectStatementContext("pg_tables");
Optional<DatabaseAdminExecutor> actual = new
OpenGaussAdminExecutorCreator()
.create(selectStatementContext, "select schemaname, tablename
from pg_tables where schemaname = 'sharding_db'", "postgres",
Collections.emptyList());
@@ -71,7 +72,7 @@ class OpenGaussAdminExecutorCreatorTest {
@Test
void assertCreateExecutorForSelectRoles() {
- setUp("pg_roles");
+ initDialectDatabaseStatisticsCollector(true);
SelectStatementContext selectStatementContext =
mockSelectStatementContext("pg_roles");
Optional<DatabaseAdminExecutor> actual = new
OpenGaussAdminExecutorCreator()
.create(selectStatementContext, "select rolname from
pg_roles", "postgres", Collections.emptyList());
@@ -81,6 +82,7 @@ class OpenGaussAdminExecutorCreatorTest {
@Test
void assertCreateExecutorForSelectVersion() {
+ initDialectDatabaseStatisticsCollector(false);
SelectStatementContext selectStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(selectStatementContext.getSqlStatement().getProjections().getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(-1, -1, "VERSION()")));
Optional<DatabaseAdminExecutor> actual = new
OpenGaussAdminExecutorCreator().create(selectStatementContext, "select
VERSION()", "postgres", Collections.emptyList());
@@ -90,6 +92,7 @@ class OpenGaussAdminExecutorCreatorTest {
@Test
void assertCreateOtherExecutor() {
+ initDialectDatabaseStatisticsCollector(false);
OpenGaussAdminExecutorCreator creator = new
OpenGaussAdminExecutorCreator();
SQLStatementContext sqlStatementContext =
mock(SQLStatementContext.class,
withSettings().extraInterfaces(TableAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
when(((TableAvailable)
sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.emptyList());
@@ -97,9 +100,9 @@ class OpenGaussAdminExecutorCreatorTest {
assertThat(creator.create(sqlStatementContext, "", "",
Collections.emptyList()), is(Optional.empty()));
}
- private void setUp(final String tableName) {
+ private void initDialectDatabaseStatisticsCollector(final boolean
isStatisticsTables) {
DialectDatabaseStatisticsCollector statisticsCollector =
mock(DialectDatabaseStatisticsCollector.class);
-
when(statisticsCollector.getStatisticsSchemaTables()).thenReturn(Collections.singletonMap("pg_catalog",
Collections.singletonList(tableName)));
+
when(statisticsCollector.isStatisticsTables(anyMap())).thenReturn(isStatisticsTables);
when(DatabaseTypedSPILoader.findService(DialectDatabaseStatisticsCollector.class,
TypedSPILoader.getService(DatabaseType.class,
"openGauss"))).thenReturn(Optional.of(statisticsCollector));
}
diff --git
a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorFactoryTest.java
b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorFactoryTest.java
index da250b123aa..5020b7cda40 100644
---
a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorFactoryTest.java
+++
b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorFactoryTest.java
@@ -43,6 +43,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -72,6 +73,9 @@ class OpenGaussAdminExecutorFactoryTest {
@Test
void assertNewInstanceWithOtherSQL() {
+ DialectDatabaseStatisticsCollector statisticsCollector =
mock(DialectDatabaseStatisticsCollector.class);
+
when(statisticsCollector.isStatisticsTables(anyMap())).thenReturn(false);
+
when(DatabaseTypedSPILoader.findService(DialectDatabaseStatisticsCollector.class,
TypedSPILoader.getService(DatabaseType.class,
"openGauss"))).thenReturn(Optional.of(statisticsCollector));
SelectStatementContext sqlStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.emptyList());
DatabaseAdminExecutor expected = mock(DatabaseAdminExecutor.class);
@@ -84,7 +88,7 @@ class OpenGaussAdminExecutorFactoryTest {
@Test
void assertNewInstanceWithSelectDatabase() {
DialectDatabaseStatisticsCollector statisticsCollector =
mock(DialectDatabaseStatisticsCollector.class);
-
when(statisticsCollector.getStatisticsSchemaTables()).thenReturn(Collections.singletonMap("pg_catalog",
Collections.singletonList("pg_database")));
+
when(statisticsCollector.isStatisticsTables(anyMap())).thenReturn(true);
when(DatabaseTypedSPILoader.findService(DialectDatabaseStatisticsCollector.class,
TypedSPILoader.getService(DatabaseType.class,
"openGauss"))).thenReturn(Optional.of(statisticsCollector));
SelectStatementContext sqlStatementContext =
mockSelectStatementContext();
String sql = "select datcompatibility from pg_database where datname =
'sharding_db'";
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
index 124fe3d4728..3a696901d74 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
@@ -117,24 +117,9 @@ public final class PostgreSQLAdminExecutorCreator
implements DatabaseAdminExecut
}
private boolean isSelectedStatisticsSystemTable(final Map<String,
Collection<String>> selectedSchemaTables) {
- if (selectedSchemaTables.isEmpty()) {
- return false;
- }
DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
Optional<DialectDatabaseStatisticsCollector>
dialectStatisticsCollector =
DatabaseTypedSPILoader.findService(DialectDatabaseStatisticsCollector.class,
databaseType);
- if (!dialectStatisticsCollector.isPresent()) {
- return false;
- }
- Map<String, Collection<String>> statisticalSchemaTables =
dialectStatisticsCollector.get().getStatisticsSchemaTables();
- for (Entry<String, Collection<String>> each :
selectedSchemaTables.entrySet()) {
- if (!statisticalSchemaTables.containsKey(each.getKey())) {
- return false;
- }
- if
(!statisticalSchemaTables.get(each.getKey()).containsAll(each.getValue())) {
- return false;
- }
- }
- return true;
+ return
dialectStatisticsCollector.map(dialectDatabaseStatisticsCollector ->
dialectDatabaseStatisticsCollector.isStatisticsTables(selectedSchemaTables)).orElse(false);
}
private boolean isSelectedShardingSphereSystemTable(final Map<String,
Collection<String>> selectedSchemaTables) {