This is an automated email from the ASF dual-hosted git repository.

panjuan 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 44d56bc075d Merge SchemaSupportedDatabaseType into DatabaseType 
(#26916)
44d56bc075d is described below

commit 44d56bc075db38b3abcbf2dbded73d7c5fac9035
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jul 12 15:25:45 2023 +0800

    Merge SchemaSupportedDatabaseType into DatabaseType (#26916)
---
 .../data/ShardingStatisticsTableCollector.java     |  7 +++--
 .../generator/impl/ProjectionsTokenGenerator.java  |  3 +--
 .../WhereClauseShardingConditionEngineTest.java    |  3 +++
 .../projection/impl/AggregationProjection.java     |  3 +--
 .../infra/binder/segment/table/TablesContext.java  |  3 +--
 .../projection/impl/AggregationProjectionTest.java |  7 +++--
 .../infra/database/type/DatabaseType.java          | 10 +++++++
 .../infra/database/type/DatabaseTypeEngine.java    | 12 +--------
 .../database/type/SchemaSupportedDatabaseType.java | 31 ----------------------
 .../type/dialect/OpenGaussDatabaseType.java        |  9 ++++---
 .../type/dialect/PostgreSQLDatabaseType.java       |  9 ++++---
 .../shardingsphere/infra/datanode/DataNode.java    |  5 ++--
 .../schema/builder/SystemSchemaBuilder.java        |  3 +--
 .../schema/loader/common/SchemaMetaDataLoader.java |  5 ++--
 .../database/schema/util/SystemSchemaUtils.java    |  5 ++--
 .../type/dialect/PostgreSQLDatabaseTypeTest.java   |  3 ++-
 .../jdbc/adapter/AbstractStatementAdapter.java     |  3 +--
 .../pipeline/common/util/JDBCStreamQueryUtils.java |  3 +--
 .../datasource/AbstractDataSourcePreparer.java     |  5 ++--
 .../pipeline/cdc/util/CDCSchemaTableUtils.java     | 11 +-------
 .../SingleRuleConfigurationDecorator.java          |  3 +--
 .../single/util/SingleTableLoadUtils.java          | 11 +++-----
 .../update/LoadSingleTableStatementUpdater.java    |  3 +--
 .../resultset/SQLFederationResultSet.java          |  3 +--
 .../mode/metadata/MetaDataContexts.java            |  3 +--
 .../database/DropDatabaseBackendHandler.java       |  3 +--
 .../distsql/rql/rule/ShowLogicalTableExecutor.java |  6 +----
 .../transaction/TransactionBackendHandler.java     |  3 +--
 .../database/DropDatabaseBackendHandlerTest.java   | 10 ++++---
 .../ral/QueryableRALBackendHandlerTest.java        |  3 +++
 .../queryable/ShowTableMetaDataExecutorTest.java   |  6 +++--
 .../updatable/RefreshTableMetaDataUpdaterTest.java |  6 +++++
 32 files changed, 76 insertions(+), 124 deletions(-)

diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
index b2a1e43ed76..e38246d08a7 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
@@ -18,16 +18,15 @@
 package org.apache.shardingsphere.sharding.metadata.data;
 
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
 import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
 import org.apache.shardingsphere.infra.datanode.DataNode;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereRowData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.collector.ShardingSphereStatisticsCollector;
-import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.sharding.rule.TableRule;
 
@@ -66,7 +65,7 @@ public final class ShardingStatisticsTableCollector 
implements ShardingSphereSta
                                                      final Map<String, 
ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
         ShardingSphereTableData result = new 
ShardingSphereTableData(SHARDING_TABLE_STATISTICS);
         DatabaseType protocolType = 
shardingSphereDatabases.values().iterator().next().getProtocolType();
-        if (protocolType instanceof SchemaSupportedDatabaseType) {
+        if (protocolType.getDefaultSchema().isPresent()) {
             collectFromDatabase(shardingSphereDatabases.get(databaseName), 
result);
         } else {
             for (ShardingSphereDatabase each : 
shardingSphereDatabases.values()) {
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
index d9edcd7cb5f..f251d94f9f8 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ProjectionsTokenGenerator.java
@@ -26,7 +26,6 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Der
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.OptionalSQLTokenGenerator;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.RouteContextAware;
@@ -140,7 +139,7 @@ public final class ProjectionsTokenGenerator implements 
OptionalSQLTokenGenerato
     }
     
     private NullsOrderType generateNewNullsOrderType(final DatabaseType 
databaseType, final OrderDirection orderDirection) {
-        if (databaseType instanceof SchemaSupportedDatabaseType || 
databaseType instanceof OracleDatabaseType) {
+        if (databaseType.getDefaultSchema().isPresent() || databaseType 
instanceof OracleDatabaseType) {
             return OrderDirection.ASC == orderDirection ? NullsOrderType.LAST 
: NullsOrderType.FIRST;
         }
         return OrderDirection.ASC == orderDirection ? NullsOrderType.FIRST : 
NullsOrderType.LAST;
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
index 81a1c3a493a..da39a3588df 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
@@ -21,8 +21,10 @@ import org.apache.groovy.util.Maps;
 import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.value.RangeShardingConditionValue;
@@ -78,6 +80,7 @@ class WhereClauseShardingConditionEngineTest {
                 ShardingSphereDatabase.create("test_db", 
DatabaseTypeEngine.getDatabaseType("MySQL"), new ConfigurationProperties(new 
Properties())), shardingRule, mock(TimestampServiceRule.class));
         
when(sqlStatementContext.getWhereSegments()).thenReturn(Collections.singleton(whereSegment));
         when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
+        
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "MySQL"));
         when(tablesContext.findTableNamesByColumnSegment(anyCollection(), 
any())).thenReturn(Maps.of("foo_sharding_col", "table_1"));
     }
     
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
index 13f650071e9..2af7b4d3fd1 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
@@ -24,7 +24,6 @@ import lombok.Setter;
 import lombok.ToString;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 
@@ -71,7 +70,7 @@ public class AggregationProjection implements Projection {
      */
     @Override
     public String getColumnLabel() {
-        return getAlias().orElseGet(() -> databaseType instanceof 
SchemaSupportedDatabaseType ? type.name().toLowerCase() : getExpression());
+        return getAlias().orElseGet(() -> 
databaseType.getDefaultSchema().isPresent() ? type.name().toLowerCase() : 
getExpression());
     }
     
     @Override
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
index aba9c48fa77..81960dda004 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.subquery.SubqueryTa
 import 
org.apache.shardingsphere.infra.binder.segment.select.subquery.engine.SubqueryTableContextEngine;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
@@ -91,7 +90,7 @@ public final class TablesContext {
     }
     
     private Optional<String> findDatabaseName(final SimpleTableSegment 
tableSegment, final DatabaseType databaseType) {
-        Optional<OwnerSegment> owner = databaseType instanceof 
SchemaSupportedDatabaseType ? 
tableSegment.getOwner().flatMap(OwnerSegment::getOwner) : 
tableSegment.getOwner();
+        Optional<OwnerSegment> owner = 
databaseType.getDefaultSchema().isPresent() ? 
tableSegment.getOwner().flatMap(OwnerSegment::getOwner) : 
tableSegment.getOwner();
         return owner.map(optional -> optional.getIdentifier().getValue());
     }
     
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
index dd41322169e..bb6086f3d0b 100644
--- 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
@@ -19,8 +19,7 @@ package 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl;
 
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
 import org.junit.jupiter.api.Test;
 
@@ -61,13 +60,13 @@ class AggregationProjectionTest {
     
     @Test
     void assertGetColumnLabelWithoutAliasForPostgreSQL() {
-        Projection projection = new 
AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, 
mock(PostgreSQLDatabaseType.class));
+        Projection projection = new 
AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, 
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
         assertThat(projection.getColumnLabel(), is("count"));
     }
     
     @Test
     void assertGetColumnLabelWithoutAliasForOpenGauss() {
-        Projection projection = new 
AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, 
mock(OpenGaussDatabaseType.class));
+        Projection projection = new 
AggregationProjection(AggregationType.COUNT, "( A.\"DIRECTION\" )", null, 
TypedSPILoader.getService(DatabaseType.class, "openGauss"));
         assertThat(projection.getColumnLabel(), is("count"));
     }
 }
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
index d918c2f913a..fc7e39a668b 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
@@ -27,6 +27,7 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * Database type.
@@ -95,6 +96,15 @@ public interface DatabaseType extends TypedSPI {
         }
     }
     
+    /**
+     * Get default schema name.
+     *
+     * @return default schema name
+     */
+    default Optional<String> getDefaultSchema() {
+        return Optional.empty();
+    }
+    
     /**
      * Format table name pattern.
      *
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
index 36a65986f8f..63d62e5487b 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngine.java
@@ -179,17 +179,7 @@ public final class DatabaseTypeEngine {
      * @return default schema name
      */
     public static String getDefaultSchemaName(final DatabaseType protocolType, 
final String databaseName) {
-        return protocolType instanceof SchemaSupportedDatabaseType ? 
((SchemaSupportedDatabaseType) protocolType).getDefaultSchema() : 
databaseName.toLowerCase();
-    }
-    
-    /**
-     * Get default schema name.
-     *
-     * @param protocolType protocol type
-     * @return default schema name
-     */
-    public static Optional<String> getDefaultSchemaName(final DatabaseType 
protocolType) {
-        return protocolType instanceof SchemaSupportedDatabaseType ? 
Optional.of(((SchemaSupportedDatabaseType) protocolType).getDefaultSchema()) : 
Optional.empty();
+        return protocolType.getDefaultSchema().orElseGet(() -> null == 
databaseName ? null : databaseName.toLowerCase());
     }
     
     /**
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/SchemaSupportedDatabaseType.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/SchemaSupportedDatabaseType.java
deleted file mode 100644
index ddc9c0e5971..00000000000
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/SchemaSupportedDatabaseType.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.database.type;
-
-/**
- * Schema supported database type.
- */
-public interface SchemaSupportedDatabaseType extends DatabaseType {
-    
-    /**
-     * Get default schema name.
-     *
-     * @return default schema name
-     */
-    String getDefaultSchema();
-}
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
index 60d47b27050..7a992f110fe 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OpenGaussDatabaseType.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.infra.database.type.dialect;
 
 import 
org.apache.shardingsphere.infra.database.metadata.dialect.OpenGaussDataSourceMetaData;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.QuoteCharacter;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -33,11 +33,12 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * Database type of openGauss.
  */
-public final class OpenGaussDatabaseType implements 
SchemaSupportedDatabaseType {
+public final class OpenGaussDatabaseType implements DatabaseType {
     
     private static final Map<String, Collection<String>> 
SYSTEM_DATABASE_SCHEMA_MAP = new HashMap<>();
     
@@ -85,8 +86,8 @@ public final class OpenGaussDatabaseType implements 
SchemaSupportedDatabaseType
     }
     
     @Override
-    public String getDefaultSchema() {
-        return "public";
+    public Optional<String> getDefaultSchema() {
+        return Optional.of("public");
     }
     
     @Override
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
index f2492c5ff8f..8c9480ba6e1 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.infra.database.type.dialect;
 
 import 
org.apache.shardingsphere.infra.database.metadata.dialect.PostgreSQLDataSourceMetaData;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.QuoteCharacter;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -33,11 +33,12 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * Database type of PostgreSQL.
  */
-public final class PostgreSQLDatabaseType implements 
SchemaSupportedDatabaseType {
+public final class PostgreSQLDatabaseType implements DatabaseType {
     
     private static final Map<String, Collection<String>> 
SYSTEM_DATABASE_SCHEMA_MAP = new HashMap<>();
     
@@ -84,8 +85,8 @@ public final class PostgreSQLDatabaseType implements 
SchemaSupportedDatabaseType
     }
     
     @Override
-    public String getDefaultSchema() {
-        return "public";
+    public Optional<String> getDefaultSchema() {
+        return Optional.of("public");
     }
     
     @Override
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
index e11dbe64148..d32b461312a 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
@@ -24,7 +24,6 @@ import lombok.RequiredArgsConstructor;
 import lombok.Setter;
 import lombok.ToString;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.exception.InvalidDataNodesFormatException;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 
@@ -87,7 +86,7 @@ public final class DataNode {
     }
     
     private String getSchemaName(final String databaseName, final DatabaseType 
databaseType, final boolean containsSchema, final List<String> segments) {
-        if (databaseType instanceof SchemaSupportedDatabaseType) {
+        if (databaseType.getDefaultSchema().isPresent()) {
             return containsSchema ? segments.get(1) : ASTERISK;
         }
         return databaseName;
@@ -117,7 +116,7 @@ public final class DataNode {
      * @return formatted data node
      */
     public String format(final DatabaseType databaseType) {
-        return databaseType instanceof SchemaSupportedDatabaseType ? 
dataSourceName + DELIMITER + schemaName + DELIMITER + tableName : 
dataSourceName + DELIMITER + tableName;
+        return databaseType.getDefaultSchema().isPresent() ? dataSourceName + 
DELIMITER + schemaName + DELIMITER + tableName : dataSourceName + DELIMITER + 
tableName;
     }
     
     @Override
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java
index 22296ab8c16..ddf3172d564 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java
@@ -22,7 +22,6 @@ import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 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.yaml.schema.pojo.YamlShardingSphereTable;
@@ -67,7 +66,7 @@ public final class SystemSchemaBuilder {
     }
     
     private static Collection<String> getSystemSchemas(final String 
originalDatabaseName, final DatabaseType databaseType) {
-        String databaseName = databaseType instanceof 
SchemaSupportedDatabaseType ? "postgres" : originalDatabaseName;
+        String databaseName = databaseType.getDefaultSchema().isPresent() ? 
"postgres" : originalDatabaseName;
         return 
databaseType.getSystemDatabaseSchemaMap().getOrDefault(databaseName, 
Collections.emptyList());
     }
     
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/SchemaMetaDataLoader.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/SchemaMetaDataLoader.java
index fb3c074158f..aeb8c22bb27 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/SchemaMetaDataLoader.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/common/SchemaMetaDataLoader.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.infra.metadata.database.schema.loader.common;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.loader.adapter.MetaDataLoaderConnectionAdapter;
 
 import javax.sql.DataSource;
@@ -65,7 +64,7 @@ public final class SchemaMetaDataLoader {
             Collection<String> schemaNames = 
loadSchemaNames(connectionAdapter, databaseType);
             Map<String, Collection<String>> result = new 
HashMap<>(schemaNames.size(), 1F);
             for (String each : schemaNames) {
-                String schemaName = databaseType instanceof 
SchemaSupportedDatabaseType ? each : databaseName;
+                String schemaName = 
databaseType.getDefaultSchema().isPresent() ? each : databaseName;
                 result.put(schemaName, loadTableNames(connectionAdapter, 
each));
             }
             return result;
@@ -81,7 +80,7 @@ public final class SchemaMetaDataLoader {
      * @throws SQLException SQL exception
      */
     public static Collection<String> loadSchemaNames(final Connection 
connection, final DatabaseType databaseType) throws SQLException {
-        if (!(databaseType instanceof SchemaSupportedDatabaseType)) {
+        if (!databaseType.getDefaultSchema().isPresent()) {
             return Collections.singletonList(connection.getSchema());
         }
         Collection<String> result = new LinkedList<>();
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
index 2ff3f23ba23..3f9aec57a5e 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.infra.metadata.database.schema.util;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
@@ -52,7 +51,7 @@ public final class SystemSchemaUtils {
      * @return whether SQL statement contains system schema or not
      */
     public static boolean containsSystemSchema(final DatabaseType 
databaseType, final Collection<String> schemaNames, final 
ShardingSphereDatabase database) {
-        if (database.isComplete() && !(databaseType instanceof 
SchemaSupportedDatabaseType)) {
+        if (database.isComplete() && 
!databaseType.getDefaultSchema().isPresent()) {
             return false;
         }
         for (String each : schemaNames) {
@@ -60,7 +59,7 @@ public final class SystemSchemaUtils {
                 return true;
             }
         }
-        return !(databaseType instanceof SchemaSupportedDatabaseType) && 
databaseType.getSystemSchemas().contains(database.getName());
+        return !databaseType.getDefaultSchema().isPresent() && 
databaseType.getSystemSchemas().contains(database.getName());
     }
     
     /**
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
index 03df4deb34f..6e4bc49142d 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
@@ -28,6 +28,7 @@ import java.sql.SQLFeatureNotSupportedException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
@@ -91,6 +92,6 @@ class PostgreSQLDatabaseTypeTest {
     
     @Test
     void assertGetDefaultSchema() {
-        assertThat(new PostgreSQLDatabaseType().getDefaultSchema(), 
is("public"));
+        assertThat(new PostgreSQLDatabaseType().getDefaultSchema(), 
is(Optional.of("public")));
     }
 }
diff --git 
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
 
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
index c82c3ea0d40..b6c6db0e11f 100644
--- 
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
+++ 
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConne
 import org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager;
 import 
org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationStatement;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -74,7 +73,7 @@ public abstract class AbstractStatementAdapter extends 
AbstractUnsupportedOperat
     protected final void handleExceptionInTransaction(final 
ShardingSphereConnection connection, final MetaDataContexts metaDataContexts) {
         if 
(connection.getDatabaseConnectionManager().getConnectionTransaction().isInTransaction())
 {
             DatabaseType databaseType = 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType();
-            if (databaseType instanceof SchemaSupportedDatabaseType) {
+            if (databaseType.getDefaultSchema().isPresent()) {
                 
connection.getDatabaseConnectionManager().getConnectionTransaction().setRollbackOnly(true);
             }
         }
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/util/JDBCStreamQueryUtils.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/util/JDBCStreamQueryUtils.java
index f76a77b5cb5..12cdd4b70d9 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/util/JDBCStreamQueryUtils.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/util/JDBCStreamQueryUtils.java
@@ -22,7 +22,6 @@ import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.database.type.BranchDatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 
@@ -51,7 +50,7 @@ public final class JDBCStreamQueryUtils {
         if (databaseType instanceof MySQLDatabaseType) {
             return generateForMySQL(connection, sql);
         }
-        if (databaseType instanceof SchemaSupportedDatabaseType) {
+        if (databaseType.getDefaultSchema().isPresent()) {
             return generateForPostgreSQL(connection, sql);
         }
         if (databaseType instanceof H2DatabaseType) {
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
index 62d0ef96ebf..7c184645029 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/AbstractDataSourcePreparer.java
@@ -25,10 +25,9 @@ import 
org.apache.shardingsphere.data.pipeline.common.datasource.PipelineDataSou
 import 
org.apache.shardingsphere.data.pipeline.common.datasource.PipelineDataSourceWrapper;
 import 
org.apache.shardingsphere.data.pipeline.common.metadata.generator.PipelineDDLGenerator;
 import 
org.apache.shardingsphere.data.pipeline.spi.sqlbuilder.PipelineSQLBuilder;
-import org.apache.shardingsphere.infra.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
 import org.apache.shardingsphere.infra.parser.SQLParserEngine;
+import org.apache.shardingsphere.infra.spi.DatabaseTypedSPILoader;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -56,7 +55,7 @@ public abstract class AbstractDataSourcePreparer implements 
DataSourcePreparer {
             return;
         }
         CreateTableConfiguration createTableConfig = 
param.getCreateTableConfig();
-        String defaultSchema = 
DatabaseTypeEngine.getDefaultSchemaName(targetDatabaseType).orElse(null);
+        String defaultSchema = 
targetDatabaseType.getDefaultSchema().orElse(null);
         PipelineSQLBuilder sqlBuilder = 
DatabaseTypedSPILoader.getService(PipelineSQLBuilder.class, targetDatabaseType);
         Collection<String> createdSchemaNames = new HashSet<>();
         for (CreateTableEntry each : 
createTableConfig.getCreateTableEntries()) {
diff --git 
a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
 
b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
index 9ac1956ee6c..d7cb2a02d24 100644
--- 
a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
+++ 
b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.data.pipeline.cdc.util;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.exception.SchemaNotFoundException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -91,20 +89,13 @@ public final class CDCSchemaTableUtils {
     
     private static Map<String, Set<String>> 
parseTableExpressionWithAllTable(final ShardingSphereDatabase database, final 
SchemaTable each) {
         Map<String, Set<String>> result = new HashMap<>();
-        String schemaName = each.getSchema().isEmpty() ? 
getDefaultSchema(database.getProtocolType()) : each.getSchema();
+        String schemaName = each.getSchema().isEmpty() ? 
database.getProtocolType().getDefaultSchema().orElseThrow(() -> new 
IllegalStateException("Default schema should exist.")) : each.getSchema();
         ShardingSphereSchema schema = database.getSchema(schemaName);
         ShardingSpherePreconditions.checkNotNull(schema, () -> new 
SchemaNotFoundException(each.getSchema()));
         schema.getAllTableNames().forEach(tableName -> 
result.computeIfAbsent(schemaName, ignored -> new HashSet<>()).add(tableName));
         return result;
     }
     
-    private static String getDefaultSchema(final DatabaseType databaseType) {
-        if (!(databaseType instanceof SchemaSupportedDatabaseType)) {
-            return null;
-        }
-        return ((SchemaSupportedDatabaseType) databaseType).getDefaultSchema();
-    }
-    
     /**
      * Parse table expression without schema.
      *
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index 5c751a1971a..15b43ff16d1 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.single.decorator;
 import 
org.apache.shardingsphere.infra.config.rule.decorator.RuleConfigurationDecorator;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datasource.state.DataSourceStateManager;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -68,7 +67,7 @@ public final class SingleRuleConfigurationDecorator 
implements RuleConfiguration
         Map<String, Collection<DataNode>> actualDataNodes = 
SingleTableDataNodeLoader.load(databaseName, databaseType, 
aggregatedDataSources, excludedTables);
         Collection<DataNode> configuredDataNodes = 
SingleTableLoadUtils.convertToDataNodes(databaseName, databaseType, 
splitTables);
         checkRuleConfiguration(databaseName, aggregatedDataSources, 
excludedTables, configuredDataNodes);
-        boolean isSchemaSupportedDatabaseType = databaseType instanceof 
SchemaSupportedDatabaseType;
+        boolean isSchemaSupportedDatabaseType = 
databaseType.getDefaultSchema().isPresent();
         if (splitTables.contains(SingleTableConstants.ALL_TABLES) || 
splitTables.contains(SingleTableConstants.ALL_SCHEMA_TABLES)) {
             return loadAllTables(isSchemaSupportedDatabaseType, 
actualDataNodes);
         }
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
index a92eae45c5e..7d893dabd23 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
@@ -21,7 +21,6 @@ import com.google.common.base.Splitter;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import 
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -154,7 +153,7 @@ public final class SingleTableLoadUtils {
      * @return node string for all tables
      */
     public static String getAllTablesNodeStr(final DatabaseType databaseType) {
-        return databaseType instanceof SchemaSupportedDatabaseType ? 
SingleTableConstants.ALL_SCHEMA_TABLES : SingleTableConstants.ALL_TABLES;
+        return databaseType.getDefaultSchema().isPresent() ? 
SingleTableConstants.ALL_SCHEMA_TABLES : SingleTableConstants.ALL_TABLES;
     }
     
     /**
@@ -166,9 +165,7 @@ public final class SingleTableLoadUtils {
      * @return node string for all tables
      */
     public static String getAllTablesNodeStrFromDataSource(final DatabaseType 
databaseType, final String dataSourceName, final String schemaName) {
-        return databaseType instanceof SchemaSupportedDatabaseType
-                ? formatDataNode(dataSourceName, schemaName, 
SingleTableConstants.ASTERISK)
-                : formatDataNode(dataSourceName, 
SingleTableConstants.ASTERISK);
+        return databaseType.getDefaultSchema().isPresent() ? 
formatDataNode(dataSourceName, schemaName, SingleTableConstants.ASTERISK) : 
formatDataNode(dataSourceName, SingleTableConstants.ASTERISK);
     }
     
     /**
@@ -181,9 +178,7 @@ public final class SingleTableLoadUtils {
      * @return data node string
      */
     public static String getDataNodeString(final DatabaseType databaseType, 
final String dataSourceName, final String schemaName, final String tableName) {
-        return databaseType instanceof SchemaSupportedDatabaseType
-                ? formatDataNode(dataSourceName, schemaName, tableName)
-                : formatDataNode(dataSourceName, tableName);
+        return databaseType.getDefaultSchema().isPresent() ? 
formatDataNode(dataSourceName, schemaName, tableName) : 
formatDataNode(dataSourceName, tableName);
     }
     
     private static String formatDataNode(final String dataSourceName, final 
String tableName) {
diff --git 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java
 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java
index 3db71ea83db..ce9f7c7ba18 100644
--- 
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java
+++ 
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java
@@ -21,7 +21,6 @@ import 
org.apache.shardingsphere.dialect.exception.syntax.table.TableExistsExcep
 import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionCreateUpdater;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.exception.InvalidDataNodesFormatException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
@@ -58,7 +57,7 @@ public final class LoadSingleTableStatementUpdater implements 
RuleDefinitionCrea
     
     private void checkDuplicatedTables(final ShardingSphereDatabase database, 
final LoadSingleTableStatement sqlStatement, final String defaultSchemaName) {
         Collection<SingleTableSegment> tableSegments = 
sqlStatement.getTables();
-        boolean isSchemaSupportedDatabaseType = database.getProtocolType() 
instanceof SchemaSupportedDatabaseType;
+        boolean isSchemaSupportedDatabaseType = 
database.getProtocolType().getDefaultSchema().isPresent();
         ShardingSphereSchema schema = database.getSchema(defaultSchemaName);
         for (SingleTableSegment each : tableSegments) {
             checkDatabaseTypeAndTableNodeStyle(isSchemaSupportedDatabaseType, 
each);
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
index f2ba2c2b73e..08ba6db35d0 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
@@ -24,7 +24,6 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projecti
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationDistinctProjection;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.util.ResultSetUtils;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -99,7 +98,7 @@ public final class SQLFederationResultSet extends 
AbstractUnsupportedOperationRe
     
     private String getColumnLabel(final Projection projection, final 
DatabaseType databaseType) {
         if (projection instanceof AggregationDistinctProjection) {
-            return databaseType instanceof SchemaSupportedDatabaseType ? 
((AggregationDistinctProjection) projection).getType().name().toLowerCase() : 
projection.getExpression();
+            return databaseType.getDefaultSchema().isPresent() ? 
((AggregationDistinctProjection) projection).getType().name().toLowerCase() : 
projection.getExpression();
         }
         return projection.getColumnLabel();
     }
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
index b6a854f2891..1fbf5f450b5 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.mode.metadata;
 
 import lombok.Getter;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereDatabaseData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereSchemaData;
@@ -61,7 +60,7 @@ public final class MetaDataContexts implements AutoCloseable {
             return new ShardingSphereStatistics();
         }
         // TODO can `protocolType instanceof SchemaSupportedDatabaseType ? 
"PostgreSQL" : protocolType.getType()` replace to trunk database type?
-        Optional<ShardingSphereStatisticsBuilder> statisticsBuilder = 
DatabaseTypedSPILoader.findService(ShardingSphereStatisticsBuilder.class, 
protocolType instanceof SchemaSupportedDatabaseType
+        Optional<ShardingSphereStatisticsBuilder> statisticsBuilder = 
DatabaseTypedSPILoader.findService(ShardingSphereStatisticsBuilder.class, 
protocolType.getDefaultSchema().isPresent()
                 ? TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")
                 : protocolType);
         if (!statisticsBuilder.isPresent()) {
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandler.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandler.java
index c780196358e..a02518514b9 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandler.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandler.java
@@ -23,7 +23,6 @@ import 
org.apache.shardingsphere.authority.checker.AuthorityChecker;
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import 
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseDropNotExistsException;
 import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -69,7 +68,7 @@ public final class DropDatabaseBackendHandler implements 
ProxyBackendHandler {
     }
     
     private void checkSupportedDropCurrentDatabase(final ConnectionSession 
connectionSession) {
-        if (connectionSession.getProtocolType() instanceof 
SchemaSupportedDatabaseType) {
+        if 
(connectionSession.getProtocolType().getDefaultSchema().isPresent()) {
             throw new UnsupportedOperationException("cannot drop the currently 
open database");
         }
     }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowLogicalTableExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowLogicalTableExecutor.java
index b5051b2e96f..8eafc908b10 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowLogicalTableExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowLogicalTableExecutor.java
@@ -19,7 +19,6 @@ package 
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.rule;
 
 import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
 import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowLogicalTablesStatement;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.util.regular.RegularUtils;
@@ -37,10 +36,7 @@ public final class ShowLogicalTableExecutor implements 
RQLExecutor<ShowLogicalTa
     
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShardingSphereDatabase database, final ShowLogicalTablesStatement sqlStatement) 
{
-        String schemaName = database.getName();
-        if (database.getProtocolType() instanceof SchemaSupportedDatabaseType) 
{
-            schemaName = ((SchemaSupportedDatabaseType) 
database.getProtocolType()).getDefaultSchema();
-        }
+        String schemaName = 
database.getProtocolType().getDefaultSchema().orElse(database.getName());
         if (null == database.getSchema(schemaName)) {
             return Collections.emptyList();
         }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
index 6f88d91a95b..96177b43a1f 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.proxy.backend.handler.transaction;
 
 import 
org.apache.shardingsphere.dialect.exception.transaction.InTransactionException;
-import 
org.apache.shardingsphere.infra.database.type.SchemaSupportedDatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.proxy.backend.connector.TransactionManager;
@@ -124,7 +123,7 @@ public final class TransactionBackendHandler implements 
ProxyBackendHandler {
     }
     
     private boolean isSchemaSupportedDatabaseType() {
-        return connectionSession.getProtocolType() instanceof 
SchemaSupportedDatabaseType;
+        return 
connectionSession.getProtocolType().getDefaultSchema().isPresent();
     }
     
     private SQLStatement getSQLStatementByCommit() {
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandlerTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandlerTest.java
index 37326327552..9bf0d039c14 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandlerTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DropDatabaseBackendHandlerTest.java
@@ -19,9 +19,10 @@ package 
org.apache.shardingsphere.proxy.backend.handler.database;
 
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import 
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseDropNotExistsException;
-import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -113,8 +114,9 @@ class DropDatabaseBackendHandlerTest {
     }
     
     @Test
-    void assertExecuteDropCurrentDatabase() {
+    void assertExecuteDropCurrentDatabaseWithMySQL() {
         when(connectionSession.getDatabaseName()).thenReturn("foo_db");
+        
when(connectionSession.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "MySQL"));
         when(sqlStatement.getDatabaseName()).thenReturn("foo_db");
         ResponseHeader responseHeader = handler.execute();
         verify(connectionSession).setCurrentDatabase(null);
@@ -122,9 +124,9 @@ class DropDatabaseBackendHandlerTest {
     }
     
     @Test
-    void assertExecuteDropCurrentDatabaseWithPG() {
+    void assertExecuteDropCurrentDatabaseWithPostgreSQL() {
         when(connectionSession.getDatabaseName()).thenReturn("foo_db");
-        when(connectionSession.getProtocolType()).thenReturn(new 
PostgreSQLDatabaseType());
+        
when(connectionSession.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "PostgreSQL"));
         when(sqlStatement.getDatabaseName()).thenReturn("foo_db");
         assertThrows(UnsupportedOperationException.class, () -> 
handler.execute());
     }
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java
index c831e22f2c4..896f202098b 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java
@@ -22,6 +22,7 @@ import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDataba
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ExportDatabaseConfigurationStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetaDataStatement;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -30,6 +31,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
 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.util.spi.exception.ServiceProviderNotFoundServerException;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
@@ -92,6 +94,7 @@ class QueryableRALBackendHandlerTest {
         
when(ProxyContext.getInstance().getDatabase("db_name")).thenReturn(database);
         ConnectionSession connectionSession = mock(ConnectionSession.class, 
RETURNS_DEEP_STUBS);
         when(connectionSession.getDatabaseName()).thenReturn("db_name");
+        
when(connectionSession.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "FIXTURE"));
         assertDoesNotThrow(() -> new 
QueryableRALBackendHandler<>(createSqlStatement(), 
connectionSession).execute());
     }
     
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
index ca41feb5e0b..8217f69a834 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
 
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetaDataStatement;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -25,6 +26,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
 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.util.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -35,7 +37,6 @@ import org.apache.shardingsphere.test.mock.StaticMockSettings;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 
-import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -53,9 +54,10 @@ import static org.mockito.Mockito.when;
 class ShowTableMetaDataExecutorTest {
     
     @Test
-    void assertExecute() throws SQLException {
+    void assertExecute() {
         ConnectionSession connectionSession = mock(ConnectionSession.class, 
RETURNS_DEEP_STUBS);
         when(connectionSession.getDatabaseName()).thenReturn("foo_db");
+        
when(connectionSession.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "FIXTURE"));
         ShowTableMetaDataExecutor executor = new ShowTableMetaDataExecutor();
         ContextManager contextManager = mockContextManager();
         
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdaterTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdaterTest.java
index 5301ac26b0c..e98b28a8237 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdaterTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdaterTest.java
@@ -22,6 +22,8 @@ import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDataba
 import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.EmptyStorageUnitException;
 import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.RefreshTableMetaDataStatement;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.UpdatableRALBackendHandler;
@@ -33,6 +35,8 @@ import org.apache.shardingsphere.test.mock.AutoMockExtension;
 import org.apache.shardingsphere.test.mock.StaticMockSettings;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
 
 import java.sql.SQLException;
 import java.util.Collections;
@@ -46,6 +50,7 @@ import static org.mockito.Mockito.when;
 
 @ExtendWith(AutoMockExtension.class)
 @StaticMockSettings(ProxyContext.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
 class RefreshTableMetaDataUpdaterTest {
     
     @Test
@@ -96,6 +101,7 @@ class RefreshTableMetaDataUpdaterTest {
     private ConnectionSession mockConnectionSession(final String databaseName) 
{
         ConnectionSession result = mock(ConnectionSession.class);
         when(result.getDatabaseName()).thenReturn(databaseName);
+        
when(result.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "FIXTURE"));
         return result;
     }
 }

Reply via email to