The sharding-jdbc query results dirty data, please help verify
Bug Report
Scene: 2 libraries, two tables
Yesterday I did a test, I opened 4 threads, each thread inserts 1 million pieces of data, about 1 hour and a half of insertion, check the data, the data in the library has no problem, the id is not repeated, but in There is a problem when querying, please see the code.
Query password 0 has a record, a total of 12, this is because I started three times when testing, so there will be 12 records, id is not repeated, please see the database record:
Database 0: user_info_0
user_info_1:
Database 1: user_info_0:
user_info_1:
Just 12 records, so once again stressed that there is no problem with the warehousing data, now look at the query results:

The sharding key is user_id, but with time query, sql statement prints out, check four tables, sql statement is no problem.
And the following four data appear user_id: 279023793651843070, this id is not a record in the database
The result is that the user_id is duplicated, using the mybatis framework, please take the time to reply as soon as possible, thank you.
When password=“password 1”, the result only partially repeats

What is your version of ShardingSphere?
<sharding-sphere.version>3.0.0</sharding-sphere.version>
please take the time to reply as soon as possible, thank you.
ok, i'm now working for this issue until it resolved.
To improve productivity please answer the questions below:
Which version of Sharding-Sphere 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).
but in There is a problem when querying,
in what?
And the following four data appear user_id: 279023793651843070, this id is not a record in the database
The result is that the user_id is duplicated, using the mybatis framework, please take the time to reply as soon as possible, thank you.
At first you say id is not a record in the database, then you say user_id is duplicated, what do you mean?
Which version of Sharding-Sphere did you use? answer:<sharding-sphere.version>3.0.0</sharding-sphere.version>
Which project did you use? Sharding-JDBC or Sharding-Proxy? Sharding-JDBC
Expected behavior Insert 4 million pieces of data into the mysql database (mysql version 5.2.65), the data is completely inserted correctly. and Execute the query.
Actual behavior
UserInfoExample example = new UserInfoExample();
example.createCriteria().andPasswordEqualTo("password 0");
example.setOrderByClause("create_time");
List
The occurred above user_id duplicate problem , I confirmed that the database data is no problem. Only the results of the query appeared。
Then I changed the test code:
UserInfoExample example = new UserInfoExample();
example.createCriteria().andUserIdBetween(279023793651843071L, 279023793651843074L);
example.setOrderByClause("create_time");
List<UserInfo> users = userInfoMapper.selectByExample(example);
The problem is still,And the result that user_id=279023793651843071L is not in the query range appears. But only part of the data has this problem,
Reason analyze (If you can) I really don't understand. Because not all of these problems occur, the same execution statement, different query conditions have no problems.
Example I test query like this , is no problem :
UserInfoExample example = new UserInfoExample();
example.createCriteria().andPasswordEqualTo("password 555500");
example.setOrderByClause("create_time");
List<UserInfo> users = userInfoMapper.selectByExample(example);
This result is correct.
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. 1.Insert 4 million pieces of data
2.Generate mapper, model, mapper.xml using mybatis-generator
3.sharding db rule : ds-$->{0..1}.user_info_$->{0..1}; sharding-table rule : user_info_$->{user_id % 4 /2}
4.No exception。
Example codes for reproduce this issue (such as a github link).
Imitate sharding-jdbc-springboot-start to package my own springbootstart
sharding-jdbc-db : https://gitee.com/vipmos/sharding-jdbc-db.git
demo springboot project: https://gitee.com/vipmos/paas-demo.git use application-sharding2.properties
And the following four data appear user_id: 279023793651843070, this id is not a record in the database
The result is that the user_id is duplicated, using the mybatis framework, please take the time to reply as soon as possible, thank you.
At first you say id is not a record in the database, then you say user_id is duplicated, what do you mean?
In two cases, one is that the user_id is duplicated, and the other is that there is no user_id in the database. Is this possibly a problem with the database cache? However, my knowledge is limited and I don't know the specific reasons.
UserInfoExample example = new UserInfoExample(); example.createCriteria().andUserIdBetween(279023793651843071L, 279023793651843074L); example.setOrderByClause("create_time"); List
users = userInfoMapper.selectByExample(example);
Codes like that have nothing useful. Why not put your sql statement instead of that ?
UserInfoExample example = new UserInfoExample(); example.createCriteria().andUserIdBetween(279023793651843071L, 279023793651843074L); example.setOrderByClause("create_time"); List users = userInfoMapper.selectByExample(example);
Codes like that have nothing useful. Why not put your sql statement instead of that ?
Please show sql statement and configuration.
=======================Sharding-JDBC transactions START ========================= 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### ds-${user_id % 4 % 2}, columnName[user_id] value[279022748112519170], selected target = ds-0 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### ds-${user_id % 4 % 2}, columnName[user_id] value[279022748112519171], selected target = ds-1 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519170], selected target = user_info_1 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519171], selected target = user_info_1 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519172], selected target = user_info_0 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519173], selected target = user_info_0 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519170], selected target = user_info_1 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519171], selected target = user_info_1 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519172], selected target = user_info_0 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] c.plat.db.algorithm.InileRangAlgorithm : ########### user_info_${user_id % 4 /2}, columnName[user_id] value[279022748112519173], selected target = user_info_0 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : Rule Type: sharding 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : Logic SQL: select
user_id, user_name, account, `password`, create_time
from user_info
WHERE ( user_id between ? and ? )
order by create_time
2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_info, alias=Optional.absent())]), conditions=Conditions(orCondition=OrCondition(andConditions=[AndCondition(conditions=[Condition(column=Column(name=user_id, tableName=user_info), operator=BETWEEN, positionValueMap={}, positionIndexMap={0=0, 1=1})])])), sqlTokens=[TableToken(skippedSchemaNameLength=0, originalLiterals=user_info)], parametersIndex=2)), containStar=false, selectListLastPosition=84, groupByLastPosition=0, items=[CommonSelectItem(expression=password, alias=Optional.absent()), CommonSelectItem(expression=create_time, alias=Optional.absent()), CommonSelectItem(expression=user_id, alias=Optional.absent()), CommonSelectItem(expression=account, alias=Optional.absent()), CommonSelectItem(expression=user_name, alias=Optional.absent())], groupByItems=[], orderByItems=[OrderItem(owner=Optional.absent(), name=Optional.of(create_time), orderDirection=ASC, nullOrderDirection=ASC, index=-1, alias=Optional.absent())], limit=null, subQueryStatement=null) 2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : Actual SQL: ds-0 ::: select
user_id, user_name, account, `password`, create_time
from user_info_0
WHERE ( user_id between ? and ? )
order by create_time ::: [[279022748112519170, 279022748112519174]]
2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : Actual SQL: ds-0 ::: select
user_id, user_name, account, `password`, create_time
from user_info_1
WHERE ( user_id between ? and ? )
order by create_time ::: [[279022748112519170, 279022748112519174]]
2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : Actual SQL: ds-1 ::: select
user_id, user_name, account, `password`, create_time
from user_info_0
WHERE ( user_id between ? and ? )
order by create_time ::: [[279022748112519170, 279022748112519174]]
2018-12-11 15:08:15 INFO 27744 --- [nio-8082-exec-1] Sharding-Sphere-SQL : Actual SQL: ds-1 ::: select
user_id, user_name, account, `password`, create_time
from user_info_1
WHERE ( user_id between ? and ? )
order by create_time ::: [[279022748112519170, 279022748112519174]]
=======================Sharding-JDBC transactions END =========================
This to mush ,I am worried that it will not look good.
Try to join wechat group
Try to join wechat group
wechat group ? the ShardingSphere官微公众号?
weixin qun
how to join ? where hava le weixin qun number?
http://shardingsphere.io/
The problem is solved, it is actually the result of json conversion long integer caused by the return of the result, the accuracy is lost, thanks weixinqun、。