shardingJDBC(4.0.0-RC2) sqlStatement parsing wrong, don't have where conditions
See original GitHub issueI’m using shardingJDBC(version: 4.0.0-RC2) but when i upgrade to version 4.0.0-RC2 , i realize my localConfig about RangeShardingAlgorithm cease to be effective。I want to solve this problem。
when i debug in source code , here is my logicSQL
select id,comment_id,product_id,shop_id,customer_id,sub_cust_id,nick_name,customer_ip_addr,order_id,order_creation_date, product_category,product_medium,score,source_type,content,content_len,is_check,check_user,check_creation_date,is_anonymous, is_top,top_reason,top_user,top_creation_date,is_wonderful,wonderful_reason,wonderful_user,wonderful_creation_date,customer_attributes, is_sync,creation_date,main_product_id,delivery_confirm_date,total_helpful_num,total_useless_num,total_reply_num,factor_change_date, last_change_date,activity_type,activity_id,failed_reason,emotion_score,comment_type,ebook_is_delete from archive_comment where 1=1 and LEFT(product_category, 2) in ('01','98') and source_type = ? and creation_date = ? and (creation_date BETWEEN ? and ?) and ebook_is_delete = ? and source_type <> 14 order by creation_date desc limit ?, ?
but in ShardingSelectOptimizeEngine.class , sqlStatement doesn’t found whereSegment.
so it can’t route to myRangeAlgorithm ‘archiveCommentTableRangeShardingAlgorithm’

here is my code and config.
here is my spring config `
<bean id="archiveCommentTablePreciseShardingAlgorithm"
class="com.seth.jcomment.sharding.table.ArchiveCommentTablePreciseShardingAlgorithm" />
<!-- archive_comment 分表策略 范围分片算法-->
<bean id="archiveCommentTableRangeShardingAlgorithm"
class="com.seth.jcomment.sharding.table.ArchiveCommentTableRangeShardingAlgorithm" />
<sharding:standard-strategy id=“archiveCommentTableStrategy” sharding-column=“creation_date” precise-algorithm-ref=“archiveCommentTablePreciseShardingAlgorithm” range-algorithm-ref=“archiveCommentTableRangeShardingAlgorithm” />
<sharding:table-rule
logic-table="archive_comment"
actual-data-nodes="archiveCommentMasterSlaveDataSource.comment_$->{2014..2029}"
database-strategy-ref="archiveCommentDatabaseStrategy"
table-strategy-ref="archiveCommentTableStrategy" />
`
here is my java code
` public class ArchiveCommentTableRangeShardingAlgorithm implements RangeShardingAlgorithm<String> {
@Override
public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<String> shardingValue) {
// 校验分片值
Range<String> valueRange = shardingValue.getValueRange();
if (null == valueRange || valueRange.isEmpty()) {
log.error("archive_comment库,范围分片算法,获取表失败,候选表:{},分片信息:{}", availableTargetNames, shardingValue);
throw new JcommentException(JcommentExceptionEnum.SHARDING_VALUE_NAME_ERROR_EXCEPTION.getErrorCode(),
JcommentExceptionEnum.SHARDING_VALUE_NAME_ERROR_EXCEPTION.getErrorMsg());
}
if (StringUtils.isBlank(valueRange.lowerEndpoint()) || StringUtils.isBlank(valueRange.upperEndpoint())){
log.error("archive_comment库,范围分片算法,获取表失败,候选表:{},分片信息:{}", availableTargetNames, shardingValue);
throw new JcommentException(JcommentExceptionEnum.SHARDING_VALUE_NAME_ERROR_EXCEPTION.getErrorCode(),
JcommentExceptionEnum.SHARDING_VALUE_NAME_ERROR_EXCEPTION.getErrorMsg());
}
LocalDateTime lowerLocalDateTime = DateUtil.stringToLocalDateTime(valueRange.lowerEndpoint(), DateUtil.TIME_PATTERN);
LocalDateTime upperLocalDateTime = DateUtil.stringToLocalDateTime(valueRange.upperEndpoint(), DateUtil.TIME_PATTERN);
Set<String> resultSet = new HashSet<String>();
for (String availableTargetName : availableTargetNames) {
int suffix = Integer.valueOf(availableTargetName.substring(availableTargetName.length() - 4));
if (suffix >= lowerLocalDateTime.getYear()
&& suffix <= upperLocalDateTime.getYear()) {
resultSet.add(availableTargetName);
}
}
log.info("archive_comment库,范围分片算法,获取表结果:{},分片信息:{}", resultSet, shardingValue);
if (resultSet.isEmpty()) {
throw new RuntimeException("archive_comment库,范围分片算法,获取表失败,请检查逻辑表名、分片键是否配置正确");
}
return resultSet;
}
}
`
here is mybatis mapper sql
<select id="queryEntityCount4CommentCenter" resultType="integer"> select count(*) from ${tableName} where 1=1 <if test="shardingCommentRequestDTO.id != null"> and id = #{shardingCommentRequestDTO.id,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.commentId != null"> and comment_id = #{shardingCommentRequestDTO.commentId,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.mainProductIds != null"> and main_product_id in <foreach collection="shardingCommentRequestDTO.mainProductIds" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </if> <if test="shardingCommentRequestDTO.mainProductId != null"> and main_product_id = #{shardingCommentRequestDTO.mainProductId,jdbcType=BIGINT} </if> <if test="shardingCommentRequestDTO.shopId != null"> and shop_id = #{shardingCommentRequestDTO.shopId,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.customerId != null"> and customer_id = #{shardingCommentRequestDTO.customerId,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.subCustId != null"> and sub_cust_id = #{shardingCommentRequestDTO.subCustId,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.nickName != null"> and nick_name = #{shardingCommentRequestDTO.nickName,jdbcType=VARCHAR} </if> <if test="shardingCommentRequestDTO.customerIpAddr != null"> and customer_ip_addr = #{shardingCommentRequestDTO.customerIpAddr,jdbcType=VARCHAR} </if> <if test="shardingCommentRequestDTO.orderId != null"> and order_id = #{shardingCommentRequestDTO.orderId,jdbcType=BIGINT} </if> <if test="shardingCommentRequestDTO.orderCreationDate != null"> and order_creation_date = #{shardingCommentRequestDTO.orderCreationDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.productCategory != null"> and product_category = #{shardingCommentRequestDTO.productCategory,jdbcType=VARCHAR} </if> <if test="shardingCommentRequestDTO.productMedium != null"> and product_medium = #{shardingCommentRequestDTO.productMedium,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.score != null"> and score = #{shardingCommentRequestDTO.score,jdbcType=REAL} </if> <if test="shardingCommentRequestDTO.sourceType != null"> and source_type = #{shardingCommentRequestDTO.sourceType,jdbcType=BIT} </if> <if test="shardingCommentRequestDTO.content != null"> and content like CONCAT('%',#{shardingCommentRequestDTO.content,jdbcType=VARCHAR},'%') </if> <if test="shardingCommentRequestDTO.totalHelpfulNum != null"> and total_helpful_num = #{shardingCommentRequestDTO.totalHelpfulNum,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.isCheck != null"> and is_check = #{shardingCommentRequestDTO.isCheck,jdbcType=BIT} </if> <if test="shardingCommentRequestDTO.checkCreationDate != null"> and check_creation_date = #{shardingCommentRequestDTO.checkCreationDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.isAnonymous != null"> and is_anonymous = #{shardingCommentRequestDTO.isAnonymous,jdbcType=BIT} </if> <if test="shardingCommentRequestDTO.isTop != null"> and is_top = #{shardingCommentRequestDTO.isTop,jdbcType=BIT} </if> <if test="shardingCommentRequestDTO.topCreationDate != null"> and top_creation_date = #{shardingCommentRequestDTO.topCreationDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.isWonderful != null"> and is_wonderful = #{shardingCommentRequestDTO.isWonderful,jdbcType=BIT} </if> <if test="shardingCommentRequestDTO.wonderfulCreationDate != null"> and wonderful_creation_date = #{shardingCommentRequestDTO.wonderfulCreationDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.customerAttributes != null"> and customer_attributes = #{shardingCommentRequestDTO.customerAttributes,jdbcType=VARCHAR} </if> <if test="shardingCommentRequestDTO.creationDate != null"> and creation_date = #{shardingCommentRequestDTO.creationDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.startCreationDate != null and shardingCommentRequestDTO.endCreationDate != null"> and (creation_date BETWEEN #{shardingCommentRequestDTO.startCreationDate,jdbcType=VARCHAR} and #{shardingCommentRequestDTO.endCreationDate,jdbcType=VARCHAR}) </if> <if test="shardingCommentRequestDTO.productId != null"> and product_id = #{shardingCommentRequestDTO.productId,jdbcType=BIGINT} </if> <if test="shardingCommentRequestDTO.totalUselessNum != null"> and total_useless_num = #{shardingCommentRequestDTO.totalUselessNum,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.totalReplyNum != null"> and total_reply_num = #{shardingCommentRequestDTO.totalReplyNum,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.deliveryConfirmDate != null"> and delivery_confirm_date = #{shardingCommentRequestDTO.deliveryConfirmDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.activityType != null"> and activity_type = #{shardingCommentRequestDTO.activityType,jdbcType=BIT} </if> <if test="shardingCommentRequestDTO.activityId != null"> and activity_id = #{shardingCommentRequestDTO.activityId,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.lastChangeDate != null"> and last_change_date <![CDATA[ >= ]]> #{shardingCommentRequestDTO.lastChangeDate,jdbcType=TIMESTAMP} </if> <if test="shardingCommentRequestDTO.commentType != null"> and comment_type = #{shardingCommentRequestDTO.commentType,jdbcType=TINYINT} </if> <if test="shardingCommentRequestDTO.emotionScore != null"> and emotion_score = #{shardingCommentRequestDTO.emotionScore,jdbcType=INTEGER} </if> <if test="shardingCommentRequestDTO.noCommentId != null"> <foreach collection="shardingCommentRequestDTO.noCommentId" item="id" index="index"> and comment_id <![CDATA[ <> ]]> #{id} </foreach> </if> <if test="shardingCommentRequestDTO.isShoppingComment != 0"> and order_id > 10000 </if> and source_type <![CDATA[ <> ]]> 14 </select>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
Can you create a demo to proof your issue?
maybe it is my fault.
last week, i have time to resolve this problem , i can’t proof this issue neither. But I’m pretty sure at that time , it might initiate some Performance Issue.
i will still focus this problem. I will tell you when i proof this issue. really sorry to bother you guys.