pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Kevin Kempter <cs_dba@consistentstate.com>
To: Andrew Dunstan <andrew@dunslane.net>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Update join performance issues
Date: Tue, 03 Apr 2012 12:49:54 -0500
Message-ID: <4F7AF1F20200002500046B3F@gw.wicourts.gov> (raw)
In-Reply-To: <4F7B35B9.50108@dunslane.net>
References: <4F7B3394.3030703@consistentstate.com>
	<4F7B35B9.50108@dunslane.net>

Andrew Dunstan <andrew@dunslane.net> wrote:
 
> Why is test_one in the from clause? update joins whatever is in
> the from clause to the table being updated. You almost never need
> it repeated in the from clause.
 
This is actually one of the nastier "gotchas" in converting from
Sybase ASE or MS SQL Server to PostgreSQL -- there are syntactically
identical UPDATE statements with very different semantics when a
FROM clause is used in an UPDATE statement.  You need to do what the
OP was showing to use an alias with the target table under those
other products.
 
I suppose it might be possible to generate a warning when it appears
that someone is making this mistake, but it wouldn't be easy and
would probably not be worth the carrying cost.  The test would need
to be something like:
 
(1)  The relation which is the target of the UPDATE has no alias.
(2)  There is a FROM clause which included the target relation (with
     an alias).
(3)  There aren't any joining references between the UPDATE target
     and the relation(s) in the FROM clause.
 
-Kevin



view thread (6+ messages)  latest in thread

Message-ID: <4F7AF1F20200002500046B3F@gw.wicourts.gov>
Permalink:  ../4F7AF1F20200002500046B3F@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4F7AF1F20200002500046B3F@gw.wicourts.gov

 · 

reply

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, cs_dba@consistentstate.com, andrew@dunslane.net
  Subject: Re: Update join performance issues
  In-Reply-To: <4F7AF1F20200002500046B3F@gw.wicourts.gov>
  References: <4F7B3394.3030703@consistentstate.com> <4F7B35B9.50108@dunslane.net> <4F7AF1F20200002500046B3F@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