sql - MySQL inefficient cross table update between 3 tables -


i'm trying port legacy database (with no primary keys) better , more structured database in mysql.

i'm running query:

update table a, table b, table c  set a.item_id = b.id  b.description = c.description , a.id = c.id; 

a.item_id , b.id both int(11) fields, , b.description , c.description both varchar fields. b.description. , c.description not have keys or indices on them. a.id , c.id both primary keys.

table a , table c both tables 50,000~ rows, , table b contains 2000 or rows. result, triple join statement taking long time run. i'm pretty sure i'm not doing efficiently, more efficient way structure query?

first, should write using join syntax:

update table join        table c        on a.id = c.id join        table b        on b.description = c.description     set a.item_id = b.id ; 

this shouldn't affect performance. however, should put index on description. suggest:

create index on b_description_id on b(description, id); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -