我们的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;
答案 0 :(得分:0)
哪个表格是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 开始?