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