Commit b65ebc7e authored by Andrew Dunstan's avatar Andrew Dunstan

fix suppress_redundant_updates_trigger() where relation has Oids, per gripe from KaiGai Kohei

parent e2a277bd
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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) ...@@ -62,6 +62,12 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
newheader = newtuple->t_data; newheader = newtuple->t_data;
oldheader = oldtuple->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 the tuple payload is the same ... */
if (newtuple->t_len == oldtuple->t_len && if (newtuple->t_len == oldtuple->t_len &&
newheader->t_hoff == oldheader->t_hoff && newheader->t_hoff == oldheader->t_hoff &&
...@@ -77,5 +83,6 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS) ...@@ -77,5 +83,6 @@ suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
rettuple = NULL; rettuple = NULL;
} }
return PointerGetDatum(rettuple); return PointerGetDatum(rettuple);
} }
...@@ -542,10 +542,18 @@ CREATE TABLE min_updates_test ( ...@@ -542,10 +542,18 @@ CREATE TABLE min_updates_test (
f1 text, f1 text,
f2 int, f2 int,
f3 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 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 CREATE TRIGGER z_min_update
BEFORE UPDATE ON min_updates_test BEFORE UPDATE ON min_updates_test
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger(); 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 \set QUIET false
UPDATE min_updates_test SET f1 = f1; UPDATE min_updates_test SET f1 = f1;
UPDATE 0 UPDATE 0
...@@ -553,6 +561,12 @@ UPDATE min_updates_test SET f2 = f2 + 1; ...@@ -553,6 +561,12 @@ UPDATE min_updates_test SET f2 = f2 + 1;
UPDATE 2 UPDATE 2
UPDATE min_updates_test SET f3 = 2 WHERE f3 is null; UPDATE min_updates_test SET f3 = 2 WHERE f3 is null;
UPDATE 1 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 \set QUIET true
SELECT * FROM min_updates_test; SELECT * FROM min_updates_test;
f1 | f2 | f3 f1 | f2 | f3
...@@ -561,4 +575,12 @@ SELECT * FROM min_updates_test; ...@@ -561,4 +575,12 @@ SELECT * FROM min_updates_test;
b | 3 | 2 b | 3 | 2
(2 rows) (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;
DROP TABLE min_updates_test_oids;
...@@ -424,12 +424,23 @@ CREATE TABLE min_updates_test ( ...@@ -424,12 +424,23 @@ CREATE TABLE min_updates_test (
f2 int, f2 int,
f3 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 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 CREATE TRIGGER z_min_update
BEFORE UPDATE ON min_updates_test BEFORE UPDATE ON min_updates_test
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger(); 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 \set QUIET false
UPDATE min_updates_test SET f1 = f1; UPDATE min_updates_test SET f1 = f1;
...@@ -438,9 +449,19 @@ UPDATE min_updates_test SET f2 = f2 + 1; ...@@ -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 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 \set QUIET true
SELECT * FROM min_updates_test; SELECT * FROM min_updates_test;
SELECT * FROM min_updates_test_oids;
DROP TABLE min_updates_test; DROP TABLE min_updates_test;
DROP TABLE min_updates_test_oids;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment