这是以下代码:
UPDATE cm_object
LEFT JOIN (SELECT T1.pandbouwjaar,T.key_id
FROM (SELECT cm_object.key_id,build_year,zipcode,housenumber,housenumber_addition
FROM cm_object
LEFT JOIN cm_key
on cm_object.key_id = cm_key.key_id
) T
LEFT JOIN (SELECT pandbouwjaar,postcode,huisnummer,huisnummertoevoeging
FROM avm_new
GROUP BY postcode,huisnummer,huisnummertoevoeging
) T1
on T.housenumber = T1.huisnummer
AND T.zipcode = T1.postcode
AND T.housenumber_addition = T1.huisnummertoevoeging
) T2
on T2.key_id = cm_object.key_id
SET cm_object.build_year = T2.pandbouwjaar
WHERE cm_object.build_year IS NULL;
我正在尝试连接两个表cm_object和cm_key。通过使用cm_key中的id,我需要获取与cm_object相关的数据
接下来,我使用连接表然后链接到另一个表(avm_new)并从中提取列。
使用该列值,我想更新cm_object
中的build_year列已为正在使用的所有列分配主键和索引。一些表有超过800万条记录。但是查询花了很长时间才完成(超过一个小时)。为什么会这样?有没有办法优化它?