Re: support for MERGE

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Simon Riggs <simon(dot)riggs(at)enterprisedb(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Daniel Westermann <dwe(at)dbi-services(dot)com>, Erik Rijkers <er(at)xs4all(dot)nl>, Jaime Casanova <jcasanov(at)systemguards(dot)com(dot)ec>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: support for MERGE
Date: 2022-08-09 12:26:22
Message-ID: 20220809122621.GC19644@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Aug 09, 2022 at 11:48:23AM +0200, Álvaro Herrera wrote:
> On 2022-Aug-01, Álvaro Herrera wrote:
>
> > > > If <command>MERGE</command> attempts an <command>INSERT</command>
> > > > and a unique index is present and a duplicate row is concurrently
> > > > + inserted, then a uniqueness violation error is raised;
> > > > + <command>MERGE</command> does not attempt to avoid such
> > > > + errors by evaluating <literal>MATCHED</literal> conditions.
> > >
> > > This was a portion of a chang that was committed as ffffeebf2.
> > >
> > > But I don't understand why this changed from "does not attempt to avoid the
> > > error by executing an <command>UPDATE</command>." to "...by evaluating
> > > <literal>MATCHED</literal> conditions."
> > >
> > > Maybe it means to say "..by re-starting evaluation of match conditions".
> >
> > Yeah, my thought there is that it may also be possible that the action
> > that would run if the conditions are re-run is a DELETE or a WHEN
> > MATCHED THEN DO NOTHING; so saying "by executing an UPDATE" it leaves
> > out those possibilities. IOW if we're evaluating NOT MATCHED INSERT and
> > we find a duplicate, we do not go back to MATCHED.
>
> So I propose to leave it as
>
> If <command>MERGE</command> attempts an <command>INSERT</command>
> and a unique index is present and a duplicate row is concurrently
> inserted, then a uniqueness violation error is raised;
> <command>MERGE</command> does not attempt to avoid such
> errors by restarting evaluation of <literal>MATCHED</literal>
> conditions.

I think by "leave it as" you mean "change it to".
(Meaning, without referencing UPDATE).

> (Is "re-starting" better than "restarting"?)

"re-starting" doesn't currently existing in the docs, so I guess not.
You could also say "starting from scratch the evaluation of MATCHED conditions".

Note that I proposed two other changes in the other thread ("MERGE and parsing
with prepared statements").

- remove the sentence with "automatic type conversion will be attempted";
- make examples more similar to emphasize their differences;

--
Justin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2022-08-09 12:35:24 Re: Generalize ereport_startup_progress infrastructure
Previous Message Amit Kapila 2022-08-09 12:09:28 Re: Perform streaming logical transactions by background workers and parallel apply