Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 040a1df

Browse files
committed
Correctly set t_self for heap tuples in expand_tuple
Commit 16828d5 incorrectly set an invalid pointer for t_self for heap tuples. This patch correctly copies it from the source tuple, and includes a regression test that relies on it being set correctly. Backpatch to release 11. Fixes bug #15448 reported by Tillmann Schulz Diagnosis and test case by Amit Langote
1 parent 5ef037c commit 040a1df

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/backend/access/common/heaptuple.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
856856
= (HeapTupleHeader) ((char *) *targetHeapTuple + HEAPTUPLESIZE);
857857
(*targetHeapTuple)->t_len = len;
858858
(*targetHeapTuple)->t_tableOid = sourceTuple->t_tableOid;
859-
ItemPointerSetInvalid(&((*targetHeapTuple)->t_self));
859+
(*targetHeapTuple)->t_self = sourceTuple->t_self;
860860

861861
targetTHeader->t_infomask = sourceTHeader->t_infomask;
862862
targetTHeader->t_hoff = hoff;

src/test/regress/expected/fast_default.out

+10
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,17 @@ SELECT * FROM t;
727727
(1 row)
728728

729729
DROP TABLE t;
730+
-- make sure expanded tuple has correct self pointer
731+
-- it will be required by the RI tigger doing the cascading delete
732+
CREATE TABLE leader (a int PRIMARY KEY, b int);
733+
CREATE TABLE follower (a int REFERENCES leader ON DELETE CASCADE, b int);
734+
INSERT INTO leader VALUES (1, 1), (2, 2);
735+
ALTER TABLE leader ADD c int;
736+
ALTER TABLE leader DROP c;
737+
DELETE FROM leader;
730738
-- cleanup
739+
DROP TABLE follower;
740+
DROP TABLE leader;
731741
DROP FUNCTION test_trigger();
732742
DROP TABLE t1;
733743
DROP FUNCTION set(name);

src/test/regress/sql/fast_default.sql

+12
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,19 @@ UPDATE t SET y = 2;
471471
SELECT * FROM t;
472472
DROP TABLE t;
473473

474+
-- make sure expanded tuple has correct self pointer
475+
-- it will be required by the RI tigger doing the cascading delete
476+
477+
CREATE TABLE leader (a int PRIMARY KEY, b int);
478+
CREATE TABLE follower (a int REFERENCES leader ON DELETE CASCADE, b int);
479+
INSERT INTO leader VALUES (1, 1), (2, 2);
480+
ALTER TABLE leader ADD c int;
481+
ALTER TABLE leader DROP c;
482+
DELETE FROM leader;
483+
474484
-- cleanup
485+
DROP TABLE follower;
486+
DROP TABLE leader;
475487
DROP FUNCTION test_trigger();
476488
DROP TABLE t1;
477489
DROP FUNCTION set(name);

0 commit comments

Comments
 (0)