From b65ebc7e8b7268c062338575f4b98ba4474742d2 Mon Sep 17 00:00:00 2001
From: Andrew Dunstan <andrew@dunslane.net>
Date: Wed, 5 Nov 2008 18:49:28 +0000
Subject: [PATCH] fix suppress_redundant_updates_trigger() where relation has
 Oids, per gripe from KaiGai Kohei

---
 src/backend/utils/adt/trigfuncs.c      |  9 ++++++++-
 src/test/regress/expected/triggers.out | 22 ++++++++++++++++++++++
 src/test/regress/sql/triggers.sql      | 21 +++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/trigfuncs.c b/src/backend/utils/adt/trigfuncs.c
index 633f3d20dc5..b13bdc36e14 100644
--- a/src/backend/utils/adt/trigfuncs.c
+++ b/src/backend/utils/adt/trigfuncs.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.2 2008/11/04 00:29:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.3 2008/11/05 18:49:27 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -62,6 +62,12 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
 	newheader = newtuple->t_data;
 	oldheader = oldtuple->t_data;
 
+ 	if (oldheader->t_infomask & HEAP_HASOID)
+	{
+		Oid oldoid = HeapTupleHeaderGetOid(oldheader);
+		HeapTupleHeaderSetOid(newheader, oldoid);
+	}
+
 	/* if the tuple payload is the same ... */
     if (newtuple->t_len == oldtuple->t_len &&
 		newheader->t_hoff == oldheader->t_hoff &&
@@ -77,5 +83,6 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
 		rettuple = NULL;
 	}
 	
+	
     return PointerGetDatum(rettuple);
 }
diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out
index e1d8f1af319..2a5cb909d70 100644
--- a/src/test/regress/expected/triggers.out
+++ b/src/test/regress/expected/triggers.out
@@ -542,10 +542,18 @@ CREATE TABLE min_updates_test (
 	f1	text,
 	f2 int,
 	f3 int);
+CREATE TABLE min_updates_test_oids (
+	f1	text,
+	f2 int,
+	f3 int) WITH OIDS;
 INSERT INTO min_updates_test VALUES ('a',1,2),('b','2',null);
+INSERT INTO min_updates_test_oids VALUES ('a',1,2),('b','2',null);
 CREATE TRIGGER z_min_update 
 BEFORE UPDATE ON min_updates_test
 FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
+CREATE TRIGGER z_min_update 
+BEFORE UPDATE ON min_updates_test_oids
+FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
 \set QUIET false
 UPDATE min_updates_test SET f1 = f1;
 UPDATE 0
@@ -553,6 +561,12 @@ UPDATE min_updates_test SET f2 = f2 + 1;
 UPDATE 2
 UPDATE min_updates_test SET f3 = 2 WHERE f3 is null;
 UPDATE 1
+UPDATE min_updates_test_oids SET f1 = f1;
+UPDATE 0
+UPDATE min_updates_test_oids SET f2 = f2 + 1;
+UPDATE 2
+UPDATE min_updates_test_oids SET f3 = 2 WHERE f3 is null;
+UPDATE 1
 \set QUIET true
 SELECT * FROM min_updates_test;
  f1 | f2 | f3 
@@ -561,4 +575,12 @@ SELECT * FROM min_updates_test;
  b  |  3 |  2
 (2 rows)
 
+SELECT * FROM min_updates_test_oids;
+ f1 | f2 | f3 
+----+----+----
+ a  |  2 |  2
+ b  |  3 |  2
+(2 rows)
+
 DROP TABLE min_updates_test;
+DROP TABLE min_updates_test_oids;
diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql
index 3cc42c6cb69..8530030ef8b 100644
--- a/src/test/regress/sql/triggers.sql
+++ b/src/test/regress/sql/triggers.sql
@@ -424,12 +424,23 @@ CREATE TABLE min_updates_test (
 	f2 int,
 	f3 int);
 
+CREATE TABLE min_updates_test_oids (
+	f1	text,
+	f2 int,
+	f3 int) WITH OIDS;
+
 INSERT INTO min_updates_test VALUES ('a',1,2),('b','2',null);
 
+INSERT INTO min_updates_test_oids VALUES ('a',1,2),('b','2',null);
+
 CREATE TRIGGER z_min_update 
 BEFORE UPDATE ON min_updates_test
 FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
 
+CREATE TRIGGER z_min_update 
+BEFORE UPDATE ON min_updates_test_oids
+FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
+
 \set QUIET false
 
 UPDATE min_updates_test SET f1 = f1;
@@ -438,9 +449,19 @@ UPDATE min_updates_test SET f2 = f2 + 1;
 
 UPDATE min_updates_test SET f3 = 2 WHERE f3 is null;
 
+UPDATE min_updates_test_oids SET f1 = f1;
+
+UPDATE min_updates_test_oids SET f2 = f2 + 1;
+
+UPDATE min_updates_test_oids SET f3 = 2 WHERE f3 is null;
+
 \set QUIET true
 
 SELECT * FROM min_updates_test;
 
+SELECT * FROM min_updates_test_oids;
+
 DROP TABLE min_updates_test;
 
+DROP TABLE min_updates_test_oids;
+
-- 
GitLab