我正在尝试优化查询,试图避免重复使用“ COMPLEX QUERY ”指示的查询,该查询使用了 2 次,并且两者都具有相同的结果。
原始查询
SELECT news.*
FROM news
INNER JOIN((SELECT myposter
FROM (SELECT **COMPLEX QUERY**))
UNION
(SELECT myposter
FROM `profiles_old` prof2
WHERE prof2.profile_id NOT IN (SELECT **COMPLEX QUERY**))) r
ON news.profile = r.p
我想知道这样的事情是否可能:
SELECT news.*
FROM (SELECT **COMPLEX QUERY**) complexQuery,
news
INNER JOIN ((SELECT myposter
FROM complexquery)
UNION
(SELECT myposter
FROM `profiles_old` prof2
WHERE prof2. profile NOT IN (SELECT myposter
FROM complexQuery))) r
ON news. profile = r.p
Mysql 会对该类型的查询进行某种缓存吗?