From: | Amit Khandekar <amitdkhan(dot)pg(at)gmail(dot)com> |
---|---|
To: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
Cc: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: UPDATE of partition key |
Date: | 2017-09-07 06:11:04 |
Message-ID: | CAJ3gD9fpBvHAEdBxHNrMaO_YV0Bnf3sWpbRhMdfBXDvO-Ut_MA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 6 September 2017 at 21:47, Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> On Mon, Sep 4, 2017 at 10:52 AM, Amit Khandekar <amitdkhan(dot)pg(at)gmail(dot)com> wrote:
>> On 4 September 2017 at 07:43, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>> Oops sorry. Now attached.
>
> I have done some basic testing and initial review of the patch. I
Thanks for taking this up for review. Attached is the updated patch
v17, that covers the below points.
> + if (mtstate->operation == CMD_UPDATE && mtstate->mt_transition_capture)
> + ExecARUpdateTriggers(estate, resultRelInfo, InvalidOid,
>
> For passing invalid ItemPointer we are using InvalidOid, this seems
> bit odd to me
> are we using simmilar convention some other place? I think it would be better to
> just pass 0?
Yes that's right. Replaced InvalidOid by NULL since ItemPointer is a pointer.
>
> ------
>
> - if ((event == TRIGGER_EVENT_DELETE && delete_old_table) ||
> - (event == TRIGGER_EVENT_UPDATE && update_old_table))
> + if (oldtup != NULL &&
> + ((event == TRIGGER_EVENT_DELETE && delete_old_table) ||
> + (event == TRIGGER_EVENT_UPDATE && update_old_table)))
> {
> Tuplestorestate *old_tuplestore;
>
> - Assert(oldtup != NULL);
>
> Only if TRIGGER_EVENT_UPDATE it is possible that oldtup can be NULL,
> so we have added an extra
> check for oldtup and removed the Assert, but if TRIGGER_EVENT_DELETE
> we never expect it to be NULL.
>
> Is it better to put Assert outside the condition check (Assert(oldtup
> != NULL || event == TRIGGER_EVENT_UPDATE)) ?
> same for the newtup.
>
> I think we should also explain in comments about why oldtup or newtup
> can be NULL in case of if
> TRIGGER_EVENT_UPDATE
Done all the above. Added two separate asserts, one for DELETE and the
other for INSERT.
>
> -------
>
> + triggers affect the row being moved. As far as <literal>AFTER ROW</>
> + triggers are concerned, <literal>AFTER</> <command>DELETE</command> and
> + <literal>AFTER</> <command>INSERT</command> triggers are applied; but
> + <literal>AFTER</> <command>UPDATE</command> triggers are not applied
> + because the <command>UPDATE</command> has been converted to a
> + <command>DELETE</command> and <command>INSERT</command>.
>
> Above comments says that ARUpdate trigger is not fired but below code call
> ARUpdateTrigger
>
> + if (mtstate->operation == CMD_UPDATE && mtstate->mt_transition_capture)
> + ExecARUpdateTriggers(estate, resultRelInfo, InvalidOid,
> + NULL,
> + tuple,
> + NULL,
> + mtstate->mt_transition_capture);
Actually, since transition tables came in, the functions like
ExecARUpdateTriggers() or ExecARInsertTriggers() have this additional
purpose of capturing transition table rows, so that the images of the
tables are visible when statement triggers are fired that refer to
these transition tables. So in the above code, these functions only
capture rows, they do not add any event for firing any ROW triggers.
AfterTriggerSaveEvent() returns without adding any event if it's
called only for transition capture. So even if UPDATE row triggers are
defined, they won't get fired in case of row movement, although the
updated rows would be captured if transition tables are referenced in
these triggers or in the statement triggers.
--
Thanks,
-Amit Khandekar
EnterpriseDB Corporation
The Postgres Database Company
Attachment | Content-Type | Size |
---|---|---|
update-partition-key_v17.patch | application/octet-stream | 114.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tatsuro Yamada | 2017-09-07 06:46:03 | Re: CLUSTER command progress monitor |
Previous Message | Anthony Bykov | 2017-09-07 06:08:59 | Re: issue: record or row variable cannot be part of multiple-item INTO list |