redis 中缓存 百万级别表的查询数据 堕落:Query execution was interrupte ...

打印 上一主题 下一主题

主题 1666|帖子 1666|积分 4998

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
项目配景:项目需要 首检及格率 这个效果,但是sql实验非常慢,就想着利用redis来优化接口的速度。如今我需要将数据库查询效果存储到redis,但是就是这一小步,也非常困难。我是用定时使命来实现上面的目的。
  1. @Component
  2. @Slf4j
  3. public class FirstInspectionPassRateTask {
  4.     @Autowired
  5.     private CheckResultMapper checkResultMapper;
  6.     @Autowired
  7.     private InspectionStationInfoMapper inspectionStationInfoMapper;
  8.     @Autowired
  9.     private RedisTemplate redisTemplate;
  10.     @Scheduled(cron = "0 32 13 * * ?")
  11.     public void calculateFirstInspectionPassRate(){
  12.         log.info("####### 定时任务开启......");
  13.         ValueOperations<String ,String> operations = redisTemplate.opsForValue();
  14.         NumberFormat numberFormat = NumberFormat.getPercentInstance();
  15.         numberFormat.setMinimumFractionDigits(2);
  16.         List<String> unitIdList = inspectionStationInfoMapper.selectUnitId();//单位id 集合
  17.         unitIdList = Optional.ofNullable(unitIdList).orElse(new ArrayList<>());
  18.         //这里只给2024表中的统计数据,因为首检合格率需要跨表,目前我也想不出如何编写 TODO
  19.         List<String> monthList = new ArrayList<>(Arrays.asList("03"));
  20.         unitIdList.forEach(unitId -> {
  21.             monthList.forEach(month -> {
  22.                 List<String> bgList = new ArrayList<>();
  23.                 //查询指定机构的 首检报告列表
  24.                 bgList = checkResultMapper.getFirstInspectionReportCount(unitId, "2024", month);
  25.                 bgList = Optional.ofNullable(bgList).orElse(new ArrayList<>());
  26.                 //计算指定机构的 首检报告数量
  27.                 Long bgSum = (long) bgList.size();
  28.                 //首检合格率
  29.                 String rate = "0.00%";
  30.                 if(bgSum != 0){
  31.                     //计算异常的首检报告数量
  32.                     Long warnBgSum = checkResultMapper.getWarnFirstInspectionReportCount(unitId,"2024",month,bgList);
  33.                     rate = numberFormat.format((bgSum-warnBgSum)/bgSum.doubleValue());
  34.                 }
  35.                 rate = rate.substring(0,rate.length() -1 );//去除最后的 % 方便前端处理
  36.                 String key = String.format("SZJDC:CHECKRESULT:BGBH:%s",unitId+"-2024-"+month);
  37.                 operations.set(key,rate,20, TimeUnit.DAYS);
  38.             });
  39.         });
  40.     }
  41. }
复制代码
 就在实验这个定时使命,我出现了非常多的报错:Query execution was interrupted
  1. Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6eaf527b]
  2. 10:45:18.655 [pool-2-thread-1] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task
  3. org.springframework.dao.QueryTimeoutException:
  4. ### Error querying database. Cause: java.sql.SQLTimeoutException: Query execution was interrupted
  5. ### The error may exist in file [D:\workspace\IdeaProjects\szjdc-service\sz-warning-platform\target\classes\mappers\CheckResultMapper.xml]
  6. ### The error may involve com.iflytek.warning.mapper.CheckResultMapper.getFirstInspectionReportCount
  7. ### The error occurred while handling results
  8. ### SQL: select BGBH from check_result_2024 cr WHERE year(CHECK_DATE) = ? and month(CHECK_DATE) = ? and UNIT_ID = ? and NOT EXISTS ( select CHECK_ID from check_result_2024 pcr WHERE pcr.CHECK_DATE between DATE_SUB(cr.CHECK_DATE, INTERVAL 4 MONTH) and DATE_SUB(cr.CHECK_DATE , INTERVAL 1 DAY) and cr.VIN = pcr.VIN and UNIT_ID = ? )
  9. ### Cause: java.sql.SQLTimeoutException: Query execution was interrupted
复制代码
这里给出我的解决办法:

 这上面处理完了之后照旧出现了该报错,然后我请教前辈

 就解决了,不愧是前辈

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

汕尾海湾

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表