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

(shardingsphere) branch master updated: Remove useless field in TablesContext (#37956)

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

chengzhang 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 f4a8ecf02a2 Remove useless field in TablesContext (#37956)
f4a8ecf02a2 is described below

commit f4a8ecf02a285600a86eb24e190872bb21879af6
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Feb 4 15:28:20 2026 +0800

    Remove useless field in TablesContext (#37956)
---
 .../connector/core/type/DatabaseTypeRegistry.java  |  2 +-
 .../core/type/DatabaseTypeRegistryTest.java        |  2 +-
 .../engine/BroadcastRouteEngineFactoryTest.java    |  2 +-
 .../sharding/rule/ShardingRuleTest.java            |  2 +-
 .../context/segment/table/TablesContext.java       | 38 +---------------------
 .../type/dml/InsertStatementBaseContext.java       |  2 +-
 .../type/dml/SelectStatementBaseContext.java       |  2 +-
 .../context/segment/table/TablesContextTest.java   |  4 +--
 8 files changed, 9 insertions(+), 45 deletions(-)

diff --git a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistry.java b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistry.java
index ed0558d4b13..45b2ef2e58d 100644
--- a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistry.java
+++ b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistry.java
@@ -57,7 +57,7 @@ public final class DatabaseTypeRegistry {
      * @return default schema name
      */
     public String getDefaultSchemaName(final String databaseName) {
-        return dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().orElseGet(() -> null == databaseName ? null : databaseName.toLowerCase());
+        return dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().orElse(databaseName);
     }
     
     /**
diff --git a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistryTest.java b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistryTest.java
index cdeb9bb6c7e..08622b41c4a 100644
--- a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistryTest.java
+++ b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/type/DatabaseTypeRegistryTest.java
@@ -47,7 +47,7 @@ class DatabaseTypeRegistryTest {
     
     @Test
     void assertGetDefaultSchemaNameWhenDatabaseTypeNotContainsDefaultSchema() {
-        assertThat(new DatabaseTypeRegistry(TypedSPILoader.getService(DatabaseType.class, "BRANCH")).getDefaultSchemaName("FOO"), is("foo"));
+        assertThat(new DatabaseTypeRegistry(TypedSPILoader.getService(DatabaseType.class, "BRANCH")).getDefaultSchemaName("FOO"), is("FOO"));
     }
     
     @Test
diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java
index 44dacbb34eb..c9e2d619f3b 100644
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java
+++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java
@@ -141,6 +141,6 @@ class BroadcastRouteEngineFactoryTest {
     }
     
     private TablesContext createTablesContext() {
-        return new TablesContext(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))), null);
+        return new TablesContext(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))));
     }
 }
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index a157e5fc7b5..e476d6170cd 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -677,7 +677,7 @@ class ShardingRuleTest {
         Collection<SimpleTableSegment> tableSegments = Arrays.asList(
                 new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("LOGIC_TABLE"))),
                 new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("SUB_LOGIC_TABLE"))));
-        TablesContext tablesContext = new TablesContext(tableSegments, Collections.emptyMap());
+        TablesContext tablesContext = new TablesContext(tableSegments);
         when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
         when(database.getName()).thenReturn("foo_db");
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
index 1240a4fcd6b..ff418e90d7c 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
@@ -17,24 +17,17 @@
 
 package org.apache.shardingsphere.infra.binder.context.segment.table;
 
-import com.cedarsoftware.util.CaseInsensitiveMap;
 import com.cedarsoftware.util.CaseInsensitiveSet;
 import com.google.common.base.Strings;
-import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.ToString;
-import org.apache.shardingsphere.infra.binder.context.segment.select.subquery.SubqueryTableContext;
-import org.apache.shardingsphere.infra.binder.context.segment.select.subquery.engine.SubqueryTableContextEngine;
-import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment;
 
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
-import java.util.Map;
 import java.util.Optional;
 
 /**
@@ -52,26 +45,12 @@ public final class TablesContext {
     
     private final Collection<String> databaseNames = new CaseInsensitiveSet<>();
     
-    @Getter(AccessLevel.NONE)
-    private final Map<String, Collection<SubqueryTableContext>> subqueryTables = new CaseInsensitiveMap<>();
-    
-    @Getter(AccessLevel.NONE)
-    private final Collection<? extends TableSegment> tables;
-    
     public TablesContext(final SimpleTableSegment table) {
         this(null == table ? Collections.emptyList() : Collections.singletonList(table));
     }
     
-    public TablesContext(final Collection<SimpleTableSegment> tables) {
-        this(tables, Collections.emptyMap());
-    }
-    
-    public TablesContext(final Collection<? extends TableSegment> tables, final Map<Integer, SelectStatementContext> subqueryContexts) {
-        this.tables = tables;
+    public TablesContext(final Collection<? extends TableSegment> tables) {
         for (TableSegment each : tables) {
-            if (each instanceof SubqueryTableSegment) {
-                subqueryTables.putAll(createSubqueryTables(subqueryContexts, (SubqueryTableSegment) each));
-            }
             if (!(each instanceof SimpleTableSegment)) {
                 continue;
             }
@@ -94,21 +73,6 @@ public final class TablesContext {
                 .ifPresent(optional -> databaseNames.add(optional.getOriginalDatabase().getValue()));
     }
     
-    private Map<String, Collection<SubqueryTableContext>> createSubqueryTables(final Map<Integer, SelectStatementContext> subqueryContexts, final SubqueryTableSegment subqueryTable) {
-        if (!subqueryContexts.containsKey(subqueryTable.getSubquery().getStartIndex())) {
-            return Collections.emptyMap();
-        }
-        SelectStatementContext subqueryContext = subqueryContexts.get(subqueryTable.getSubquery().getStartIndex());
-        Map<String, SubqueryTableContext> subqueryTableContexts = new SubqueryTableContextEngine().createSubqueryTableContexts(subqueryContext, subqueryTable.getAliasName().orElse(null));
-        Map<String, Collection<SubqueryTableContext>> result = new CaseInsensitiveMap<>(subqueryTableContexts.size(), 1F);
-        for (SubqueryTableContext each : subqueryTableContexts.values()) {
-            if (null != each.getAliasName()) {
-                result.computeIfAbsent(each.getAliasName(), unused -> new LinkedList<>()).add(each);
-            }
-        }
-        return result;
-    }
-    
     /**
      * Get database name.
      *
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementBaseContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementBaseContext.java
index fbad6e6fa19..d0fa582c702 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementBaseContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementBaseContext.java
@@ -74,7 +74,7 @@ public final class InsertStatementBaseContext implements SQLStatementContext {
         this.currentDatabaseName = currentDatabaseName;
         valueExpressions = getAllValueExpressions(sqlStatement);
         Collection<TableSegment> tableSegments = getAllSimpleTableSegments();
-        tablesContext = new TablesContext(tableSegments, Collections.emptyMap());
+        tablesContext = new TablesContext(tableSegments);
         List<String> insertColumnNames = getInsertColumnNames();
         schema = getSchema(metaData, currentDatabaseName);
         columnNames = containsInsertColumns()
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementBaseContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementBaseContext.java
index ed07eb2e817..c945349271e 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementBaseContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementBaseContext.java
@@ -114,7 +114,7 @@ public final class SelectStatementBaseContext implements SQLStatementContext {
         Collection<TableSegment> tableSegments = getAllTableSegments(inheritedTables);
         ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments);
         subqueryContexts = createSubqueryContexts(metaData, currentDatabaseName, tableSegments);
-        tablesContext = new TablesContext(tableSegments, subqueryContexts);
+        tablesContext = new TablesContext(tableSegments);
         groupByContext = new GroupByContextEngine().createGroupByContext(sqlStatement);
         orderByContext = new OrderByContextEngine(sqlStatement.getDatabaseType()).createOrderBy(sqlStatement, groupByContext);
         projectionsContext = new ProjectionsContextEngine(sqlStatement.getDatabaseType()).createProjectionsContext(sqlStatement.getProjections(), groupByContext, orderByContext);
diff --git a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java
index d0510d024d6..d2d9af3ea52 100644
--- a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java
+++ b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java
@@ -40,12 +40,12 @@ class TablesContextTest {
     
     @Test
     void assertGetTableNamesWithoutTableSegments() {
-        assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap()).getTableNames().isEmpty());
+        assertTrue(new TablesContext(Collections.emptyList()).getTableNames().isEmpty());
     }
     
     @Test
     void assertGetTableNamesWithoutSimpleTableSegments() {
-        assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap()).getTableNames().isEmpty());
+        assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class))).getTableNames().isEmpty());
     }
     
     @Test