From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: pgsql-performance@postgresql.org
To: Harry Mantheakis <harry.mantheakis@riskcontrollimited.com>
Subject: Re: Long Running Update
Date: Thu, 23 Jun 2011 14:32:24 -0500
Message-ID: <4E034E78020000250003EB37@gw.wicourts.gov> (raw)
In-Reply-To: <4E035649.20007@riskcontrollimited.com>
References: <4E035649.20007@riskcontrollimited.com>
Harry Mantheakis <harry.mantheakis@riskcontrollimited.com> wrote:
> UPDATE
> table_A
> SET
> (
> field_1
> , field_2
> ) = (
> table_B.field_1
> , table_B.field_2
> )
> FROM
> table_B
> WHERE
> table_B.id = table_A.id
> ;
I would have just done:
SET field_1 = table_B.field_1, field_2 = table_B.field_2
instead of using row value constructors. That might be slowing
things down a bit.
> I tested (the logic of) this statement with a very small sample,
> and it worked correctly.
Always a good sign. :-)
> The statement has been running for 18+ hours so far.
> My question is: can I reasonably expect a statement like this to
> complete with such a large data-set, even if it takes several
> days?
If it's not leaking memory, I expect that it will complete.
To get some sense of what it's doing, you could log on to another
connection and EXPLAIN the statement. (NOTE: Be careful *not* to
use EXPLAIN ANALYZE.)
Another thing to consider if you run something like this again is
that an UPDATE is an awful lot like an INSERT combined with a
DELETE. The way PostgreSQL MVCC works, the old version of each row
must remain until the updating transaction completes. If you were
to divide this update into a series of updates by key range, the new
versions of the rows from later updates could re-use the space
previously occupied by the old version of rows from earlier updates.
For similar reasons, you might want to add something like this to
your WHERE clause, to prevent unnecessary updates:
AND (table_B.field_1 IS DISTINCT FROM table_A.field_1
OR table_B.field_2 IS DISTINCT FROM table_A.field_2);
-Kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: Kevin.Grittner@wicourts.gov, harry.mantheakis@riskcontrollimited.com
Subject: Re: Long Running Update
In-Reply-To: <4E034E78020000250003EB37@gw.wicourts.gov>
References: <4E035649.20007@riskcontrollimited.com> <4E034E78020000250003EB37@gw.wicourts.gov>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox