In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `tbl_activities` ADD INDEX `tbl_activities_idx_user_id` (`user_id`);
ALTER TABLE `tbl_subscriptions` ADD INDEX `tbl_subscriptions_idx_subscriber_id_subscribed_uid` (`subscriber_id`,`subscribed_uid`);
ALTER TABLE `tbl_users` ADD INDEX `tbl_users_idx_id` (`id`);
SELECT
tbl_users.id,
tbl_users.user_name
FROM
tbl_users
WHERE
EXISTS (
SELECT
1
FROM
(SELECT
act.user_id
FROM
tbl_activities act
INNER JOIN
tbl_users u
ON act.user_id = u.id
WHERE
NOT EXISTS (
SELECT
1
FROM
tbl_subscriptions s
INNER JOIN
tbl_users u1
ON s.subscribed_uid = u1.id
WHERE
(
s.subscriber_id = 1
)
AND (
u.id = s.subscribed_uid
)
)
GROUP BY
act.user_id
ORDER BY
COUNT(act.user_id) DESC LIMIT 0,
15) AS t
WHERE
(
tbl_users.id = t.user_id
))