結合されている場合はファイルソートを使用するこのクエリがありますが(ユニオンオール)、個別に実行するとファイルソートなしで正常に動作します。ここでは、個別に実行したくありませんが、union all オプションを実装したいと考えています。誰か助けてください。
(SELECT STRAIGHT_JOIN *,
topic_post_time,
topic_title,
topic_id AS tid,
p.userid AS profile_id,
Concat(first_name, ' ', last_name) AS poster_name,
Concat(first_name, '.', last_name) AS profile_name,
forum_id,
topic_last_post_time,
sch_name_abbrev,
picture_small_url,
profile_pix_upload_path,
profile_pix_upload_path,
LEFT(post_text, 100) AS post_text
FROM _forum_topics FORCE INDEX(topic_poster)
INNER JOIN _profile p
ON ( p.userid = _forum_topics.topic_poster )
INNER JOIN _users
ON p.userid = _users.userid
INNER JOIN _class
ON _users.classid = _class.classid
INNER JOIN _unit
ON _class.unitid = _unit.unitid
INNER JOIN _department
ON _unit.deptid = _department.deptid
INNER JOIN _faculty
ON _department.facid = _faculty.facid
INNER JOIN _university
ON ( _faculty.schid = _university.schid )
WHERE _forum_topics.sub_forum_id IN( 133, 134, 135, 136,
137, 138 )
ORDER BY topic_last_post_time DESC
LIMIT 0, 20)
UNION ALL
(SELECT STRAIGHT_JOIN *,
topic_post_time,
topic_title,
topic_id AS tid,
p.userid AS profile_id,
Concat(first_name, ' ', last_name) AS poster_name,
Concat(first_name, '.', last_name) AS profile_name,
forum_id,
topic_last_post_time,
sch_name_abbrev,
picture_small_url,
profile_pix_upload_path,
profile_pix_upload_path,
LEFT(post_text, 100) AS post_text
FROM _sch_forum_topics s FORCE INDEX(topic_poster)
INNER JOIN _profile p
ON ( p.userid = s.topic_poster )
INNER JOIN _users
ON p.userid = _users.userid
INNER JOIN _class
ON _users.classid = _class.classid
INNER JOIN _unit
ON _class.unitid = _unit.unitid
INNER JOIN _department
ON _unit.deptid = _department.deptid
INNER JOIN _faculty
ON _department.facid = _faculty.facid
INNER JOIN _university
ON _faculty.schid = _university.schid
ORDER BY topic_last_post_time DESC
LIMIT 0, 20)
LIMIT
0, 20