如何在PostgreSQL中更新一个包含数百万条记录的表?

时间:2016-09-19 08:35:17

标签: postgresql postgresql-performance

我需要在Postgres中更新表t1的9列,其中包含近1000万行。我申请的查询是:

update t1 
set 
  class = t2.class,
  direction = t2.direction,
  bt = t2.bt,
  rf = t2.rf,
  private = t2.private,
  cat = t2.cat,
  ref = t2.ref,
  to_ref = t2.to_ref, 
  public = t2.public
from table2 t2 
where  t2.link_id = t1.link_id

t1和table2都有近1000万行。问题是查询需要太长时间(天仍然没有完成)。我做错了吗?有没有其他可能的方法使它工作?

link_id字符在两个表中都有变化,它是table2的PRIMARY KEY。有什么建议吗?

0 个答案:

没有答案