mysql 自带client 中执行show processlist state是executing,但Info中的Sql并不是正在执行的sql

发布时间 2023-08-07 06:22:02作者: zjhgx

某日半夜发现cpu占用率很高,原来后台在执行sql脚本,用show processlist打出来看。

| 7063 | root            | 127.0.0.1:57370     | hjdang  | Query   |      2 | executing              | SELECT  id,goods_source_sn,goods_info_url,source,url_code,thumb_url,zhi_count,buzhi_count,star_count |

代码是:

    @Override
//    @Transactional
    public void archiveCrawlItems() {
        log.info("archiveCrawlItems starting .....");
        List<CrawlItem48h> historyItems = super.baseMapper.getItemsAfter48Hours();
        log.info("getItemsAfter48Hours finish .{}",historyItems.size());

        historyItems.stream().forEach(a -> {
            Long id = a.getId();
            CrawlItemArchive item = BeanUtil.toBean(a,CrawlItemArchive.class);

            QueryWrapper<CrawlItemArchive> wrapper = new QueryWrapper<CrawlItemArchive>();
            wrapper.eq("source",a.getSource());
            wrapper.eq("goods_source_sn", a.getGoodsSourceSn());
            CrawlItemArchive exist = crawlItemArchiveMapper.selectOne(wrapper);
            log.info("crawlItemArchiveMapper.selectOne finish . ");
            if(exist == null) {
                log.info("exist == null .");
                crawlItemArchiveMapper.insert(item);
            }else {
                log.info("exist is {} .",exist.getId());
                crawlItemArchiveMapper.updateById(exist);
            }
            crawlItem48hMapper.deleteById(id);
        });

    }

其实现在执行的是查询结束后的循环插入的sql,但Info里显示的还是查询的语句。可能和spring 里的mysql 的连接还没释放有关。