Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 0FFE4B5DBEA for ; Fri, 24 Jun 2011 10:43:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 76861-08 for ; Fri, 24 Jun 2011 13:43:12 +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 61AFCB5DBC8 for ; Fri, 24 Jun 2011 10:43:12 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Fri, 24 Jun 2011 08:43:11 -0500 Message-Id: <4E044E1C020000250003EB9C@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Fri, 24 Jun 2011 08:43:08 -0500 From: "Kevin Grittner" To: "Mark Thornton" , "Harry Mantheakis" Cc: Subject: Re: Long Running Update References: <4E035649.20007@riskcontrollimited.com> <4E04889B.2030806@optrak.com> In-Reply-To: <4E04889B.2030806@optrak.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/228 X-Sequence-Number: 44161 Mark Thornton wrote: > On 23/06/11 16:05, Harry Mantheakis wrote: >> UPDATE >> table_A >> [ ... ] >> FROM >> table_B >> WHERE >> table_B.id = table_A.id > I frequently get updates involving a FROM clause wrong --- the > resulting table is correct but the running time is quadratic. The most frequent way I've seen that happen is for someone to do: UPDATE table_A [ ... ] FROM table_A a, table_B b WHERE b.id = a.id Because a FROM clause on an UPDATE statement is not in the standard, different products have implemented this differently. In Sybase ASE or Microsoft SQL Server you need to do the above to alias table_A, and the two references to table_A are treated as one. In PostgreSQL this would be two separate references and you would effectively be doing the full update of all rows in table_A once for every row in table_A. I don't think that is happening here based on the plan posted earlier in the thread. -Kevin