为什么在命令行中单个 SQL 查询花费了 0.02 秒,但在产品服务器上的 Springboot 应用程序中花费了近 10 秒?
环境: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论