[POC]Enable tuple change partition caused by BEFORE TRIGGER - Mailing list pgsql-hackers

From movead.li@highgo.ca
Subject [POC]Enable tuple change partition caused by BEFORE TRIGGER
Date
Msg-id 20200821155540390217109@highgo.ca
Whole thread Raw
Responses Re: [POC]Enable tuple change partition caused by BEFORE TRIGGER  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
List pgsql-hackers
Hello hackers,

Currently, if BEFORE TRIGGER causes a partition change, it reports an error 'moving row
to another partition during a BEFORE FOR EACH ROW trigger is not supported' and fails
to execute. I want to try to address this limitation and have made an initial patch to get
feedback  from other hackers.


The implemented approach is similar to when a change partition caused by an UPDATE

statement. If it's a BEFORE INSERT TRIGGER then we just need to insert the row produced

by a trigger to the new partition, and if it's a BEFORE UPDATE TRIGGER we need to delete

the old tuple and insert the row produced by the trigger to the new partition.


In current BEFORE TRIGGER implementation, it reports an error once a trigger result out

of current partition, but I think it should check it after finish all triggers call, and you can

see the discussion in [1][2]. In the attached patch I have changed this rule, I check the

partition constraint only once after all BEFORE TRIGGERS have been called. If you do not

agree with this way, I can change the implementation.


And another point is that when inserting to new partition caused by BEFORE TRIGGER,

then it will not trigger the BEFORE TRIGGER on a new partition. I think it's the right way,

what's more, I think the UPDATE approach cause partition change should not trigger the

BEFORE TRIGGERS too, you can see discussed on [1].




Regards,
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca
EMAIL: mailto:movead(dot)li(at)highgo(dot)ca
Attachment

pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: proposal - function string_to_table
Next
From: Yugo NAGATA
Date:
Subject: Re: Implementing Incremental View Maintenance