gpt4 book ai didi

java - MYSQL慢查询

转载 作者:行者123 更新时间:2023-11-29 22:31:19 25 4
gpt4 key购买 nike

我们的 Java 应用程序运行速度非常慢。

出现这种情况的原因有多种,其中一个主要原因可能是应用程序中的 MySQL 代码使用两个不同的表来获取这些数据,进行连接。有谁能建议如何更好地编写此查询以提高性能吗?

SELECT DISTINCT uniqueId
FROM advertisementmodule
JOIN advertisement ON advertisementmodule.idAdvertisement = advertisement.idAdvertisement
JOIN advertisementschedule ON advertisement.idAdvertisementSchedule = advertisementschedule.idAdvertisementSchedule
JOIN adschedulegroup ON advertisementschedule.idAdScheduleGroup = adschedulegroup.idAdScheduleGroup
WHERE adschedulegroup.publisherCode = 'ABC';

SELECT *
FROM taurustour
JOIN searchthemestaurus
WHERE uniqueId IN (
'18538'
,'17142'
,'11248'
,'18458'
)
AND air IS true;

最佳答案

uniqueId 位于哪个表中?

更具可读性:

SELECT  DISTINCT uniqueId
FROM advertisementmodule AS m
JOIN advertisement AS a
ON m.idAdvertisement = a.idAdvertisement
JOIN advertisementschedule AS s
ON a.idAdvertisementSchedule = s.idAdvertisementSchedule
JOIN adschedulegroup AS g
ON s.idAdScheduleGroup = g.idAdScheduleGroup
WHERE g.publisherCode = 'ABC';

您是否有以publisherCode 开头的索引?

关于java - MYSQL慢查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29755143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com