pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix optimization of foreign-key on update actions
2+ messages / 2 participants
[nested] [flat]

* pgsql: Fix optimization of foreign-key on update actions
@ 2019-03-18 16:21  Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Peter Eisentraut @ 2019-03-18 16:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix optimization of foreign-key on update actions

In RI_FKey_pk_upd_check_required(), we check among other things
whether the old and new key are equal, so that we don't need to run
cascade actions when nothing has actually changed.  This was using the
equality operator.  But the effect of this is that if a value in the
primary key is changed to one that "looks" different but compares as
equal, the update is not propagated.  (Examples are float -0 and 0 and
case-insensitive text.)  This appears to violate the SQL standard, and
it also behaves inconsistently if in a multicolumn key another key is
also updated that would cause the row to compare as not equal.

To fix, if we are looking at the PK table in ri_KeysEqual(), then do a
bytewise comparison similar to record_image_eq() instead of using the
equality operators.  This only makes a difference for ON UPDATE
CASCADE, but for consistency we treat all changes to the PK the same.  For
the FK table, we continue to use the equality operators.

Discussion: https://www.postgresql.org/message-id/flat/3326fc2e-bc02-d4c5-e3e5-e54da466e89a@2ndquadrant.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1ffa59a85cb40a61f4523fb03c8960db97eea124

Modified Files
--------------
src/backend/utils/adt/datum.c             | 57 +++++++++++++++++++++++++++++++
src/backend/utils/adt/ri_triggers.c       | 40 +++++++++++++++-------
src/backend/utils/adt/rowtypes.c          | 41 ++--------------------
src/include/utils/datum.h                 |  9 +++++
src/test/regress/expected/foreign_key.out | 34 ++++++++++++++++++
src/test/regress/sql/foreign_key.sql      | 20 +++++++++++
6 files changed, 149 insertions(+), 52 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pgsql: Fix optimization of foreign-key on update actions
@ 2019-08-26 00:06  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Geoghegan @ 2019-08-26 00:06 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; +Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>

On Mon, Mar 18, 2019 at 9:21 AM Peter Eisentraut <peter@eisentraut.org> wrote:
> Fix optimization of foreign-key on update actions

It looks like datum_image_eq() doesn't handle the cstring case (i.e.
the "typLen == -2" case) correctly. I think that it should.

-- 
Peter Geoghegan





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-08-26 00:06 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 16:21 pgsql: Fix optimization of foreign-key on update actions Peter Eisentraut <peter@eisentraut.org>
2019-08-26 00:06 ` Peter Geoghegan <pg@bowt.ie>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox