Three sqls only one route to shard tables When I execute updateBatch operation
Bug Report
For English only, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed GitHub issues.
- Read documentation: ShardingSphere Doc.
Please pay attention on issues you submitted, because we maybe need more details. If no response anymore 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?
4.1.1
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
Expected behavior
every sql route to shard tables
Actual behavior
three sqls only one sql route shard tables
Reason analyze (If you can)
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Actual SQL: ds0 ::: UPDATE oral_cw_classwork_stu_0 SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ::: [2020-09-16 20:19:24.309, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 85a006abbedc41e6add74b2b3c3aba98, 0, 2020-09-16 20:19:24.314, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, f4b91a8834ba4de5be2041804c56398b, 0, 2020-09-16 20:19:24.319, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 01364ab96ad54c68bd0c8794e712aecf, 0]
my shard column is schoolId
《update id="updateBatchNoAssessCountByStuCwId"》 《foreach collection="list" item="item" index="index" open="" close="" separator=";"》 UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = #{item.updateTime} 《where》 《if test="item.teaCwId != null"》 AND tea_cw_id = #{item.teaCwId} 《/if》 《if test="item.schoolId != null"》 AND school_id = #{item.schoolId} 《/if》 《if test="item.classId != null"》 AND class_id = #{item.classId} 《/if》 《if test="item.stuCwId != null"》 AND stu_cw_id = #{item.stuCwId} 《/if》 《if test="item.cwShowStatus != null"》 AND cw_show_status = #{item.cwShowStatus}《/if》 《/where》 《/foreach》 《/update》
Example codes for reproduce this issue (such as a github link).
what's your original sql?
what's your original sql?
sorry i forget my mapper.xml as follow :
what's your original sql?
sorry i forget my mapper.xml as follow :
《update id="updateBatchNoAssessCountByStuCwId"》 《foreach collection="list" item="item" index="index" open="" close="" separator=";"》 UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = #{item.updateTime} 《where》 《if test="item.teaCwId != null"》 AND tea_cw_id = #{item.teaCwId} 《/if》 《if test="item.schoolId != null"》 AND school_id = #{item.schoolId} 《/if》 《if test="item.classId != null"》 AND class_id = #{item.classId} 《/if》 《if test="item.stuCwId != null"》 AND stu_cw_id = #{item.stuCwId} 《/if》 《if test="item.cwShowStatus != null"》 AND cw_show_status = #{item.cwShowStatus}《/if》 《/where》 《/foreach》 《/update》
In my sql , I use "《" and "》" instead of " <" and ">" symbol
my mapper as follow: void updateBatchNoAssessCountByStuCwId(@param("list") List classworkStus);
Actual SQL: ds0 ::: UPDATE oral_cw_classwork_stu_0 SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ::: [2020-09-16 20:19:24.309, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 85a006abbedc41e6add74b2b3c3aba98, 0, 2020-09-16 20:19:24.314, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, f4b91a8834ba4de5be2041804c56398b, 0, 2020-09-16 20:19:24.319, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 01364ab96ad54c68bd0c8794e712aecf, 0]
Sorry, but you put three independent SQLs together as one SQL, didn't you? If so, currently, that is unsupported. My suggestion is to split one SQL as one query for ShardingJDBC.
Bug Report
For English only, other languages will not accept.
Before report a bug, make sure you have:
* Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues). * Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).Please pay attention on issues you submitted, because we maybe need more details. If no response anymore 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?
4.1.1
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-JDBC
Expected behavior
every sql route to shard tables
Actual behavior
three sqls only one sql route shard tables
Reason analyze (If you can)
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
Actual SQL: ds0 ::: UPDATE oral_cw_classwork_stu_0 SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ::: [2020-09-16 20:19:24.309, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 85a006abbedc41e6add74b2b3c3aba98, 0, 2020-09-16 20:19:24.314, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, f4b91a8834ba4de5be2041804c56398b, 0, 2020-09-16 20:19:24.319, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 01364ab96ad54c68bd0c8794e712aecf, 0]
my shard column is schoolId UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = #{item.updateTime} AND tea_cw_id = #{item.teaCwId} AND school_id = #{item.schoolId} AND class_id = #{item.classId} AND stu_cw_id = #{item.stuCwId} AND cw_show_status = #{item.cwShowStatus} ### Example codes for reproduce this issue (such as a github link).
Sorry, but you put three independent SQLs together as one SQL, didn't you? If so, currently, that is unsupported. My suggestion is to split one SQL as one query for ShardingJDBC
Thanks for your reply.Actually I do not make three sqls to one sql. according to the actual sql result,I think mybatis did it.Can you send your email to me.I can send my mapper.xml to you if you willing
Actual SQL: ds0 ::: UPDATE oral_cw_classwork_stu_0 SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ; UPDATE oral_cw_classwork_stu SET no_assess_count = if(ISNULL(no_assess_count),0,no_assess_count) + 1,update_time = ? WHERE tea_cw_id = ? AND school_id = ? AND class_id = ? AND stu_cw_id = ? AND cw_show_status = ? ::: [2020-09-16 20:19:24.309, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 85a006abbedc41e6add74b2b3c3aba98, 0, 2020-09-16 20:19:24.314, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, f4b91a8834ba4de5be2041804c56398b, 0, 2020-09-16 20:19:24.319, e52b673ea8474602a1ad4bf97ea943a4, 2811000226000000690, 2811000226000215069, 01364ab96ad54c68bd0c8794e712aecf, 0]
Sorry, but you put three independent SQLs together as one SQL, didn't you? If so, currently, that is unsupported. My suggestion is to split one SQL as one query for ShardingJDBC. thank you again. Make sure joint SQL is not supported,I change my code
It doesn't support for three statement in one sql. And you need one by one pass update statement to shardingsphere.