JamesRTaylor opened a new issue, #31658:
URL: https://github.com/apache/shardingsphere/issues/31658

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   5.5.1-SNAPSHOT
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   Testing through unit tests
   
   ### Expected behavior
   The join condition should help determine how the logical query is rewritten.
   
   ### Actual behavior
   Only the name of the column referenced seems to have an impact on how the 
logical query is rewritten. The join condition doesn't impact it at all. For 
example, if an inequality join condition is used, the join would need to be run 
across all shards, while with an equality join, you'd be able to run it against 
a single shard.
   
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   Add the following to select.xml and run ShardingSQLRewriterIT:
   
       <rewrite-assertion id="select_with_inequality_join">
           <input sql="SELECT * FROM t_account o, t_account_detail i WHERE 
o.account_id>i.account_id AND o.account_id = ?" parameters="100" />
           <output sql="SELECT * FROM t_account_0 o, t_account_detail_0 i WHERE 
o.account_id > i.account_id AND o.account_id = ?" parameters="100" />
           <output sql="SELECT * FROM t_account_0 o, t_account_detail_1 i WHERE 
o.account_id>i.account_id AND o.account_id = ?" parameters="100" />
       </rewrite-assertion>
   
   ShardingSphere only produces the first output query, which is correct if the 
join condition is an equality join, but not if it's an inequality join. Note 
that if there's no correlation between the two tables being joined, 
ShardingSphere produces the expected output queries. For example, this is 
correct:
   
       <rewrite-assertion id="select_with_unconstrained_user">
           <input sql="SELECT * FROM t_account o, t_user u WHERE 
o.account_id=u.id AND o.account_id = ?" parameters="100" />
           <output sql="SELECT * FROM t_account_0 o, t_user_0 u WHERE 
o.account_id=u.id AND o.account_id = ?" parameters="100" />
           <output sql="SELECT * FROM t_account_0 o, t_user_1 u WHERE 
o.account_id=u.id AND o.account_id = ?" parameters="100" />
       </rewrite-assertion>
   
   
   ### 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: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to