mysql - SQL UPDATE query taking too long -


so new mysql, , trying run query update column if cell value present in both tables, , query taking forever run (it's been running 10 minutes , no result yet). 1 of tables 250,000 rows, , other 80,000, i'm not sure why taking long. query using is:

use the_db; update table1 join table2 on table2.a = table1.b set table1.c = "y"; 

i've changed names of tables , columns, query same. i've looked @ other answers on here , of them take long time well. appreciated, thanks.

for query:

update table1 join        table2        on table2.a = table1.b     set table1.c = 'y';  

you want index on table2(a):

create index idx_table2_a on table2(a); 

also, if there multiple values of a match each b, generating lot of intermediate rows, , have big impact on performance.

if case, phrase query as:

update table1     set table1.c = 'y'     exists (select 1 table2 table2.a = table1.b); 

and need same index.

the difference between queries 1 stops @ first matching row in table2.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -