假如有 2 张表水平分表,且分表算法如下
public class ResultPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {
@Override
public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
try {
Integer id = preciseShardingValue.getValue();
if (id < 8000000) {
return "inspection_result";
} else {
return "inspection_result_home";
}
} catch (NumberFormatException e) {
log.error("在分表时 id 转换异常");
throw new RuntimeException(e);
}
}
}
在我想查询某张表中的数据时,首先想到的就是根据 id 比较
public Result<Object> testSj(){
LambdaQueryWrapper<InspectionResult> wrapper = new LambdaQueryWrapper<>();
wrapper.ge(InspectionResult::getId, 8000000);
return Result.ok(inspectionResultMapper.selectList(wrapper));
}
但是它报错了
Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql :
SELECT COUNT(1) FROM inspection_result WHERE (id >= ?)
搜了很多都没找到解释,有没有大佬解释下原因? shareding jdbc 版本 4.1.1
