shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

only sharding db, use pagehelper, report error: Must have sharding column with subquery

Open fantacy2001 opened this issue 6 years ago • 8 comments

sharding version: 4.0.0-RC1 Only by business sharding databases, use pagehelper to Paging sql. Original sql: select DISTINCT m.id, m.receipt_no, m.customs_no, m.receipt_type, m.owner_no, m.owner_name, m.tenant_id, m.org_no, m.distribute_no, m.warehouse_no from ib_receipt_task_m m LEFT JOIN ib_receipt_task_d as d on d.receipt_no = m.receipt_no and d.tenant_id = m.tenant_id and d.warehouse_no = m.warehouse_no where m.is_delete = 0 AND m.tenant_id = '123456' AND m.warehouse_no = '123456' AND (m.receipt_no IN ('123','456') OR m.source_no IN ('1','2')) AND m.status = 0 order by m.id desc

both table ib_receipt_task_m and table ib_receipt_task_d are in same database, Error reporting after execution: com.jclps.jwms.service.inbound.impl.asn.AsnService.getReceiptTaskPageList():659 - 分页查询异常!异常信息:【nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalStateException: Must have sharding column with subquery.
### The error may exist in file [E:\workspace\jwms_alone\jwms\dao\target\classes\mapper\inbound\mapper\ReceiptTaskMMapper.xml]
### The error may involve com.jclps.jwms.dao.inbound.ReceiptTaskMDao.findPageListByDataAccess-Inline
### The error occurred while setting parameters
### Cause: java.lang.IllegalStateException: Must have sharding column with subquery.】
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalStateException: Must have sharding column with subquery.
### The error may exist in file [E:\workspace\jwms_alone\jwms\dao\target\classes\mapper\inbound\mapper\ReceiptTaskMMapper.xml]
### The error may involve com.jclps.jwms.dao.inbound.ReceiptTaskMDao.findPageListByDataAccess-Inline
### The error occurred while setting parameters
### Cause: java.lang.IllegalStateException: Must have sharding column with subquery.

fantacy2001 avatar Mar 05 '20 10:03 fantacy2001

which column is the databases sharding key ?

kimmking avatar Mar 05 '20 12:03 kimmking

which column is the databases sharding key ?

i have no column as sharding key. each database has different table name , i Force routing in my configuration Here is part of my configuration: spring.shardingsphere.sharding.tables.au_data_rule.actual-data-nodes=center.au_data_rule spring.shardingsphere.sharding.tables.au_module.actual-data-nodes=center.au_module spring.shardingsphere.sharding.tables.ib_book_task_d.actual-data-nodes=inbound.ib_book_task_d spring.shardingsphere.sharding.tables.ib_book_task_m.actual-data-nodes=inbound.ib_book_task_m spring.shardingsphere.sharding.tables.b2b_locate_batch.actual-data-nodes=outbound.b2b_locate_batch spring.shardingsphere.sharding.tables.b2b_locate_d.actual-data-nodes=outbound.b2b_locate_d

fantacy2001 avatar Mar 05 '20 12:03 fantacy2001

Oh... what is your database-strategy,table-strategy ?

kimmking avatar Mar 06 '20 05:03 kimmking

We are doing the subquery now, so I just pending this issue after we finish the subquery.

terrymanu avatar Mar 08 '20 08:03 terrymanu

We are doing the subquery now, so I just pending this issue after we finish the subquery.

pagehelper use subquery , when i upgrade to 4.0.0-release, this exception is not reported, but the sql find wrong route(default route) ,this is Not expected.
sql: select count(1) count from (select DISTINCT m.id, m.receipt_no, m.customs_no, m.receipt_type, m.owner_no, m.owner_name, m.supplier_no, m.supplier_name, m.order_time, m.source_no, m.source, m.carrier_no, m.carrier_name, m.print_times, m.status, m.remark, m.tenant_id, m.org_no, m.distribute_no, m.warehouse_no, m.create_time, m.update_time, m.create_user, m.update_user, m.is_delete, m.total_sku_qty, m.total_sku_sort, m.version, m.bill_type, m.is_cross_docking, m.order_no, m.order_amount, m.isv_order_no, m.isv_source_no, m.loadteam_no, m.grade from ib_receipt_task_m m left join ib_receipt_task_d d on m.receipt_no = d.receipt_no and m.warehouse_no = d.warehouse_no and m.tenant_id = d.tenant_id where m.is_delete = 0 AND m.tenant_id = ? AND m.warehouse_no = ? and m.create_time >= CONCAT(?,' 00:00:00') and m.create_time < CONCAT(?,' 23:59:59') and m.receipt_type = ? order by m.id desc ) t

fantacy2001 avatar Mar 12 '20 04:03 fantacy2001

We are doing the subquery now, so I just pending this issue after we finish the subquery.

Has the problem been solved?

hsgmj avatar Apr 07 '20 16:04 hsgmj

We are doing the subquery now, so I just pending this issue after we finish the subquery.

pagehelper use subquery , when i upgrade to 4.0.0-release, this exception is not reported, but the sql find wrong route(default route) ,this is Not expected. sql: select count(1) count from (select DISTINCT m.id, m.receipt_no, m.customs_no, m.receipt_type, m.owner_no, m.owner_name, m.supplier_no, m.supplier_name, m.order_time, m.source_no, m.source, m.carrier_no, m.carrier_name, m.print_times, m.status, m.remark, m.tenant_id, m.org_no, m.distribute_no, m.warehouse_no, m.create_time, m.update_time, m.create_user, m.update_user, m.is_delete, m.total_sku_qty, m.total_sku_sort, m.version, m.bill_type, m.is_cross_docking, m.order_no, m.order_amount, m.isv_order_no, m.isv_source_no, m.loadteam_no, m.grade from ib_receipt_task_m m left join ib_receipt_task_d d on m.receipt_no = d.receipt_no and m.warehouse_no = d.warehouse_no and m.tenant_id = d.tenant_id where m.is_delete = 0 AND m.tenant_id = ? AND m.warehouse_no = ? and m.create_time >= CONCAT(?,' 00:00:00') and m.create_time < CONCAT(?,' 23:59:59') and m.receipt_type = ? order by m.id desc ) t

Has the problem been solved?

hsgmj avatar Apr 07 '20 16:04 hsgmj

The 5.0.0-beta version supports federation engine which can process subquery, please try it, thank you.

terrymanu avatar Sep 26 '21 07:09 terrymanu