mysql LEFT加入查询优化

时间:2016-07-07 06:01:40

标签: mysql

我有查询

SELECT  P.*, COUNT(L.to) AS likes, U.name AS ownerName, U.username AS ownerUsername,
    U.picture AS ownerPicture
FROM sn_posts P LEFT JOIN sn_users AS U
    ON U.id = P.ownerID
LEFT JOIN sn_likes AS L
    ON L.to = P.id
WHERE (P.ownerID = 69)
GROUP BY P.id
ORDER BY P.id DESC

它正在服用 - 0.3337秒,

1 个答案:

答案 0 :(得分:0)

为表sn_posts添加ownerID字段的索引 更好