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 1ac47a320ec Optimize single router distributed table name lookup
(#38729)
1ac47a320ec is described below
commit 1ac47a320eceb2b049c6bd433b3af63dd1c45001
Author: ZhangCheng <[email protected]>
AuthorDate: Wed May 27 17:52:54 2026 +0800
Optimize single router distributed table name lookup (#38729)
* Optimize single router distributed table name lookup
* Optimize single router distributed table name lookup
---
.../shardingsphere/single/route/SingleSQLRouter.java | 20 ++++++++++----------
pom.xml | 2 +-
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
index ffb8244299b..a78f73a26d3 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.single.route;
-import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
@@ -108,23 +107,24 @@ public final class SingleSQLRouter implements
EntranceSQLRouter<SingleRule>, Dec
}
private Collection<QualifiedTable> getSingleTables(final
ShardingSphereDatabase database, final SingleRule rule, final
SQLStatementContext sqlStatementContext) {
- Collection<QualifiedTable> qualifiedTables =
rule.getQualifiedTables(sqlStatementContext, database);
- Collection<String> distributedTableNames =
getDistributedTableNames(database);
Collection<QualifiedTable> result = new LinkedList<>();
- for (QualifiedTable each : qualifiedTables) {
- if (!distributedTableNames.contains(each.getTableName())) {
+ Collection<TableMapperRuleAttribute> tableMapperRuleAttributes =
database.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class);
+ for (QualifiedTable each :
rule.getQualifiedTables(sqlStatementContext, database)) {
+ if (!isDistributedTable(tableMapperRuleAttributes,
each.getTableName())) {
result.add(each);
}
}
return sqlStatementContext.getSqlStatement() instanceof
CreateTableStatement ? result : rule.getSingleTables(result, database);
}
- private Collection<String> getDistributedTableNames(final
ShardingSphereDatabase database) {
- Collection<String> result = new CaseInsensitiveSet<>();
- for (TableMapperRuleAttribute each :
database.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class)) {
- result.addAll(each.getDistributedTableNames());
+ private boolean isDistributedTable(final
Collection<TableMapperRuleAttribute> tableMapperRuleAttributes, final String
tableName) {
+ for (TableMapperRuleAttribute each : tableMapperRuleAttributes) {
+ Collection<String> distributedTableNames =
each.getDistributedTableNames();
+ if (!distributedTableNames.isEmpty() &&
distributedTableNames.contains(tableName)) {
+ return true;
+ }
}
- return result;
+ return false;
}
@Override
diff --git a/pom.xml b/pom.xml
index 4ccbf9ac11b..4db66cdfc28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,7 +75,7 @@
<guava.version>33.4.6-jre</guava.version>
<checker-qual.version>3.39.0</checker-qual.version>
<error_prone_annotations.version>2.22.0</error_prone_annotations.version>
- <java-util.version>4.90.0</java-util.version>
+ <java-util.version>4.103.0</java-util.version>
<calcite.version>1.40.0</calcite.version>
<commons-lang3.version>3.18.0</commons-lang3.version>