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 `article` ADD INDEX `article_idx_published_date` (`published_date`);
ALTER TABLE `device` ADD INDEX `device_idx_status_type_latest_dat` (`status`,`type`,`latest_activity_date`);
ALTER TABLE `device` ADD INDEX `device_idx_registration_id` (`registration_id`);
SELECT
m.registration_id,
COUNT(a.id)
FROM
device m,
article a
WHERE
(
m.latest_activity_date < CURRENT_TIMESTAMP
AND a.published_date >= m.latest_activity_date
AND m.status = 'enabled'
AND a.published_date <= CURRENT_TIMESTAMP
AND (
m.registration_id <> ''
OR m.registration_id IS NOT NULL
)
)
AND m.type = 'foo'
GROUP BY
m.registration_id
HAVING
COUNT(a.id) > 0
ORDER BY
NULL