I am trying to select a number of items from table1 that are not in table2. table1 has approximately 3 million rows, and table2 has approximately 8,000. I already have an index on table1 for (expire,unreliable,block,deleted,flag,expirationDate). How can I optimize this:
SELECT table1.*
FROM table1
LEFT JOIN table2
ON table1.item_ID = table2.item_ID
WHERE table1.expire = '0'
AND table1.unreliable = '0'
AND table1.block = '0'
AND table1.deleted = '0'
AND table1.flag = '0'
AND table1.expirationDate >= CURDATE()
AND table2.item_ID IS NULL
GROUP BY item_ID
LIMIT 5000