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

mspsb9vt  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(248)
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
pkln4tw6

pkln4tw61#

如手册所述:
除非打算自联接,否则不要将目标表作为from\项重复
因此,不要重复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

相关问题