mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Improve representation of 'moved partitions' indicator on deleted tuples.
Previously a tuple that has been moved to a different partition (see
f16241bef7), set the block number on the old tuple to an invalid
value to indicate that fact. But the tuple offset was left
untouched. That turned out to trigger a wal_consistency_checking
failure as reported by Peter Geoghegan, as the offset wasn't
always overwritten during WAL replay.
Heikki observed that we're wasting valuable data by not putting
information also in the offset. Thus set that to
MovedPartitionsOffsetNumber when a tuple indicates it has moved.
We continue to set the block number to MovedPartitionsBlockNumber, as
that seems more likely to cause problems for code not updated to know
about moved tuples.
As t_ctid's offset number is now always set, this refinement also
fixes the wal_consistency_checking issue.
This technically is a minor disk format break, with previously created
moved tuples not being recognized anymore. But since there not even
has been a beta release since f16241bef7c...
Reported-By: Peter Geoghegan
Author: Heikki Linnakangas, Amul Sul
Discussion: https://postgr.es/m/CAH2-Wzm9ty+1BX7-GMNJ=xPRg67oJTVeDNdA9LSyJJtMgRiCMA@mail.gmail.com
This commit is contained in:
@@ -48,6 +48,28 @@ ItemPointerData;
|
||||
|
||||
typedef ItemPointerData *ItemPointer;
|
||||
|
||||
/* ----------------
|
||||
* special values used in heap tuples (t_ctid)
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* If a heap tuple holds a speculative insertion token rather than a real
|
||||
* TID, ip_posid is set to SpecTokenOffsetNumber, and the token is stored in
|
||||
* ip_blkid. SpecTokenOffsetNumber must be higher than MaxOffsetNumber, so
|
||||
* that it can be distinguished from a valid offset number in a regular item
|
||||
* pointer.
|
||||
*/
|
||||
#define SpecTokenOffsetNumber 0xfffe
|
||||
|
||||
/*
|
||||
* When a tuple is moved to a different partition by UPDATE, the t_ctid of
|
||||
* the old tuple version is set to this magic value.
|
||||
*/
|
||||
#define MovedPartitionsOffsetNumber 0xfffd
|
||||
#define MovedPartitionsBlockNumber InvalidBlockNumber
|
||||
|
||||
|
||||
/* ----------------
|
||||
* support macros
|
||||
* ----------------
|
||||
@@ -160,7 +182,10 @@ typedef ItemPointerData *ItemPointer;
|
||||
* partition.
|
||||
*/
|
||||
#define ItemPointerIndicatesMovedPartitions(pointer) \
|
||||
!BlockNumberIsValid(ItemPointerGetBlockNumberNoCheck(pointer))
|
||||
( \
|
||||
ItemPointerGetOffsetNumber(pointer) == MovedPartitionsOffsetNumber && \
|
||||
ItemPointerGetBlockNumberNoCheck(pointer) == MovedPartitionsBlockNumber \
|
||||
)
|
||||
|
||||
/*
|
||||
* ItemPointerSetMovedPartitions
|
||||
@@ -168,7 +193,7 @@ typedef ItemPointerData *ItemPointer;
|
||||
* different partition.
|
||||
*/
|
||||
#define ItemPointerSetMovedPartitions(pointer) \
|
||||
ItemPointerSetBlockNumber((pointer), InvalidBlockNumber)
|
||||
ItemPointerSet((pointer), MovedPartitionsBlockNumber, MovedPartitionsOffsetNumber)
|
||||
|
||||
/* ----------------
|
||||
* externs
|
||||
|
||||
Reference in New Issue
Block a user