多个连接确实减慢了MySQL查询速度

时间:2012-10-26 05:47:28

标签: mysql performance join

这是我第一次做这么大的查询和很多连接。当我执行此查询时,它非常慢。我不确定如何使用外键,如果它甚至可以帮助...但如果有人知道一种方法,我可以加快这一点,这将是非常有帮助的。这是我的疑问:

SELECT FLOOR(AVG(ra.double)) AS price, hi.hname,  hi.hotel_id as hid, hi.hstars, hi.haddress, im.image_file, hd.short_desc, pr.promo_name, pr.discount, pr.discount_type, pr.book_start, pr.book_end 
    FROM hotel_info AS hi 
    JOIN images AS im ON im.foreign_id = hi.hotel_id 
    LEFT JOIN hotel_desc AS hd ON hd.hotel_id = hi.hotel_id 
    RIGHT JOIN rates AS ra ON ra.hotel_id = hi.hotel_id 
    RIGHT JOIN promotions AS pr ON pr.hotel_id = ra.hotel_id 
    WHERE ra.booking_date  BETWEEN '2012-01-01' AND '2012-01-06' 
    AND ra.double != '0.00' 
    AND hi.status = '1' 
    AND hi.destination_id = '$destination' 
    GROUP BY hi.hotel_id

0 个答案:

没有答案