Currently I am doing mass deletes using variations of the following query:
DELETE FROM t1 WHERE t1.key NOT IN (SELECT t2.key FROM t2)
I am told that sub queries too slow in MySQL and the should be optimized. But I cannot find a better example. Is it possible to do a join and delete?
And repeat until nothing is left, this allows not blocking table for a long time.
UPD: but if you need to join on the same table this solution will not work.
UPD2: I overlooked the
NOT, here is the corrected query:I should note that this is the case where the subquery would perform at the same speed as the JOIN, look into a good post of Quassnoi about the issue.