I found that the following query is causing some bottleneck (the execution time takes more than 40 seconds!)
DELETE FROM doctors
WHERE (SELECT COUNT(loc_id)
FROM locations
WHERE locations.loc_doctor = doctors.doc_id) = 0 AND
doctors.doc_user = $myVar
I guess the problem lies in the (SELECT COUNT(loc_id) FROM locations WHERE locations.loc_doctor = doctors.doc_id) = 0 section, am I right?
Is there a way to improve it?
This should be a little bit faster:
As your counting for 0 is actually a
NOT EXISTScheck. You should also consider an index for locations.loc_doctor column (if you don’t have one already).