I got this huge query here:
SELECT `l`.`web_id`, `rn`.`resort_id`, `rn`.`name`,
`rn`.`address1`, `rn`.`city`, `rn`.`state`, `rn`.`postal_code`,
`rn`.`country`, `p`.`picture_name`, `p`.`picture_url`,
`ra`.`destination`, COUNT(`d`.`web_id`) AS `adsnum`
FROM `resort_name` `rn`
LEFT JOIN `location` `l` ON `rn`.`name`=`l`.`property_name`
LEFT JOIN `pictures` `p` ON `p`.`resort_id`=`rn`.`resort_id`
AND `p`.`picture_name` = (
SELECT `picture_name` FROM `pictures`
WHERE `resort_id`=`rn`.`resort_id`
ORDER BY `priority` ASC
LIMIT 1
)
LEFT JOIN `addata` `d` ON `d`.`web_id`=`l`.`web_id`
AND `d`.`caption_header`="Sale"
AND `d`.`price_desc` != "Sold"
AND `d`.`frea`="1"
LEFT JOIN `resort_attributes` `ra` ON `ra`.`resort_id`=`rn`.`resort_id`
WHERE `rn`.`name` != ""
AND `rn`.`status`="Active"
AND `rn`.`name` LIKE "%test%"
GROUP BY `rn`.`name`
ORDER BY `rn`.`name` ASC
LIMIT 0, 50
The query takes 80+ seconds to run.
The explain statement results picture is attached:

I believe that's that type ALL that kills the performance.
How do I index the tables properly so the performance improves?
Thanks.
EXPLAIN PLANoutput in your question.LIKE "%test%"and your dependent picture_name subquery will likely slow you down.rn.nameLIKE "%test%" is the real killer here. MySQL can't leverage an index on a LIKE statement like that. More info on that here: stackoverflow.com/questions/10354248/…. Also, double check that your join conditions are uniquely identifying rows in the other tables. The explain output on tables l, p, and pictures might indicate your key is not specific enough (it might not though; it's not conclusive from the output of that explain statement)rn.name LIKE "%test%", removern.name != "".