PostgreSQL Source Code  git master
relation.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * relation.c
3  * PostgreSQL logical replication relation mapping cache
4  *
5  * Copyright (c) 2016-2022, PostgreSQL Global Development Group
6  *
7  * IDENTIFICATION
8  * src/backend/replication/logical/relation.c
9  *
10  * NOTES
11  * Routines in this file mainly have to do with mapping the properties
12  * of local replication target relations to the properties of their
13  * remote counterpart.
14  *
15  *-------------------------------------------------------------------------
16  */
17 
18 #include "postgres.h"
19 
20 #include "access/table.h"
21 #include "catalog/namespace.h"
23 #include "executor/executor.h"
24 #include "nodes/makefuncs.h"
27 #include "utils/inval.h"
28 
29 
31 
32 static HTAB *LogicalRepRelMap = NULL;
33 
34 /*
35  * Partition map (LogicalRepPartMap)
36  *
37  * When a partitioned table is used as replication target, replicated
38  * operations are actually performed on its leaf partitions, which requires
39  * the partitions to also be mapped to the remote relation. Parent's entry
40  * (LogicalRepRelMapEntry) cannot be used as-is for all partitions, because
41  * individual partitions may have different attribute numbers, which means
42  * attribute mappings to remote relation's attributes must be maintained
43  * separately for each partition.
44  */
46 static HTAB *LogicalRepPartMap = NULL;
47 typedef struct LogicalRepPartMapEntry
48 {
49  Oid partoid; /* LogicalRepPartMap's key */
52 
53 /*
54  * Relcache invalidation callback for our relation map cache.
55  */
56 static void
58 {
59  LogicalRepRelMapEntry *entry;
60 
61  /* Just to be sure. */
62  if (LogicalRepRelMap == NULL)
63  return;
64 
65  if (reloid != InvalidOid)
66  {
68 
70 
71  /* TODO, use inverse lookup hashtable? */
72  while ((entry = (LogicalRepRelMapEntry *) hash_seq_search(&status)) != NULL)
73  {
74  if (entry->localreloid == reloid)
75  {
76  entry->localrelvalid = false;
78  break;
79  }
80  }
81  }
82  else
83  {
84  /* invalidate all cache entries */
86 
88 
89  while ((entry = (LogicalRepRelMapEntry *) hash_seq_search(&status)) != NULL)
90  entry->localrelvalid = false;
91  }
92 }
93 
94 /*
95  * Initialize the relation map cache.
96  */
97 static void
99 {
100  HASHCTL ctl;
101 
105  "LogicalRepRelMapContext",
107 
108  /* Initialize the relation hash table. */
109  ctl.keysize = sizeof(LogicalRepRelId);
110  ctl.entrysize = sizeof(LogicalRepRelMapEntry);
112 
113  LogicalRepRelMap = hash_create("logicalrep relation map cache", 128, &ctl,
115 
116  /* Watch for invalidation events. */
118  (Datum) 0);
119 }
120 
121 /*
122  * Free the entry of a relation map cache.
123  */
124 static void
126 {
127  LogicalRepRelation *remoterel;
128 
129  remoterel = &entry->remoterel;
130 
131  pfree(remoterel->nspname);
132  pfree(remoterel->relname);
133 
134  if (remoterel->natts > 0)
135  {
136  int i;
137 
138  for (i = 0; i < remoterel->natts; i++)
139  pfree(remoterel->attnames[i]);
140 
141  pfree(remoterel->attnames);
142  pfree(remoterel->atttyps);
143  }
144  bms_free(remoterel->attkeys);
145 
146  if (entry->attrmap)
147  free_attrmap(entry->attrmap);
148 }
149 
150 /*
151  * Add new entry or update existing entry in the relation map cache.
152  *
153  * Called when new relation mapping is sent by the publisher to update
154  * our expected view of incoming data from said publisher.
155  */
156 void
158 {
159  MemoryContext oldctx;
160  LogicalRepRelMapEntry *entry;
161  bool found;
162  int i;
163 
164  if (LogicalRepRelMap == NULL)
166 
167  /*
168  * HASH_ENTER returns the existing entry if present or creates a new one.
169  */
170  entry = hash_search(LogicalRepRelMap, (void *) &remoterel->remoteid,
171  HASH_ENTER, &found);
172 
173  if (found)
175 
176  memset(entry, 0, sizeof(LogicalRepRelMapEntry));
177 
178  /* Make cached copy of the data */
180  entry->remoterel.remoteid = remoterel->remoteid;
181  entry->remoterel.nspname = pstrdup(remoterel->nspname);
182  entry->remoterel.relname = pstrdup(remoterel->relname);
183  entry->remoterel.natts = remoterel->natts;
184  entry->remoterel.attnames = palloc(remoterel->natts * sizeof(char *));
185  entry->remoterel.atttyps = palloc(remoterel->natts * sizeof(Oid));
186  for (i = 0; i < remoterel->natts; i++)
187  {
188  entry->remoterel.attnames[i] = pstrdup(remoterel->attnames[i]);
189  entry->remoterel.atttyps[i] = remoterel->atttyps[i];
190  }
191  entry->remoterel.replident = remoterel->replident;
192  entry->remoterel.attkeys = bms_copy(remoterel->attkeys);
193  MemoryContextSwitchTo(oldctx);
194 }
195 
196 /*
197  * Find attribute index in TupleDesc struct by attribute name.
198  *
199  * Returns -1 if not found.
200  */
201 static int
203 {
204  int i;
205 
206  for (i = 0; i < remoterel->natts; i++)
207  {
208  if (strcmp(remoterel->attnames[i], attname) == 0)
209  return i;
210  }
211 
212  return -1;
213 }
214 
215 /*
216  * Report error with names of the missing local relation column(s), if any.
217  */
218 static void
220  Bitmapset *missingatts)
221 {
222  if (!bms_is_empty(missingatts))
223  {
224  StringInfoData missingattsbuf;
225  int missingattcnt = 0;
226  int i;
227 
228  initStringInfo(&missingattsbuf);
229 
230  while ((i = bms_first_member(missingatts)) >= 0)
231  {
232  missingattcnt++;
233  if (missingattcnt == 1)
234  appendStringInfo(&missingattsbuf, _("\"%s\""),
235  remoterel->attnames[i]);
236  else
237  appendStringInfo(&missingattsbuf, _(", \"%s\""),
238  remoterel->attnames[i]);
239  }
240 
241  ereport(ERROR,
242  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
243  errmsg_plural("logical replication target relation \"%s.%s\" is missing replicated column: %s",
244  "logical replication target relation \"%s.%s\" is missing replicated columns: %s",
245  missingattcnt,
246  remoterel->nspname,
247  remoterel->relname,
248  missingattsbuf.data)));
249  }
250 }
251 
252 /*
253  * Check if replica identity matches and mark the updatable flag.
254  *
255  * We allow for stricter replica identity (fewer columns) on subscriber as
256  * that will not stop us from finding unique tuple. IE, if publisher has
257  * identity (id,timestamp) and subscriber just (id) this will not be a
258  * problem, but in the opposite scenario it will.
259  *
260  * We just mark the relation entry as not updatable here if the local
261  * replica identity is found to be insufficient for applying
262  * updates/deletes (inserts don't care!) and leave it to
263  * check_relation_updatable() to throw the actual error if needed.
264  */
265 static void
267 {
268  Bitmapset *idkey;
269  LogicalRepRelation *remoterel = &entry->remoterel;
270  int i;
271 
272  entry->updatable = true;
273 
274  idkey = RelationGetIndexAttrBitmap(entry->localrel,
276  /* fallback to PK if no replica identity */
277  if (idkey == NULL)
278  {
279  idkey = RelationGetIndexAttrBitmap(entry->localrel,
281 
282  /*
283  * If no replica identity index and no PK, the published table must
284  * have replica identity FULL.
285  */
286  if (idkey == NULL && remoterel->replident != REPLICA_IDENTITY_FULL)
287  entry->updatable = false;
288  }
289 
290  i = -1;
291  while ((i = bms_next_member(idkey, i)) >= 0)
292  {
294 
296  ereport(ERROR,
297  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
298  errmsg("logical replication target relation \"%s.%s\" uses "
299  "system columns in REPLICA IDENTITY index",
300  remoterel->nspname, remoterel->relname)));
301 
303 
304  if (entry->attrmap->attnums[attnum] < 0 ||
305  !bms_is_member(entry->attrmap->attnums[attnum], remoterel->attkeys))
306  {
307  entry->updatable = false;
308  break;
309  }
310  }
311 }
312 
313 /*
314  * Open the local relation associated with the remote one.
315  *
316  * Rebuilds the Relcache mapping if it was invalidated by local DDL.
317  */
320 {
321  LogicalRepRelMapEntry *entry;
322  bool found;
323  LogicalRepRelation *remoterel;
324 
325  if (LogicalRepRelMap == NULL)
327 
328  /* Search for existing entry. */
329  entry = hash_search(LogicalRepRelMap, (void *) &remoteid,
330  HASH_FIND, &found);
331 
332  if (!found)
333  elog(ERROR, "no relation map entry for remote relation ID %u",
334  remoteid);
335 
336  remoterel = &entry->remoterel;
337 
338  /* Ensure we don't leak a relcache refcount. */
339  if (entry->localrel)
340  elog(ERROR, "remote relation ID %u is already open", remoteid);
341 
342  /*
343  * When opening and locking a relation, pending invalidation messages are
344  * processed which can invalidate the relation. Hence, if the entry is
345  * currently considered valid, try to open the local relation by OID and
346  * see if invalidation ensues.
347  */
348  if (entry->localrelvalid)
349  {
350  entry->localrel = try_table_open(entry->localreloid, lockmode);
351  if (!entry->localrel)
352  {
353  /* Table was renamed or dropped. */
354  entry->localrelvalid = false;
355  }
356  else if (!entry->localrelvalid)
357  {
358  /* Note we release the no-longer-useful lock here. */
359  table_close(entry->localrel, lockmode);
360  entry->localrel = NULL;
361  }
362  }
363 
364  /*
365  * If the entry has been marked invalid since we last had lock on it,
366  * re-open the local relation by name and rebuild all derived data.
367  */
368  if (!entry->localrelvalid)
369  {
370  Oid relid;
371  TupleDesc desc;
372  MemoryContext oldctx;
373  int i;
374  Bitmapset *missingatts;
375 
376  /* Release the no-longer-useful attrmap, if any. */
377  if (entry->attrmap)
378  {
379  free_attrmap(entry->attrmap);
380  entry->attrmap = NULL;
381  }
382 
383  /* Try to find and lock the relation by name. */
384  relid = RangeVarGetRelid(makeRangeVar(remoterel->nspname,
385  remoterel->relname, -1),
386  lockmode, true);
387  if (!OidIsValid(relid))
388  ereport(ERROR,
389  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
390  errmsg("logical replication target relation \"%s.%s\" does not exist",
391  remoterel->nspname, remoterel->relname)));
392  entry->localrel = table_open(relid, NoLock);
393  entry->localreloid = relid;
394 
395  /* Check for supported relkind. */
396  CheckSubscriptionRelkind(entry->localrel->rd_rel->relkind,
397  remoterel->nspname, remoterel->relname);
398 
399  /*
400  * Build the mapping of local attribute numbers to remote attribute
401  * numbers and validate that we don't miss any replicated columns as
402  * that would result in potentially unwanted data loss.
403  */
404  desc = RelationGetDescr(entry->localrel);
406  entry->attrmap = make_attrmap(desc->natts);
407  MemoryContextSwitchTo(oldctx);
408 
409  /* check and report missing attrs, if any */
410  missingatts = bms_add_range(NULL, 0, remoterel->natts - 1);
411  for (i = 0; i < desc->natts; i++)
412  {
413  int attnum;
414  Form_pg_attribute attr = TupleDescAttr(desc, i);
415 
416  if (attr->attisdropped || attr->attgenerated)
417  {
418  entry->attrmap->attnums[i] = -1;
419  continue;
420  }
421 
423  NameStr(attr->attname));
424 
425  entry->attrmap->attnums[i] = attnum;
426  if (attnum >= 0)
427  missingatts = bms_del_member(missingatts, attnum);
428  }
429 
430  logicalrep_report_missing_attrs(remoterel, missingatts);
431 
432  /* be tidy */
433  bms_free(missingatts);
434 
435  /*
436  * Set if the table's replica identity is enough to apply
437  * update/delete.
438  */
440 
441  entry->localrelvalid = true;
442  }
443 
444  if (entry->state != SUBREL_STATE_READY)
446  entry->localreloid,
447  &entry->statelsn);
448 
449  return entry;
450 }
451 
452 /*
453  * Close the previously opened logical relation.
454  */
455 void
457 {
458  table_close(rel->localrel, lockmode);
459  rel->localrel = NULL;
460 }
461 
462 /*
463  * Partition cache: look up partition LogicalRepRelMapEntry's
464  *
465  * Unlike relation map cache, this is keyed by partition OID, not remote
466  * relation OID, because we only have to use this cache in the case where
467  * partitions are not directly mapped to any remote relation, such as when
468  * replication is occurring with one of their ancestors as target.
469  */
470 
471 /*
472  * Relcache invalidation callback
473  */
474 static void
476 {
477  LogicalRepPartMapEntry *entry;
478 
479  /* Just to be sure. */
480  if (LogicalRepPartMap == NULL)
481  return;
482 
483  if (reloid != InvalidOid)
484  {
486 
488 
489  /* TODO, use inverse lookup hashtable? */
490  while ((entry = (LogicalRepPartMapEntry *) hash_seq_search(&status)) != NULL)
491  {
492  if (entry->relmapentry.localreloid == reloid)
493  {
494  entry->relmapentry.localrelvalid = false;
496  break;
497  }
498  }
499  }
500  else
501  {
502  /* invalidate all cache entries */
504 
506 
507  while ((entry = (LogicalRepPartMapEntry *) hash_seq_search(&status)) != NULL)
508  entry->relmapentry.localrelvalid = false;
509  }
510 }
511 
512 /*
513  * Reset the entries in the partition map that refer to remoterel.
514  *
515  * Called when new relation mapping is sent by the publisher to update our
516  * expected view of incoming data from said publisher.
517  *
518  * Note that we don't update the remoterel information in the entry here,
519  * we will update the information in logicalrep_partition_open to avoid
520  * unnecessary work.
521  */
522 void
524 {
526  LogicalRepPartMapEntry *part_entry;
527  LogicalRepRelMapEntry *entry;
528 
529  if (LogicalRepPartMap == NULL)
530  return;
531 
533  while ((part_entry = (LogicalRepPartMapEntry *) hash_seq_search(&status)) != NULL)
534  {
535  entry = &part_entry->relmapentry;
536 
537  if (entry->remoterel.remoteid != remoterel->remoteid)
538  continue;
539 
541 
542  memset(entry, 0, sizeof(LogicalRepRelMapEntry));
543  }
544 }
545 
546 /*
547  * Initialize the partition map cache.
548  */
549 static void
551 {
552  HASHCTL ctl;
553 
557  "LogicalRepPartMapContext",
559 
560  /* Initialize the relation hash table. */
561  ctl.keysize = sizeof(Oid); /* partition OID */
562  ctl.entrysize = sizeof(LogicalRepPartMapEntry);
564 
565  LogicalRepPartMap = hash_create("logicalrep partition map cache", 64, &ctl,
567 
568  /* Watch for invalidation events. */
570  (Datum) 0);
571 }
572 
573 /*
574  * logicalrep_partition_open
575  *
576  * Returned entry reuses most of the values of the root table's entry, save
577  * the attribute map, which can be different for the partition. However,
578  * we must physically copy all the data, in case the root table's entry
579  * gets freed/rebuilt.
580  *
581  * Note there's no logicalrep_partition_close, because the caller closes the
582  * component relation.
583  */
586  Relation partrel, AttrMap *map)
587 {
588  LogicalRepRelMapEntry *entry;
589  LogicalRepPartMapEntry *part_entry;
590  LogicalRepRelation *remoterel = &root->remoterel;
591  Oid partOid = RelationGetRelid(partrel);
592  AttrMap *attrmap = root->attrmap;
593  bool found;
594  MemoryContext oldctx;
595 
596  if (LogicalRepPartMap == NULL)
598 
599  /* Search for existing entry. */
601  (void *) &partOid,
602  HASH_ENTER, &found);
603 
604  entry = &part_entry->relmapentry;
605 
606  /*
607  * We must always overwrite entry->localrel with the latest partition
608  * Relation pointer, because the Relation pointed to by the old value may
609  * have been cleared after the caller would have closed the partition
610  * relation after the last use of this entry. Note that localrelvalid is
611  * only updated by the relcache invalidation callback, so it may still be
612  * true irrespective of whether the Relation pointed to by localrel has
613  * been cleared or not.
614  */
615  if (found && entry->localrelvalid)
616  {
617  entry->localrel = partrel;
618  return entry;
619  }
620 
621  /* Switch to longer-lived context. */
623 
624  if (!found)
625  {
626  memset(part_entry, 0, sizeof(LogicalRepPartMapEntry));
627  part_entry->partoid = partOid;
628  }
629 
630  /* Release the no-longer-useful attrmap, if any. */
631  if (entry->attrmap)
632  {
633  free_attrmap(entry->attrmap);
634  entry->attrmap = NULL;
635  }
636 
637  if (!entry->remoterel.remoteid)
638  {
639  int i;
640 
641  /* Remote relation is copied as-is from the root entry. */
642  entry = &part_entry->relmapentry;
643  entry->remoterel.remoteid = remoterel->remoteid;
644  entry->remoterel.nspname = pstrdup(remoterel->nspname);
645  entry->remoterel.relname = pstrdup(remoterel->relname);
646  entry->remoterel.natts = remoterel->natts;
647  entry->remoterel.attnames = palloc(remoterel->natts * sizeof(char *));
648  entry->remoterel.atttyps = palloc(remoterel->natts * sizeof(Oid));
649  for (i = 0; i < remoterel->natts; i++)
650  {
651  entry->remoterel.attnames[i] = pstrdup(remoterel->attnames[i]);
652  entry->remoterel.atttyps[i] = remoterel->atttyps[i];
653  }
654  entry->remoterel.replident = remoterel->replident;
655  entry->remoterel.attkeys = bms_copy(remoterel->attkeys);
656  }
657 
658  entry->localrel = partrel;
659  entry->localreloid = partOid;
660 
661  /*
662  * If the partition's attributes don't match the root relation's, we'll
663  * need to make a new attrmap which maps partition attribute numbers to
664  * remoterel's, instead of the original which maps root relation's
665  * attribute numbers to remoterel's.
666  *
667  * Note that 'map' which comes from the tuple routing data structure
668  * contains 1-based attribute numbers (of the parent relation). However,
669  * the map in 'entry', a logical replication data structure, contains
670  * 0-based attribute numbers (of the remote relation).
671  */
672  if (map)
673  {
674  AttrNumber attno;
675 
676  entry->attrmap = make_attrmap(map->maplen);
677  for (attno = 0; attno < entry->attrmap->maplen; attno++)
678  {
679  AttrNumber root_attno = map->attnums[attno];
680 
681  /* 0 means it's a dropped attribute. See comments atop AttrMap. */
682  if (root_attno == 0)
683  entry->attrmap->attnums[attno] = -1;
684  else
685  entry->attrmap->attnums[attno] = attrmap->attnums[root_attno - 1];
686  }
687  }
688  else
689  {
690  /* Lacking copy_attmap, do this the hard way. */
691  entry->attrmap = make_attrmap(attrmap->maplen);
692  memcpy(entry->attrmap->attnums, attrmap->attnums,
693  attrmap->maplen * sizeof(AttrNumber));
694  }
695 
696  /* Set if the table's replica identity is enough to apply update/delete. */
698 
699  entry->localrelvalid = true;
700 
701  /* state and statelsn are left set to 0. */
702  MemoryContextSwitchTo(oldctx);
703 
704  return entry;
705 }
void free_attrmap(AttrMap *map)
Definition: attmap.c:57
AttrMap * make_attrmap(int maplen)
Definition: attmap.c:41
int16 AttrNumber
Definition: attnum.h:21
#define AttrNumberGetAttrOffset(attNum)
Definition: attnum.h:51
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
Definition: attnum.h:41
Subscription * MySubscription
Definition: worker.c:253
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1045
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
Bitmapset * bms_del_member(Bitmapset *a, int x)
Definition: bitmapset.c:775
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:703
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Definition: bitmapset.c:836
int bms_first_member(Bitmapset *a)
Definition: bitmapset.c:998
#define NameStr(name)
Definition: c.h:692
#define OidIsValid(objectId)
Definition: c.h:721
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
void hash_seq_term(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1512
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1014
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define _(x)
Definition: elog.c:89
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
void CheckSubscriptionRelkind(char relkind, const char *nspname, const char *relname)
@ HASH_FIND
Definition: hsearch.h:113
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg)
Definition: inval.c:1561
int i
Definition: isn.c:73
int LOCKMODE
Definition: lockdefs.h:26
#define NoLock
Definition: lockdefs.h:34
uint32 LogicalRepRelId
Definition: logicalproto.h:96
struct LogicalRepRelMapEntry LogicalRepRelMapEntry
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:423
char * pstrdup(const char *in)
Definition: mcxt.c:1305
void pfree(void *pointer)
Definition: mcxt.c:1175
MemoryContext CacheMemoryContext
Definition: mcxt.c:51
void * palloc(Size size)
Definition: mcxt.c:1068
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:79
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:83
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
void * arg
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229
char GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn)
uintptr_t Datum
Definition: postgres.h:411
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:489
#define RelationGetDescr(relation)
Definition: rel.h:515
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
Definition: relcache.c:5105
@ INDEX_ATTR_BITMAP_PRIMARY_KEY
Definition: relcache.h:60
@ INDEX_ATTR_BITMAP_IDENTITY_KEY
Definition: relcache.h:61
static MemoryContext LogicalRepPartMapContext
Definition: relation.c:45
void logicalrep_partmap_reset_relmap(LogicalRepRelation *remoterel)
Definition: relation.c:523
static void logicalrep_partmap_init(void)
Definition: relation.c:550
static void logicalrep_report_missing_attrs(LogicalRepRelation *remoterel, Bitmapset *missingatts)
Definition: relation.c:219
static void logicalrep_relmap_free_entry(LogicalRepRelMapEntry *entry)
Definition: relation.c:125
LogicalRepRelMapEntry * logicalrep_partition_open(LogicalRepRelMapEntry *root, Relation partrel, AttrMap *map)
Definition: relation.c:585
struct LogicalRepPartMapEntry LogicalRepPartMapEntry
static void logicalrep_partmap_invalidate_cb(Datum arg, Oid reloid)
Definition: relation.c:475
static HTAB * LogicalRepPartMap
Definition: relation.c:46
static HTAB * LogicalRepRelMap
Definition: relation.c:32
static void logicalrep_rel_mark_updatable(LogicalRepRelMapEntry *entry)
Definition: relation.c:266
static MemoryContext LogicalRepRelMapContext
Definition: relation.c:30
void logicalrep_relmap_update(LogicalRepRelation *remoterel)
Definition: relation.c:157
static void logicalrep_relmap_init(void)
Definition: relation.c:98
LogicalRepRelMapEntry * logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
Definition: relation.c:319
static int logicalrep_rel_att_by_name(LogicalRepRelation *remoterel, const char *attname)
Definition: relation.c:202
static void logicalrep_relmap_invalidate_cb(Datum arg, Oid reloid)
Definition: relation.c:57
void logicalrep_rel_close(LogicalRepRelMapEntry *rel, LOCKMODE lockmode)
Definition: relation.c:456
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: attmap.h:35
int maplen
Definition: attmap.h:37
AttrNumber * attnums
Definition: attmap.h:36
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
MemoryContext hcxt
Definition: hsearch.h:86
Definition: dynahash.c:220
LogicalRepRelMapEntry relmapentry
Definition: relation.c:50
LogicalRepRelation remoterel
LogicalRepRelId remoteid
Definition: logicalproto.h:102
Bitmapset * attkeys
Definition: logicalproto.h:110
Form_pg_class rd_rel
Definition: rel.h:110
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
Relation try_table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:69
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92