This is an automated email from the ASF dual-hosted git repository.
strongduanmu 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 440a930fc76 Optimize route lookup and sharding table find (#38794)
440a930fc76 is described below
commit 440a930fc7687baf9ece33f48243bf85cb3691d9
Author: ZhangCheng <[email protected]>
AuthorDate: Thu Jun 4 11:22:13 2026 +0800
Optimize route lookup and sharding table find (#38794)
---
.../java/org/apache/shardingsphere/sharding/rule/ShardingRule.java | 5 +----
.../executor/sql/prepare/driver/DriverExecutionPrepareEngine.java | 6 +++---
.../org/apache/shardingsphere/infra/route/context/RouteUnit.java | 5 ++++-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index ad014f0e693..dcc2df976a3 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -307,10 +307,7 @@ public final class ShardingRule implements DatabaseRule {
* @return sharding table
*/
public Optional<ShardingTable> findShardingTable(final String
logicTableName) {
- if (Strings.isNullOrEmpty(logicTableName) ||
!shardingTables.containsKey(logicTableName)) {
- return Optional.empty();
- }
- return Optional.of(shardingTables.get(logicTableName));
+ return Strings.isNullOrEmpty(logicTableName) ? Optional.empty() :
Optional.ofNullable(shardingTables.get(logicTableName));
}
/**
diff --git
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
index 01316397fe6..0a98ac09d71 100644
---
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
+++
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
@@ -35,8 +35,8 @@ import
org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -94,7 +94,7 @@ public final class DriverExecutionPrepareEngine<T extends
DriverExecutionUnit<?>
@Override
protected List<ExecutionGroup<T>> group(final String databaseName, final
String dataSourceName, final int connectionOffset, final
List<List<ExecutionUnit>> executionUnitGroups,
final ConnectionMode
connectionMode) throws SQLException {
- List<ExecutionGroup<T>> result = new LinkedList<>();
+ List<ExecutionGroup<T>> result = new
ArrayList<>(executionUnitGroups.size());
List<C> connections =
databaseConnectionManager.getConnections(databaseName, dataSourceName,
connectionOffset, executionUnitGroups.size(), connectionMode);
int count = 0;
for (List<ExecutionUnit> each : executionUnitGroups) {
@@ -106,7 +106,7 @@ public final class DriverExecutionPrepareEngine<T extends
DriverExecutionUnit<?>
@SuppressWarnings("unchecked")
private ExecutionGroup<T> createExecutionGroup(final String databaseName,
final String dataSourceName, final List<ExecutionUnit> executionUnits, final C
connection, final int connectionOffset,
final ConnectionMode
connectionMode) throws SQLException {
- List<T> inputs = new LinkedList<>();
+ List<T> inputs = new ArrayList<>(executionUnits.size());
ShardingSphereDatabase database = metaData.getDatabase(databaseName);
ShardingSpherePreconditions.checkNotNull(database, () -> new
UnknownDatabaseException(databaseName));
Map<String, StorageUnit> storageUnits =
database.getResourceMetaData().getStorageUnits();
diff --git
a/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/context/RouteUnit.java
b/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/context/RouteUnit.java
index 44f4ef97346..fcfbc35ec67 100644
---
a/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/context/RouteUnit.java
+++
b/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/context/RouteUnit.java
@@ -83,8 +83,11 @@ public final class RouteUnit {
* @return table mapper
*/
public Optional<RouteMapper> findTableMapper(final String
logicDataSourceName, final String actualTableName) {
+ if
(!logicDataSourceName.equalsIgnoreCase(dataSourceMapper.getLogicName())) {
+ return Optional.empty();
+ }
for (RouteMapper each : tableMappers) {
- if
(logicDataSourceName.equalsIgnoreCase(dataSourceMapper.getLogicName()) &&
actualTableName.equalsIgnoreCase(each.getActualName())) {
+ if (actualTableName.equalsIgnoreCase(each.getActualName())) {
return Optional.of(each);
}
}