postgresql/src/backend
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
..
access Fix bug leading to restoring unlogged relations from empty files. 2015-12-10 16:39:25 +01:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Fix handling of inherited check constraints in ALTER COLUMN TYPE (again). 2015-11-20 14:55:28 -05:00
commands Fix handling of inherited check constraints in ALTER COLUMN TYPE (again). 2015-11-20 14:55:28 -05:00
executor Fix ON CONFLICT UPDATE bug breaking AFTER UPDATE triggers. 2015-12-10 16:39:28 +01:00
foreign Code review for foreign/custom join pushdown patch. 2015-05-10 14:36:36 -04:00
lib Avoid use of float arithmetic in bipartite_match.c. 2015-08-23 13:02:19 -04:00
libpq Message improvements 2015-11-16 21:16:42 -05:00
main Revoke support for strxfrm() that write past the specified array length. 2015-07-08 20:44:25 -04:00
nodes Simplify LATERAL-related calculations within add_paths_to_joinrel(). 2015-12-09 18:54:25 -05:00
optimizer Simplify LATERAL-related calculations within add_paths_to_joinrel(). 2015-12-09 18:54:25 -05:00
parser Message improvements 2015-11-16 21:16:42 -05:00
po Translation updates 2015-11-09 10:21:11 -05:00
port On Windows, ensure shared memory handle gets closed if not being used. 2015-10-13 11:21:33 -04:00
postmaster Message improvements 2015-11-16 21:16:42 -05:00
regex Fix enforcement of restrictions inside regexp lookaround constraints. 2015-11-07 12:43:24 -05:00
replication Adopt the GNU convention for handling tar-archive members exceeding 8GB. 2015-11-21 20:21:32 -05:00
rewrite Apply SELECT policies in INSERT/UPDATE+RETURNING 2015-10-05 07:55:11 -04:00
snowball Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
storage Fix bug leading to restoring unlogged relations from empty files. 2015-12-10 16:39:25 +01:00
tcop Message style improvements 2015-10-28 20:23:53 -04:00
tsearch pgindent run for 9.5 2015-05-23 21:35:49 -04:00
utils Make gincostestimate() cope with hypothetical GIN indexes. 2015-12-01 16:24:34 -05:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile AIX: Link the postgres executable with -Wl,-brtllib. 2015-07-15 21:00:30 -04:00
nls.mk Translation updates 2015-02-01 23:23:40 -05:00