为什么在命令行中单个 SQL 查询花费了 0.02 秒,但在产品服务器上的 Springboot 应用程序中花费了近 10 秒?

发布于 2025-01-11 13:07:45 字数 2313 浏览 0 评论 0原文

环境:Centos 7、JDK8、Mysql5.6、Springboot 2.1.7.RELEASE 这是 SQL:

SELECT alarm.id, alarm.driver, alarm.deviceCode, subway.route, alarm.carNumber, subway.type as carType, alarm.name, alarm.type, alarm.createTime, alarm.path, alarm.alarmVideo, alarm.videoId, alarm.carName
FROM alarm, subway 
WHERE alarm.deviceCode = subway.deviceCode 
      and createTime between '2022-03-03 10:00:12' and '2022-03-04 10:00:13'
      and subway.city like concat('%','ChengDu', '%')
order by createTime
desc limit 15,15

,java 是 :

@GetMapping(value = "/getAll", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResultMsg getAll(
        @RequestParam(value = "route", required = false) String route,
        @RequestParam(value = "carNumber", required = false) String carNumber,
        @RequestParam(value = "carType", required = false) String carType,
        @RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "type", required = false) String type,
        @RequestParam(value = "dateStart", required = false, defaultValue = "") String dateStart,
        @RequestParam(value = "dateEnd", required = false) String dateEnd,
        @RequestParam(value = "page", required = true) int page,
        @RequestParam(value = "size", required = true) int size,
        @RequestParam(value = "city", required = true) String city) {
    if (page == 0)
        page = 1;

    if (null != carNumber) {
        carNumber = carNumber.toLowerCase();
    }
    InetAddress address = null;
    try {
        address = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    String url = serverIp + "/file/";
    List<Alarm> alarmList = iAlarm.getAll(route, carNumber, carType, name, type, dateStart, dateEnd, page, size, city);
    for (int i = 0; i < alarmList.size(); i++) {
        alarmList.get(i).setAlarmVideo(url + videoUrl + alarmList.get(i).getAlarmVideo());
        alarmList.get(i).setPath(url + imageUrl + alarmList.get(i).getPath());
    }
    Integer count = iAlarm.count(route, carNumber, carType, name, type, dateStart, dateEnd, page, 0, city);
    return Result.success(new RespData(count, alarmList));
}

我知道目前有点奇怪,让我很困惑。以上是浏览器用来检索数据的所有代码。 请大家给我一些优化建议,非常感谢。

environment: Centos 7, JDK8, Mysql5.6, Springboot 2.1.7.RELEASE
here is the SQL:

SELECT alarm.id, alarm.driver, alarm.deviceCode, subway.route, alarm.carNumber, subway.type as carType, alarm.name, alarm.type, alarm.createTime, alarm.path, alarm.alarmVideo, alarm.videoId, alarm.carName
FROM alarm, subway 
WHERE alarm.deviceCode = subway.deviceCode 
      and createTime between '2022-03-03 10:00:12' and '2022-03-04 10:00:13'
      and subway.city like concat('%','ChengDu', '%')
order by createTime
desc limit 15,15

and the java is :

@GetMapping(value = "/getAll", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResultMsg getAll(
        @RequestParam(value = "route", required = false) String route,
        @RequestParam(value = "carNumber", required = false) String carNumber,
        @RequestParam(value = "carType", required = false) String carType,
        @RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "type", required = false) String type,
        @RequestParam(value = "dateStart", required = false, defaultValue = "") String dateStart,
        @RequestParam(value = "dateEnd", required = false) String dateEnd,
        @RequestParam(value = "page", required = true) int page,
        @RequestParam(value = "size", required = true) int size,
        @RequestParam(value = "city", required = true) String city) {
    if (page == 0)
        page = 1;

    if (null != carNumber) {
        carNumber = carNumber.toLowerCase();
    }
    InetAddress address = null;
    try {
        address = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    String url = serverIp + "/file/";
    List<Alarm> alarmList = iAlarm.getAll(route, carNumber, carType, name, type, dateStart, dateEnd, page, size, city);
    for (int i = 0; i < alarmList.size(); i++) {
        alarmList.get(i).setAlarmVideo(url + videoUrl + alarmList.get(i).getAlarmVideo());
        alarmList.get(i).setPath(url + imageUrl + alarmList.get(i).getPath());
    }
    Integer count = iAlarm.count(route, carNumber, carType, name, type, dateStart, dateEnd, page, 0, city);
    return Result.success(new RespData(count, alarmList));
}

I know it's a little bit strange at present and makes me confused a lot. Above are all the codes that the browser uses to retrieve data.
anybody, please give me some suggestions to optimize it, thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文