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 `mailing_list` ADD INDEX `mailing_list_idx_optout` (`optout`);
ALTER TABLE `mailing_list` ADD INDEX `mailing_list_idx_email_optout` (`email`,`optout`);
SELECT
DISTINCT TRIM(mailing_list.email) AS emails
FROM
mailing_list
WHERE
mailing_list.optout = 0
AND NOT EXISTS (
SELECT
1
FROM
mailing_list AS mailing_list1
WHERE
(
mailing_list1.optout = 1
)
AND (
mailing_list.email = mailing_list1.email
)
)
ORDER BY
emails