I'm having the trouble with the following query due to the growing size of the database ( websites is around a million rows, misspelled goes up to a couple millions )
It can reach up to 165 seconds in run time, I was wondering if there was a way to improve this without having to add additional columns to the tables, maybe using some king of index ?
SELECT contacturl, url
FROM websites
WHERE contactable = true
AND websites.contacted = false
AND url IN (
SELECT url
FROM scans
WHERE scanid IN (
SELECT distinct(scanid)
FROM misspelled
WHERE word = ?
)
)
;
Edit : As requested, the output of the explain analyze :
Edit (1) : After Checking the explain statement output, this sing select seems to be taking most of the time :
select distinct(scanid) from misspelled where word = ?
explain analyze
output.