OSDN Git Service

fix suppress_redundant_updates_trigger() where relation has Oids, per gripe from...
authorAndrew Dunstan <andrew@dunslane.net>
Wed, 5 Nov 2008 18:49:28 +0000 (18:49 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Wed, 5 Nov 2008 18:49:28 +0000 (18:49 +0000)
src/backend/utils/adt/trigfuncs.c
src/test/regress/expected/triggers.out
src/test/regress/sql/triggers.sql

index 633f3d2..b13bdc3 100644 (file)
@@ -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);
 }
index e1d8f1a..2a5cb90 100644 (file)
@@ -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;
index 3cc42c6..8530030 100644 (file)
@@ -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;
+