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 2021/07/08 08:49:46 UTC

[GitHub] [shardingsphere] setamv opened a new issue #11218: Bug in parse sharding value from binding table rules

setamv opened a new issue #11218:
URL: https://github.com/apache/shardingsphere/issues/11218


   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   5.0.0-beta
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   
   ### Expected behavior
   correctly analysis sharding value from binding table 
   
   ### Actual behavior
   get wrong sharding value analized from binding table under certain conditions. 
   
   ### Reason analyze (If you can)
   in code bellow, it get `bindingTableRule` by `shardingRule.findBindingTableRule(logicTableName)`,which leads to the result of `bindingTableRule.isPresent() && bindingTableRule.get().hasLogicTable(logicTableName)` to always be `true` if we configed the binding relation on `logicTableName`. :
   ```
   // source code from: org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine
   private List<ShardingConditionValue> getShardingValuesFromShardingConditions(final ShardingRule shardingRule, final Collection<String> shardingColumns, final ShardingCondition shardingCondition) {
           List<ShardingConditionValue> result = new ArrayList<>(shardingColumns.size());
           for (ShardingConditionValue each : shardingCondition.getValues()) {
               Optional<BindingTableRule> bindingTableRule = shardingRule.findBindingTableRule(logicTableName);
               if ((logicTableName.equals(each.getTableName()) || bindingTableRule.isPresent() && bindingTableRule.get().hasLogicTable(logicTableName)) 
                       && shardingColumns.contains(each.getColumnName())) {
                   result.add(each);
               }
           }
           return result;
       }
   ```
   
   Imagine the following scenario:
   we have 4 tables: T1、T2、T3、T4,and they have same sharding columns named 'col',if we config binding relation as follows:
   ```
   - T1, T2
   - T3, T4
   ```
   the Logic SQL bellow will leads to only one Actual SQL even if the table `T1` and `T3` are not bounded.
   ```
   SELECT a.col1, a.col FROM T1 a JOIN T3 b ON a.col = b.col WHERE a.col = 'xxx' 
   ```
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   Imagine the following scenario:
   we have 4 tables: T1、T2、T3、T4,and they have same sharding columns named 'col',and they all have 2 sharding tables(physic table) as follows: 
   - T1_0、T1_1
   - T2_0、T2_1
   - T3_0、T3_1
   - T4_0、T4_1
   if we config binding relations as follows:
   ```
   - T1, T2
   - T3, T4
   ```
   the Logic SQL bellow will leads to only one Actual SQL even if the table `T1` and `T3` are not bounded.
   the Logic SQL is:
   ```
   SELECT a.col1, a.col FROM T1 a JOIN T3 b ON a.col = b.col WHERE a.col = '0' 
   ```
   the possible Actual SQL is(assume the sharding value "0" is in sharding table `T1_0`):
   ```
   SELECT a.col1, a.col FROM T1_0 a JOIN T3_0 b ON a.col = b.col WHERE a.col = 'xxx' 
   ```
   
   ### Example codes for reproduce this issue (such as a github link).
   


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

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu closed issue #11218: Bug in parse sharding value from binding table rules

Posted by GitBox <gi...@apache.org>.
strongduanmu closed issue #11218:
URL: https://github.com/apache/shardingsphere/issues/11218


   


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

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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