shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

After using the sharding-proxy sub-table to sub-table, use the PageHelper plug-in to query one-to-many data, and the number of returned records is incorrect.

Open haj8888888 opened this issue 7 years ago • 21 comments

Code screenshot: image image image image Return result: [DEBUG] 2019-05-15 18:27:44,559 --main-- [com.mec.dao.OrderDao.selectByJoin_COUNT] ==> Preparing: SELECT count() FROM t_order t JOIN t_order_item ti ON t.order_id = ti.order_id
[DEBUG] 2019-05-15 18:27:44,617 --main-- [com.mec.dao.OrderDao.selectByJoin_COUNT] ==> Parameters:
[DEBUG] 2019-05-15 18:27:44,634 --main-- [com.mec.dao.OrderDao.selectByJoin_COUNT] <== Total: 1 [DEBUG] 2019-05-15 18:27:44,636 --main-- [com.mec.dao.OrderDao.selectByJoin] ==> Preparing: SELECT t.
, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order t JOIN t_order_item ti ON t.order_id = ti.order_id limit ?,?
[DEBUG] 2019-05-15 18:27:44,642 --main-- [com.mec.dao.OrderDao.selectByJoin] ==> Parameters: 0(Integer), 2(Integer) [DEBUG] 2019-05-15 18:27:44,649 --main-- [com.mec.dao.OrderDao.selectByJoin] <== Total: 2 [INFO ] 2019-05-15 18:27:44,651 --main-- [com.mec.order.test.ShardingProxyMybatisTest] Order{orderId=1557913094808, userId=688, status='ON', orderItemList=[OrderItem{orderItemId=1557913094807, orderId=1557913094808, userId=688, status='OFF'}, OrderItem{orderItemId=1557913094808, orderId=1557913094808, userId=688, status='ON'}]}

**Problem Description:**After using the sharding-proxy sub-table to sub-table, use the PageHelper plug-in to query one-to-many data, and the number of returned records is incorrect.Actually should return 2 records mysql5.7+mybatis-spring-boot-starter1.0.0+springboot1.5.7.RELEASE+junit

haj8888888 avatar May 16 '19 01:05 haj8888888

@haj8888888 Please fill in the bug report template:

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

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

Expected behavior

Actual behavior

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

tuohai666 avatar May 16 '19 04:05 tuohai666

Which version of ShardingSphere did you use? sharding-proxy-3.0.0 Which project did you use? Sharding-JDBC or Sharding-Proxy? Sharding-Proxy Expected behavior Expect to return two records, actually returning a record Actual behavior Expect to return two records, actually returning a record Reason analyze (If you can) Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. Example codes for reproduce this issue (such as a github link). View code screenshot

haj8888888 avatar May 16 '19 04:05 haj8888888

Please set the sql.show = true and put on the logs.

tuohai666 avatar May 16 '19 04:05 tuohai666

Please set the sql.show = true and put on the logs.

Return result: [DEBUG] 2019-05-15 18:27:44,559 --main-- [com.mec.dao.OrderDao.selectByJoin_COUNT] ==> Preparing: SELECT count() FROM t_order t JOIN t_order_item ti ON t.order_id = ti.order_id [DEBUG] 2019-05-15 18:27:44,617 --main-- [com.mec.dao.OrderDao.selectByJoin_COUNT] ==> Parameters: [DEBUG] 2019-05-15 18:27:44,634 --main-- [com.mec.dao.OrderDao.selectByJoin_COUNT] <== Total: 1 [DEBUG] 2019-05-15 18:27:44,636 --main-- [com.mec.dao.OrderDao.selectByJoin] ==> Preparing: SELECT t., ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order t JOIN t_order_item ti ON t.order_id = ti.order_id limit ?,? [DEBUG] 2019-05-15 18:27:44,642 --main-- [com.mec.dao.OrderDao.selectByJoin] ==> Parameters: 0(Integer), 2(Integer) [DEBUG] 2019-05-15 18:27:44,649 --main-- [com.mec.dao.OrderDao.selectByJoin] <== Total: 2 [INFO ] 2019-05-15 18:27:44,651 --main-- [com.mec.order.test.ShardingProxyMybatisTest] Order{orderId=1557913094808, userId=688, status='ON', orderItemList=[OrderItem{orderItemId=1557913094807, orderId=1557913094808, userId=688, status='OFF'}, OrderItem{orderItemId=1557913094808, orderId=1557913094808, userId=688, status='ON'}]}

haj8888888 avatar May 16 '19 04:05 haj8888888

I noticed there's limit subclause in the SQL. 3.0.0 exists a limit issue which make the result set wrong. Can you try 4.0.0-RC1 or 4.0.0-RC2-SNAPSHOT?

tuohai666 avatar May 16 '19 04:05 tuohai666

4.0.0

okay, thank you

haj8888888 avatar May 16 '19 04:05 haj8888888

I noticed there's limit subclause in the SQL. 3.0.0 exists a limit issue which make the result set wrong. Can you try 4.0.0-RC1 or 4.0.0-RC2-SNAPSHOT?

Can provide a download address?

haj8888888 avatar May 16 '19 04:05 haj8888888

https://shardingsphere.apache.org/document/current/en/downloads/

tuohai666 avatar May 16 '19 05:05 tuohai666

  1. Also please show me the desc table to all your actual tables.
  2. The result of select * from all your actual tables.
  3. Open server.yaml in conf directory of sharding-proxy and set sql.show: true, this will log actual SQLs to actual databases.

tuohai666 avatar May 16 '19 05:05 tuohai666

https://shardingsphere.apache.org/document/current/en/downloads/

image image

Version:sharding-proxy-4.0.0-RC1+mybatis

After paging, the number of records returned in a one-to-many relationship is incorrect.

haj8888888 avatar May 16 '19 06:05 haj8888888

  1. Also please show me the desc table to all your actual tables.
  2. The result of select * from all your actual tables.
  3. Open server.yaml in conf directory of sharding-proxy and set sql.show: true, this will log actual SQLs to actual databases. `schemaName: sharding_db

dataSources: ds_0: url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false username: root password: Mec123.. connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 ds_1: url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false username: root password: Mec123.. connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50

shardingRule: tables: t_order: actualDataNodes: ds_${0..1}.t_order_${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_${order_id % 2} keyGenerator: type: SNOWFLAKE column: order_id t_order_item: actualDataNodes: ds_${0..1}.t_order_item_${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_item_${order_id % 2} keyGenerator: type: SNOWFLAKE column: order_item_id t_order_union: actualDataNodes: ds_${0..1}.t_order_union${0..1} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_union${order_id % 2} keyGenerator: type: SNOWFLAKE column: order_id bindingTables: - t_order,t_order_union,t_order_item defaultDatabaseStrategy: inline: shardingColumn: user_id algorithmExpression: ds_${user_id % 2} defaultTableStrategy: none: `

haj8888888 avatar May 16 '19 06:05 haj8888888

This is not the answer to any of my three questions.

tuohai666 avatar May 16 '19 06:05 tuohai666

  1. Also please show me the desc table to all your actual tables. desc table CREATE TABLE t_order( order_idbigint(20) NOT NULL AUTO_INCREMENT, user_idint(11) NOT NULL, STATUS varchar(50) DEFAULT NULL, PRIMARY KEY (order_id) ) CREATE TABLE t_order_item( order_item_idbigint(20) NOT NULL AUTO_INCREMENT, order_idbigint(20) DEFAULT NULL, user_idint(11) NOT NULL, STATUS varchar(50) DEFAULT NULL, PRIMARY KEY (order_item_id) ) table Rule: image
  1. The result of select * from all your actual tables. image
  1. Open server.yaml in conf directory of sharding-proxy and set sql.show: true, this will log actual SQLs to actual databases. Already open SQL INFO: [INFO ] 14:53:12.800 [ShardingSphere-Command-7] ShardingSphere-SQL - Rule Type: sharding [INFO ] 14:53:12.801 [ShardingSphere-Command-7] ShardingSphere-SQL - Logic SQL: SELECT t.*, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order t LEFT JOIN t_order_item ti ON t.order_id = ti.order_id LIMIT ?,? [INFO ] 14:53:12.801 [ShardingSphere-Command-7] ShardingSphere-SQL - SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=t_order, alias=Optional.of(t)), Table(name=t_order_item, alias=Optional.of(ti))]), routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), sqlTokens=[TableToken(tableName=t_order, quoteCharacter=NONE, schemaNameLength=0), TableToken(tableName=t_order_item, quoteCharacter=NONE, schemaNameLength=0)], parametersIndex=2, logicSQL=SELECT t.*, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order t LEFT JOIN t_order_item ti ON t.order_id = ti.order_id LIMIT ?,?)), containStar=true, firstSelectItemStartIndex=15, selectListStopIndex=163, groupByLastIndex=0, items=[StarSelectItem(owner=Optional.of(t)), CommonSelectItem(expression=ti.order_item_id, alias=Optional.of(a_order_item_id)), CommonSelectItem(expression=ti.order_id, alias=Optional.of(a_order_id)), CommonSelectItem(expression=ti.user_id, alias=Optional.of(a_user_id)), CommonSelectItem(expression=ti.status, alias=Optional.of(a_status))], groupByItems=[], orderByItems=[], limit=Limit(offset=LimitValue(value=-1, index=0, boundOpened=false), rowCount=LimitValue(value=-1, index=1, boundOpened=false)), subqueryStatement=null, subqueryStatements=[], subqueryConditions=[]) [INFO ] 14:53:12.801 [ShardingSphere-Command-7] ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT t.*, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order_0 t LEFT JOIN t_order_item_0 ti ON t.order_id = ti.order_id LIMIT ?,? ::: [0, 2] [INFO ] 14:53:12.801 [ShardingSphere-Command-7] ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT t.*, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order_1 t LEFT JOIN t_order_item_1 ti ON t.order_id = ti.order_id LIMIT ?,? ::: [0, 2] [INFO ] 14:53:12.801 [ShardingSphere-Command-7] ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT t.*, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.status as a_status FROM t_order_0 t LEFT JOIN t_order_item_0 ti ON t.order_id = ti.order_id LIMIT ?,? ::: [0, 2] [INFO ] 14:53:12.801 [ShardingSphere-Command-7] ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT t.*, ti.order_item_id as a_order_item_id, ti.order_id as a_order_id, ti.user_id as a_user_id, ti.statusas a_status FROM t_order_1 t LEFT JOIN t_order_item_1 ti ON t.order_id = ti.order_id LIMIT ?,? ::: [0, 2]

haj8888888 avatar May 16 '19 06:05 haj8888888

When I say actual table I mention the physical table, in your case it should be ds_0.t_order_0/ds_0.t_order_1/ds_1.t_order_0, and so on. Plese show me select * from actual_table_name.

tuohai666 avatar May 16 '19 07:05 tuohai666

I'd better describe more clearly. Please show me: select * from ds_0.t_order_0; select * from ds_0.t_order_1; select * from ds_1.t_order_0; select * from ds_1.t_order_1; select * from ds_0.t_order_item_0; select * from ds_0.t_order_item_1; select * from ds_1.t_order_item_0; select * from ds_1.t_order_item_1;

tuohai666 avatar May 16 '19 07:05 tuohai666

I'd better describe more clearly. Please show me: select * from ds_0.t_order_0; select * from ds_0.t_order_1; select * from ds_1.t_order_0; select * from ds_1.t_order_1; select * from ds_0.t_order_item_0; select * from ds_0.t_order_item_1; select * from ds_1.t_order_item_0; select * from ds_1.t_order_item_1;

OK, image image image image image image image

haj8888888 avatar May 16 '19 07:05 haj8888888

I found the root cause is that the actual SQLs cross databases. ShardingSphere don't support this scenario (cross databases join)for now.

tuohai666 avatar May 16 '19 07:05 tuohai666

I found the root cause is that the actual SQLs cross databases. ShardingSphere don't support this scenario (cross databases join)for now.

Support single library multi-table, associated query?

haj8888888 avatar May 16 '19 07:05 haj8888888

Yes

tuohai666 avatar May 16 '19 07:05 tuohai666

Yes

OK,thank you

haj8888888 avatar May 16 '19 08:05 haj8888888