when I run this query it just never seems to do anything, the cpu usage goes up to ~30% and stays there, and eventually mysql workbench times out. is there a way to do it more efficiently?
insert ignore into tbl_sub_model_image
select sub_model_sk,tbl_image.image_id
from tbl_sub_model sm
inner join autotalk_identicar_old.ad_vehicle av on av.vehiclekey=sm.oldid
inner join autotalk_identicar_old.id_ad_link al on av.vehiclekey=al.rbvehiclekey
inner join autotalk_identicar_old.id_features f on f.vehiclekey=al.idvehiclekey
inner join autotalk_identicar_old.id_images i on i.id_vehiclekey=f.vehiclekey
inner join tbl_image im on i.id_images.image=im.img_lnk
where substring(id_images.image,-4) <> '.tif';
basically in the old db one record in ad_vehicle is linked to one(?) in id_ad_link. many in id_ad_link are linked to one in id_features and id_features and id_images are one – one.
in tbl_sub_model (which is in the new database) I have a field called oldid which is the primary key for ad_vehicle.
what I am trying to do is, I have a tbl_image but the images have been assigned new autonumbers, so I need to join the old db together to find out which images I need to assign to which sub model in the new one by using their file path.
none of the tables are more than 60,000 records but still it just never seems to be able to be executed, what makes it stranger is that for the last few months I have been executing it fine on another virtual machine, but now on a new one it just won’t work. it’s either stuck in a loop or it’s just taking forever.
could somebody please help me fix/improve it?
figured out the problem. some of the columns used on the joins aren’t indexed so that’s why it’s taking forever to do the query.
so the moral of the story is… indexes are your friends