shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

sharding jdbc the sql of select DISTINCT in version 4.0.0 is support but in version 4.1.1 is not support

Open fantacy2001 opened this issue 6 years ago • 4 comments

sql: select count(1) count from (select DISTINCT header.id, header.uuid, header.machining_no, header.machining_type, header.tenant_id, header.warehouse_no, header. STATUS, header.create_user, header.update_user, header.create_time, header.update_time, header.is_delete, header.memo, header.oper_location_no, header.fail_reason, header.order_origin, header.end_time from machining_header header LEFT JOIN machining_src_detail src ON src.machining_no = header.machining_no AND src.tenant_id = header.tenant_id AND src.warehouse_no = header.warehouse_no LEFT JOIN machining_dest_detail dest ON dest.machining_no = header.machining_no AND dest.tenant_id = header.tenant_id AND dest.warehouse_no = header.warehouse_no where header.is_delete=0
and header.machining_no = 'MA18012110000001'
and header.tenant_id = 'aa'
and header.warehouse_no = '26' ) t

use version 4.0.0, it can route to right db, but use 4.1.1, it route to wrong db mybatis + spring

fantacy2001 avatar Aug 26 '20 15:08 fantacy2001

can you show your configuration and actual sql?

kimmking avatar Aug 26 '20 16:08 kimmking

can you show your configuration and actual sql?

version 4.1.1, When routing, the PreciseShardingAlgorithm do not called, so route to default db. The actual SQL is what I sent above。 Because I redefined sharding's access with Java, the configuration file is different from the official one。 It is divided into two libraries, each of which has one master and two slaves。 sharding field: tenant_id KeyGenerator is baidu UID bindingTables is machining_src_detail 、machining_dest_detail the customize sharding Algorithm ,implements PreciseShardingAlgorithm

fantacy2001 avatar Aug 27 '20 02:08 fantacy2001

It's a bug. test is a logic table with id as sharding key.

select distinct id,name from test where id=1000 will be converted to select distinct id,name from test00 where id=1000

but the subquery can't routing to sharidng table:

select count(1) from (select distinct id,name from test where id=1000)t; will be converted to select count(1) from (select distinct id,name from test where id=1000)t;

@jingshanglu

kimmking avatar Aug 27 '20 05:08 kimmking

@kimmking @fantacy2001 Now, it has been fixed on master branch, new version will be ok.

jingshanglu avatar Sep 18 '20 10:09 jingshanglu