{"record":{"id":"5712fa0d49fb736e","repo":"apache/shardingsphere","slug":"3","errorCode":"3","errorMessage":"Sharding rules '%s' in database '%s' are still in used by sharding table reference.","messagePattern":"Sharding rules '(.+?)' in database '(.+?)' are still in used by sharding table reference\\.","errorType":"exception","errorClass":"InUsedRuleException","httpStatus":null,"severity":"error","filePath":"features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java","lineNumber":82,"sourceCode":"        ShardingSpherePreconditions.checkMustEmpty(notExistedTableNames, () -> new MissingRequiredRuleException(\"sharding\", database.getName(), notExistedTableNames));\n    }\n    \n    private Collection<String> getToBeDroppedShardingTableNames(final DropShardingTableRuleStatement sqlStatement) {\n        return sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());\n    }\n    \n    private Collection<String> getCurrentShardingTableNames() {\n        Collection<String> result = new CaseInsensitiveSet<>();\n        result.addAll(rule.getConfiguration().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));\n        result.addAll(rule.getConfiguration().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));\n        return result;\n    }\n    \n    private void checkBindingTables(final DropShardingTableRuleStatement sqlStatement) {\n        Collection<String> bindingTables = getBindingTables();\n        Collection<String> usedTableNames = getToBeDroppedShardingTableNames(sqlStatement).stream().filter(bindingTables::contains).collect(Collectors.toList());\n        if (!usedTableNames.isEmpty()) {\n            throw new InUsedRuleException(\"Sharding\", database.getName(), usedTableNames, \"sharding table reference\");\n        }\n    }\n    \n    private Collection<String> getBindingTables() {\n        Collection<String> result = new CaseInsensitiveSet<>();\n        rule.getConfiguration().getBindingTableGroups().forEach(each -> result.addAll(Splitter.on(\",\").splitToList(each.getReference())));\n        return result;\n    }\n    \n    @Override\n    public boolean hasAnyOneToBeDropped(final DropShardingTableRuleStatement sqlStatement) {\n        Collection<String> currentTableNames = new LinkedList<>();\n        currentTableNames.addAll(rule.getConfiguration().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));\n        currentTableNames.addAll(rule.getConfiguration().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet()));\n        return !Collections.disjoint(currentTableNames, sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toSet()));\n    }\n    \n    @Override","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java#L64-L100","documentation":"InUsedRuleException thrown by DropShardingTableRuleExecutor.checkBindingTables when a DROP SHARDING TABLE RULE statement names tables that still appear in a sharding binding table group (rule configuration's bindingTableGroups references, split by comma). ShardingSphere refuses to drop rules that other configuration still references, to avoid leaving dangling binding-table entries.","triggerScenarios":"DROP SHARDING TABLE RULE t_order while a binding group like 't_order,t_order_item' exists: the to-be-dropped names intersect getBindingTables(), so the drop is rejected listing the still-used table names.","commonSituations":"Decommissioning or migrating one table of a binding group; cleanup scripts that drop sharding rules but forget binding groups; re-sharding a table that participates in a binding relationship.","solutions":["Drop or rewrite the binding rule first: ALTER SHARDING BINDING TABLE RULES without the affected table (or DROP SHARDING BINDING TABLE RULES), then re-run the DROP SHARDING TABLE RULE.","If dropping the whole group, drop all member tables' rules together with the binding rule.","Inspect current references first with SHOW SHARDING BINDING TABLE RULES."],"exampleFix":"-- before: drop rejected while binding exists\nDROP SHARDING TABLE RULE t_order;\n\n-- after: remove from binding group, then drop\nALTER SHARDING BINDING TABLE RULES ();\nDROP SHARDING TABLE RULE t_order;","handlingStrategy":"validation","validationCode":"-- Check binding references before dropping\nSHOW SHARDING BINDING TABLE RULES;\n-- if the target appears in any reference list, first run:\n--   ALTER SHARDING BINDING TABLE RULES (...) without it, or DROP SHARDING BINDING TABLE RULES","typeGuard":null,"tryCatchPattern":"try {\n    executeDistSql(\"DROP SHARDING TABLE RULE t_order\");\n} catch (final InUsedRuleException ex) {\n    // remove the table from binding groups first, then retry the drop\n}","preventionTips":["Make teardown scripts drop dependent objects in order: binding rules, then table rules.","Treat InUsedRuleException as a dependency graph hint — always resolve the reference, never force."],"tags":["sharding","distsql","drop-rule","binding-table","in-use"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}