1/*-------------------------------------------------------------------------
4 * Support functions to rewrite tables.
6 * These functions provide a facility to completely rewrite a heap, while
7 * preserving visibility information and update chains.
11 * The caller is responsible for creating the new heap, all catalog
12 * changes, supplying the tuples to be written to the new heap, and
13 * rebuilding indexes. The caller must hold AccessExclusiveLock on the
14 * target table, because we assume no one else is writing into it.
16 * To use the facility:
19 * while (fetch next tuple)
22 * rewrite_heap_dead_tuple
25 * // do any transformations here if required
31 * The contents of the new relation shouldn't be relied on until after
32 * end_heap_rewrite is called.
37 * This would be a fairly trivial affair, except that we need to maintain
38 * the ctid chains that link versions of an updated tuple together.
39 * Since the newly stored tuples will have tids different from the original
40 * ones, if we just copied t_ctid fields to the new table the links would
41 * be wrong. When we are required to copy a (presumably recently-dead or
42 * delete-in-progress) tuple whose ctid doesn't point to itself, we have
43 * to substitute the correct ctid instead.
45 * For each ctid reference from A -> B, we might encounter either A first
46 * or B first. (Note that a tuple in the middle of a chain is both A and B
47 * of different pairs.)
49 * If we encounter A first, we'll store the tuple in the unresolved_tups
50 * hash table. When we later encounter B, we remove A from the hash table,
51 * fix the ctid to point to the new location of B, and insert both A and B
54 * If we encounter B first, we can insert B to the new heap right away.
55 * We then add an entry to the old_new_tid_map hash table showing B's
56 * original tid (in the old heap) and new tid (in the new heap).
57 * When we later encounter A, we get the new location of B from the table,
58 * and can write A immediately with the correct ctid.
60 * Entries in the hash tables can be removed as soon as the later tuple
61 * is encountered. That helps to keep the memory usage down. At the end,
62 * both tables are usually empty; we should have encountered both A and B
63 * of each pair. However, it's possible for A to be RECENTLY_DEAD and B
64 * entirely DEAD according to HeapTupleSatisfiesVacuum, because the test
65 * for deadness using OldestXmin is not exact. In such a case we might
66 * encounter B first, and skip it, and find A later. Then A would be added
67 * to unresolved_tups, and stay there until end of the rewrite. Since
68 * this case is very unusual, we don't worry about the memory usage.
70 * Using in-memory hash tables means that we use some memory for each live
71 * update chain in the table, from the time we find one end of the
72 * reference until we find the other end. That shouldn't be a problem in
73 * practice, but if you do something like an UPDATE without a where-clause
74 * on a large table, and then run CLUSTER in the same transaction, you
75 * could run out of memory. It doesn't seem worthwhile to add support for
76 * spill-to-disk, as there shouldn't be that many RECENTLY_DEAD tuples in a
77 * table under normal circumstances. Furthermore, in the typical scenario
78 * of CLUSTERing on an unchanging key column, we'll see all the versions
79 * of a given tuple together anyway, and so the peak memory usage is only
80 * proportional to the number of RECENTLY_DEAD versions of a single row, not
81 * in the whole table. Note that if we do fail halfway through a CLUSTER,
82 * the old table is still valid, so failure is not catastrophic.
84 * We can't use the normal heap_insert function to insert into the new
85 * heap, because heap_insert overwrites the visibility information.
86 * We use a special-purpose raw_heap_insert function instead, which
87 * is optimized for bulk inserting a lot of tuples, knowing that we have
88 * exclusive access to the heap. raw_heap_insert builds new pages in
89 * local storage. When a page is full, or at the end of the process,
90 * we insert it to WAL as a single record and then write it to disk with
91 * the bulk smgr writer. Note, however, that any data sent to the new
92 * heap's TOAST table will go through the normal bufmgr.
95 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
96 * Portions Copyright (c) 1994-5, Regents of the University of California
99 * src/backend/access/heap/rewriteheap.c
101 *-------------------------------------------------------------------------
127 * State associated with a rewrite operation. This is opaque to the user
128 * of the rewrite facility.
139 * tuple visibility */
143 * for logical rewrites */
145 * point for multixacts */
156 * The lookup keys for the hash tables are tuple TID and xmin (we must check
157 * both to avoid false matches from dead tuples). Beware that there is
158 * probably some padding space in this struct; it must be zeroed out for
159 * correct hashtable operation.
168 * Entry structures for the hash tables
188 * In-Memory data for an xid that might need logical remapping entries
194 int vfd;
/* fd of mappings file */
195 off_t
off;
/* how far have we written yet */
201 * A single In-Memory logical rewrite mapping, hanging off
202 * RewriteMappingFile->mappings.
212/* prototypes for internal functions */
215/* internal logical remapping prototypes */
222 * Begin a rewrite of a table
224 * old_heap old, locked heap relation tuples will be read from
225 * new_heap new, locked heap relation to insert tuples to
226 * oldest_xmin xid used by the caller to determine which tuples are dead
227 * freeze_xid xid before which tuples will be frozen
228 * cutoff_multi multixact before which multis will be removed
230 * Returns an opaque RewriteState, allocated in current memory context,
231 * to be used in subsequent calls to the other functions.
243 * To ease cleanup, make a separate context that will contain the
244 * RewriteState struct itself plus all subsidiary data.
251 /* Create and fill in the state struct */
254 state->rs_old_rel = old_heap;
255 state->rs_new_rel = new_heap;
256 state->rs_buffer = NULL;
257 /* new_heap needn't be empty, just locked */
259 state->rs_oldest_xmin = oldest_xmin;
260 state->rs_freeze_xid = freeze_xid;
261 state->rs_cutoff_multi = cutoff_multi;
262 state->rs_cxt = rw_cxt;
265 /* Initialize hash tables used to track update chains */
270 state->rs_unresolved_tups =
272 128,
/* arbitrary initial size */
278 state->rs_old_new_tid_map =
280 128,
/* arbitrary initial size */
294 * state and any other resources are freed.
303 * Write any remaining tuples in the UnresolvedTups table. If we have any
304 * left, they should in fact be dead, but let's err on the safe side.
314 /* Write the last page, if any */
315 if (
state->rs_buffer)
318 state->rs_buffer = NULL;
325 /* Deleting the context frees everything */
330 * Add a tuple to the new heap.
332 * Visibility information is copied from the original tuple, except that
333 * we "freeze" very-old tuples. Note that since we scribble on new_tuple,
334 * it had better be temp storage not a pointer to the original tuple.
336 * state opaque state as returned by begin_heap_rewrite
337 * old_tuple original tuple in the old heap
338 * new_tuple new, rewritten tuple to be inserted to new heap
353 * Copy the original tuple's visibility information into new_tuple.
355 * XXX we might later need to copy some t_infomask2 bits, too? Right now,
356 * we intentionally clear the HOT status bits.
368 * While we have our hands on the tuple, we may as well freeze any
369 * eligible xmin or xmax, so that future VACUUM effort can be saved.
372 state->rs_old_rel->rd_rel->relfrozenxid,
373 state->rs_old_rel->rd_rel->relminmxid,
374 state->rs_freeze_xid,
375 state->rs_cutoff_multi);
378 * Invalid ctid means that ctid should point to the tuple itself. We'll
379 * override it later if the tuple is part of an update chain.
384 * If the tuple has been updated, check the old-to-new mapping hash table.
394 memset(&hashkey, 0,
sizeof(hashkey));
405 * We've already copied the tuple that t_ctid points to, so we can
406 * set the ctid of this tuple to point to the new location, and
407 * insert it right away.
411 /* We don't need the mapping entry anymore */
419 * We haven't seen the tuple t_ctid points to yet. Stash this
420 * tuple into unresolved_tups to be written later.
432 * We can't do anything more now, since we don't know where the
433 * tuple will be written.
441 * Now we will write the tuple, and then check to see if it is the B tuple
442 * in any new or known pair. When we resolve a known pair, we will be
443 * able to write that pair's A tuple, and then we have to check if it
444 * resolves some other pair. Hence, we need a loop here.
446 old_tid = old_tuple->
t_self;
453 /* Insert the tuple and find out where it's put in new_heap */
455 new_tid = new_tuple->
t_self;
460 * If the tuple is the updated version of a row, and the prior version
461 * wouldn't be DEAD yet, then we need to either resolve the prior
462 * version (if it's waiting in rs_unresolved_tups), or make an entry
463 * in rs_old_new_tid_map (so we can resolve it when we do see it). The
464 * previous tuple's xmax would equal this one's xmin, so it's
465 * RECENTLY_DEAD if and only if the xmin is not before OldestXmin.
469 state->rs_oldest_xmin))
472 * Okay, this is B in an update pair. See if we've seen A.
476 memset(&hashkey, 0,
sizeof(hashkey));
478 hashkey.
tid = old_tid;
483 if (unresolved != NULL)
486 * We have seen and memorized the previous tuple already. Now
487 * that we know where we inserted the tuple its t_ctid points
488 * to, fix its t_ctid and insert it to the new heap.
492 new_tuple = unresolved->
tuple;
498 * We don't need the hash entry anymore, but don't free its
505 /* loop back to insert the previous tuple in the chain */
511 * Remember the new tid of this tuple. We'll use it to set the
512 * ctid when we find the previous tuple in the chain.
524 /* Done with this (chain of) tuples, for now */
534 * Register a dead tuple with an ongoing rewrite. Dead tuples are not
535 * copied to the new table, but we still make note of them so that we
536 * can release some resources earlier.
538 * Returns true if a tuple was removed from the unresolved_tups table.
539 * This indicates that that tuple, previously thought to be "recently dead",
540 * is now known really dead and won't be written to the output.
546 * If we have already seen an earlier tuple in the update chain that
547 * points to this tuple, let's forget about that earlier tuple. It's in
548 * fact dead as well, our simple xmax < OldestXmin test in
549 * HeapTupleSatisfiesVacuum just wasn't enough to detect it. It happens
550 * when xmin of a tuple is greater than xmax, which sounds
551 * counter-intuitive but is perfectly valid.
553 * We don't bother to try to detect the situation the other way round,
554 * when we encounter the dead tuple first and then the recently dead one
555 * that points to it. If that happens, we'll have some unmatched entries
556 * in the UnresolvedTups hash table at the end. That can happen anyway,
557 * because a vacuum might have removed the dead tuple in the chain before
564 memset(&hashkey, 0,
sizeof(hashkey));
571 if (unresolved != NULL)
573 /* Need to free the contained tuple as well as the hashtable entry */
585 * Insert a tuple to the new relation. This has to track heap_insert
586 * and its subsidiary functions!
588 * t_self of the tuple is set to the new TID of the tuple. If t_ctid of the
589 * tuple is invalid on entry, it's replaced with the new TID as well (in
590 * the inserted data only, not in the caller's copy).
603 * If the new tuple is too big for storage or contains already toasted
604 * out-of-line attributes from some other relation, invoke the toaster.
606 * Note: below this point, heaptup is the data we actually intend to store
607 * into the relation; tup is the caller's original untoasted data.
609 if (
state->rs_new_rel->rd_rel->relkind == RELKIND_TOASTVALUE)
611 /* toast table entries should never be recursively toasted */
620 * While rewriting the heap for VACUUM FULL / CLUSTER, make sure data
621 * for the TOAST table are not logically decoded. The main heap is
622 * WAL-logged as XLOG FPI records, which are not logically decoded.
635 * If we're gonna fail for oversize tuple, do it right away
639 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
640 errmsg(
"row is too big: size %zu, maximum size %zu",
643 /* Compute desired extra freespace due to fillfactor option */
647 /* Now we can check to see if there's enough free space already. */
653 if (
len + saveFreeSpace > pageFreeSpace)
656 * Doesn't fit, so write out the existing page. It always
657 * contains a tuple. Hence, unlike RelationGetBufferForTuple(),
658 * enforce saveFreeSpace unconditionally.
661 state->rs_buffer = NULL;
669 /* Initialize a new empty page */
675 /* And now we can insert the tuple into the page */
681 /* Update caller's t_self to the actual position where it was stored */
685 * Insert the correct position into CTID of the stored tuple, too, if the
686 * caller didn't supply a valid CTID.
699 /* If heaptup is a private copy, release it. */
704/* ------------------------------------------------------------------------
705 * Logical rewrite support
707 * When doing logical decoding - which relies on using cmin/cmax of catalog
708 * tuples, via xl_heap_new_cid records - heap rewrites have to log enough
709 * information to allow the decoding backend to update its internal mapping
710 * of (relfilelocator,ctid) => (cmin, cmax) to be correct for the rewritten heap.
712 * For that, every time we find a tuple that's been modified in a catalog
713 * relation within the xmin horizon of any decoding slot, we log a mapping
714 * from the old to the new location.
716 * To deal with rewrites that abort the filename of a mapping file contains
717 * the xid of the transaction performing the rewrite, which then can be
718 * checked before being read in.
720 * For efficiency we don't immediately spill every single map mapping for a
721 * row to disk but only do so in batches when we've collected several of them
722 * in memory or when end_heap_rewrite() has been called.
724 * Crash-Safety: This module diverts from the usual patterns of doing WAL
725 * since it cannot rely on checkpoint flushing out all buffers and thus
726 * waiting for exclusive locks on buffers. Usually the XLogInsert() covering
727 * buffer modifications is performed while the buffer(s) that are being
728 * modified are exclusively locked guaranteeing that both the WAL record and
729 * the modified heap are on either side of the checkpoint. But since the
730 * mapping files we log aren't in shared_buffers that interlock doesn't work.
732 * Instead we simply write the mapping files out to disk, *before* the
733 * XLogInsert() is performed. That guarantees that either the XLogInsert() is
734 * inserted after the checkpoint's redo pointer or that the checkpoint (via
735 * CheckPointLogicalRewriteHeap()) has flushed the (partial) mapping file to
736 * disk. That leaves the tail end that has not yet been flushed open to
737 * corruption, which is solved by including the current offset in the
738 * xl_heap_rewrite_mapping records and truncating the mapping file to it
739 * during replay. Every time a rewrite is finished all generated mapping files
740 * are synced to disk.
742 * Note that if we were only concerned about crash safety we wouldn't have to
743 * deal with WAL logging at all - an fsync() at the end of a rewrite would be
744 * sufficient for crash safety. Any mapping that hasn't been safely flushed to
745 * disk has to be by an aborted (explicitly or via a crash) transaction and is
746 * ignored by virtue of the xid in its name being subject to a
747 * TransactionDidCommit() check. But we want to support having standbys via
748 * physical replication, both for availability and to do logical decoding
750 * ------------------------------------------------------------------------
754 * Do preparations for logging logical mappings during a rewrite if
755 * necessary. If we detect that we don't need to log anything we'll prevent
756 * any further action by the various logical rewrite functions.
765 * We only need to persist these mappings if the rewritten table can be
766 * accessed during logical decoding, if not, we can skip doing any
769 state->rs_logical_rewrite =
772 if (!
state->rs_logical_rewrite)
778 * If there are no logical slots in progress we don't need to do anything,
779 * there cannot be any remappings for relevant rows yet. The relation's
780 * lock protects us against races.
784 state->rs_logical_rewrite =
false;
788 state->rs_logical_xmin = logical_xmin;
790 state->rs_num_rewrite_mappings = 0;
796 state->rs_logical_mappings =
798 128,
/* arbitrary initial size */
804 * Flush all logical in-memory mappings to disk, but don't fsync them yet.
815 /* no logical rewrite in progress, no need to iterate over mappings */
816 if (
state->rs_num_rewrite_mappings == 0)
819 elog(
DEBUG1,
"flushing %u logical rewrite mapping entries",
820 state->rs_num_rewrite_mappings);
833 /* this file hasn't got any new mappings */
834 if (num_mappings == 0)
837 if (
state->rs_old_rel->rd_rel->relisshared)
849 /* write all mappings consecutively */
854 * collect data we need to write out, but don't modify ondisk data yet
862 memcpy(waldata, &pmap->
map,
sizeof(pmap->
map));
863 waldata +=
sizeof(pmap->
map);
865 /* remove from the list and free */
869 /* update bookkeeping */
870 state->rs_num_rewrite_mappings--;
877 * Note that we deviate from the usual WAL coding practices here,
878 * check the above "Logical rewrite support" comment for reasoning.
881 WAIT_EVENT_LOGICAL_REWRITE_WRITE);
885 errmsg(
"could not write to file \"%s\", wrote %d of %d: %m", src->
path,
893 /* write xlog record */
896 pfree(waldata_start);
902 * Logical remapping part of end_heap_rewrite().
910 /* done, no logical rewrite in progress */
911 if (!
state->rs_logical_rewrite)
914 /* writeout remaining in-memory entries */
915 if (
state->rs_num_rewrite_mappings > 0)
918 /* Iterate over all mappings we have written and fsync the files. */
922 if (
FileSync(src->
vfd, WAIT_EVENT_LOGICAL_REWRITE_SYNC) != 0)
925 errmsg(
"could not fsync file \"%s\": %m", src->
path)));
928 /* memory context cleanup will deal with the rest */
932 * Log a single (old->new) mapping for 'xid'.
945 /* look for existing mappings for this 'mapped' xid */
950 * We haven't yet had the need to map anything for this xid, create
951 * per-xid data structures.
958 if (
state->rs_old_rel->rd_rel->relisshared)
971 memcpy(src->
path, path,
sizeof(path));
973 O_CREAT | O_EXCL | O_WRONLY |
PG_BINARY);
977 errmsg(
"could not create file \"%s\": %m", path)));
984 state->rs_num_rewrite_mappings++;
987 * Write out buffer every time we've too many in-memory entries across all
990 if (
state->rs_num_rewrite_mappings >= 1000
/* arbitrary number */ )
995 * Perform logical remapping for a tuple that's mapped from old_tid to
996 * new_tuple->t_self by rewrite_heap_tuple() if necessary for the tuple.
1006 bool do_log_xmin =
false;
1007 bool do_log_xmax =
false;
1010 /* no logical rewrite in progress, we don't need to log anything */
1011 if (!
state->rs_logical_rewrite)
1015 /* use *GetUpdateXid to correctly deal with multixacts */
1019 * Log the mapping iff the tuple has been created recently.
1027 * no xmax is set, can't have any permanent ones, so this check is
1033 /* only locked, we don't care */
1037 /* tuple has been deleted recently, log */
1041 /* if neither needs to be logged, we're done */
1042 if (!do_log_xmin && !do_log_xmax)
1045 /* fill out mapping information */
1052 * Now persist the mapping for the individual xids that are affected. We
1053 * need to log for both xmin and xmax if they aren't the same transaction
1054 * since the mapping files are per "affected" xid.
1055 * We don't muster all that much effort detecting whether xmin and xmax
1056 * are actually the same transaction, we just check whether the xid is the
1057 * same disregarding subtransactions. Logging too much is relatively
1058 * harmless and we could never do the check fully since subtransaction
1059 * data is thrown away during restarts.
1064 /* separately log mapping for xmax unless it'd be redundant */
1070 * Replay XLOG_HEAP2_REWRITE records
1094 errmsg(
"could not create file \"%s\": %m", path)));
1097 * Truncate all data that's not guaranteed to have been safely fsynced (by
1098 * previous record or by the last checkpoint).
1101 if (ftruncate(
fd, xlrec->
offset) != 0)
1104 errmsg(
"could not truncate file \"%s\" to %u: %m",
1112 /* write out tail end of mapping file (again) */
1117 /* if write didn't set errno, assume problem is no disk space */
1122 errmsg(
"could not write to file \"%s\": %m", path)));
1127 * Now fsync all previously written data. We could improve things and only
1128 * do this for the last write to a file, but the required bookkeeping
1129 * doesn't seem worth the trouble.
1135 errmsg(
"could not fsync file \"%s\": %m", path)));
1141 errmsg(
"could not close file \"%s\": %m", path)));
1145 * Perform a checkpoint for logical rewrite mappings
1147 * This serves two tasks:
1148 * 1) Remove all mappings not needed anymore based on the logical restart LSN
1149 * 2) Flush all remaining mappings to disk, so that replay after a checkpoint
1150 * only has to deal with the parts of a mapping that have been written out
1151 * after the checkpoint started.
1160 struct dirent *mapping_de;
1164 * We start of with a minimum of the last redo pointer. No new decoding
1165 * slot will start before that, so that's a safe upper bound for removal.
1169 /* now check for the restart ptrs from existing slots */
1172 /* don't start earlier than the restart lsn */
1188 if (strcmp(mapping_de->
d_name,
".") == 0 ||
1189 strcmp(mapping_de->
d_name,
"..") == 0)
1198 /* Skip over files that cannot be ours. */
1199 if (strncmp(mapping_de->
d_name,
"map-", 4) != 0)
1203 &dboid, &relid, &hi, &lo, &rewrite_xid, &create_xid) != 6)
1206 lsn = ((
uint64) hi) << 32 | lo;
1210 elog(
DEBUG1,
"removing logical rewrite file \"%s\"", path);
1211 if (unlink(path) < 0)
1214 errmsg(
"could not remove file \"%s\": %m", path)));
1218 /* on some operating systems fsyncing a file requires O_RDWR */
1222 * The file cannot vanish due to concurrency since this function
1223 * is the only one removing logical mappings and only one
1224 * checkpoint can be in progress at a time.
1229 errmsg(
"could not open file \"%s\": %m", path)));
1232 * We could try to avoid fsyncing files that either haven't
1233 * changed or have only been created since the checkpoint's start,
1234 * but it's currently not deemed worth the effort.
1240 errmsg(
"could not fsync file \"%s\": %m", path)));
1246 errmsg(
"could not close file \"%s\": %m", path)));
1251 /* persist directory entries to disk */
#define RelationGetNumberOfBlocks(reln)
Size PageGetHeapFreeSpace(const PageData *page)
void PageInit(Page page, Size pageSize, Size specialSize)
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
BulkWriteState * smgr_bulk_start_rel(Relation rel, ForkNumber forknum)
void smgr_bulk_write(BulkWriteState *bulkstate, BlockNumber blocknum, BulkWriteBuffer buf, bool page_std)
BulkWriteBuffer smgr_bulk_get_buf(BulkWriteState *bulkstate)
void smgr_bulk_finish(BulkWriteState *bulkstate)
TransactionId MultiXactId
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int FileSync(File file, uint32 wait_event_info)
int CloseTransientFile(int fd)
void FileClose(File file)
void fsync_fname(const char *fname, bool isdir)
int data_sync_elevel(int elevel)
File PathNameOpenFile(const char *fileName, int fileFlags)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
int OpenTransientFile(const char *fileName, int fileFlags)
static ssize_t FileWrite(File file, const void *buffer, size_t amount, off_t offset, uint32 wait_event_info)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Assert(PointerIsAligned(start, uint64))
bool heap_freeze_tuple(HeapTupleHeader tuple, TransactionId relfrozenxid, TransactionId relminmxid, TransactionId FreezeLimit, TransactionId MultiXactCutoff)
#define HEAP_INSERT_SKIP_FSM
#define HEAP_INSERT_NO_LOGICAL
bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple)
#define XLOG_HEAP2_REWRITE
HeapTuple heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, int options)
#define TOAST_TUPLE_THRESHOLD
HeapTuple heap_copytuple(HeapTuple tuple)
void heap_freetuple(HeapTuple htup)
HeapTupleHeaderData * HeapTupleHeader
static bool HEAP_XMAX_IS_LOCKED_ONLY(uint16 infomask)
static bool HeapTupleHasExternal(const HeapTupleData *tuple)
static TransactionId HeapTupleHeaderGetXmin(const HeapTupleHeaderData *tup)
static bool HeapTupleHeaderIndicatesMovedPartitions(const HeapTupleHeaderData *tup)
#define HEAP_XMAX_INVALID
static TransactionId HeapTupleHeaderGetUpdateXid(const HeapTupleHeaderData *tup)
#define dclist_container(type, membername, ptr)
static void dclist_push_tail(dclist_head *head, dlist_node *node)
static uint32 dclist_count(const dclist_head *head)
static void dclist_delete_from(dclist_head *head, dlist_node *node)
static void dclist_init(dclist_head *head)
#define dclist_foreach_modify(iter, lhead)
if(TABLE==NULL||TABLE_index==NULL)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
static bool ItemPointerIsValid(const ItemPointerData *pointer)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define InvalidOffsetNumber
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int fd(const char *x, int i)
void ProcArrayGetReplicationSlotXmin(TransactionId *xmin, TransactionId *catalog_xmin)
#define RelationGetRelid(relation)
#define RelationGetTargetPageFreeSpace(relation, defaultff)
#define RelationIsAccessibleInLogicalDecoding(relation)
#define HEAP_DEFAULT_FILLFACTOR
#define PG_LOGICAL_MAPPINGS_DIR
struct RewriteMappingDataEntry RewriteMappingDataEntry
static void raw_heap_insert(RewriteState state, HeapTuple tup)
void end_heap_rewrite(RewriteState state)
bool rewrite_heap_dead_tuple(RewriteState state, HeapTuple old_tuple)
UnresolvedTupData * UnresolvedTup
RewriteState begin_heap_rewrite(Relation old_heap, Relation new_heap, TransactionId oldest_xmin, TransactionId freeze_xid, MultiXactId cutoff_multi)
static void logical_rewrite_heap_tuple(RewriteState state, ItemPointerData old_tid, HeapTuple new_tuple)
static void logical_heap_rewrite_flush_mappings(RewriteState state)
void heap_xlog_logical_rewrite(XLogReaderState *r)
static void logical_begin_heap_rewrite(RewriteState state)
void CheckPointLogicalRewriteHeap(void)
struct RewriteMappingFile RewriteMappingFile
static void logical_end_heap_rewrite(RewriteState state)
OldToNewMappingData * OldToNewMapping
struct RewriteStateData RewriteStateData
void rewrite_heap_tuple(RewriteState state, HeapTuple old_tuple, HeapTuple new_tuple)
static void logical_rewrite_log_mapping(RewriteState state, TransactionId xid, LogicalRewriteMappingData *map)
#define LOGICAL_REWRITE_FORMAT
struct LogicalRewriteMappingData LogicalRewriteMappingData
XLogRecPtr ReplicationSlotsComputeLogicalRestartLSN(void)
RelFileLocator old_locator
RelFileLocator new_locator
LogicalRewriteMappingData map
TransactionId rs_freeze_xid
TransactionId rs_oldest_xmin
HTAB * rs_logical_mappings
HTAB * rs_unresolved_tups
uint32 rs_num_rewrite_mappings
TransactionId rs_logical_xmin
BulkWriteState * rs_bulkstate
BulkWriteBuffer rs_buffer
HTAB * rs_old_new_tid_map
MultiXactId rs_cutoff_multi
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
#define InvalidTransactionId
#define TransactionIdEquals(id1, id2)
#define TransactionIdIsNormal(xid)
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
TransactionId GetCurrentTransactionId(void)
XLogRecPtr GetRedoRecPtr(void)
XLogRecPtr GetXLogInsertRecPtr(void)
#define LSN_FORMAT_ARGS(lsn)
#define InvalidXLogRecPtr
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const void *data, uint32 len)
void XLogBeginInsert(void)
#define XLogRecGetData(decoder)
#define XLogRecGetXid(decoder)