From a93c38a9af6abd98319e0c065674ed9f17f43979 Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Wed, 10 Jun 2020 14:21:47 +0300 Subject: [PATCH] [CORE][DATABASE] Another approach to semi-join in the inboxnoticestream query Compared to the solution with INNER JOIN this seems to have better performance as there is no need to deduplicate the subquery result before use. --- lib/notices/inboxnoticestream.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/notices/inboxnoticestream.php b/lib/notices/inboxnoticestream.php index a261da5495..2304612c7a 100644 --- a/lib/notices/inboxnoticestream.php +++ b/lib/notices/inboxnoticestream.php @@ -93,22 +93,25 @@ class RawInboxNoticeStream extends FullNoticeStream // Subscription:: is a table of subscriptions (every user is subscribed to themselves) $notice->_join .= sprintf( "\n" . <<<'END' - INNER JOIN ( - (SELECT id FROM notice - WHERE profile_id - IN (SELECT subscribed FROM subscription WHERE subscriber = %1$d)) - UNION - (SELECT notice_id AS id FROM reply WHERE profile_id = %1$d) - UNION - (SELECT notice_id AS id FROM attention WHERE profile_id = %1$d) - UNION - (SELECT notice_id AS id FROM group_inbox INNER JOIN group_member USING (group_id) - WHERE group_member.profile_id = %1$d) + LEFT JOIN ( + SELECT notice.id + FROM notice INNER JOIN subscription + ON notice.profile_id = subscription.subscribed + WHERE subscription.subscriber = %1$d + UNION ALL + SELECT notice_id AS id FROM reply WHERE profile_id = %1$d + UNION ALL + SELECT notice_id AS id FROM attention WHERE profile_id = %1$d + UNION ALL + SELECT notice_id AS id FROM group_inbox INNER JOIN group_member USING (group_id) + WHERE group_member.profile_id = %1$d ) AS t1 USING (id) END, $this->target->getID() ); + $notice->whereAdd('t1.id IS NOT NULL'); + $notice->whereAdd(sprintf( "notice.created > TIMESTAMP '%s'", $notice->escape($this->target->created)