-
-
Save NinoSkopac/746ff4fc38696e747923c6c7f3d6a640 to your computer and use it in GitHub Desktop.
https://dba.stackexchange.com/questions/234785/mysql-need-help-making-a-query-faster: trying out WHERE NOT EXISTS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM ( | |
SELECT discovery.id, discovery.resource AS url, discovery.event_datetime, whitelisted.keyword | |
FROM discovery | |
INNER JOIN whitelisted | |
ON discovery.`resource` LIKE concat('%', whitelisted.`keyword`, '%') | |
WHERE | |
NOT EXISTS ( | |
SELECT * FROM `logs` WHERE `logs`.discovery_id = discovery.id | |
) | |
AND | |
discovery.event_datetime >= NOW() | |
AND | |
discovery.provider = 'XXX' | |
AND | |
`logs`.id IS NULL | |
AND | |
discovery.resource NOT LIKE '%SOMETHING-TO-EXCLUDE%' | |
LIMIT 0, 20 | |
) logless_resources | |
GROUP BY logless_resources.url | |
ORDER BY logless_resources.event_datetime ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment