shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

In query route error

Open guowdxp opened this issue 7 years ago • 5 comments

Bug Report

Which version of ShardingSphere did you use?

4.0.0.M1

Which project did you use? Sharding-JDBC or Sharding-Proxy?

sharding-proxy

Expected behavior

sql:

 select * from customer t where party_id in(8001,8002,8003,8004);

config:

customer:
  actualDataNodes: ds_0.customer_000${0..1},ds_1.customer_000${2..3}
  databaseStrategy:
    inline:
      shardingColumn: party_id
      algorithmExpression: ds_${(party_id % 4).intdiv(2)}
  tableStrategy:
    inline:
      shardingColumn: party_id
      algorithmExpression: customer_${"000" + (party_id % 4)}

route result error:

 ds_0 ::: select * from customer_0000 t where party_id in(8001,8002,8003,8004);
 ds_0 ::: select * from customer_0001 t where party_id in(8001,8002,8003,8004);
 ds_0 ::: select * from customer_0002 t where party_id in(8001,8002,8003,8004);
 ds_0 ::: select * from customer_0003 t where party_id in(8001,8002,8003,8004);
 ds_1 ::: select * from customer_0000 t where party_id in(8001,8002,8003,8004);
 ds_1 ::: select * from customer_0001 t where party_id in(8001,8002,8003,8004);
 ds_1 ::: select * from customer_0002 t where party_id in(8001,8002,8003,8004);
 ds_1 ::: select * from customer_0003 t where party_id in(8001,8002,8003,8004);

The correct routing result should be as follows:

 ds_0 ::: select * from customer_0000 t where party_id in(8001,8002,8003,8004);
 ds_0 ::: select * from customer_0001 t where party_id in(8001,8002,8003,8004);
 ds_1 ::: select * from customer_0002 t where party_id in(8001,8002,8003,8004);
 ds_1 ::: select * from customer_0003 t where party_id in(8001,8002,8003,8004);

guowdxp avatar Feb 22 '19 05:02 guowdxp

@guowdxp it compute availableTargetDatabases using sharding condition, then use each availableTargetDatabases and sharding condition value compute actual table, it cause datasource Cartesian with actual table, when database sharding column is the same as table sharding column ,it execute more actual sql, but the result is correct. StandardRoutingEngine#routeDataSources method return a Map<String,List>, key is datasource name, value is this datasource RouteValues , doSharding(availableTargetDatabases, databaseShardingValues) , split databaseShardingValues ,each databaseShardingValues with one element,StandardRoutingEngine#routeTables(final TableRule tableRule, final String routedDataSource, final List tableShardingValues, Map<String,List> datasourceRouteValues) ,when database sharding column is the same as table sharding column, use datasourceRouteValues compute actual tables。

codefairy08 avatar Mar 11 '19 10:03 codefairy08

We need to consider about some new design to enhance route results

terrymanu avatar Mar 18 '19 15:03 terrymanu

maybe we can provide a user defined filter to get the corrected combination result.

techzealot avatar Apr 17 '19 08:04 techzealot

or we can use actualDataNodes to filter the Cartesian result

techzealot avatar Apr 17 '19 15:04 techzealot

duplicate with #2193

KomachiSion avatar Sep 16 '19 10:09 KomachiSion