You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2026/05/13 04:27:13 UTC

(shardingsphere) branch master updated: Find identifier table for remove table (#38688)

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

menghaoranss 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 398e5099514 Find identifier table for remove table (#38688)
398e5099514 is described below

commit 398e50995147c27185a1999e5274c500a37ae799
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Wed May 13 12:27:05 2026 +0800

    Find identifier table for remove table (#38688)
---
 .../schema/model/ShardingSphereSchema.java         | 13 +++++------
 .../model/ShardingSphereSchemaIdentifierTest.java  | 26 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
index 8f816764499..b26764495b9 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
@@ -182,13 +182,12 @@ public final class ShardingSphereSchema {
      * @param tableName table name
      */
     public void removeTable(final String tableName) {
-        ShardingSphereTable table = getTable(tableName);
-        if (null == table) {
-            return;
-        }
-        tableIndex.remove(table.getName());
-        if (null != logicalTableIndex) {
-            logicalTableIndex.remove(table.getName());
+        Optional<ShardingSphereTable> table = findTable(new IdentifierValue(tableName, QuoteCharacter.NONE));
+        if (table.isPresent()) {
+            tableIndex.remove(table.get().getName());
+            if (null != logicalTableIndex) {
+                logicalTableIndex.remove(table.get().getName());
+            }
         }
     }
     
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaIdentifierTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaIdentifierTest.java
index af10eaff98e..bdaca4e1c2d 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaIdentifierTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaIdentifierTest.java
@@ -34,6 +34,7 @@ import java.util.Map;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class ShardingSphereSchemaIdentifierTest {
@@ -131,4 +132,29 @@ class ShardingSphereSchemaIdentifierTest {
         schema.refreshIdentifierContext(context);
         assertThat(schema.getTable("FOO_TBL"), is(upperCaseTable));
     }
+    
+    @Test
+    void assertRemoveTableByLogicalTableIndexWhenHeterogeneousLookupEnabled() {
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+        ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema", postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+        Map<IdentifierScope, IdentifierCaseRule> scopedRules = new EnumMap<>(IdentifierScope.class);
+        scopedRules.put(IdentifierScope.LOGICAL_TABLE, IdentifierCaseRuleSets.newLowerCaseRuleSet().getRule(IdentifierScope.TABLE));
+        DatabaseIdentifierContext context = new DatabaseIdentifierContext(new IdentifierCaseRuleSet(IdentifierCaseRuleSets.newUpperCaseRuleSet().getRule(IdentifierScope.TABLE), scopedRules), true);
+        schema.refreshIdentifierContext(context);
+        schema.removeTable("FOO_TBL");
+        assertNull(schema.getTable("foo_tbl"));
+    }
+    
+    @Test
+    void assertRemoveTablePrioritizesPhysicalTableIndexWhenBothIndexesCanMatch() {
+        ShardingSphereTable lowerCaseTable = new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+        ShardingSphereTable upperCaseTable = new ShardingSphereTable("FOO_TBL", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+        ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema", postgreSQLDatabaseType, Arrays.asList(lowerCaseTable, upperCaseTable), Collections.emptyList());
+        Map<IdentifierScope, IdentifierCaseRule> scopedRules = new EnumMap<>(IdentifierScope.class);
+        scopedRules.put(IdentifierScope.LOGICAL_TABLE, IdentifierCaseRuleSets.newLowerCaseRuleSet().getRule(IdentifierScope.TABLE));
+        DatabaseIdentifierContext context = new DatabaseIdentifierContext(new IdentifierCaseRuleSet(IdentifierCaseRuleSets.newUpperCaseRuleSet().getRule(IdentifierScope.TABLE), scopedRules), true);
+        schema.refreshIdentifierContext(context);
+        schema.removeTable("FOO_TBL");
+        assertThat(schema.getTable("FOO_TBL"), is(lowerCaseTable));
+    }
 }