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

   I'm trying to implement the ComplexKeyShardingAlgorithm and I'm having an 
issue with IN statement queries when only a partial match is found.
   
   For example for the routing configuration as following (Keeping it simple 
with one keyed column):
   
   Default Datasource = DS1
   Default Table = Table1
   Strategy 1: Value A -> DS1.table1
   Strategy 2: Value B -> DS1.table2
   Strategy 3: Value C -> DS2.table1
   Strategy 4: Value D -> DS2.table2
   
   with the following query:
   ```
   SELECT *
   FROM logical_table
   WHERE column = C OR column = D
   ```
   Th Sharding Result should be :
   `DS2.table1 because it C is routed there by stratedy 3`
   `DS1.table1 because D doesn't match any strategyand default is selected`
   
   now if I execute the query like this
   
   ```
   SELECT *
   FROM logical_table
   WHERE column IN (C, D)
   ```
   how am I supposed to get the same result of the OR statement?
   This is the code from the StandardRoutingEngine:
   
   ```
   private Collection<DataNode> route0(final TableRule tableRule, final 
List<RouteValue> databaseShardingValues, 
                                       final List<RouteValue> 
tableShardingValues) {
       Collection<String> routedDataSources = routeDataSources(tableRule, 
databaseShardingValues);
       Collection<DataNode> result = new LinkedList<>();
       for (String each : routedDataSources) {
           result.addAll(routeTables(tableRule, each, tableShardingValues));
       }
       return result;
   }
   ```
   
   When routing datasources it's pretty straitght forward, select the ones from 
strategies that match, and if there's sharding value that doesn't match any add 
the Default datasource as well.
   Now when routing tables for each datasource it becomes tricky: when doing it 
with tables from a datasource match I should just return the table value that 
match, but how do I know when I am sharding table values of the default 
datasource which was selected because there was an unconsidered sharding value? 
(that no strategy matched)
   Since I only have the tableShardingValues information available when 
implementing the doSharding method it's really hard to do so. I guess it is 
possible but would be too complicated, and probably not very friendly for 
performance, and would require some stateful events to be cached somewhere.
   
   I hope I am missing something here and that there's a better way to do this, 
some help would be very appreciated.
   
   Thank you very much.
   
   
   
   


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