From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Fix ON CONFLICT UPDATE bug breaking AFTER UPDATE triggers. |
Date: | 2015-12-10 15:50:20 |
Message-ID: | E1a73U4-0002ya-Td@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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(at)mail(dot)gmail(dot)com
Backpatch: 9.5, where ON CONFLICT was introduced
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/84ac126ee728ede5b6370d60dd2b1c299f49ed2f
Modified Files
--------------
src/backend/executor/nodeModifyTable.c | 11 ++++++++++-
src/test/regress/expected/triggers.out | 8 ++++----
src/test/regress/expected/with.out | 10 +++++++---
src/test/regress/sql/triggers.sql | 2 +-
src/test/regress/sql/with.sql | 5 +++--
5 files changed, 25 insertions(+), 11 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2015-12-10 15:50:23 | pgsql: Fix ON CONFLICT UPDATE bug breaking AFTER UPDATE triggers. |
Previous Message | Tom Lane | 2015-12-10 15:19:57 | pgsql: Accept flex > 2.5.x on Windows, too. |