I already have the (your) new query running without using filesorts :)
Subselects are really better than joins.
So in my upcoming commit there will be some changes to the database. Adding a view indexes to harmonize this query and to get rid of filesorts (yeah, if data is indexed, MySQL is smart enough to use them. Even subselect ones).
Code: [Select]
Subselects are really better than joins.
So in my upcoming commit there will be some changes to the database. Adding a view indexes to harmonize this query and to get rid of filesorts (yeah, if data is indexed, MySQL is smart enough to use them. Even subselect ones).
$where = $is_boards ? 'id_board' : 'id_topic';
$request = wesql::query('
SELECT COUNT(DISTINCT m.id_msg) AS co, m.id_board
FROM {db_prefix}messages AS m
WHERE m.poster_time >= (UNIX_TIMESTAMP(NOW()) - 30 * 24 * 3600)
AND (
m.id_msg >
IFNULL(
(SELECT lt.id_msg FROM {db_prefix}log_topics AS lt WHERE (lt.id_topic = m.id_topic AND lt.id_member = 1)),
IFNULL(
(SELECT lmr.id_msg FROM {db_prefix}log_mark_read AS lmr WHERE (lmr.id_board = m.id_board AND lmr.id_member = 1)),
0
)
)
)
ORDER BY ' . $where . ' DESC',
array(
'id_member' => MID,
'has_unread' => $has_unread
)
);