Skip to content

Commit b65ebc7

Browse files
committed
fix suppress_redundant_updates_trigger() where relation has Oids, per gripe from KaiGai Kohei
1 parent e2a277b commit b65ebc7

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/backend/utils/adt/trigfuncs.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.2 2008/11/04 00:29:39 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.3 2008/11/05 18:49:27 adunstan Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -62,6 +62,12 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
6262
newheader = newtuple->t_data;
6363
oldheader = oldtuple->t_data;
6464

65+
if (oldheader->t_infomask & HEAP_HASOID)
66+
{
67+
Oid oldoid = HeapTupleHeaderGetOid(oldheader);
68+
HeapTupleHeaderSetOid(newheader, oldoid);
69+
}
70+
6571
/* if the tuple payload is the same ... */
6672
if (newtuple->t_len == oldtuple->t_len &&
6773
newheader->t_hoff == oldheader->t_hoff &&
@@ -77,5 +83,6 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
7783
rettuple = NULL;
7884
}
7985

86+
8087
return PointerGetDatum(rettuple);
8188
}

src/test/regress/expected/triggers.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,31 @@ CREATE TABLE min_updates_test (
542542
f1 text,
543543
f2 int,
544544
f3 int);
545+
CREATE TABLE min_updates_test_oids (
546+
f1 text,
547+
f2 int,
548+
f3 int) WITH OIDS;
545549
INSERT INTO min_updates_test VALUES ('a',1,2),('b','2',null);
550+
INSERT INTO min_updates_test_oids VALUES ('a',1,2),('b','2',null);
546551
CREATE TRIGGER z_min_update
547552
BEFORE UPDATE ON min_updates_test
548553
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
554+
CREATE TRIGGER z_min_update
555+
BEFORE UPDATE ON min_updates_test_oids
556+
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
549557
\set QUIET false
550558
UPDATE min_updates_test SET f1 = f1;
551559
UPDATE 0
552560
UPDATE min_updates_test SET f2 = f2 + 1;
553561
UPDATE 2
554562
UPDATE min_updates_test SET f3 = 2 WHERE f3 is null;
555563
UPDATE 1
564+
UPDATE min_updates_test_oids SET f1 = f1;
565+
UPDATE 0
566+
UPDATE min_updates_test_oids SET f2 = f2 + 1;
567+
UPDATE 2
568+
UPDATE min_updates_test_oids SET f3 = 2 WHERE f3 is null;
569+
UPDATE 1
556570
\set QUIET true
557571
SELECT * FROM min_updates_test;
558572
f1 | f2 | f3
@@ -561,4 +575,12 @@ SELECT * FROM min_updates_test;
561575
b | 3 | 2
562576
(2 rows)
563577

578+
SELECT * FROM min_updates_test_oids;
579+
f1 | f2 | f3
580+
----+----+----
581+
a | 2 | 2
582+
b | 3 | 2
583+
(2 rows)
584+
564585
DROP TABLE min_updates_test;
586+
DROP TABLE min_updates_test_oids;

src/test/regress/sql/triggers.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,23 @@ CREATE TABLE min_updates_test (
424424
f2 int,
425425
f3 int);
426426

427+
CREATE TABLE min_updates_test_oids (
428+
f1 text,
429+
f2 int,
430+
f3 int) WITH OIDS;
431+
427432
INSERT INTO min_updates_test VALUES ('a',1,2),('b','2',null);
428433

434+
INSERT INTO min_updates_test_oids VALUES ('a',1,2),('b','2',null);
435+
429436
CREATE TRIGGER z_min_update
430437
BEFORE UPDATE ON min_updates_test
431438
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
432439

440+
CREATE TRIGGER z_min_update
441+
BEFORE UPDATE ON min_updates_test_oids
442+
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
443+
433444
\set QUIET false
434445

435446
UPDATE min_updates_test SET f1 = f1;
@@ -438,9 +449,19 @@ UPDATE min_updates_test SET f2 = f2 + 1;
438449

439450
UPDATE min_updates_test SET f3 = 2 WHERE f3 is null;
440451

452+
UPDATE min_updates_test_oids SET f1 = f1;
453+
454+
UPDATE min_updates_test_oids SET f2 = f2 + 1;
455+
456+
UPDATE min_updates_test_oids SET f3 = 2 WHERE f3 is null;
457+
441458
\set QUIET true
442459

443460
SELECT * FROM min_updates_test;
444461

462+
SELECT * FROM min_updates_test_oids;
463+
445464
DROP TABLE min_updates_test;
446465

466+
DROP TABLE min_updates_test_oids;
467+

0 commit comments

Comments
 (0)