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

wuweijie 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 c6383f1  Refactor exception for RDL (#10452)
c6383f1 is described below

commit c6383f11390bbeeca79d263ac3f8a506fd4d8d93
Author: Haoran Meng <[email protected]>
AuthorDate: Tue May 25 15:05:54 2021 +0800

    Refactor exception for RDL (#10452)
    
    Co-authored-by: menghaoranss <[email protected]>
---
 .../db/protocol/error/CommonErrorCode.java         | 12 +--
 .../db/protocol/error/CommonErrorCodeTest.java     |  2 +-
 .../exception/EncryptRulesNotExistedException.java |  2 +
 .../exception/ShardingRuleNotExistedException.java | 31 --------
 .../ShardingTableRuleExistedException.java         | 35 --------
 .../ShardingTableRuleNotExistedException.java      |  4 +-
 .../rdl/impl/AlterEncryptRuleBackendHandler.java   | 13 +--
 ...terShardingBindingTableRulesBackendHandler.java | 34 +++++---
 ...rShardingBroadcastTableRulesBackendHandler.java |  4 +-
 .../impl/AlterShardingTableRuleBackendHandler.java | 93 +++++++++++-----------
 ...ateShardingBindingTableRulesBackendHandler.java | 34 +++++---
 .../rdl/impl/DropEncryptRuleBackendHandler.java    |  8 +-
 ...ropShardingBindingTableRulesBackendHandler.java |  3 +-
 ...pShardingBroadcastTableRulesBackendHandler.java |  6 +-
 .../impl/DropShardingTableRuleBackendHandler.java  |  5 +-
 ...rdingBroadcastTableRulesBackendHandlerTest.java |  4 +-
 .../AlterShardingTableRuleBackendHandlerTest.java  |  8 +-
 ...hardingBindingTableRulesBackendHandlerTest.java |  3 +-
 ...rdingBroadcastTableRulesBackendHandlerTest.java |  3 +-
 .../DropShardingTableRuleBackendHandlerTest.java   |  3 +-
 .../frontend/mysql/err/MySQLErrPacketFactory.java  | 14 +---
 .../mysql/err/MySQLErrPacketFactoryTest.java       |  4 +-
 22 files changed, 131 insertions(+), 194 deletions(-)

diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
index f2a759d..9dc288a 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/main/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCode.java
@@ -29,7 +29,7 @@ public enum CommonErrorCode implements SQLErrorCode {
     
     CIRCUIT_BREAK_MODE(1000, "C1000", "Circuit break mode is ON."),
     
-    SHARDING_TABLE_RULES_NOT_EXISTED(1101, "C1101", "Sharding table rule %s is 
not exist."),
+    SHARDING_TABLE_RULES_NOT_EXISTED(1101, "C1101", "Sharding table rules %s 
do not exist in schema %s."),
     
     SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE(1102, "C1102", "Sharding 
table rules %s are still used by binding table rule."),
 
@@ -43,10 +43,6 @@ public enum CommonErrorCode implements SQLErrorCode {
 
     READWRITE_SPLITTING_RULE_EXIST(1108, "C1108", "Readwrite splitting rule 
already exists in schema %s."),
     
-    SHARDING_RULE_NOT_EXIST(1109, "C1109", "Sharding rule does not exist."),
-    
-    SHARDING_TABLE_RULE_EXIST(1110, "C1110", "Sharding table rules: [%s] 
already exists."),
-    
     INVALID_RESOURCE(1111, "C1111", "Can not add invalid resources %s."),
     
     DUPLICATE_RESOURCE(1112, "C1112", "Duplicate resource names %s."),
@@ -55,9 +51,9 @@ public enum CommonErrorCode implements SQLErrorCode {
     
     SHARDING_BROADCAST_EXIST(1114, "C1114", "Sharding broadcast table rules 
already exists in schema %s."),
 
-    SHARDING_BINDING_TABLE_RULES_NOT_EXIST(1115, "C1115", "Sharding binding 
table rules not exist in schema %s."),
+    SHARDING_BINDING_TABLE_RULES_NOT_EXIST(1115, "C1115", "Sharding binding 
table rules do not exist in schema %s."),
 
-    SHARDING_BROADCAST_TABLE_RULES_NOT_EXIST(1116, "C1116", "Sharding 
broadcast table rules not exist in schema %s."),
+    SHARDING_BROADCAST_TABLE_RULES_NOT_EXIST(1116, "C1116", "Sharding 
broadcast table rules do not exist in schema %s."),
 
     INVALID_LOAD_BALANCERS(1117, "C1117", "Invalid load balancers %s."),
 
@@ -71,7 +67,7 @@ public enum CommonErrorCode implements SQLErrorCode {
 
     INVALID_ENCRYPTORS(1123, "C1123", "Invalid encryptors %s."),
 
-    ENCRYPT_RULES_NOT_EXIST(1124, "C1124", "Encrypt rules %s do not exist."),
+    ENCRYPT_RULES_NOT_EXIST(1124, "C1124", "Encrypt rules %s do not exist in 
schema %s."),
 
     SCALING_JOB_NOT_EXIST(1201, "C1201", "Scaling job %s does not exist."),
     
diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
index 9f1a19d..f740204 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-core/src/test/java/org/apache/shardingsphere/db/protocol/error/CommonErrorCodeTest.java
@@ -35,7 +35,7 @@ public final class CommonErrorCodeTest {
     public void assertSharingTableRulesNotExisted() {
         
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED.getErrorCode(), 
is(1101));
         
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED.getSqlState(), 
is("C1101"));
-        
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED.getErrorMessage(), 
is("Sharding table rule %s is not exist."));
+        
assertThat(CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED.getErrorMessage(), 
is("Sharding table rules %s do not exist in schema %s."));
     }
     
     @Test
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/EncryptRulesNotExistedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/EncryptRulesNotExistedException.java
index eeeb762..0f0671d 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/EncryptRulesNotExistedException.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/EncryptRulesNotExistedException.java
@@ -31,5 +31,7 @@ public final class EncryptRulesNotExistedException extends 
BackendException {
 
     private static final long serialVersionUID = -3070306238552517428L;
 
+    private final String schemaName;
+
     private final Collection<String> tables;
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingRuleNotExistedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingRuleNotExistedException.java
deleted file mode 100644
index c644bcf..0000000
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingRuleNotExistedException.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.proxy.backend.exception;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Sharding rule not existed exception.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ShardingRuleNotExistedException extends BackendException {
-    
-    private static final long serialVersionUID = -875932845262766838L;
-}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleExistedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleExistedException.java
deleted file mode 100644
index 8fe3ce9..0000000
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleExistedException.java
+++ /dev/null
@@ -1,35 +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.proxy.backend.exception;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.Collection;
-
-/**
- * Sharding table rule existed exception.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ShardingTableRuleExistedException extends BackendException {
-    
-    private static final long serialVersionUID = 258686465701003401L;
-    
-    private final Collection<String> tableNames;
-}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleNotExistedException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleNotExistedException.java
index cee6727..3fc5479 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleNotExistedException.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/ShardingTableRuleNotExistedException.java
@@ -30,6 +30,8 @@ import java.util.Collection;
 public final class ShardingTableRuleNotExistedException extends 
BackendException {
     
     private static final long serialVersionUID = 8565541404478688849L;
-    
+
+    private final String schemaName;
+
     private final Collection<String> tableNames;
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
index 3874904..99a6eea 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandler.java
@@ -58,9 +58,9 @@ public final class AlterEncryptRuleBackendHandler extends 
SchemaRequiredBackendH
         Optional<EncryptRuleConfiguration> ruleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
                 .filter(each -> each instanceof 
EncryptRuleConfiguration).map(each -> (EncryptRuleConfiguration) 
each).findFirst();
         if (!ruleConfig.isPresent()) {
-            throw new 
EncryptRulesNotExistedException(getAlteredTables(sqlStatement));
+            throw new EncryptRulesNotExistedException(schemaName, 
getAlteredTables(sqlStatement));
         }
-        check(sqlStatement, ruleConfig.get());
+        check(schemaName, sqlStatement, ruleConfig.get());
         YamlEncryptRuleConfiguration alterConfig = alter(ruleConfig.get(), 
sqlStatement);
         Collection<RuleConfiguration> rules = new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(alterConfig));
         post(schemaName, rules);
@@ -71,17 +71,18 @@ public final class AlterEncryptRuleBackendHandler extends 
SchemaRequiredBackendH
         return 
sqlStatement.getEncryptRules().stream().map(EncryptRuleSegment::getTableName).collect(Collectors.toList());
     }
 
-    private void check(final AlterEncryptRuleStatement sqlStatement, final 
EncryptRuleConfiguration encryptRuleConfiguration) {
-        checkAlteredTables(encryptRuleConfiguration, sqlStatement);
+    private void check(final String schemaName, final 
AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration 
encryptRuleConfiguration) {
+        checkAlteredTables(schemaName, encryptRuleConfiguration, sqlStatement);
         checkEncryptors(sqlStatement);
     }
 
-    private void checkAlteredTables(final EncryptRuleConfiguration 
encryptRuleConfiguration, final AlterEncryptRuleStatement sqlStatement) {
+    private void checkAlteredTables(final String schemaName, final 
EncryptRuleConfiguration encryptRuleConfiguration,
+                                    final AlterEncryptRuleStatement 
sqlStatement) {
         Collection<String> existTables = 
getExistTables(encryptRuleConfiguration);
         Collection<String> notExistTables = 
getAlteredTables(sqlStatement).stream()
                 .filter(each -> 
!existTables.contains(each)).collect(Collectors.toList());
         if (!notExistTables.isEmpty()) {
-            throw new EncryptRulesNotExistedException(notExistTables);
+            throw new EncryptRulesNotExistedException(schemaName, 
notExistTables);
         }
     }
 
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
index e7cf40c..600c090 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBindingTableRulesBackendHandler.java
@@ -24,7 +24,7 @@ import 
org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRulesNotExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -52,23 +52,17 @@ public final class 
AlterShardingBindingTableRulesBackendHandler extends SchemaRe
     @Override
     public ResponseHeader execute(final String schemaName, final 
AlterShardingBindingTableRulesStatement sqlStatement) {
         YamlShardingRuleConfiguration config = 
ShardingRuleStatementConverter.convert(sqlStatement);
-        ShardingRuleConfiguration shardingRuleConfiguration = 
check(schemaName, config);
+        check(schemaName, config);
+        ShardingRuleConfiguration shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
         shardingRuleConfiguration.getBindingTableGroups().clear();
         
shardingRuleConfiguration.getBindingTableGroups().addAll(config.getBindingTables());
         post(schemaName, 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations());
         return new UpdateResponseHeader(sqlStatement);
     }
     
-    private ShardingRuleConfiguration check(final String schemaName, final 
YamlShardingRuleConfiguration configuration) {
-        Optional<ShardingRuleConfiguration> shardingRuleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
-                .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
-        if (!shardingRuleConfig.isPresent()) {
-            throw new ShardingRuleNotExistedException();
-        }
+    private void check(final String schemaName, final 
YamlShardingRuleConfiguration configuration) {
         Collection<String> invalidBindingTables = new HashSet<>();
-        Collection<String> existLogicTables = new HashSet<>();
-        
existLogicTables.addAll(shardingRuleConfig.get().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
-        
existLogicTables.addAll(shardingRuleConfig.get().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
+        Collection<String> existLogicTables = getLogicTables(schemaName);
         for (String bindingTable : configuration.getBindingTables()) {
             for (String logicTable : 
Splitter.on(",").splitToList(bindingTable)) {
                 if (!existLogicTables.contains(logicTable.trim())) {
@@ -77,7 +71,23 @@ public final class 
AlterShardingBindingTableRulesBackendHandler extends SchemaRe
             }
         }
         if (!invalidBindingTables.isEmpty()) {
-            throw new 
ShardingTableRuleNotExistedException(invalidBindingTables);
+            throw new ShardingTableRuleNotExistedException(schemaName, 
invalidBindingTables);
+        }
+    }
+
+    private Collection<String> getLogicTables(final String schemaName) {
+        ShardingRuleConfiguration shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
+        Collection<String> existLogicTables = new HashSet<>();
+        
existLogicTables.addAll(shardingRuleConfiguration.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
+        
existLogicTables.addAll(shardingRuleConfiguration.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
+        return existLogicTables;
+    }
+
+    private ShardingRuleConfiguration getShardingRuleConfiguration(final 
String schemaName) {
+        Optional<ShardingRuleConfiguration> shardingRuleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
+                .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
+        if (!shardingRuleConfig.isPresent()) {
+            throw new ShardingBindingTableRulesNotExistsException(schemaName);
         }
         return shardingRuleConfig.get();
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
index 347a36e..d2bb9d3 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandler.java
@@ -23,7 +23,7 @@ import 
org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRulesNotExistsException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
@@ -46,7 +46,7 @@ public final class 
AlterShardingBroadcastTableRulesBackendHandler extends Schema
         Optional<ShardingRuleConfiguration> shardingRuleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
                 .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
         if (!shardingRuleConfig.isPresent()) {
-            throw new ShardingRuleNotExistedException();
+            throw new 
ShardingBroadcastTableRulesNotExistsException(schemaName);
         }
         shardingRuleConfig.get().getBroadcastTables().clear();
         
shardingRuleConfig.get().getBroadcastTables().addAll(sqlStatement.getTables());
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
index fa3517f..864d8b2 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandler.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
 
-import org.apache.shardingsphere.distsql.parser.segment.TableRuleSegment;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterShardingTableRuleStatement;
 import 
org.apache.shardingsphere.governance.core.registry.listener.event.rule.RuleConfigurationsAlteredEvent;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -26,7 +25,6 @@ import 
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -37,12 +35,9 @@ import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfi
 import 
org.apache.shardingsphere.sharding.converter.ShardingRuleStatementConverter;
 import 
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
 
-import java.util.Set;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -57,64 +52,68 @@ public final class AlterShardingTableRuleBackendHandler 
extends SchemaRequiredBa
     
     @Override
     public ResponseHeader execute(final String schemaName, final 
AlterShardingTableRuleStatement sqlStatement) {
-        if (!getShardingRuleConfiguration(schemaName).isPresent()) {
-            throw new ShardingRuleNotExistedException();
-        }
         check(schemaName, sqlStatement);
-        Optional<YamlShardingRuleConfiguration> yamlShardingRuleConfig = new 
YamlRuleConfigurationSwapperEngine()
-                
.swapToYamlRuleConfigurations(Collections.singleton(getShardingRuleConfiguration(schemaName).get())).stream()
-                .filter(each -> each instanceof 
YamlShardingRuleConfiguration).map(each -> (YamlShardingRuleConfiguration) 
each).findFirst();
-        if (!yamlShardingRuleConfig.isPresent()) {
-            throw new ShardingRuleNotExistedException();
-        }
-        YamlShardingRuleConfiguration existYamlShardingRuleConfiguration = 
yamlShardingRuleConfig.get();
-        YamlShardingRuleConfiguration yamlShardingRuleConfiguration = 
ShardingRuleStatementConverter.convert(sqlStatement);
-        
existYamlShardingRuleConfiguration.getShardingAlgorithms().putAll(yamlShardingRuleConfiguration.getShardingAlgorithms());
-        yamlShardingRuleConfiguration.getTables().keySet().forEach(each -> {
-            if 
(existYamlShardingRuleConfiguration.getTables().keySet().contains(each)) {
-                existYamlShardingRuleConfiguration.getTables().remove(each);
-            }
-        });
-        
existYamlShardingRuleConfiguration.getAutoTables().putAll(yamlShardingRuleConfiguration.getAutoTables());
-        post(schemaName, new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(existYamlShardingRuleConfiguration)));
+        YamlShardingRuleConfiguration yamlShardingRuleConfiguration = 
alter(schemaName, sqlStatement);
+        post(schemaName, new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(yamlShardingRuleConfiguration)));
         return new UpdateResponseHeader(sqlStatement);
     }
 
     private void check(final String schemaName, final 
AlterShardingTableRuleStatement sqlStatement) {
-        Collection<String> logicTableNames = new 
ArrayList<>(sqlStatement.getTables().size());
-        Set<String> duplicateTableNames = new 
HashSet<>(sqlStatement.getTables().size(), 1);
-        for (TableRuleSegment tableRuleSegment : sqlStatement.getTables()) {
-            if (logicTableNames.contains(tableRuleSegment.getLogicTable())) {
-                duplicateTableNames.add(tableRuleSegment.getLogicTable());
-            }
-            logicTableNames.add(tableRuleSegment.getLogicTable());
+        Collection<String> duplicateTables = getDuplicateTables(sqlStatement);
+        if (!duplicateTables.isEmpty()) {
+            throw new DuplicateTablesException(duplicateTables);
         }
-        if (!duplicateTableNames.isEmpty()) {
-            throw new DuplicateTablesException(duplicateTableNames);
+        Collection<String> alteredTables = getAlteredTables(sqlStatement);
+        if (!getShardingRuleConfiguration(schemaName).isPresent()) {
+            throw new ShardingTableRuleNotExistedException(schemaName, 
alteredTables);
         }
-        Collection<String> existTables = getLogicTables(schemaName);
-        Collection<String> notExistTables = 
logicTableNames.stream().filter(each -> 
!existTables.contains(each)).collect(Collectors.toList());
+        Collection<String> existTables = 
getShardingTables(getShardingRuleConfiguration(schemaName).get());
+        Collection<String> notExistTables = alteredTables.stream().filter(each 
-> !existTables.contains(each)).collect(Collectors.toList());
         if (!notExistTables.isEmpty()) {
-            throw new ShardingTableRuleNotExistedException(notExistTables);
+            throw new ShardingTableRuleNotExistedException(schemaName, 
notExistTables);
         }
     }
 
-    private Collection<String> getLogicTables(final String schemaName) {
-        Optional<ShardingRuleConfiguration> shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
-        Collection<String> result = new LinkedList<>();
-        if (!shardingRuleConfiguration.isPresent()) {
-            return result;
-        }
-        
result.addAll(shardingRuleConfiguration.get().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
-        
result.addAll(shardingRuleConfiguration.get().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
-        return result;
+    private Collection<String> getDuplicateTables(final 
AlterShardingTableRuleStatement sqlStatement) {
+        return sqlStatement.getTables().stream()
+                .collect(Collectors.toMap(e -> e.getLogicTable(), e -> 1, (a, 
b) -> a + b))
+                .entrySet().stream()
+                .filter(entry -> entry.getValue() > 1)
+                .map(entry -> entry.getKey())
+                .collect(Collectors.toList());
+    }
+
+    private Collection<String> getAlteredTables(final 
AlterShardingTableRuleStatement sqlStatement) {
+        return sqlStatement.getTables().stream().map(each -> 
each.getLogicTable()).collect(Collectors.toList());
     }
 
     private Optional<ShardingRuleConfiguration> 
getShardingRuleConfiguration(final String schemaName) {
         return 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
                 .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
     }
-    
+
+    private Collection<String> getShardingTables(final 
ShardingRuleConfiguration shardingRuleConfiguration) {
+        Collection<String> result = new LinkedList<>();
+        
result.addAll(shardingRuleConfiguration.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
+        
result.addAll(shardingRuleConfiguration.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
+        return result;
+    }
+
+    private YamlShardingRuleConfiguration alter(final String schemaName, final 
AlterShardingTableRuleStatement sqlStatement) {
+        YamlShardingRuleConfiguration result = new 
YamlRuleConfigurationSwapperEngine()
+                
.swapToYamlRuleConfigurations(Collections.singleton(getShardingRuleConfiguration(schemaName).get())).stream()
+                .filter(each -> each instanceof 
YamlShardingRuleConfiguration).map(each -> (YamlShardingRuleConfiguration) 
each).findFirst().get();
+        YamlShardingRuleConfiguration yamlShardingRuleConfiguration = 
ShardingRuleStatementConverter.convert(sqlStatement);
+        
result.getShardingAlgorithms().putAll(yamlShardingRuleConfiguration.getShardingAlgorithms());
+        yamlShardingRuleConfiguration.getTables().keySet().forEach(each -> {
+            if (result.getTables().keySet().contains(each)) {
+                result.getTables().remove(each);
+            }
+        });
+        
result.getAutoTables().putAll(yamlShardingRuleConfiguration.getAutoTables());
+        return result;
+    }
+
     private void post(final String schemaName, final 
Collection<RuleConfiguration> rules) {
         ShardingSphereEventBus.getInstance().post(new 
RuleConfigurationsAlteredEvent(schemaName, rules));
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
index 011f7ac..58ff1a1 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingBindingTableRulesBackendHandler.java
@@ -24,7 +24,7 @@ import 
org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRulesNotExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -52,22 +52,16 @@ public final class 
CreateShardingBindingTableRulesBackendHandler extends SchemaR
     @Override
     public ResponseHeader execute(final String schemaName, final 
CreateShardingBindingTableRulesStatement sqlStatement) {
         YamlShardingRuleConfiguration config = 
ShardingRuleStatementConverter.convert(sqlStatement);
-        ShardingRuleConfiguration shardingRuleConfiguration = 
check(schemaName, config);
+        check(schemaName, config);
+        ShardingRuleConfiguration shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
         
shardingRuleConfiguration.getBindingTableGroups().addAll(config.getBindingTables());
         post(schemaName, 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations());
         return new UpdateResponseHeader(sqlStatement);
     }
     
-    private ShardingRuleConfiguration check(final String schemaName, final 
YamlShardingRuleConfiguration configuration) {
-        Optional<ShardingRuleConfiguration> shardingRuleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
-                .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
-        if (!shardingRuleConfig.isPresent()) {
-            throw new ShardingRuleNotExistedException();
-        }
+    private void check(final String schemaName, final 
YamlShardingRuleConfiguration configuration) {
         Collection<String> invalidBindingTables = new HashSet<>();
-        Collection<String> existLogicTables = new HashSet<>();
-        
existLogicTables.addAll(shardingRuleConfig.get().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
-        
existLogicTables.addAll(shardingRuleConfig.get().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
+        Collection<String> existLogicTables = getLogicTables(schemaName);
         for (String bindingTable : configuration.getBindingTables()) {
             for (String logicTable : 
Splitter.on(",").splitToList(bindingTable)) {
                 if (!existLogicTables.contains(logicTable.trim())) {
@@ -76,7 +70,23 @@ public final class 
CreateShardingBindingTableRulesBackendHandler extends SchemaR
             }
         }
         if (!invalidBindingTables.isEmpty()) {
-            throw new 
ShardingTableRuleNotExistedException(invalidBindingTables);
+            throw new ShardingTableRuleNotExistedException(schemaName, 
invalidBindingTables);
+        }
+    }
+
+    private Collection<String> getLogicTables(final String schemaName) {
+        ShardingRuleConfiguration shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
+        Collection<String> existLogicTables = new HashSet<>();
+        
existLogicTables.addAll(shardingRuleConfiguration.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
+        
existLogicTables.addAll(shardingRuleConfiguration.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));
+        return existLogicTables;
+    }
+
+    private ShardingRuleConfiguration getShardingRuleConfiguration(final 
String schemaName) {
+        Optional<ShardingRuleConfiguration> shardingRuleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
+                .filter(each -> each instanceof 
ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) 
each).findFirst();
+        if (!shardingRuleConfig.isPresent()) {
+            throw new ShardingBindingTableRulesNotExistsException(schemaName);
         }
         return shardingRuleConfig.get();
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
index 8eb6545..3d475f2 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropEncryptRuleBackendHandler.java
@@ -51,9 +51,9 @@ public final class DropEncryptRuleBackendHandler extends 
SchemaRequiredBackendHa
         Optional<EncryptRuleConfiguration> ruleConfig = 
ProxyContext.getInstance().getMetaData(schemaName).getRuleMetaData().getConfigurations().stream()
                 .filter(each -> each instanceof 
EncryptRuleConfiguration).map(each -> (EncryptRuleConfiguration) 
each).findFirst();
         if (!ruleConfig.isPresent()) {
-            throw new 
EncryptRulesNotExistedException(sqlStatement.getTables());
+            throw new EncryptRulesNotExistedException(schemaName, 
sqlStatement.getTables());
         }
-        check(ruleConfig.get(), sqlStatement.getTables());
+        check(schemaName, ruleConfig.get(), sqlStatement.getTables());
         YamlEncryptRuleConfiguration yamlEncryptRuleConfiguration = new 
YamlRuleConfigurationSwapperEngine()
                 
.swapToYamlRuleConfigurations(Collections.singletonList(ruleConfig.get())).stream()
                 .map(each -> (YamlEncryptRuleConfiguration) 
each).findFirst().get();
@@ -63,11 +63,11 @@ public final class DropEncryptRuleBackendHandler extends 
SchemaRequiredBackendHa
         return new UpdateResponseHeader(sqlStatement);
     }
     
-    private void check(final EncryptRuleConfiguration ruleConfig, final 
Collection<String> droppedTables) {
+    private void check(final String schemaName, final EncryptRuleConfiguration 
ruleConfig, final Collection<String> droppedTables) {
         Collection<String> encryptTables = 
ruleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
         Collection<String> notExistedTables = 
droppedTables.stream().filter(each -> 
!encryptTables.contains(each)).collect(Collectors.toList());
         if (!notExistedTables.isEmpty()) {
-            throw new EncryptRulesNotExistedException(notExistedTables);
+            throw new EncryptRulesNotExistedException(schemaName, 
notExistedTables);
         }
     }
 
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
index c9d0704..fe4d9e7 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandler.java
@@ -23,7 +23,6 @@ import 
org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRulesNotExistsException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
@@ -44,7 +43,7 @@ public final class 
DropShardingBindingTableRulesBackendHandler extends SchemaReq
     public ResponseHeader execute(final String schemaName, final 
DropShardingBindingTableRulesStatement sqlStatement) {
         Optional<ShardingRuleConfiguration> shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
         if (!shardingRuleConfiguration.isPresent()) {
-            throw new ShardingRuleNotExistedException();
+            throw new ShardingBindingTableRulesNotExistsException(schemaName);
         }
         if (shardingRuleConfiguration.get().getBindingTableGroups().isEmpty()) 
{
             throw new ShardingBindingTableRulesNotExistsException(schemaName);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
index 69aac63..aec1adf 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandler.java
@@ -23,7 +23,6 @@ import 
org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRulesNotExistsException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
@@ -43,10 +42,7 @@ public final class 
DropShardingBroadcastTableRulesBackendHandler extends SchemaR
     @Override
     public ResponseHeader execute(final String schemaName, final 
DropShardingBroadcastTableRulesStatement sqlStatement) {
         Optional<ShardingRuleConfiguration> shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
-        if (!shardingRuleConfiguration.isPresent()) {
-            throw new ShardingRuleNotExistedException();
-        }
-        if (shardingRuleConfiguration.get().getBroadcastTables().isEmpty()) {
+        if (!shardingRuleConfiguration.isPresent() || 
shardingRuleConfiguration.get().getBroadcastTables().isEmpty()) {
             throw new 
ShardingBroadcastTableRulesNotExistsException(schemaName);
         }
         shardingRuleConfiguration.get().getBroadcastTables().clear();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
index 7309821..db26737 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandler.java
@@ -23,7 +23,6 @@ import 
org.apache.shardingsphere.governance.core.registry.listener.event.rule.Ru
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -59,12 +58,12 @@ public final class DropShardingTableRuleBackendHandler 
extends SchemaRequiredBac
     private ShardingRuleConfiguration check(final String schemaName, final 
Collection<String> tableNames) {
         Optional<ShardingRuleConfiguration> shardingRuleConfiguration = 
getShardingRuleConfiguration(schemaName);
         if (!shardingRuleConfiguration.isPresent()) {
-            throw new ShardingRuleNotExistedException();
+            throw new ShardingTableRuleNotExistedException(schemaName, 
tableNames);
         }
         Collection<String> shardingTableNames = 
getShardingTables(shardingRuleConfiguration.get());
         Collection<String> notExistedTableNames = 
tableNames.stream().filter(each -> 
!shardingTableNames.contains(each)).collect(Collectors.toList());
         if (!notExistedTableNames.isEmpty()) {
-            throw new 
ShardingTableRuleNotExistedException(notExistedTableNames);
+            throw new ShardingTableRuleNotExistedException(schemaName, 
notExistedTableNames);
         }
         // TODO issue#10417
         return shardingRuleConfiguration.get();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandlerTest.java
index 6fda00e..2fd5d16 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingBroadcastTableRulesBackendHandlerTest.java
@@ -23,7 +23,7 @@ import 
org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRulesNotExistsException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -68,7 +68,7 @@ public final class 
AlterShardingBroadcastTableRulesBackendHandlerTest {
         
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData);
     }
     
-    @Test(expected = ShardingRuleNotExistedException.class)
+    @Test(expected = ShardingBroadcastTableRulesNotExistsException.class)
     public void assertExecuteWithoutShardingRuleConfiguration() {
         when(shardingSphereRuleMetaData.getConfigurations()).thenReturn(new 
ArrayList<>());
         AlterShardingBroadcastTableRulesStatement statement = new 
AlterShardingBroadcastTableRulesStatement();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
index f3013ea..63b8e79 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
@@ -27,7 +27,6 @@ import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.DuplicateTablesException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -41,11 +40,11 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Properties;
-import java.util.Collection;
-import java.util.ArrayList;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -83,7 +82,7 @@ public final class AlterShardingTableRuleBackendHandlerTest {
         
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
     }
     
-    @Test(expected = ShardingRuleNotExistedException.class)
+    @Test(expected = ShardingTableRuleNotExistedException.class)
     public void assertExecuteWithoutShardingRule() {
         handler.execute("test", sqlStatement);
     }
@@ -110,7 +109,6 @@ public final class AlterShardingTableRuleBackendHandlerTest 
{
     public void assertExecuteWithDuplicateTablesInRDL() {
         TableRuleSegment tableRuleSegment = new TableRuleSegment();
         tableRuleSegment.setLogicTable("t_order");
-        
when(ruleMetaData.getConfigurations()).thenReturn(buildShardingConfigurations());
         
when(sqlStatement.getTables()).thenReturn(Arrays.asList(tableRuleSegment, 
tableRuleSegment));
         handler.execute("test", sqlStatement);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandlerTest.java
index 9f7b0d6..67785ed 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBindingTableRulesBackendHandlerTest.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRulesNotExistsException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -79,7 +78,7 @@ public final class 
DropShardingBindingTableRulesBackendHandlerTest {
         
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
     }
     
-    @Test(expected = ShardingRuleNotExistedException.class)
+    @Test(expected = ShardingBindingTableRulesNotExistsException.class)
     public void assertExecuteWithoutShardingRule() {
         handler.execute("test", sqlStatement);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandlerTest.java
index 9cf1c60..19e7dda 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingBroadcastTableRulesBackendHandlerTest.java
@@ -25,7 +25,6 @@ import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRulesNotExistsException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -79,7 +78,7 @@ public final class 
DropShardingBroadcastTableRulesBackendHandlerTest {
         
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
     }
     
-    @Test(expected = ShardingRuleNotExistedException.class)
+    @Test(expected = ShardingBroadcastTableRulesNotExistsException.class)
     public void assertExecuteWithoutShardingRule() {
         handler.execute("test", sqlStatement);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
index 5132026..011b742 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/DropShardingTableRuleBackendHandlerTest.java
@@ -24,7 +24,6 @@ import 
org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -83,7 +82,7 @@ public final class DropShardingTableRuleBackendHandlerTest {
         
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
     }
     
-    @Test(expected = ShardingRuleNotExistedException.class)
+    @Test(expected = ShardingTableRuleNotExistedException.class)
     public void assertExecuteWithoutShardingRule() {
         handler.execute("test", sqlStatement);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index 36d584b..c2177af 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -46,8 +46,6 @@ import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBindingTableRulesNotExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRulesExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingBroadcastTableRulesNotExistsException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingRuleNotExistedException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRuleNotExistedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.ShardingTableRulesInUsedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.TableLockWaitTimeoutException;
@@ -112,7 +110,8 @@ public final class MySQLErrPacketFactory {
             return new MySQLErrPacket(1, CommonErrorCode.CIRCUIT_BREAK_MODE);
         }
         if (cause instanceof ShardingTableRuleNotExistedException) {
-            return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED, 
((ShardingTableRuleNotExistedException) cause).getTableNames());
+            return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_TABLE_RULES_NOT_EXISTED, 
((ShardingTableRuleNotExistedException) cause).getTableNames(),
+                    ((ShardingTableRuleNotExistedException) 
cause).getSchemaName());
         }
         if (cause instanceof ShardingTableRulesInUsedException) {
             return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_TABLE_RULES_IN_USED_BY_BINDING_TABLE, 
((ShardingTableRulesInUsedException) cause).getTableNames());
@@ -157,12 +156,6 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof ShardingBroadcastTableRulesExistsException) {
             return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_BROADCAST_EXIST, 
((ShardingBroadcastTableRulesExistsException) cause).getSchemaName());
         }
-        if (cause instanceof ShardingRuleNotExistedException) {
-            return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_RULE_NOT_EXIST);
-        }
-        if (cause instanceof ShardingTableRuleExistedException) {
-            return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_TABLE_RULE_EXIST, ((ShardingTableRuleExistedException) 
cause).getTableNames());
-        }
         if (cause instanceof ShardingBindingTableRulesNotExistsException) {
             return new MySQLErrPacket(1, 
CommonErrorCode.SHARDING_BINDING_TABLE_RULES_NOT_EXIST, 
((ShardingBindingTableRulesNotExistsException) cause).getSchemaName());
         }
@@ -202,7 +195,8 @@ public final class MySQLErrPacketFactory {
             return new MySQLErrPacket(1, CommonErrorCode.INVALID_ENCRYPTORS, 
((InvalidEncryptorsException) cause).getEncryptors());
         }
         if (cause instanceof EncryptRulesNotExistedException) {
-            return new MySQLErrPacket(1, 
CommonErrorCode.ENCRYPT_RULES_NOT_EXIST, ((EncryptRulesNotExistedException) 
cause).getTables());
+            return new MySQLErrPacket(1, 
CommonErrorCode.ENCRYPT_RULES_NOT_EXIST, ((EncryptRulesNotExistedException) 
cause).getTables(),
+                    ((EncryptRulesNotExistedException) cause).getSchemaName());
         }
         return new MySQLErrPacket(1, CommonErrorCode.UNKNOWN_EXCEPTION, 
cause.getMessage());
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 08bcee1..ab8a2df 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -195,11 +195,11 @@ public final class MySQLErrPacketFactoryTest {
     
     @Test
     public void assertNewInstanceWithShardingTableRuleNotExistedException() {
-        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
ShardingTableRuleNotExistedException(Collections.singleton("tbl")));
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
ShardingTableRuleNotExistedException("test", Collections.singleton("tbl")));
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(1101));
         assertThat(actual.getSqlState(), is("C1101"));
-        assertThat(actual.getErrorMessage(), is("Sharding table rule [tbl] is 
not exist."));
+        assertThat(actual.getErrorMessage(), is("Sharding table rules [tbl] do 
not exist in schema test."));
     }
     
     @Test

Reply via email to