mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Allow UPDATE to move rows between partitions.
When an UPDATE causes a row to no longer match the partition constraint, try to move it to a different partition where it does match the partition constraint. In essence, the UPDATE is split into a DELETE from the old partition and an INSERT into the new one. This can lead to surprising behavior in concurrency scenarios because EvalPlanQual rechecks won't work as they normally did; the known problems are documented. (There is a pending patch to improve the situation further, but it needs more review.) Amit Khandekar, reviewed and tested by Amit Langote, David Rowley, Rajkumar Raghuwanshi, Dilip Kumar, Amul Sul, Thomas Munro, Álvaro Herrera, Amit Kapila, and me. A few final revisions by me. Discussion: http://postgr.es/m/CAJ3gD9do9o2ccQ7j7+tSgiE1REY65XRiMb=yJO3u3QhyP8EEPQ@mail.gmail.com
This commit is contained in:
@@ -153,6 +153,29 @@
|
||||
triggers.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If an <command>UPDATE</command> on a partitioned table causes a row to move
|
||||
to another partition, it will be performed as a <command>DELETE</command>
|
||||
from the original partition followed by an <command>INSERT</command> into
|
||||
the new partition. In this case, all row-level <literal>BEFORE</literal>
|
||||
<command>UPDATE</command> triggers and all row-level
|
||||
<literal>BEFORE</literal> <command>DELETE</command> triggers are fired on
|
||||
the original partition. Then all row-level <literal>BEFORE</literal>
|
||||
<command>INSERT</command> triggers are fired on the destination partition.
|
||||
The possibility of surprising outcomes should be considered when all these
|
||||
triggers affect the row being moved. As far as <literal>AFTER ROW</literal>
|
||||
triggers are concerned, <literal>AFTER</literal> <command>DELETE</command>
|
||||
and <literal>AFTER</literal> <command>INSERT</command> triggers are
|
||||
applied; but <literal>AFTER</literal> <command>UPDATE</command> triggers
|
||||
are not applied because the <command>UPDATE</command> has been converted to
|
||||
a <command>DELETE</command> and an <command>INSERT</command>. As far as
|
||||
statement-level triggers are concerned, none of the
|
||||
<command>DELETE</command> or <command>INSERT</command> triggers are fired,
|
||||
even if row movement occurs; only the <command>UPDATE</command> triggers
|
||||
defined on the target table used in the <command>UPDATE</command> statement
|
||||
will be fired.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Trigger functions invoked by per-statement triggers should always
|
||||
return <symbol>NULL</symbol>. Trigger functions invoked by per-row
|
||||
|
Reference in New Issue
Block a user