PostgreSQL Source Code  git master
rewriteheap.h File Reference
#include "access/htup.h"
#include "storage/itemptr.h"
#include "storage/relfilelocator.h"
#include "utils/relcache.h"
Include dependency graph for rewriteheap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LogicalRewriteMappingData
 

Macros

#define LOGICAL_REWRITE_FORMAT   "map-%x-%x-%X_%X-%x-%x"
 

Typedefs

typedef struct RewriteStateDataRewriteState
 
typedef struct LogicalRewriteMappingData LogicalRewriteMappingData
 

Functions

RewriteState begin_heap_rewrite (Relation old_heap, Relation new_heap, TransactionId oldest_xmin, TransactionId freeze_xid, MultiXactId cutoff_multi)
 
void end_heap_rewrite (RewriteState state)
 
void rewrite_heap_tuple (RewriteState state, HeapTuple old_tuple, HeapTuple new_tuple)
 
bool rewrite_heap_dead_tuple (RewriteState state, HeapTuple old_tuple)
 
void CheckPointLogicalRewriteHeap (void)
 

Macro Definition Documentation

◆ LOGICAL_REWRITE_FORMAT

#define LOGICAL_REWRITE_FORMAT   "map-%x-%x-%X_%X-%x-%x"

Definition at line 54 of file rewriteheap.h.

Typedef Documentation

◆ LogicalRewriteMappingData

◆ RewriteState

typedef struct RewriteStateData* RewriteState

Definition at line 22 of file rewriteheap.h.

Function Documentation

◆ begin_heap_rewrite()

RewriteState begin_heap_rewrite ( Relation  old_heap,
Relation  new_heap,
TransactionId  oldest_xmin,
TransactionId  freeze_xid,
MultiXactId  cutoff_multi 
)

Definition at line 236 of file rewriteheap.c.

238 {
240  MemoryContext rw_cxt;
241  MemoryContext old_cxt;
242  HASHCTL hash_ctl;
243 
244  /*
245  * To ease cleanup, make a separate context that will contain the
246  * RewriteState struct itself plus all subsidiary data.
247  */
249  "Table rewrite",
251  old_cxt = MemoryContextSwitchTo(rw_cxt);
252 
253  /* Create and fill in the state struct */
254  state = palloc0(sizeof(RewriteStateData));
255 
256  state->rs_old_rel = old_heap;
257  state->rs_new_rel = new_heap;
258  state->rs_buffer = (Page) palloc_aligned(BLCKSZ, PG_IO_ALIGN_SIZE, 0);
259  /* new_heap needn't be empty, just locked */
260  state->rs_blockno = RelationGetNumberOfBlocks(new_heap);
261  state->rs_buffer_valid = false;
262  state->rs_oldest_xmin = oldest_xmin;
263  state->rs_freeze_xid = freeze_xid;
264  state->rs_cutoff_multi = cutoff_multi;
265  state->rs_cxt = rw_cxt;
266 
267  /* Initialize hash tables used to track update chains */
268  hash_ctl.keysize = sizeof(TidHashKey);
269  hash_ctl.entrysize = sizeof(UnresolvedTupData);
270  hash_ctl.hcxt = state->rs_cxt;
271 
272  state->rs_unresolved_tups =
273  hash_create("Rewrite / Unresolved ctids",
274  128, /* arbitrary initial size */
275  &hash_ctl,
277 
278  hash_ctl.entrysize = sizeof(OldToNewMappingData);
279 
280  state->rs_old_new_tid_map =
281  hash_create("Rewrite / Old to new tid map",
282  128, /* arbitrary initial size */
283  &hash_ctl,
285 
286  MemoryContextSwitchTo(old_cxt);
287 
289 
290  return state;
291 }
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:227
Pointer Page
Definition: bufpage.h:78
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
void * palloc0(Size size)
Definition: mcxt.c:1257
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void * palloc_aligned(Size size, Size alignto, int flags)
Definition: mcxt.c:1446
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define PG_IO_ALIGN_SIZE
static void logical_begin_heap_rewrite(RewriteState state)
Definition: rewriteheap.c:793
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
MemoryContext hcxt
Definition: hsearch.h:86
Definition: regguts.h:323

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CurrentMemoryContext, HASHCTL::entrysize, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASHCTL::hcxt, HASHCTL::keysize, logical_begin_heap_rewrite(), MemoryContextSwitchTo(), palloc0(), palloc_aligned(), PG_IO_ALIGN_SIZE, and RelationGetNumberOfBlocks.

Referenced by heapam_relation_copy_for_cluster().

◆ CheckPointLogicalRewriteHeap()

void CheckPointLogicalRewriteHeap ( void  )

Definition at line 1189 of file rewriteheap.c.

1190 {
1191  XLogRecPtr cutoff;
1192  XLogRecPtr redo;
1193  DIR *mappings_dir;
1194  struct dirent *mapping_de;
1195  char path[MAXPGPATH + 20];
1196 
1197  /*
1198  * We start of with a minimum of the last redo pointer. No new decoding
1199  * slot will start before that, so that's a safe upper bound for removal.
1200  */
1201  redo = GetRedoRecPtr();
1202 
1203  /* now check for the restart ptrs from existing slots */
1205 
1206  /* don't start earlier than the restart lsn */
1207  if (cutoff != InvalidXLogRecPtr && redo < cutoff)
1208  cutoff = redo;
1209 
1210  mappings_dir = AllocateDir("pg_logical/mappings");
1211  while ((mapping_de = ReadDir(mappings_dir, "pg_logical/mappings")) != NULL)
1212  {
1213  Oid dboid;
1214  Oid relid;
1215  XLogRecPtr lsn;
1216  TransactionId rewrite_xid;
1217  TransactionId create_xid;
1218  uint32 hi,
1219  lo;
1220  PGFileType de_type;
1221 
1222  if (strcmp(mapping_de->d_name, ".") == 0 ||
1223  strcmp(mapping_de->d_name, "..") == 0)
1224  continue;
1225 
1226  snprintf(path, sizeof(path), "pg_logical/mappings/%s", mapping_de->d_name);
1227  de_type = get_dirent_type(path, mapping_de, false, DEBUG1);
1228 
1229  if (de_type != PGFILETYPE_ERROR && de_type != PGFILETYPE_REG)
1230  continue;
1231 
1232  /* Skip over files that cannot be ours. */
1233  if (strncmp(mapping_de->d_name, "map-", 4) != 0)
1234  continue;
1235 
1236  if (sscanf(mapping_de->d_name, LOGICAL_REWRITE_FORMAT,
1237  &dboid, &relid, &hi, &lo, &rewrite_xid, &create_xid) != 6)
1238  elog(ERROR, "could not parse filename \"%s\"", mapping_de->d_name);
1239 
1240  lsn = ((uint64) hi) << 32 | lo;
1241 
1242  if (lsn < cutoff || cutoff == InvalidXLogRecPtr)
1243  {
1244  elog(DEBUG1, "removing logical rewrite file \"%s\"", path);
1245  if (unlink(path) < 0)
1246  ereport(ERROR,
1248  errmsg("could not remove file \"%s\": %m", path)));
1249  }
1250  else
1251  {
1252  /* on some operating systems fsyncing a file requires O_RDWR */
1253  int fd = OpenTransientFile(path, O_RDWR | PG_BINARY);
1254 
1255  /*
1256  * The file cannot vanish due to concurrency since this function
1257  * is the only one removing logical mappings and only one
1258  * checkpoint can be in progress at a time.
1259  */
1260  if (fd < 0)
1261  ereport(ERROR,
1263  errmsg("could not open file \"%s\": %m", path)));
1264 
1265  /*
1266  * We could try to avoid fsyncing files that either haven't
1267  * changed or have only been created since the checkpoint's start,
1268  * but it's currently not deemed worth the effort.
1269  */
1271  if (pg_fsync(fd) != 0)
1274  errmsg("could not fsync file \"%s\": %m", path)));
1276 
1277  if (CloseTransientFile(fd) != 0)
1278  ereport(ERROR,
1280  errmsg("could not close file \"%s\": %m", path)));
1281  }
1282  }
1283  FreeDir(mappings_dir);
1284 
1285  /* persist directory entries to disk */
1286  fsync_fname("pg_logical/mappings", true);
1287 }
unsigned int uint32
Definition: c.h:490
#define PG_BINARY
Definition: c.h:1278
uint32 TransactionId
Definition: c.h:636
int errcode_for_file_access(void)
Definition: elog.c:881
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define DEBUG1
Definition: elog.h:30
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2806
int FreeDir(DIR *dir)
Definition: fd.c:2858
int CloseTransientFile(int fd)
Definition: fd.c:2706
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:667
int data_sync_elevel(int elevel)
Definition: fd.c:3833
int pg_fsync(int fd)
Definition: fd.c:361
int OpenTransientFile(const char *fileName, int fileFlags)
Definition: fd.c:2530
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2740
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Definition: file_utils.c:406
PGFileType
Definition: file_utils.h:19
@ PGFILETYPE_REG
Definition: file_utils.h:22
@ PGFILETYPE_ERROR
Definition: file_utils.h:20
#define MAXPGPATH
#define snprintf
Definition: port.h:238
unsigned int Oid
Definition: postgres_ext.h:31
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define LOGICAL_REWRITE_FORMAT
Definition: rewriteheap.h:54
XLogRecPtr ReplicationSlotsComputeLogicalRestartLSN(void)
Definition: slot.c:941
Definition: dirent.c:26
Definition: dirent.h:10
char d_name[MAX_PATH]
Definition: dirent.h:15
@ WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC
Definition: wait_event.h:194
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:271
static void pgstat_report_wait_end(void)
Definition: wait_event.h:287
XLogRecPtr GetRedoRecPtr(void)
Definition: xlog.c:6024
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References AllocateDir(), CloseTransientFile(), dirent::d_name, data_sync_elevel(), DEBUG1, elog(), ereport, errcode_for_file_access(), errmsg(), ERROR, fd(), FreeDir(), fsync_fname(), get_dirent_type(), GetRedoRecPtr(), InvalidXLogRecPtr, LOGICAL_REWRITE_FORMAT, MAXPGPATH, OpenTransientFile(), PG_BINARY, pg_fsync(), PGFILETYPE_ERROR, PGFILETYPE_REG, pgstat_report_wait_end(), pgstat_report_wait_start(), ReadDir(), ReplicationSlotsComputeLogicalRestartLSN(), snprintf, and WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC.

Referenced by CheckPointGuts().

◆ end_heap_rewrite()

void end_heap_rewrite ( RewriteState  state)

Definition at line 299 of file rewriteheap.c.

300 {
301  HASH_SEQ_STATUS seq_status;
302  UnresolvedTup unresolved;
303 
304  /*
305  * Write any remaining tuples in the UnresolvedTups table. If we have any
306  * left, they should in fact be dead, but let's err on the safe side.
307  */
308  hash_seq_init(&seq_status, state->rs_unresolved_tups);
309 
310  while ((unresolved = hash_seq_search(&seq_status)) != NULL)
311  {
312  ItemPointerSetInvalid(&unresolved->tuple->t_data->t_ctid);
313  raw_heap_insert(state, unresolved->tuple);
314  }
315 
316  /* Write the last page, if any */
317  if (state->rs_buffer_valid)
318  {
319  if (RelationNeedsWAL(state->rs_new_rel))
320  log_newpage(&state->rs_new_rel->rd_locator,
321  MAIN_FORKNUM,
322  state->rs_blockno,
323  state->rs_buffer,
324  true);
325 
326  PageSetChecksumInplace(state->rs_buffer, state->rs_blockno);
327 
329  state->rs_blockno, state->rs_buffer, true);
330  }
331 
332  /*
333  * When we WAL-logged rel pages, we must nonetheless fsync them. The
334  * reason is the same as in storage.c's RelationCopyStorage(): we're
335  * writing data that's not in shared buffers, and so a CHECKPOINT
336  * occurring during the rewriteheap operation won't have fsync'd data we
337  * wrote before the checkpoint.
338  */
339  if (RelationNeedsWAL(state->rs_new_rel))
341 
343 
344  /* Deleting the context frees everything */
345  MemoryContextDelete(state->rs_cxt);
346 }
void PageSetChecksumInplace(Page page, BlockNumber blkno)
Definition: bufpage.c:1542
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
static SMgrRelation RelationGetSmgr(Relation rel)
Definition: rel.h:572
#define RelationNeedsWAL(relation)
Definition: rel.h:629
@ MAIN_FORKNUM
Definition: relpath.h:50
static void raw_heap_insert(RewriteState state, HeapTuple tup)
Definition: rewriteheap.c:612
static void logical_end_heap_rewrite(RewriteState state)
Definition: rewriteheap.c:939
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:720
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition: smgr.c:497
HeapTupleHeader t_data
Definition: htup.h:68
ItemPointerData t_ctid
Definition: htup_details.h:161
XLogRecPtr log_newpage(RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blkno, Page page, bool page_std)
Definition: xloginsert.c:1131

References hash_seq_init(), hash_seq_search(), ItemPointerSetInvalid(), log_newpage(), logical_end_heap_rewrite(), MAIN_FORKNUM, MemoryContextDelete(), PageSetChecksumInplace(), raw_heap_insert(), RelationGetSmgr(), RelationNeedsWAL, smgrextend(), smgrimmedsync(), HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, and UnresolvedTupData::tuple.

Referenced by heapam_relation_copy_for_cluster().

◆ rewrite_heap_dead_tuple()

bool rewrite_heap_dead_tuple ( RewriteState  state,
HeapTuple  old_tuple 
)

Definition at line 562 of file rewriteheap.c.

563 {
564  /*
565  * If we have already seen an earlier tuple in the update chain that
566  * points to this tuple, let's forget about that earlier tuple. It's in
567  * fact dead as well, our simple xmax < OldestXmin test in
568  * HeapTupleSatisfiesVacuum just wasn't enough to detect it. It happens
569  * when xmin of a tuple is greater than xmax, which sounds
570  * counter-intuitive but is perfectly valid.
571  *
572  * We don't bother to try to detect the situation the other way round,
573  * when we encounter the dead tuple first and then the recently dead one
574  * that points to it. If that happens, we'll have some unmatched entries
575  * in the UnresolvedTups hash table at the end. That can happen anyway,
576  * because a vacuum might have removed the dead tuple in the chain before
577  * us.
578  */
579  UnresolvedTup unresolved;
580  TidHashKey hashkey;
581  bool found;
582 
583  memset(&hashkey, 0, sizeof(hashkey));
584  hashkey.xmin = HeapTupleHeaderGetXmin(old_tuple->t_data);
585  hashkey.tid = old_tuple->t_self;
586 
587  unresolved = hash_search(state->rs_unresolved_tups, &hashkey,
588  HASH_FIND, NULL);
589 
590  if (unresolved != NULL)
591  {
592  /* Need to free the contained tuple as well as the hashtable entry */
593  heap_freetuple(unresolved->tuple);
594  hash_search(state->rs_unresolved_tups, &hashkey,
595  HASH_REMOVE, &found);
596  Assert(found);
597  return true;
598  }
599 
600  return false;
601 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:953
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
@ HASH_FIND
Definition: hsearch.h:113
@ HASH_REMOVE
Definition: hsearch.h:115
#define HeapTupleHeaderGetXmin(tup)
Definition: htup_details.h:309
Assert(fmt[strlen(fmt) - 1] !='\n')
ItemPointerData t_self
Definition: htup.h:65
TransactionId xmin
Definition: rewriteheap.c:165
ItemPointerData tid
Definition: rewriteheap.c:166

References Assert(), HASH_FIND, HASH_REMOVE, hash_search(), heap_freetuple(), HeapTupleHeaderGetXmin, HeapTupleData::t_data, HeapTupleData::t_self, TidHashKey::tid, UnresolvedTupData::tuple, and TidHashKey::xmin.

Referenced by heapam_relation_copy_for_cluster().

◆ rewrite_heap_tuple()

void rewrite_heap_tuple ( RewriteState  state,
HeapTuple  old_tuple,
HeapTuple  new_tuple 
)

Definition at line 360 of file rewriteheap.c.

362 {
363  MemoryContext old_cxt;
364  ItemPointerData old_tid;
365  TidHashKey hashkey;
366  bool found;
367  bool free_new;
368 
369  old_cxt = MemoryContextSwitchTo(state->rs_cxt);
370 
371  /*
372  * Copy the original tuple's visibility information into new_tuple.
373  *
374  * XXX we might later need to copy some t_infomask2 bits, too? Right now,
375  * we intentionally clear the HOT status bits.
376  */
377  memcpy(&new_tuple->t_data->t_choice.t_heap,
378  &old_tuple->t_data->t_choice.t_heap,
379  sizeof(HeapTupleFields));
380 
381  new_tuple->t_data->t_infomask &= ~HEAP_XACT_MASK;
382  new_tuple->t_data->t_infomask2 &= ~HEAP2_XACT_MASK;
383  new_tuple->t_data->t_infomask |=
384  old_tuple->t_data->t_infomask & HEAP_XACT_MASK;
385 
386  /*
387  * While we have our hands on the tuple, we may as well freeze any
388  * eligible xmin or xmax, so that future VACUUM effort can be saved.
389  */
390  heap_freeze_tuple(new_tuple->t_data,
391  state->rs_old_rel->rd_rel->relfrozenxid,
392  state->rs_old_rel->rd_rel->relminmxid,
393  state->rs_freeze_xid,
394  state->rs_cutoff_multi);
395 
396  /*
397  * Invalid ctid means that ctid should point to the tuple itself. We'll
398  * override it later if the tuple is part of an update chain.
399  */
400  ItemPointerSetInvalid(&new_tuple->t_data->t_ctid);
401 
402  /*
403  * If the tuple has been updated, check the old-to-new mapping hash table.
404  */
405  if (!((old_tuple->t_data->t_infomask & HEAP_XMAX_INVALID) ||
406  HeapTupleHeaderIsOnlyLocked(old_tuple->t_data)) &&
408  !(ItemPointerEquals(&(old_tuple->t_self),
409  &(old_tuple->t_data->t_ctid))))
410  {
411  OldToNewMapping mapping;
412 
413  memset(&hashkey, 0, sizeof(hashkey));
414  hashkey.xmin = HeapTupleHeaderGetUpdateXid(old_tuple->t_data);
415  hashkey.tid = old_tuple->t_data->t_ctid;
416 
417  mapping = (OldToNewMapping)
418  hash_search(state->rs_old_new_tid_map, &hashkey,
419  HASH_FIND, NULL);
420 
421  if (mapping != NULL)
422  {
423  /*
424  * We've already copied the tuple that t_ctid points to, so we can
425  * set the ctid of this tuple to point to the new location, and
426  * insert it right away.
427  */
428  new_tuple->t_data->t_ctid = mapping->new_tid;
429 
430  /* We don't need the mapping entry anymore */
431  hash_search(state->rs_old_new_tid_map, &hashkey,
432  HASH_REMOVE, &found);
433  Assert(found);
434  }
435  else
436  {
437  /*
438  * We haven't seen the tuple t_ctid points to yet. Stash this
439  * tuple into unresolved_tups to be written later.
440  */
441  UnresolvedTup unresolved;
442 
443  unresolved = hash_search(state->rs_unresolved_tups, &hashkey,
444  HASH_ENTER, &found);
445  Assert(!found);
446 
447  unresolved->old_tid = old_tuple->t_self;
448  unresolved->tuple = heap_copytuple(new_tuple);
449 
450  /*
451  * We can't do anything more now, since we don't know where the
452  * tuple will be written.
453  */
454  MemoryContextSwitchTo(old_cxt);
455  return;
456  }
457  }
458 
459  /*
460  * Now we will write the tuple, and then check to see if it is the B tuple
461  * in any new or known pair. When we resolve a known pair, we will be
462  * able to write that pair's A tuple, and then we have to check if it
463  * resolves some other pair. Hence, we need a loop here.
464  */
465  old_tid = old_tuple->t_self;
466  free_new = false;
467 
468  for (;;)
469  {
470  ItemPointerData new_tid;
471 
472  /* Insert the tuple and find out where it's put in new_heap */
473  raw_heap_insert(state, new_tuple);
474  new_tid = new_tuple->t_self;
475 
476  logical_rewrite_heap_tuple(state, old_tid, new_tuple);
477 
478  /*
479  * If the tuple is the updated version of a row, and the prior version
480  * wouldn't be DEAD yet, then we need to either resolve the prior
481  * version (if it's waiting in rs_unresolved_tups), or make an entry
482  * in rs_old_new_tid_map (so we can resolve it when we do see it). The
483  * previous tuple's xmax would equal this one's xmin, so it's
484  * RECENTLY_DEAD if and only if the xmin is not before OldestXmin.
485  */
486  if ((new_tuple->t_data->t_infomask & HEAP_UPDATED) &&
488  state->rs_oldest_xmin))
489  {
490  /*
491  * Okay, this is B in an update pair. See if we've seen A.
492  */
493  UnresolvedTup unresolved;
494 
495  memset(&hashkey, 0, sizeof(hashkey));
496  hashkey.xmin = HeapTupleHeaderGetXmin(new_tuple->t_data);
497  hashkey.tid = old_tid;
498 
499  unresolved = hash_search(state->rs_unresolved_tups, &hashkey,
500  HASH_FIND, NULL);
501 
502  if (unresolved != NULL)
503  {
504  /*
505  * We have seen and memorized the previous tuple already. Now
506  * that we know where we inserted the tuple its t_ctid points
507  * to, fix its t_ctid and insert it to the new heap.
508  */
509  if (free_new)
510  heap_freetuple(new_tuple);
511  new_tuple = unresolved->tuple;
512  free_new = true;
513  old_tid = unresolved->old_tid;
514  new_tuple->t_data->t_ctid = new_tid;
515 
516  /*
517  * We don't need the hash entry anymore, but don't free its
518  * tuple just yet.
519  */
520  hash_search(state->rs_unresolved_tups, &hashkey,
521  HASH_REMOVE, &found);
522  Assert(found);
523 
524  /* loop back to insert the previous tuple in the chain */
525  continue;
526  }
527  else
528  {
529  /*
530  * Remember the new tid of this tuple. We'll use it to set the
531  * ctid when we find the previous tuple in the chain.
532  */
533  OldToNewMapping mapping;
534 
535  mapping = hash_search(state->rs_old_new_tid_map, &hashkey,
536  HASH_ENTER, &found);
537  Assert(!found);
538 
539  mapping->new_tid = new_tid;
540  }
541  }
542 
543  /* Done with this (chain of) tuples, for now */
544  if (free_new)
545  heap_freetuple(new_tuple);
546  break;
547  }
548 
549  MemoryContextSwitchTo(old_cxt);
550 }
bool heap_freeze_tuple(HeapTupleHeader tuple, TransactionId relfrozenxid, TransactionId relminmxid, TransactionId FreezeLimit, TransactionId MultiXactCutoff)
Definition: heapam.c:6923
bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple)
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
@ HASH_ENTER
Definition: hsearch.h:114
#define HeapTupleHeaderIndicatesMovedPartitions(tup)
Definition: htup_details.h:444
#define HEAP2_XACT_MASK
Definition: htup_details.h:279
#define HEAP_XACT_MASK
Definition: htup_details.h:215
#define HEAP_XMAX_INVALID
Definition: htup_details.h:208
#define HEAP_UPDATED
Definition: htup_details.h:210
#define HeapTupleHeaderGetUpdateXid(tup)
Definition: htup_details.h:361
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:35
static void logical_rewrite_heap_tuple(RewriteState state, ItemPointerData old_tid, HeapTuple new_tuple)
Definition: rewriteheap.c:1033
OldToNewMappingData * OldToNewMapping
Definition: rewriteheap.c:187
union HeapTupleHeaderData::@44 t_choice
HeapTupleFields t_heap
Definition: htup_details.h:157
ItemPointerData new_tid
Definition: rewriteheap.c:184
ItemPointerData old_tid
Definition: rewriteheap.c:175
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280

References Assert(), HASH_ENTER, HASH_FIND, HASH_REMOVE, hash_search(), HEAP2_XACT_MASK, heap_copytuple(), heap_freetuple(), heap_freeze_tuple(), HEAP_UPDATED, HEAP_XACT_MASK, HEAP_XMAX_INVALID, HeapTupleHeaderGetUpdateXid, HeapTupleHeaderGetXmin, HeapTupleHeaderIndicatesMovedPartitions, HeapTupleHeaderIsOnlyLocked(), ItemPointerEquals(), ItemPointerSetInvalid(), logical_rewrite_heap_tuple(), MemoryContextSwitchTo(), OldToNewMappingData::new_tid, UnresolvedTupData::old_tid, raw_heap_insert(), HeapTupleHeaderData::t_choice, HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleHeaderData::t_heap, HeapTupleHeaderData::t_infomask, HeapTupleHeaderData::t_infomask2, HeapTupleData::t_self, TidHashKey::tid, TransactionIdPrecedes(), UnresolvedTupData::tuple, and TidHashKey::xmin.

Referenced by reform_and_rewrite_tuple().