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/29 07:35:58 UTC

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

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



##########
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:
       1、 I didn't expect that RangeValue. 

##########
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:
       2、just care algorithms

##########
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:
       you are right




----------------------------------------------------------------
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