postgresql中的update语句用于多个表的联接,我想对下面的update语句进行优化更新,下面的语句需要很长时


update tabel1 t1 set column5 = t2.column1, column2 = 0
from table1 t
join table2 t2 on t2.column3 = t.column3
left join table3 t3 on t3.coulmn4 = t.column4
where t3.column5 is null

如手册所述:

除非您打算自加入,否则不要将目标表作为from_item重复

因此,不要重复FROM子句中的目标表:

update table1 t1
set column5 = t2.column1, 
column2 = 0
from table2 t2 
left join table3 t3 on t3.column4 = t2.column4
where t2.column3 = t1.column3 --<< this replaces the original JOIN to t1
and t3.column5 is null