如何提高Left Join Inner Join sql(mysql)的性能

时间:2011-10-18 20:54:55

标签: mysql performance

SELECT SQL_CACHE se_media.* 
FROM se_media 
  LEFT JOIN se_albums 
    ON se_albums.album_id=se_media.media_album_id 
  LEFT JOIN se_users 
    ON se_albums.album_user_id=se_users.user_id 
  LEFT JOIN ( SELECT s1.media_id AS tableprimary 
               FROM se_media as s1 
               WHERE  s1.media_title 
               LIKE '%funny%' 
             ) AS tagobjects_1 
    ON se_media.media_id=tagobjects_1.tableprimary 
WHERE   media_date_created <= '1318949954' 
  AND media_search='1' 
ORDER BY media_date_created DESC 
LIMIT 0, 10 

500秒

SELECT se_media.* 
FROM se_media 
  INNER JOIN se_albums 
    ON se_albums.album_id=se_media.media_album_id 
  INNER JOIN se_users 
    ON se_albums.album_user_id=se_users.user_id 
  INNER JOIN ( SELECT s1.media_id AS tableprimary 
               FROM se_media as s1 
               WHERE  s1.media_title 
               LIKE '%funny%' 
             ) AS tagobjects_1 
    ON se_media.media_id=tagobjects_1.tableprimary 
WHERE   media_date_created <= '1318949954' 
  AND media_search='1' 
ORDER BY media_date_created DESC 
LIMIT 0, 10 

仅-5秒

为什么?

我认为左连接比INNER JOIN快。

如何执行查询?哪个订单?找到所有行然后加入然后在哪里?

感谢。

0 个答案:

没有答案