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