Re: support for MERGE
Japin Li <japinli@hotmail.com>
From: Japin Li <japinli@hotmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Justin Pryzby <pryzby@telsasoft.com>, Amit Langote
<amitlangote09@gmail.com>, Zhihong Yu <zyu@yugabyte.com>, Simon Riggs
<simon.riggs@enterprisedb.com>, Pg Hackers
<pgsql-hackers@lists.postgresql.org>, Tomas Vondra
<tomas.vondra@enterprisedb.com>, Daniel Westermann <dwe@dbi-services.com>,
Erik Rijkers <er@xs4all.nl>, Jaime Casanova
<jcasanov@systemguards.com.ec>, Andres Freund <andres@anarazel.de>
Date: 2022-03-17T00:14:07Z
Lists: pgsql-hackers
On Thu, 17 Mar 2022 at 03:18, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
> v16.
> On 2022-Mar-14, Japin Li wrote:
>
>> + ar_delete_trig_tcs = mtstate->mt_transition_capture;
>> + if (mtstate->operation == CMD_UPDATE && mtstate->mt_transition_capture &&
>> + mtstate->mt_transition_capture->tcs_update_old_table)
>> + {
>> + ExecARUpdateTriggers(estate, resultRelInfo, tupleid, oldtuple,
>> + NULL, NULL, mtstate->mt_transition_capture);
>> +
>> + /*
>> + * We've already captured the NEW TABLE row, so make sure any AR
>> + * DELETE trigger fired below doesn't capture it again.
>> + */
>> + ar_delete_trig_tcs = NULL;
>> + }
>>
>> Maybe we can use ar_delete_trig_tcs in if condition and
>> ExecARUpdateTriggers() to make the code shorter.
>
> ... Well, the code inside the block is about UPDATE triggers, so it's a
> nasty to use the variable whose name says it's for DELETE triggers.
> That variable really is just a clever flag that indicates whether or not
> to call the DELETE part. It's a bit of strange coding, but ...
>
>> +MERGE is a multiple-table, multiple-action command: it specifies a target
>> +table and a source relation, and can contain multiple WHEN MATCHED and
>> +WHEN NOT MATCHED clauses, each of which specifies one UPDATE, INSERT,
>> +UPDATE, or DO NOTHING actions. The target table is modified by MERGE,
>> +and the source relation supplies additional data for the actions
>>
>> I think the "source relation" is inaccurate. How about using "data
>> source" like document?
>
> I debated this with myself when I started using the term "source
> relation" here. The result of a query is also a relation, so this term
> is not incorrect; in fact, the glossary entry for "relation" explains
> this:
> https://www.postgresql.org/docs/14/glossary.html#GLOSSARY-RELATION
>
> It's true that it's not the typical use of the term in our codebase.
>
> Overall, I'm -0 for changing this. (If we decide to change it, there
> are other places that would need to change as well.)
Thanks for the detailed explanation.
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
Commits
-
Doc fixes for MERGE statement
- 5dcebd10baa8 16.0 landed
- 5bb88967ed5c 15.0 landed
-
MERGE docs adjustments
- d6d1fbf353d1 15.0 landed
- 3d895bc846f2 16.0 landed
-
Link to MVCC docs in MERGE docs
- ffffeebf2447 15.0 landed
-
Fix EXPLAIN MERGE output when no tuples are processed
- 12e423e21d8e 15.0 landed
-
Make EXPLAIN MERGE output format more compact
- 598ac10be1c2 15.0 landed
-
Add support for MERGE SQL command
- 7103ebb7aae8 15.0 landed
-
Split ExecUpdate and ExecDelete into reusable pieces
- 25e777cf8e54 15.0 landed
-
Add API of sorts for transition table handling in trigger.c
- 3a46a45f6f00 15.0 landed
-
Represent Lists as expansible arrays, not chains of cons-cells.
- 1cff1b95ab6d 13.0 cited