[英]MYSQL Slow Query
Our Java Application is running very slowly. 我们的Java应用程序运行非常缓慢。
This is the case for various reasons, one of the main maybe being that the MySQL code within the application uses two different tables to get this data, doing joins. 造成这种情况的原因多种多样,其中主要原因之一可能是应用程序中的MySQL代码使用两个不同的表来获取此数据并进行联接。 Is anyone able to advise how this Query could be written better for performance? 有谁能建议如何更好地编写此查询以提高性能?
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;
Which table is uniqueId
in? 哪个表中的uniqueId
是?
A little more readable: 更具可读性:
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';
Do you have an index starting with publisherCode ? 您是否有以PublisherCode 开头的索引?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.