简体   繁体   English

简单更新查询花费的时间太长-Postgres

[英]Simple update query taking too long - Postgres

I have a table with 28 million rows that I want to update. 我有一个要更新的2800万行的表。 It has around 60 columns and a ID column (primary key) with an index created on it. 它具有约60列和一个ID列(主键),并在其上创建了索引。 I created four new columns and I want to populate them with the data from four columns from other table which also has an ID column with an index created on it. 我创建了四个新列,并希望使用来自其他表的四个列的数据来填充它们,该表还具有一个ID列,并在该列上创建了索引。 Both tables have the same amount of rows and just the primary key and the index on the IDENTI column. 两个表的行数相同,而IDENTI列上只有主键和索引。 The query has been running for 15 hours and since it is high priority work, we are starting to get nervous about it and we don't have so much time to experiment with queries. 该查询已经运行了15个小时,并且由于它是高优先级的工作,因此我们开始对此感到紧张,而且我们没有太多时间来进行查询实验。 We have never update a table so big (7 GB), so we are not sure if this amount of time is normal. 我们从未更新过如此大的表(7 GB),因此我们不确定该时间是否正常。

This is the query: 这是查询:

UPDATE consolidated
SET IDEDUP2=uni.IDEDUP2
USE21=uni.USE21
USE22=uni.USE22
PESOXX2=uni.PESOXX2
FROM uni_group uni, consolidated con
WHERE con.IDENTI=uni.IDENTI

How can I make it faster? 我怎样才能使其更快? Is it possible? 可能吗? If not, is there a way to check how much longer it is going to take (without killing the process)? 如果不是,是否有一种方法可以检查需要多长时间(不终止进程)?

Just as additional information, we have ran before much more complex queries for 3 million row tables (postgis) and It has taken it about 15 hours as well. 就像其他信息一样,我们之前已经对300万行表(postgis)进行了更复杂的查询,并且还花了大约15个小时。

You should not repeat the target table in the FROM clause. 应该重复目标表在FROM子句中。 Your statement creates a cartesian join of the consolidated table with itself, which is not what you want. 您的语句创建consolidated表与其自身的笛卡尔连接,这不是您想要的。

You should use the following: 您应该使用以下内容:

UPDATE consolidated con
   SET IDEDUP2=uni.IDEDUP2
       USE21=uni.USE21
       USE22=uni.USE22
       PESOXX2=uni.PESOXX2
FROM uni_group uni
WHERE con.IDENTI = uni.IDENTI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM