Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B303CB5DBC9 for ; Thu, 23 Jun 2011 16:32:33 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 40917-01 for ; Thu, 23 Jun 2011 19:32:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 4C494B5D944 for ; Thu, 23 Jun 2011 16:32:27 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Thu, 23 Jun 2011 14:32:26 -0500 Message-Id: <4E034E78020000250003EB37@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Thu, 23 Jun 2011 14:32:24 -0500 From: "Kevin Grittner" To: , "Harry Mantheakis" Subject: Re: Long Running Update References: <4E035649.20007@riskcontrollimited.com> In-Reply-To: <4E035649.20007@riskcontrollimited.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/220 X-Sequence-Number: 44153 Harry Mantheakis 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