Re: problem with RETURNING and update row movement
Etsuro Fujita <etsuro.fujita@gmail.com>
From: Etsuro Fujita <etsuro.fujita@gmail.com>
To: Amit Langote <amitlangote09@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2020-08-02T08:57:41Z
Lists: pgsql-hackers
Attachments
- v4-0001-Fix-a-bug-with-RETURNING-when-UPDATE-moves-tuple.patch (application/octet-stream) patch v4-0001
Yet another thing I noticed is that the patch incorrectly produces
values for the tableoid columns specified in the RETURNING list, like
this:
+UPDATE range_parted r set a = 'c' FROM (VALUES ('a', 1), ('a', 10),
('b', 12)) s(x, y) WHERE s.x = r.a AND s.y = r.b RETURNING
tableoid::regclass, *;
+ tableoid | a | b | c | d | e | x | y
+----------------+---+----+-----+---+---------------+---+----
+ part_a_1_a_10 | c | 1 | 1 | 1 | in trigfunc() | a | 1
+ part_a_10_a_20 | c | 10 | 200 | 1 | in trigfunc() | a | 10
+ part_c_1_100 | c | 12 | 96 | 1 | in trigfunc() | b | 12
+(3 rows)
The source partitions are shown as tableoid, but the destination
partition (ie, part_c_1_c_20) should be shown. To fix this, I
modified the patch further so that 1) we override tts_tableOid of the
original slot with the OID of the destination partition before calling
ExecProcessReturning() if needed, and 2) in ExecProcessReturning(), we
only initialize ecxt_scantuple's tts_tableOid when needed, which would
save cycles a bit for non-foreign-table-direct-modification cases.
Attached is a new version of the patch.
Best regards,
Etsuro Fujita
Commits
-
Fix bugs in RETURNING in cross-partition UPDATE cases.
- a71cfc56bf60 13.3 landed
- 3fb93103a9fd 12.7 landed
- 27835b547664 11.12 landed
-
postgres_fdw: Clean up handling of system columns.
- da7d44b627ba 9.6.0 cited