You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/04/08 12:23:08 UTC

[shardingsphere] branch master updated: Remove use of Stream API to avoid performance degradation (#16668)

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

panjuan 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 0abd878700a Remove use of Stream API to avoid performance degradation (#16668)
0abd878700a is described below

commit 0abd878700a41818c9bce48dfbc64d02326d16e0
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Fri Apr 8 20:22:49 2022 +0800

    Remove use of Stream API to avoid performance degradation (#16668)
---
 .../shardingsphere/infra/binder/segment/table/TablesContext.java | 9 +++++++++
 .../infra/binder/statement/dml/SelectStatementContext.java       | 2 +-
 .../communication/jdbc/JDBCDatabaseCommunicationEngine.java      | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
index 64c158742c6..1d012f0c420 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
@@ -297,4 +297,13 @@ public final class TablesContext {
         Preconditions.checkState(databaseNames.size() <= 1, "Can not support multiple different database.");
         return databaseNames.isEmpty() ? Optional.empty() : Optional.of(databaseNames.iterator().next());
     }
+    
+    /**
+     * Get schema name.
+     *
+     * @return schema name
+     */
+    public Optional<String> getSchemaName() {
+        return schemaNames.isEmpty() ? Optional.empty() : Optional.of(schemaNames.iterator().next());
+    }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 104ffe73f97..8dbb71f3a46 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -138,7 +138,7 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
                 throw new SchemaNotExistedException(databaseName);
             }
         }
-        String schemaName = tablesContext.getSchemaNames().stream().findFirst().orElse(databaseName);
+        String schemaName = tablesContext.getSchemaName().orElse(databaseName);
         return metaData.getSchemaByName(schemaName);
     }
     
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
index da3ef791537..113fda36334 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
@@ -88,7 +88,7 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication
         this.backendConnection = backendConnection;
         MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
         String databaseName = backendConnection.getConnectionSession().getSchemaName();
-        String schemaName = logicSQL.getSqlStatementContext().getTablesContext().getSchemaNames().stream().findFirst().orElse(databaseName);
+        String schemaName = logicSQL.getSqlStatementContext().getTablesContext().getSchemaName().orElse(databaseName);
         federationExecutor = FederationExecutorFactory.newInstance(databaseName, schemaName, metaDataContexts.getOptimizerContext(),
                 metaDataContexts.getProps(), new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), backendConnection.isSerialExecute()));
     }