别名列是否会受益于索引?

时间:2018-06-18 12:25:26

标签: mysql sql

假设此查询:

SELECT x.*
FROM (
    SELECT COALESCE(p2.id,p1.id) id,
           COALESCE(p2.subject,p2.subject) subject,
           body
    FROM posts p1
    LEFT JOIN posts p2 ON p1.related = p2.id
    WHERE MATCH(subject,body) AGAINST(:entry)
) x INNER JOIN pivot p ON x.id = p.post_id
    INNER JOIN tags  t ON t.id = p.tag_id AND t.name = "tag_name"

如您所见,x是一个虚拟表,x.id不是真正的列。此外,x.id已加入pivot上的pivot.post_id。它会带来索引的好处吗?如果没有,解决方案是什么?

0 个答案:

没有答案