From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Mark Thornton <mthornton@optrak.com>
To: Harry Mantheakis <harry.mantheakis@riskcontrollimited.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Long Running Update
Date: Fri, 24 Jun 2011 08:43:08 -0500
Message-ID: <4E044E1C020000250003EB9C@gw.wicourts.gov> (raw)
In-Reply-To: <4E04889B.2030806@optrak.com>
References: <4E035649.20007@riskcontrollimited.com>
<4E04889B.2030806@optrak.com>
Mark Thornton <mthornton@optrak.com> 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
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, mthornton@optrak.com, harry.mantheakis@riskcontrollimited.com
Subject: Re: Long Running Update
In-Reply-To: <4E044E1C020000250003EB9C@gw.wicourts.gov>
References: <4E035649.20007@riskcontrollimited.com> <4E04889B.2030806@optrak.com> <4E044E1C020000250003EB9C@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