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 `sand` ADD INDEX `sand_idx_started_at` (`started_at`);
ALTER TABLE `sand` ADD INDEX `sand_idx_user_id` (`user_id`);
SELECT
m.distinct_days_1week
FROM
table1 t1,
(SELECT
s.user_id,
count(DISTINCT date(s.started_at)) AS count_s
FROM
sand s
WHERE
s.started_at >= (
DATE(NOW()) - INTERVAL 7 DAY
)
GROUP BY
s.user_id) t2
WHERE
m.user_id = t2.user_id