I have a possibly very very large InnoDB table in a MySQL 5.0 db. For the sake of simplicity, let's say it has 4 columns, 3 of those being email columns, like email, e_alt1, e_alt2 and the primary key is id. I've run into an issue that I need to cleanup. The issue is that sometimes there may be two different id values that have (id=1, email = [email protected]) and then (id=2, email = [email protected], [email protected]). So what I want is to set e_alt1 = NULL if I find out it's listed in the email column of a different id value. So stupidly I tried:
which works fine for a smallish number of rows, but of course with a large set...well...that just won't work, even though there are indexes on all 4 columns we're operating on here. (In real the table has at least 25 columns and probably more like 40+ in the wild.)
Can anyone help me optimize this query or am I stuck and need to just protect against the possibility of this issue in my UI?
Code:
UPDATE table1 t1, table t2 SET t1.e_alt1 = NULL WHERE t1.email=t2.e_alt1
Can anyone help me optimize this query or am I stuck and need to just protect against the possibility of this issue in my UI?