postgresql/src
Andres Freund 34263e8e4a Fix ON CONFLICT UPDATE bug breaking AFTER UPDATE triggers.
ExecOnConflictUpdate() passed t_ctid of the to-be-updated tuple to
ExecUpdate(). That's problematic primarily because of two reason: First
and foremost t_ctid could point to a different tuple. Secondly, and
that's what triggered the complaint by Stanislav, t_ctid is changed by
heap_update() to point to the new tuple version.  The behavior of AFTER
UPDATE triggers was therefore broken, with NEW.* and OLD.* tuples
spuriously identical within AFTER UPDATE triggers.

To fix both issues, pass a pointer to t_self of a on-stack HeapTuple
instead.

Fixing this bug lead to one change in regression tests, which previously
failed due to the first issue mentioned above. There's a reasonable
expectation that test fails, as it updates one row repeatedly within one
INSERT ... ON CONFLICT statement. That is only possible if the second
update is triggered via ON CONFLICT ... SET, ON CONFLICT ... WHERE, or
by a WITH CHECK expression, as those are executed after
ExecOnConflictUpdate() does a visibility check. That could easily be
prohibited, but given it's allowed for plain UPDATEs and a rare corner
case, it doesn't seem worthwhile.

Reported-By: Stanislav Grozev
Author: Andres Freund and Peter Geoghegan
Discussion: CAA78GVqy1+LisN-8DygekD_Ldfy=BJLarSpjGhytOsgkpMavfQ@mail.gmail.com
Backpatch: 9.5, where ON CONFLICT was introduced
2015-12-10 16:39:28 +01:00
..
backend Fix ON CONFLICT UPDATE bug breaking AFTER UPDATE triggers. 2015-12-10 16:39:28 +01:00
bin Make failure to open psql's --log-file fatal. 2015-12-08 17:14:46 -05:00
common pgindent run for 9.5 2015-05-23 21:35:49 -04:00
include Fix bug leading to restoring unlogged relations from empty files. 2015-12-10 16:39:25 +01:00
interfaces Use "g" not "f" format in ecpg's PGTYPESnumeric_from_double(). 2015-12-01 11:42:35 -05:00
makefiles Link $(WIN32RES) into single-file modules only when PGFILEDESC is set. 2015-08-05 20:45:21 -04:00
pl Instruct Coverity using an assertion. 2015-12-05 03:04:30 -05:00
port Adopt the GNU convention for handling tar-archive members exceeding 8GB. 2015-11-21 20:21:32 -05:00
template AIX: Test the -qlonglong option before use. 2015-07-17 03:01:29 -04:00
test Fix ON CONFLICT UPDATE bug breaking AFTER UPDATE triggers. 2015-12-10 16:39:28 +01:00
timezone Update time zone data files to tzdata release 2015g. 2015-10-02 19:15:49 -04:00
tools Accept flex > 2.5.x on Windows, too. 2015-12-10 10:19:18 -05:00
tutorial Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Back-patch fixes to make TAP tests work on Windows. 2015-11-17 14:10:24 -05:00
Makefile.shlib AIX: Link TRANSFORM modules with their dependencies. 2015-07-15 21:00:30 -04:00
nls-global.mk Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00