lukik
lukik

Reputation: 4060

How can I speed up this Update Statement

Wondering if there is a way to make the SQL statement below any faster.

UPDATE table_one SET column_x = table_two.column_x FROM table_two
WHERE table_one.column_y = table_two.column_y;

Currently the above query has been running for more 3 hours. Any suggestions on how to make it faster?

Details:

Am running on a VM with 120GB of RAM and 22 Cores with Postgresql 9.3.

Upvotes: 0

Views: 63

Answers (1)

Roman Tkachuk
Roman Tkachuk

Reputation: 3266

You do not need to update all records, at least:

UPDATE table_one
      SET column_x = table_two.column_x
     FROM table_two
      WHERE table_one.column_y = table_two.column_y
        AND table_one.column_x != table_two.column_x;

Also probably might help is to create index for both field x and y for both tables.

Upvotes: 3

Related Questions