PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_publication.h File Reference
#include "catalog/genbki.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_publication_d.h"
Include dependency graph for pg_publication.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PublicationActions
 
struct  PublicationDesc
 
struct  Publication
 
struct  PublicationRelInfo
 

Typedefs

typedef struct PublicationActions PublicationActions
 
typedef struct PublicationDesc PublicationDesc
 
typedef struct Publication Publication
 
typedef struct PublicationRelInfo PublicationRelInfo
 
typedef enum PublicationPartOpt PublicationPartOpt
 

Enumerations

enum  PublicationPartOpt { PUBLICATION_PART_ROOT , PUBLICATION_PART_LEAF , PUBLICATION_PART_ALL }
 

Functions

BEGIN_CATALOG_STRUCT CATALOG (pg_publication, 6104, PublicationRelationId)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_publication_oid_index, 6110, PublicationObjectIndexId, pg_publication, btree(oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_publication_pubname_index, 6111, PublicationNameIndexId, pg_publication, btree(pubname name_ops))
 
 MAKE_SYSCACHE (PUBLICATIONOID, pg_publication_oid_index, 8)
 
 MAKE_SYSCACHE (PUBLICATIONNAME, pg_publication_pubname_index, 8)
 
PublicationGetPublication (Oid pubid)
 
PublicationGetPublicationByName (const char *pubname, bool missing_ok)
 
ListGetRelationIncludedPublications (Oid relid)
 
ListGetRelationExcludedPublications (Oid relid)
 
ListGetIncludedPublicationRelations (Oid pubid, PublicationPartOpt pub_partopt)
 
ListGetExcludedPublicationTables (Oid pubid, PublicationPartOpt pub_partopt)
 
ListGetAllTablesPublications (void)
 
ListGetAllPublicationRelations (Oid pubid, char relkind, bool pubviaroot)
 
ListGetPublicationSchemas (Oid pubid)
 
ListGetSchemaPublications (Oid schemaid)
 
ListGetSchemaPublicationRelations (Oid schemaid, PublicationPartOpt pub_partopt)
 
ListGetAllSchemaPublicationRelations (Oid pubid, PublicationPartOpt pub_partopt)
 
ListGetPubPartitionOptionRelations (List *result, PublicationPartOpt pub_partopt, Oid relid)
 
Oid GetTopMostAncestorInPublication (Oid puboid, List *ancestors, int *ancestor_level)
 
bool is_publishable_relation (Relation rel)
 
bool is_schema_publication (Oid pubid)
 
bool is_table_publication (Oid pubid)
 
bool check_and_fetch_column_list (Publication *pub, Oid relid, MemoryContext mcxt, Bitmapset **cols)
 
ObjectAddress publication_add_relation (Oid pubid, PublicationRelInfo *pri, bool if_not_exists, AlterPublicationStmt *alter_stmt)
 
Bitmapsetpub_collist_validate (Relation targetrel, List *columns)
 
ObjectAddress publication_add_schema (Oid pubid, Oid schemaid, bool if_not_exists)
 
Bitmapsetpub_collist_to_bitmapset (Bitmapset *columns, Datum pubcols, MemoryContext mcxt)
 
Bitmapsetpub_form_cols_map (Relation relation, PublishGencolsType include_gencols_type)
 

Variables

END_CATALOG_STRUCT typedef FormData_pg_publicationForm_pg_publication
 
 FormData_pg_publication
 

Typedef Documentation

◆ Publication

◆ PublicationActions

◆ PublicationDesc

◆ PublicationPartOpt

◆ PublicationRelInfo

Enumeration Type Documentation

◆ PublicationPartOpt

Enumerator
PUBLICATION_PART_ROOT 
PUBLICATION_PART_LEAF 
PUBLICATION_PART_ALL 

Definition at line 171 of file pg_publication.h.

172{
PublicationPartOpt
@ PUBLICATION_PART_LEAF
@ PUBLICATION_PART_ROOT
@ PUBLICATION_PART_ALL

Function Documentation

◆ CATALOG()

Definition at line 31 of file pg_publication.h.

32{
33 Oid oid; /* oid */
34
35 NameData pubname; /* name of the publication */
36
37 Oid pubowner BKI_LOOKUP(pg_authid); /* publication owner */
38
39 /*
40 * indicates that this is special publication which should encompass all
41 * tables in the database (except for the unlogged and temp ones)
42 */
43 bool puballtables;
44
45 /*
46 * indicates that this is special publication which should encompass all
47 * sequences in the database (except for the unlogged and temp ones)
48 */
49 bool puballsequences;
50
51 /* true if inserts are published */
52 bool pubinsert;
53
54 /* true if updates are published */
55 bool pubupdate;
56
57 /* true if deletes are published */
58 bool pubdelete;
59
60 /* true if truncates are published */
61 bool pubtruncate;
62
63 /* true if partition changes are published using root schema */
64 bool pubviaroot;
65
66 /*
67 * 'n'(none) if generated column data should not be published. 's'(stored)
68 * if stored generated column data should be published.
69 */
70 char pubgencols;
#define BKI_LOOKUP(catalog)
Definition genbki.h:65
FormData_pg_publication
unsigned int Oid
static int fb(int x)
Definition c.h:889

References BKI_LOOKUP, and fb().

◆ check_and_fetch_column_list()

bool check_and_fetch_column_list ( Publication pub,
Oid  relid,
MemoryContext  mcxt,
Bitmapset **  cols 
)
extern

Definition at line 373 of file pg_publication.c.

375{
377 bool found = false;
378
379 if (pub->alltables)
380 return false;
381
383 ObjectIdGetDatum(relid),
384 ObjectIdGetDatum(pub->oid));
386 {
388 bool isnull;
389
390 /* Lookup the column list attribute. */
393
394 /* Was a column list found? */
395 if (!isnull)
396 {
397 /* Build the column list bitmap in the given memory context. */
398 if (cols)
399 *cols = pub_collist_to_bitmapset(*cols, cfdatum, mcxt);
400
401 found = true;
402 }
403
405 }
406
407 return found;
408}
#define HeapTupleIsValid(tuple)
Definition htup.h:78
Bitmapset * pub_collist_to_bitmapset(Bitmapset *columns, Datum pubcols, MemoryContext mcxt)
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:231
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References Publication::alltables, fb(), HeapTupleIsValid, ObjectIdGetDatum(), Publication::oid, pub_collist_to_bitmapset(), ReleaseSysCache(), SearchSysCache2(), and SysCacheGetAttr().

Referenced by check_and_init_gencol(), pgoutput_column_list_init(), and pub_contains_invalid_column().

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_publication_pubname_index  ,
6111  ,
PublicationNameIndexId  ,
pg_publication  ,
btree(pubname name_ops  
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_publication_oid_index  ,
6110  ,
PublicationObjectIndexId  ,
pg_publication  ,
btree(oid oid_ops  
)

◆ GetAllPublicationRelations()

List * GetAllPublicationRelations ( Oid  pubid,
char  relkind,
bool  pubviaroot 
)
extern

Definition at line 1055 of file pg_publication.c.

1056{
1058 ScanKeyData key[1];
1059 TableScanDesc scan;
1060 HeapTuple tuple;
1061 List *result = NIL;
1062 List *exceptlist = NIL;
1063
1064 Assert(!(relkind == RELKIND_SEQUENCE && pubviaroot));
1065
1066 /* EXCEPT filtering applies only to relations, not sequences */
1067 if (relkind == RELKIND_RELATION)
1068 exceptlist = GetExcludedPublicationTables(pubid, pubviaroot ?
1071
1073
1074 ScanKeyInit(&key[0],
1077 CharGetDatum(relkind));
1078
1079 scan = table_beginscan_catalog(classRel, 1, key);
1080
1081 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1082 {
1084 Oid relid = relForm->oid;
1085
1086 if (is_publishable_class(relid, relForm) &&
1087 !(relForm->relispartition && pubviaroot) &&
1088 !list_member_oid(exceptlist, relid))
1089 result = lappend_oid(result, relid);
1090 }
1091
1092 table_endscan(scan);
1093
1094 if (pubviaroot)
1095 {
1096 ScanKeyInit(&key[0],
1100
1101 scan = table_beginscan_catalog(classRel, 1, key);
1102
1103 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1104 {
1106 Oid relid = relForm->oid;
1107
1108 if (is_publishable_class(relid, relForm) &&
1109 !relForm->relispartition &&
1110 !list_member_oid(exceptlist, relid))
1111 result = lappend_oid(result, relid);
1112 }
1113
1114 table_endscan(scan);
1115 }
1116
1118 return result;
1119}
#define Assert(condition)
Definition c.h:1002
uint32 result
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition heapam.c:1436
static void * GETSTRUCT(const HeapTupleData *tuple)
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
bool list_member_oid(const List *list, Oid datum)
Definition list.c:722
#define AccessShareLock
Definition lockdefs.h:36
FormData_pg_class * Form_pg_class
Definition pg_class.h:160
#define NIL
Definition pg_list.h:68
static bool is_publishable_class(Oid relid, Form_pg_class reltuple)
List * GetExcludedPublicationTables(Oid pubid, PublicationPartOpt pub_partopt)
static Datum CharGetDatum(char X)
Definition postgres.h:132
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
@ ForwardScanDirection
Definition sdir.h:28
#define BTEqualStrategyNumber
Definition stratnum.h:31
Definition pg_list.h:54
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
Definition tableam.c:113
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1061

References AccessShareLock, Assert, BTEqualStrategyNumber, CharGetDatum(), fb(), ForwardScanDirection, GetExcludedPublicationTables(), GETSTRUCT(), heap_getnext(), is_publishable_class(), lappend_oid(), list_member_oid(), NIL, PUBLICATION_PART_LEAF, PUBLICATION_PART_ROOT, result, ScanKeyInit(), table_beginscan_catalog(), table_close(), table_endscan(), and table_open().

Referenced by pg_get_publication_sequences(), and pg_get_publication_tables().

◆ GetAllSchemaPublicationRelations()

List * GetAllSchemaPublicationRelations ( Oid  pubid,
PublicationPartOpt  pub_partopt 
)
extern

Definition at line 1248 of file pg_publication.c.

1249{
1250 List *result = NIL;
1252 ListCell *cell;
1253
1254 foreach(cell, pubschemalist)
1255 {
1256 Oid schemaid = lfirst_oid(cell);
1257 List *schemaRels = NIL;
1258
1261 }
1262
1263 return result;
1264}
List * list_concat(List *list1, const List *list2)
Definition list.c:561
#define lfirst_oid(lc)
Definition pg_list.h:174
List * GetPublicationSchemas(Oid pubid)
List * GetSchemaPublicationRelations(Oid schemaid, PublicationPartOpt pub_partopt)

References fb(), GetPublicationSchemas(), GetSchemaPublicationRelations(), lfirst_oid, list_concat(), NIL, and result.

Referenced by AlterPublicationOptions(), InvalidatePubRelSyncCache(), and pg_get_publication_tables().

◆ GetAllTablesPublications()

List * GetAllTablesPublications ( void  )
extern

Definition at line 1009 of file pg_publication.c.

1010{
1011 List *result;
1012 Relation rel;
1014 SysScanDesc scan;
1015 HeapTuple tup;
1016
1017 /* Find all publications that are marked as for all tables. */
1019
1023 BoolGetDatum(true));
1024
1025 scan = systable_beginscan(rel, InvalidOid, false,
1026 NULL, 1, &scankey);
1027
1028 result = NIL;
1029 while (HeapTupleIsValid(tup = systable_getnext(scan)))
1030 {
1031 Oid oid = ((Form_pg_publication) GETSTRUCT(tup))->oid;
1032
1033 result = lappend_oid(result, oid);
1034 }
1035
1036 systable_endscan(scan);
1038
1039 return result;
1040}
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:604
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:515
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
END_CATALOG_STRUCT typedef FormData_pg_publication * Form_pg_publication
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
#define InvalidOid

References AccessShareLock, BoolGetDatum(), BTEqualStrategyNumber, fb(), Form_pg_publication, GETSTRUCT(), HeapTupleIsValid, InvalidOid, lappend_oid(), NIL, result, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by RelationBuildPublicationDesc().

◆ GetExcludedPublicationTables()

List * GetExcludedPublicationTables ( Oid  pubid,
PublicationPartOpt  pub_partopt 
)
extern

Definition at line 998 of file pg_publication.c.

999{
1000 Assert(GetPublication(pubid)->alltables);
1001
1002 return get_publication_relations(pubid, pub_partopt, true);
1003}
static List * get_publication_relations(Oid pubid, PublicationPartOpt pub_partopt, bool except_flag)
Publication * GetPublication(Oid pubid)

References Assert, fb(), get_publication_relations(), and GetPublication().

Referenced by AlterPublicationTables(), and GetAllPublicationRelations().

◆ GetIncludedPublicationRelations()

List * GetIncludedPublicationRelations ( Oid  pubid,
PublicationPartOpt  pub_partopt 
)
extern

◆ GetPublication()

Publication * GetPublication ( Oid  pubid)
extern

Definition at line 1272 of file pg_publication.c.

1273{
1274 HeapTuple tup;
1275 Publication *pub;
1277
1279 if (!HeapTupleIsValid(tup))
1280 elog(ERROR, "cache lookup failed for publication %u", pubid);
1281
1283
1285 pub->oid = pubid;
1286 pub->name = pstrdup(NameStr(pubform->pubname));
1287 pub->alltables = pubform->puballtables;
1288 pub->allsequences = pubform->puballsequences;
1289 pub->pubactions.pubinsert = pubform->pubinsert;
1290 pub->pubactions.pubupdate = pubform->pubupdate;
1291 pub->pubactions.pubdelete = pubform->pubdelete;
1292 pub->pubactions.pubtruncate = pubform->pubtruncate;
1293 pub->pubviaroot = pubform->pubviaroot;
1294 pub->pubgencols_type = pubform->pubgencols;
1295
1297
1298 return pub;
1299}
#define NameStr(name)
Definition c.h:894
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define palloc_object(type)
Definition fe_memutils.h:89
char * pstrdup(const char *in)
Definition mcxt.c:1910
PublishGencolsType pubgencols_type
PublicationActions pubactions
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References Publication::allsequences, Publication::alltables, elog, ERROR, fb(), Form_pg_publication, GETSTRUCT(), HeapTupleIsValid, Publication::name, NameStr, ObjectIdGetDatum(), Publication::oid, palloc_object, pstrdup(), Publication::pubactions, PublicationActions::pubdelete, Publication::pubgencols_type, PublicationActions::pubinsert, PublicationActions::pubtruncate, PublicationActions::pubupdate, Publication::pubviaroot, ReleaseSysCache(), and SearchSysCache1().

Referenced by GetExcludedPublicationTables(), GetIncludedPublicationRelations(), GetPublicationByName(), pg_get_publication_tables(), pub_contains_invalid_column(), publication_add_relation(), and publication_add_schema().

◆ GetPublicationByName()

Publication * GetPublicationByName ( const char pubname,
bool  missing_ok 
)
extern

Definition at line 1305 of file pg_publication.c.

1306{
1307 Oid oid;
1308
1309 oid = get_publication_oid(pubname, missing_ok);
1310
1311 return OidIsValid(oid) ? GetPublication(oid) : NULL;
1312}
#define OidIsValid(objectId)
Definition c.h:917
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition lsyscache.c:3986

References fb(), get_publication_oid(), GetPublication(), and OidIsValid.

Referenced by get_object_address_publication_rel(), get_object_address_publication_schema(), LoadPublications(), pg_get_publication_sequences(), and pg_get_publication_tables().

◆ GetPublicationSchemas()

List * GetPublicationSchemas ( Oid  pubid)
extern

◆ GetPubPartitionOptionRelations()

List * GetPubPartitionOptionRelations ( List result,
PublicationPartOpt  pub_partopt,
Oid  relid 
)
extern

Definition at line 415 of file pg_publication.c.

417{
420 {
422 NULL);
423
427 {
428 ListCell *lc;
429
430 foreach(lc, all_parts)
431 {
433
436 }
437 }
438 else
439 Assert(false);
440 }
441 else
442 result = lappend_oid(result, relid);
443
444 return result;
445}
#define NoLock
Definition lockdefs.h:34
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2317
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)

References Assert, fb(), find_all_inheritors(), get_rel_relkind(), lappend_oid(), lfirst_oid, list_concat(), NoLock, PUBLICATION_PART_ALL, PUBLICATION_PART_LEAF, PUBLICATION_PART_ROOT, and result.

Referenced by AlterPublicationOptions(), get_publication_relations(), GetSchemaPublicationRelations(), publication_add_relation(), and RemovePublicationRelById().

◆ GetRelationExcludedPublications()

List * GetRelationExcludedPublications ( Oid  relid)
extern

Definition at line 922 of file pg_publication.c.

923{
924 return get_relation_publications(relid, true);
925}
static List * get_relation_publications(Oid relid, bool except_flag)

References get_relation_publications().

Referenced by ATExecAttachPartition(), get_rel_sync_entry(), and RelationBuildPublicationDesc().

◆ GetRelationIncludedPublications()

List * GetRelationIncludedPublications ( Oid  relid)
extern

◆ GetSchemaPublicationRelations()

List * GetSchemaPublicationRelations ( Oid  schemaid,
PublicationPartOpt  pub_partopt 
)
extern

Definition at line 1191 of file pg_publication.c.

1192{
1194 ScanKeyData key[1];
1195 TableScanDesc scan;
1196 HeapTuple tuple;
1197 List *result = NIL;
1198
1200
1202
1203 ScanKeyInit(&key[0],
1207
1208 /* get all the relations present in the specified schema */
1209 scan = table_beginscan_catalog(classRel, 1, key);
1210 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1211 {
1213 Oid relid = relForm->oid;
1214 char relkind;
1215
1216 if (!is_publishable_class(relid, relForm))
1217 continue;
1218
1219 relkind = get_rel_relkind(relid);
1220 if (relkind == RELKIND_RELATION)
1221 result = lappend_oid(result, relid);
1222 else if (relkind == RELKIND_PARTITIONED_TABLE)
1223 {
1225
1226 /*
1227 * It is quite possible that some of the partitions are in a
1228 * different schema than the parent table, so we need to get such
1229 * partitions separately.
1230 */
1233 relForm->oid);
1235 }
1236 }
1237
1238 table_endscan(scan);
1240 return result;
1241}
List * list_concat_unique_oid(List *list1, const List *list2)
Definition list.c:1469
List * GetPubPartitionOptionRelations(List *result, PublicationPartOpt pub_partopt, Oid relid)

References AccessShareLock, Assert, BTEqualStrategyNumber, fb(), ForwardScanDirection, get_rel_relkind(), GetPubPartitionOptionRelations(), GETSTRUCT(), heap_getnext(), is_publishable_class(), lappend_oid(), list_concat_unique_oid(), NIL, ObjectIdGetDatum(), OidIsValid, result, ScanKeyInit(), table_beginscan_catalog(), table_close(), table_endscan(), and table_open().

Referenced by GetAllSchemaPublicationRelations(), publication_add_schema(), and RemovePublicationSchemaById().

◆ GetSchemaPublications()

List * GetSchemaPublications ( Oid  schemaid)
extern

Definition at line 1165 of file pg_publication.c.

1166{
1167 List *result = NIL;
1169 int i;
1170
1171 /* Find all publications associated with the schema */
1174 for (i = 0; i < pubschlist->n_members; i++)
1175 {
1176 HeapTuple tup = &pubschlist->members[i]->tuple;
1178
1179 result = lappend_oid(result, pubid);
1180 }
1181
1183
1184 return result;
1185}
int i
Definition isn.c:77
#define ReleaseSysCacheList(x)
Definition syscache.h:134
#define SearchSysCacheList1(cacheId, key1)
Definition syscache.h:127

References fb(), Form_pg_publication_namespace, GETSTRUCT(), i, lappend_oid(), NIL, ObjectIdGetDatum(), ReleaseSysCacheList, result, and SearchSysCacheList1.

Referenced by get_rel_sync_entry(), GetTopMostAncestorInPublication(), and RelationBuildPublicationDesc().

◆ GetTopMostAncestorInPublication()

Oid GetTopMostAncestorInPublication ( Oid  puboid,
List ancestors,
int ancestor_level 
)
extern

Definition at line 459 of file pg_publication.c.

460{
461 ListCell *lc;
463 int level = 0;
464
465 /*
466 * Find the "topmost" ancestor that is in this publication.
467 */
468 foreach(lc, ancestors)
469 {
473
474 level++;
475
477 {
479
480 if (ancestor_level)
481 *ancestor_level = level;
482 }
483 else
484 {
487 {
489
490 if (ancestor_level)
491 *ancestor_level = level;
492 }
493 }
494
497 }
498
499 return topmost_relid;
500}
void list_free(List *list)
Definition list.c:1546
Oid get_rel_namespace(Oid relid)
Definition lsyscache.c:2266
List * GetRelationIncludedPublications(Oid relid)
List * GetSchemaPublications(Oid schemaid)

References fb(), get_rel_namespace(), GetRelationIncludedPublications(), GetSchemaPublications(), InvalidOid, lfirst_oid, list_free(), list_member_oid(), and NIL.

Referenced by get_rel_sync_entry(), is_table_publishable_in_publication(), pub_contains_invalid_column(), and pub_rf_contains_invalid_column().

◆ is_publishable_relation()

bool is_publishable_relation ( Relation  rel)
extern

Definition at line 178 of file pg_publication.c.

179{
181}
#define RelationGetRelid(relation)
Definition rel.h:516
Form_pg_class rd_rel
Definition rel.h:111

References is_publishable_class(), RelationData::rd_rel, and RelationGetRelid.

Referenced by pgoutput_change(), pgoutput_truncate(), and RelationBuildPublicationDesc().

◆ is_schema_publication()

◆ is_table_publication()

bool is_table_publication ( Oid  pubid)
extern

Definition at line 326 of file pg_publication.c.

327{
330 SysScanDesc scan;
332 bool result = false;
333
338 ObjectIdGetDatum(pubid));
339
342 true, NULL, 1, &scankey);
343 tup = systable_getnext(scan);
345 {
347
349
350 /*
351 * For any publication, pg_publication_rel contains either only EXCEPT
352 * entries or only explicitly included tables. Therefore, examining
353 * the first tuple is sufficient to determine table inclusion.
354 */
355 result = !pubrel->prexcept;
356 }
357
358 systable_endscan(scan);
360
361 return result;
362}
END_CATALOG_STRUCT typedef FormData_pg_publication_rel * Form_pg_publication_rel

References AccessShareLock, BTEqualStrategyNumber, fb(), Form_pg_publication_rel, GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), result, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by CheckAlterPublication().

◆ MAKE_SYSCACHE() [1/2]

MAKE_SYSCACHE ( PUBLICATIONNAME  ,
pg_publication_pubname_index  ,
 
)

◆ MAKE_SYSCACHE() [2/2]

MAKE_SYSCACHE ( PUBLICATIONOID  ,
pg_publication_oid_index  ,
 
)

◆ pub_collist_to_bitmapset()

Bitmapset * pub_collist_to_bitmapset ( Bitmapset columns,
Datum  pubcols,
MemoryContext  mcxt 
)
extern

Definition at line 734 of file pg_publication.c.

735{
736 Bitmapset *result = columns;
737 ArrayType *arr;
738 int nelems;
739 int16 *elems;
741
743 nelems = ARR_DIMS(arr)[0];
744 elems = (int16 *) ARR_DATA_PTR(arr);
745
746 /* If a memory context was specified, switch to it. */
747 if (mcxt)
749
750 for (int i = 0; i < nelems; i++)
751 result = bms_add_member(result, elems[i]);
752
753 if (mcxt)
755
756 return result;
757}
#define ARR_DATA_PTR(a)
Definition array.h:322
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define ARR_DIMS(a)
Definition array.h:294
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:934
int16_t int16
Definition c.h:678
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138

References ARR_DATA_PTR, ARR_DIMS, bms_add_member(), DatumGetArrayTypeP, fb(), i, MemoryContextSwitchTo(), and result.

Referenced by AlterPublicationTables(), and check_and_fetch_column_list().

◆ pub_collist_validate()

Bitmapset * pub_collist_validate ( Relation  targetrel,
List columns 
)
extern

Definition at line 685 of file pg_publication.c.

686{
687 Bitmapset *set = NULL;
688 ListCell *lc;
690
691 foreach(lc, columns)
692 {
693 char *colname = strVal(lfirst(lc));
695
699 errmsg("column \"%s\" of relation \"%s\" does not exist",
701
705 errmsg("cannot use system column \"%s\" in publication column list",
706 colname));
707
708 if (TupleDescAttr(tupdesc, attnum - 1)->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
711 errmsg("cannot use virtual generated column \"%s\" in publication column list",
712 colname));
713
714 if (bms_is_member(attnum, set))
717 errmsg("duplicate column \"%s\" in publication column list",
718 colname));
719
720 set = bms_add_member(set, attnum);
721 }
722
723 return set;
724}
int16 AttrNumber
Definition attnum.h:21
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
Definition attnum.h:41
#define InvalidAttrNumber
Definition attnum.h:23
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:645
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
AttrNumber get_attnum(Oid relid, const char *attname)
Definition lsyscache.c:1084
static char * errmsg
int16 attnum
#define lfirst(lc)
Definition pg_list.h:172
#define RelationGetDescr(relation)
Definition rel.h:542
#define RelationGetRelationName(relation)
Definition rel.h:550
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178
#define strVal(v)
Definition value.h:82

References attnum, AttrNumberIsForUserDefinedAttr, bms_add_member(), bms_is_member(), ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg, ERROR, fb(), get_attnum(), InvalidAttrNumber, lfirst, RelationGetDescr, RelationGetRelationName, RelationGetRelid, strVal, and TupleDescAttr().

Referenced by AlterPublicationTables(), and publication_add_relation().

◆ pub_form_cols_map()

Bitmapset * pub_form_cols_map ( Relation  relation,
PublishGencolsType  include_gencols_type 
)
extern

Definition at line 766 of file pg_publication.c.

767{
769 TupleDesc desc = RelationGetDescr(relation);
770
771 for (int i = 0; i < desc->natts; i++)
772 {
773 Form_pg_attribute att = TupleDescAttr(desc, i);
774
775 if (att->attisdropped)
776 continue;
777
778 if (att->attgenerated)
779 {
780 /* We only support replication of STORED generated cols. */
781 if (att->attgenerated != ATTRIBUTE_GENERATED_STORED)
782 continue;
783
784 /* User hasn't requested to replicate STORED generated cols. */
785 if (include_gencols_type != PUBLISH_GENCOLS_STORED)
786 continue;
787 }
788
789 result = bms_add_member(result, att->attnum);
790 }
791
792 return result;
793}
FormData_pg_attribute * Form_pg_attribute

References bms_add_member(), fb(), i, TupleDescData::natts, RelationGetDescr, result, and TupleDescAttr().

Referenced by pgoutput_column_list_init().

◆ publication_add_relation()

ObjectAddress publication_add_relation ( Oid  pubid,
PublicationRelInfo pri,
bool  if_not_exists,
AlterPublicationStmt alter_stmt 
)
extern

Definition at line 533 of file pg_publication.c.

535{
536 Relation rel;
539 bool nulls[Natts_pg_publication_rel];
540 Relation targetrel = pri->relation;
543 Bitmapset *attnums;
544 Publication *pub = GetPublication(pubid);
547 List *relids = NIL;
548 int i;
550
552
553 /*
554 * Check for duplicates. Note that this does not really prevent
555 * duplicates, it's here just to provide nicer error message in common
556 * case. The real protection is the unique key on the catalog.
557 */
559 ObjectIdGetDatum(pubid)))
560 {
562
563 if (if_not_exists)
565
568 errmsg("relation \"%s\" is already member of publication \"%s\"",
570 }
571
573
574 /* Validate and translate column names into a Bitmapset of attnums. */
575 attnums = pub_collist_validate(pri->relation, pri->columns);
576
577 /* Form a tuple. */
578 memset(values, 0, sizeof(values));
579 memset(nulls, false, sizeof(nulls));
580
585 ObjectIdGetDatum(pubid);
587 ObjectIdGetDatum(relid);
589 BoolGetDatum(pri->except);
590
591 /* Add qualifications, if available */
592 if (pri->whereClause != NULL)
594 else
595 nulls[Anum_pg_publication_rel_prqual - 1] = true;
596
597 /* Add column list, if available */
598 if (pri->columns)
600 else
601 nulls[Anum_pg_publication_rel_prattrs - 1] = true;
602
604
605 /* Insert tuple into catalog. */
608
609 /* Register dependencies as needed */
611
612 /* Add dependency on the publication */
615
616 /* Add dependency on the relation */
619
620 /* Add dependency on the objects mentioned in the qualifications */
621 if (pri->whereClause)
622 recordDependencyOnSingleRelExpr(&myself, pri->whereClause, relid,
624 false);
625
626 /* Add dependency on the columns, if any are listed */
627 i = -1;
628 while ((i = bms_next_member(attnums, i)) >= 0)
629 {
632 }
633
634 /* Close the table. */
636
637 /*
638 * Determine whether EXCEPT tables require explicit relcache invalidation.
639 *
640 * For CREATE PUBLICATION with EXCEPT tables, invalidation is skipped
641 * here, as CreatePublication() function invalidates all relations as part
642 * of defining a FOR ALL TABLES publication.
643 *
644 * For ALTER PUBLICATION, invalidation is needed only when adding an
645 * EXCEPT table to a publication already marked as ALL TABLES. For
646 * publications that were originally empty or defined as ALL SEQUENCES and
647 * are being converted to ALL TABLES, invalidation is skipped here, as
648 * AlterPublicationAllFlags() function invalidates all relations while
649 * marking the publication as ALL TABLES publication.
650 */
652 (alter_stmt->for_all_tables && pri->except);
653
654 if (!pri->except || inval_except_table)
655 {
656 /*
657 * Invalidate relcache so that publication info is rebuilt.
658 *
659 * For the partitioned tables, we must invalidate all partitions
660 * contained in the respective partition hierarchies, not just the one
661 * explicitly mentioned in the publication. This is required because
662 * we implicitly publish the child tables when the parent table is
663 * published.
664 */
666 relid);
667
669 }
670
671 return myself;
672}
int bms_next_member(const Bitmapset *a, int prevbit)
Definition bitmapset.c:1425
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define CStringGetTextDatum(s)
Definition builtins.h:98
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:475
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
@ DEPENDENCY_AUTO
Definition dependency.h:34
@ DEPENDENCY_NORMAL
Definition dependency.h:33
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1372
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
#define RowExclusiveLock
Definition lockdefs.h:38
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
char * nodeToString(const void *obj)
Definition outfuncs.c:811
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition pg_depend.c:51
static int2vector * attnumstoint2vector(Bitmapset *attrs)
Bitmapset * pub_collist_validate(Relation targetrel, List *columns)
static void check_publication_add_relation(PublicationRelInfo *pri)
#define PointerGetDatum(X)
Definition postgres.h:354
void InvalidatePublicationRels(List *relids)
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition syscache.h:102

References Publication::alltables, attnumstoint2vector(), bms_next_member(), BoolGetDatum(), CatalogTupleInsert(), check_publication_add_relation(), CStringGetTextDatum, DEPENDENCY_AUTO, DEPENDENCY_NORMAL, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg, ERROR, fb(), GetNewOidWithIndex(), GetPublication(), GetPubPartitionOptionRelations(), heap_form_tuple(), heap_freetuple(), i, InvalidatePublicationRels(), InvalidObjectAddress, Publication::name, NIL, nodeToString(), ObjectAddressSet, ObjectAddressSubSet, ObjectIdGetDatum(), PointerGetDatum, pub_collist_validate(), PUBLICATION_PART_ALL, recordDependencyOn(), recordDependencyOnSingleRelExpr(), RelationGetDescr, RelationGetRelationName, RelationGetRelid, RowExclusiveLock, SearchSysCacheExists2, table_close(), table_open(), and values.

Referenced by PublicationAddTables().

◆ publication_add_schema()

ObjectAddress publication_add_schema ( Oid  pubid,
Oid  schemaid,
bool  if_not_exists 
)
extern

Definition at line 799 of file pg_publication.c.

800{
801 Relation rel;
805 Oid psschid;
806 Publication *pub = GetPublication(pubid);
810
812
813 /*
814 * Check for duplicates. Note that this does not really prevent
815 * duplicates, it's here just to provide nicer error message in common
816 * case. The real protection is the unique key on the catalog.
817 */
820 ObjectIdGetDatum(pubid)))
821 {
823
824 if (if_not_exists)
826
829 errmsg("schema \"%s\" is already member of publication \"%s\"",
831 }
832
834
835 /* Form a tuple */
836 memset(values, 0, sizeof(values));
837 memset(nulls, false, sizeof(nulls));
838
843 ObjectIdGetDatum(pubid);
846
848
849 /* Insert tuple into catalog */
852
854
855 /* Add dependency on the publication */
858
859 /* Add dependency on the schema */
862
863 /* Close the table */
865
866 /*
867 * Invalidate relcache so that publication info is rebuilt. See
868 * publication_add_relation for why we need to consider all the
869 * partitions.
870 */
874
875 return myself;
876}
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3682
static void check_publication_add_schema(Oid schemaid)

References CatalogTupleInsert(), check_publication_add_schema(), DEPENDENCY_AUTO, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg, ERROR, fb(), get_namespace_name(), GetNewOidWithIndex(), GetPublication(), GetSchemaPublicationRelations(), heap_form_tuple(), heap_freetuple(), InvalidatePublicationRels(), InvalidObjectAddress, Publication::name, NIL, ObjectAddressSet, ObjectIdGetDatum(), PUBLICATION_PART_ALL, recordDependencyOn(), RelationGetDescr, RowExclusiveLock, SearchSysCacheExists2, table_close(), table_open(), and values.

Referenced by PublicationAddSchemas().

Variable Documentation

◆ Form_pg_publication

◆ FormData_pg_publication

FormData_pg_publication

Definition at line 71 of file pg_publication.h.