You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/07/22 08:03:22 UTC

[GitHub] [shardingsphere] KomachiSion commented on a change in pull request #6085: optimize route table where database and table shared columns

KomachiSion commented on a change in pull request #6085:
URL: https://github.com/apache/shardingsphere/pull/6085#discussion_r458606196



##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java
##########
@@ -191,8 +193,38 @@ private boolean isGettingShardingValuesFromHint(final ShardingStrategy shardingS
     private Collection<DataNode> route0(final ShardingRule shardingRule, final TableRule tableRule, final List<RouteValue> databaseShardingValues, final List<RouteValue> tableShardingValues) {
         Collection<String> routedDataSources = routeDataSources(shardingRule, tableRule, databaseShardingValues);
         Collection<DataNode> result = new LinkedList<>();
+        List<RouteValue> copiedTableShardingValues = tableShardingValues;
         for (String each : routedDataSources) {
-            result.addAll(routeTables(shardingRule, tableRule, each, tableShardingValues));
+
+            if (null != tableRule.getDatabaseShardingStrategy() && null != tableRule.getTableShardingStrategy()
+                && 0 != tableRule.getDatabaseShardingStrategy().getShardingColumns().size() && 0 != tableRule.getTableShardingStrategy().getShardingColumns().size()
+                && databaseShardingValues.size() > 0 && tableShardingValues.size() > 0
+                && tableRule.getDatabaseShardingStrategy().getShardingColumns().size() == tableRule.getTableShardingStrategy().getShardingColumns().size()
+                && tableRule.getDatabaseShardingStrategy().getShardingColumns().containsAll(tableRule.getTableShardingStrategy().getShardingColumns())) {
+                Collection<Object> relateValueList = Lists.newArrayList();
+
+                ListRouteValue tableRouteValue = (ListRouteValue) tableShardingValues.get(0);

Review comment:
       How can you confirm that the first sharding value is list not range? And what's the result if  there are more than list sharding values?

##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java
##########
@@ -191,8 +193,38 @@ private boolean isGettingShardingValuesFromHint(final ShardingStrategy shardingS
     private Collection<DataNode> route0(final ShardingRule shardingRule, final TableRule tableRule, final List<RouteValue> databaseShardingValues, final List<RouteValue> tableShardingValues) {
         Collection<String> routedDataSources = routeDataSources(shardingRule, tableRule, databaseShardingValues);
         Collection<DataNode> result = new LinkedList<>();
+        List<RouteValue> copiedTableShardingValues = tableShardingValues;
         for (String each : routedDataSources) {
-            result.addAll(routeTables(shardingRule, tableRule, each, tableShardingValues));
+
+            if (null != tableRule.getDatabaseShardingStrategy() && null != tableRule.getTableShardingStrategy()
+                && 0 != tableRule.getDatabaseShardingStrategy().getShardingColumns().size() && 0 != tableRule.getTableShardingStrategy().getShardingColumns().size()
+                && databaseShardingValues.size() > 0 && tableShardingValues.size() > 0
+                && tableRule.getDatabaseShardingStrategy().getShardingColumns().size() == tableRule.getTableShardingStrategy().getShardingColumns().size()
+                && tableRule.getDatabaseShardingStrategy().getShardingColumns().containsAll(tableRule.getTableShardingStrategy().getShardingColumns())) {
+                Collection<Object> relateValueList = Lists.newArrayList();
+
+                ListRouteValue tableRouteValue = (ListRouteValue) tableShardingValues.get(0);
+                Collection<Object> tablueRouteValues = tableRouteValue.getValues();
+
+                for (Object eachRouteValues : tablueRouteValues) {
+                    RouteValue routeValue = new ListRouteValue(tableRouteValue.getColumnName(), tableRouteValue.getTableName(), Lists.newArrayList(eachRouteValues));
+
+                    Collection<String> reRouteDbRoute = routeDataSources(shardingRule, tableRule, Lists.newArrayList(routeValue));

Review comment:
       There will route datasource second time for each value. It may cost much time.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org