简体   繁体   中英

MYSQL Slow Query

Our Java Application is running very slowly.

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. 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?

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 ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM