I have below query that I need to run on a table with 100million records but it's extremely slow (been running for 5 hours so far)
I am not sure how to optimize it, would be grateful for any help.
The table has an index on DID and week_no, and contains several other columns not indexed, and a primary key (id) indexed
DELETE FROM test
WHERE "DID" IN (SELECT "DID"
FROM test
GROUP BY "DID"
having count(distinct week_no) < 4 );