|
83 | 83 | *
|
84 | 84 | * A word about t_ctid: whenever a new tuple is stored on disk, its t_ctid
|
85 | 85 | * is initialized with its own TID (location). If the tuple is ever updated,
|
86 |
| - * its t_ctid is changed to point to the replacement version of the tuple or |
87 |
| - * the block number (ip_blkid) is invalidated if the tuple is moved from one |
88 |
| - * partition to another partition relation due to an update of the partition |
89 |
| - * key. Thus, a tuple is the latest version of its row iff XMAX is invalid or |
| 86 | + * its t_ctid is changed to point to the replacement version of the tuple. Or |
| 87 | + * if the tuple is moved from one partition to another, due to an update of |
| 88 | + * the partition key, t_ctid is set to a special value to indicate that |
| 89 | + * (see ItemPointerSetMovedPartitions). Thus, a tuple is the latest version |
| 90 | + * of its row iff XMAX is invalid or |
90 | 91 | * t_ctid points to itself (in which case, if XMAX is valid, the tuple is
|
91 | 92 | * either locked or deleted). One can follow the chain of t_ctid links
|
92 |
| - * to find the newest version of the row. Beware however that VACUUM might |
| 93 | + * to find the newest version of the row, unless it was moved to a different |
| 94 | + * partition. Beware however that VACUUM might |
93 | 95 | * erase the pointed-to (newer) tuple before erasing the pointing (older)
|
94 | 96 | * tuple. Hence, when following a t_ctid link, it is necessary to check
|
95 | 97 | * to see if the referenced slot is empty or contains an unrelated tuple.
|
@@ -287,14 +289,6 @@ struct HeapTupleHeaderData
|
287 | 289 | */
|
288 | 290 | #define HEAP_TUPLE_HAS_MATCH HEAP_ONLY_TUPLE /* tuple has a join match */
|
289 | 291 |
|
290 |
| -/* |
291 |
| - * Special value used in t_ctid.ip_posid, to indicate that it holds a |
292 |
| - * speculative insertion token rather than a real TID. This must be higher |
293 |
| - * than MaxOffsetNumber, so that it can be distinguished from a valid |
294 |
| - * offset number in a regular item pointer. |
295 |
| - */ |
296 |
| -#define SpecTokenOffsetNumber 0xfffe |
297 |
| - |
298 | 292 | /*
|
299 | 293 | * HeapTupleHeader accessor macros
|
300 | 294 | *
|
@@ -447,11 +441,12 @@ do { \
|
447 | 441 | ItemPointerSet(&(tup)->t_ctid, token, SpecTokenOffsetNumber) \
|
448 | 442 | )
|
449 | 443 |
|
450 |
| -#define HeapTupleHeaderSetMovedPartitions(tup) \ |
451 |
| - ItemPointerSetMovedPartitions(&(tup)->t_ctid) |
452 |
| - |
453 | 444 | #define HeapTupleHeaderIndicatesMovedPartitions(tup) \
|
454 |
| - ItemPointerIndicatesMovedPartitions(&tup->t_ctid) |
| 445 | + (ItemPointerGetOffsetNumber(&(tup)->t_ctid) == MovedPartitionsOffsetNumber && \ |
| 446 | + ItemPointerGetBlockNumberNoCheck(&(tup)->t_ctid) == MovedPartitionsBlockNumber) |
| 447 | + |
| 448 | +#define HeapTupleHeaderSetMovedPartitions(tup) \ |
| 449 | + ItemPointerSet(&(tup)->t_ctid, MovedPartitionsBlockNumber, MovedPartitionsOffsetNumber) |
455 | 450 |
|
456 | 451 | #define HeapTupleHeaderGetDatumLength(tup) \
|
457 | 452 | VARSIZE(tup)
|
|
0 commit comments