Skip to content

Commit 372102b

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 374fe86 commit 372102b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
893893
= (HeapTupleHeader) ((char *) *targetHeapTuple + HEAPTUPLESIZE);
894894
(*targetHeapTuple)->t_len = len;
895895
(*targetHeapTuple)->t_tableOid = sourceTuple->t_tableOid;
896-
ItemPointerSetInvalid(&((*targetHeapTuple)->t_self));
896+
(*targetHeapTuple)->t_self = sourceTuple->t_self;
897897

898898
targetTHeader->t_infomask = sourceTHeader->t_infomask;
899899
targetTHeader->t_hoff = hoff;

src/test/regress/expected/fast_default.out

Lines changed: 10 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy