The use of the 'Or'
Which version of Sharding-Sphere do you using?
sharding-jdbc 3.0.0.M1
Expected behavior
shardingConditions.getShardingConditions() should only one
Actual behavior
I get multiple of the same conditions
Steps to reproduce the behavior
sql:select * from table1 where shardingcolumn = *** and ( field1='test' or field2 ='test' )
Only one shardingCondition is met, but shardingConditions.getShardingConditions() contains multiple identical conditions The final routing result is correct, however ComplexKeysShardingAlgorithm.doSharding() is executed multiple times
Sharding-sphere don't parse column if they are not sharding column
yeah,But what seems to make this sharding column repeat,I can see the shardingConditions.getShardingConditions() really has duplicate ShardingCondition on 79 line of StandardRoutingEngine.java:

@weiduan please give me a full sql, i will help you
@ma-xiao-guang-64 SELECT * FROM order
WHERE business_id = ?
AND ( member_discount = 1
OR order_discount = 1
OR order_derate = 1
OR order_derate_zero = 1
OR item_member_discount = 1
OR order_promotion = 1
OR coupon_promotion = 1
OR order_bargain = 1
OR timed_item_discount = 1
OR x_discount = 1 )
I deleted some unrelated fields, where business_id is shardingKey, and it repeats ten times
@weiduan ok,repeats ten times is correct. in sharding parser this sql will change to WHERE business_id = ? AND member_discount = 1 OR business_id = ? AND order_discount = 1 OR business_id = ? AND order_derate = 1 OR business_id = ? AND order_derate_zero = 1 OR business_id = ? AND item_member_discount = 1 OR business_id = ? AND order_promotion = 1 OR business_id = ? AND coupon_promotion = 1 OR business_id = ? AND order_bargain = 1 OR business_id = ? AND timed_item_discount = 1 OR business_id = ? AND x_discount = 1 ) why you look shardingConditions size is 10! in doSharding work the ten shardingConditions will to doSharding
英文捉急以下为中文 sql解析阶段 将OR用类似乘法分配律的方法解析 所以会出现10个OR条件也就是10个sharidngConditions
路由阶段 分别对10个OR条件路由然后将路由结果去并集以上看到虽然doSharding执行了10次但是最终执行sql的时候只会去business_id = ?的分片去执行
关于解析后的Conditions
采用的是List<List
@ma-xiao-guang-64 Oh,i see.The routing result was indeed correct. Is it possible to optimize the repeating sharidngConditions to one in the future? After all, doSharding() will be executed too many times.Thank you for your answer!
@weiduan it is so hard, we possible merge it in future
can we close this issue?