As an assignment I need to clean up a movie database.
Some users has been deleted, and i have to remove ratings from users no longer in the database.
I made this query
DELETE rating FROM rating LEFT JOIN (SELECT id FROM user) as A ON A.id = rating.userId WHERE A.id IS NULL;
I've made indexes on rating.userId and user.Id
As there is 6000 users and 1.000.000 ratings, this takes insanely long time. Can anyone figure out how i can perform this, or a query like this, with better performance?
A.id = rating.userId WHERE A.id IS NULLisn't that equivalent torating.userId = NULL?