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:832

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 325 of file pg_publication.c.

327{
329 bool found = false;
330
331 if (pub->alltables)
332 return false;
333
335 ObjectIdGetDatum(relid),
336 ObjectIdGetDatum(pub->oid));
338 {
340 bool isnull;
341
342 /* Lookup the column list attribute. */
345
346 /* Was a column list found? */
347 if (!isnull)
348 {
349 /* Build the column list bitmap in the given memory context. */
350 if (cols)
351 *cols = pub_collist_to_bitmapset(*cols, cfdatum, mcxt);
352
353 found = true;
354 }
355
357 }
358
359 return found;
360}
#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:264
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:230
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595

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 1007 of file pg_publication.c.

1008{
1010 ScanKeyData key[1];
1011 TableScanDesc scan;
1012 HeapTuple tuple;
1013 List *result = NIL;
1014 List *exceptlist = NIL;
1015
1016 Assert(!(relkind == RELKIND_SEQUENCE && pubviaroot));
1017
1018 /* EXCEPT filtering applies only to relations, not sequences */
1019 if (relkind == RELKIND_RELATION)
1020 exceptlist = GetExcludedPublicationTables(pubid, pubviaroot ?
1023
1025
1026 ScanKeyInit(&key[0],
1029 CharGetDatum(relkind));
1030
1031 scan = table_beginscan_catalog(classRel, 1, key);
1032
1033 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1034 {
1036 Oid relid = relForm->oid;
1037
1038 if (is_publishable_class(relid, relForm) &&
1039 !(relForm->relispartition && pubviaroot) &&
1040 !list_member_oid(exceptlist, relid))
1041 result = lappend_oid(result, relid);
1042 }
1043
1044 table_endscan(scan);
1045
1046 if (pubviaroot)
1047 {
1048 ScanKeyInit(&key[0],
1052
1053 scan = table_beginscan_catalog(classRel, 1, key);
1054
1055 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1056 {
1058 Oid relid = relForm->oid;
1059
1060 if (is_publishable_class(relid, relForm) &&
1061 !relForm->relispartition &&
1062 !list_member_oid(exceptlist, relid))
1063 result = lappend_oid(result, relid);
1064 }
1065
1066 table_endscan(scan);
1067 }
1068
1070 return result;
1071}
#define Assert(condition)
Definition c.h:945
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition heapam.c:1420
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:1004

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, 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 1200 of file pg_publication.c.

1201{
1202 List *result = NIL;
1204 ListCell *cell;
1205
1206 foreach(cell, pubschemalist)
1207 {
1208 Oid schemaid = lfirst_oid(cell);
1209 List *schemaRels = NIL;
1210
1212 result = list_concat(result, schemaRels);
1213 }
1214
1215 return result;
1216}
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(), and NIL.

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

◆ GetAllTablesPublications()

List * GetAllTablesPublications ( void  )
extern

Definition at line 961 of file pg_publication.c.

962{
963 List *result;
964 Relation rel;
966 SysScanDesc scan;
968
969 /* Find all publications that are marked as for all tables. */
971
975 BoolGetDatum(true));
976
977 scan = systable_beginscan(rel, InvalidOid, false,
978 NULL, 1, &scankey);
979
980 result = NIL;
981 while (HeapTupleIsValid(tup = systable_getnext(scan)))
982 {
983 Oid oid = ((Form_pg_publication) GETSTRUCT(tup))->oid;
984
985 result = lappend_oid(result, oid);
986 }
987
988 systable_endscan(scan);
990
991 return result;
992}
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
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, 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 950 of file pg_publication.c.

951{
952 Assert(GetPublication(pubid)->alltables);
953
954 return get_publication_relations(pubid, pub_partopt, true);
955}
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 1224 of file pg_publication.c.

1225{
1226 HeapTuple tup;
1227 Publication *pub;
1229
1231 if (!HeapTupleIsValid(tup))
1232 elog(ERROR, "cache lookup failed for publication %u", pubid);
1233
1235
1237 pub->oid = pubid;
1238 pub->name = pstrdup(NameStr(pubform->pubname));
1239 pub->alltables = pubform->puballtables;
1240 pub->allsequences = pubform->puballsequences;
1241 pub->pubactions.pubinsert = pubform->pubinsert;
1242 pub->pubactions.pubupdate = pubform->pubupdate;
1243 pub->pubactions.pubdelete = pubform->pubdelete;
1244 pub->pubactions.pubtruncate = pubform->pubtruncate;
1245 pub->pubviaroot = pubform->pubviaroot;
1246 pub->pubgencols_type = pubform->pubgencols;
1247
1249
1250 return pub;
1251}
#define NameStr(name)
Definition c.h:837
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define palloc_object(type)
Definition fe_memutils.h:74
char * pstrdup(const char *in)
Definition mcxt.c:1781
PublishGencolsType pubgencols_type
PublicationActions pubactions
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

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 1257 of file pg_publication.c.

1258{
1259 Oid oid;
1260
1261 oid = get_publication_oid(pubname, missing_ok);
1262
1263 return OidIsValid(oid) ? GetPublication(oid) : NULL;
1264}
#define OidIsValid(objectId)
Definition c.h:860
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition lsyscache.c:3847

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

Definition at line 1079 of file pg_publication.c.

1080{
1081 List *result = NIL;
1084 SysScanDesc scan;
1085 HeapTuple tup;
1086
1087 /* Find all schemas associated with the publication */
1089
1093 ObjectIdGetDatum(pubid));
1094
1097 true, NULL, 1, &scankey);
1098 while (HeapTupleIsValid(tup = systable_getnext(scan)))
1099 {
1101
1103
1104 result = lappend_oid(result, pubsch->pnnspid);
1105 }
1106
1107 systable_endscan(scan);
1109
1110 return result;
1111}
END_CATALOG_STRUCT typedef FormData_pg_publication_namespace * Form_pg_publication_namespace

References AccessShareLock, BTEqualStrategyNumber, fb(), Form_pg_publication_namespace, GETSTRUCT(), HeapTupleIsValid, lappend_oid(), NIL, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by AlterPublicationSchemas(), and GetAllSchemaPublicationRelations().

◆ GetPubPartitionOptionRelations()

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

Definition at line 367 of file pg_publication.c.

369{
372 {
374 NULL);
375
377 result = list_concat(result, all_parts);
379 {
380 ListCell *lc;
381
382 foreach(lc, all_parts)
383 {
385
387 result = lappend_oid(result, partOid);
388 }
389 }
390 else
391 Assert(false);
392 }
393 else
394 result = lappend_oid(result, relid);
395
396 return result;
397}
#define NoLock
Definition lockdefs.h:34
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2223
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, and PUBLICATION_PART_ROOT.

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

◆ GetRelationExcludedPublications()

List * GetRelationExcludedPublications ( Oid  relid)
extern

Definition at line 874 of file pg_publication.c.

875{
876 return get_relation_publications(relid, true);
877}
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 1143 of file pg_publication.c.

1144{
1146 ScanKeyData key[1];
1147 TableScanDesc scan;
1148 HeapTuple tuple;
1149 List *result = NIL;
1150
1152
1154
1155 ScanKeyInit(&key[0],
1159
1160 /* get all the relations present in the specified schema */
1161 scan = table_beginscan_catalog(classRel, 1, key);
1162 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1163 {
1165 Oid relid = relForm->oid;
1166 char relkind;
1167
1168 if (!is_publishable_class(relid, relForm))
1169 continue;
1170
1171 relkind = get_rel_relkind(relid);
1172 if (relkind == RELKIND_RELATION)
1173 result = lappend_oid(result, relid);
1174 else if (relkind == RELKIND_PARTITIONED_TABLE)
1175 {
1177
1178 /*
1179 * It is quite possible that some of the partitions are in a
1180 * different schema than the parent table, so we need to get such
1181 * partitions separately.
1182 */
1185 relForm->oid);
1186 result = list_concat_unique_oid(result, partitionrels);
1187 }
1188 }
1189
1190 table_endscan(scan);
1192 return result;
1193}
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, 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 1117 of file pg_publication.c.

1118{
1119 List *result = NIL;
1121 int i;
1122
1123 /* Find all publications associated with the schema */
1126 for (i = 0; i < pubschlist->n_members; i++)
1127 {
1128 HeapTuple tup = &pubschlist->members[i]->tuple;
1130
1131 result = lappend_oid(result, pubid);
1132 }
1133
1135
1136 return result;
1137}
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, 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 411 of file pg_publication.c.

412{
413 ListCell *lc;
415 int level = 0;
416
417 /*
418 * Find the "topmost" ancestor that is in this publication.
419 */
420 foreach(lc, ancestors)
421 {
425
426 level++;
427
429 {
431
432 if (ancestor_level)
433 *ancestor_level = level;
434 }
435 else
436 {
439 {
441
442 if (ancestor_level)
443 *ancestor_level = level;
444 }
445 }
446
449 }
450
451 return topmost_relid;
452}
void list_free(List *list)
Definition list.c:1546
Oid get_rel_namespace(Oid relid)
Definition lsyscache.c:2172
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(), pub_contains_invalid_column(), and pub_rf_contains_invalid_column().

◆ is_publishable_relation()

bool is_publishable_relation ( Relation  rel)
extern

Definition at line 161 of file pg_publication.c.

162{
164}
#define RelationGetRelid(relation)
Definition rel.h:514
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 278 of file pg_publication.c.

279{
282 SysScanDesc scan;
284 bool result = false;
285
290 ObjectIdGetDatum(pubid));
291
294 true, NULL, 1, &scankey);
295 tup = systable_getnext(scan);
297 {
299
301
302 /*
303 * For any publication, pg_publication_rel contains either only EXCEPT
304 * entries or only explicitly included tables. Therefore, examining
305 * the first tuple is sufficient to determine table inclusion.
306 */
307 result = !pubrel->prexcept;
308 }
309
310 systable_endscan(scan);
312
313 return result;
314}
END_CATALOG_STRUCT typedef FormData_pg_publication_rel * Form_pg_publication_rel

References AccessShareLock, BTEqualStrategyNumber, fb(), Form_pg_publication_rel, GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), 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 686 of file pg_publication.c.

687{
688 Bitmapset *result = columns;
689 ArrayType *arr;
690 int nelems;
691 int16 *elems;
693
695 nelems = ARR_DIMS(arr)[0];
696 elems = (int16 *) ARR_DATA_PTR(arr);
697
698 /* If a memory context was specified, switch to it. */
699 if (mcxt)
701
702 for (int i = 0; i < nelems; i++)
703 result = bms_add_member(result, elems[i]);
704
705 if (mcxt)
707
708 return result;
709}
#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:799
int16_t int16
Definition c.h:613
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124

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

Referenced by AlterPublicationTables(), and check_and_fetch_column_list().

◆ pub_collist_validate()

Bitmapset * pub_collist_validate ( Relation  targetrel,
List columns 
)
extern

Definition at line 637 of file pg_publication.c.

638{
639 Bitmapset *set = NULL;
640 ListCell *lc;
642
643 foreach(lc, columns)
644 {
645 char *colname = strVal(lfirst(lc));
647
651 errmsg("column \"%s\" of relation \"%s\" does not exist",
653
657 errmsg("cannot use system column \"%s\" in publication column list",
658 colname));
659
660 if (TupleDescAttr(tupdesc, attnum - 1)->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
663 errmsg("cannot use virtual generated column \"%s\" in publication column list",
664 colname));
665
666 if (bms_is_member(attnum, set))
669 errmsg("duplicate column \"%s\" in publication column list",
670 colname));
671
672 set = bms_add_member(set, attnum);
673 }
674
675 return set;
676}
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:510
int errcode(int sqlerrcode)
Definition elog.c:874
#define ereport(elevel,...)
Definition elog.h:150
AttrNumber get_attnum(Oid relid, const char *attname)
Definition lsyscache.c:977
static char * errmsg
int16 attnum
#define lfirst(lc)
Definition pg_list.h:172
#define RelationGetDescr(relation)
Definition rel.h:540
#define RelationGetRelationName(relation)
Definition rel.h:548
#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 718 of file pg_publication.c.

719{
720 Bitmapset *result = NULL;
721 TupleDesc desc = RelationGetDescr(relation);
722
723 for (int i = 0; i < desc->natts; i++)
724 {
726
727 if (att->attisdropped)
728 continue;
729
730 if (att->attgenerated)
731 {
732 /* We only support replication of STORED generated cols. */
733 if (att->attgenerated != ATTRIBUTE_GENERATED_STORED)
734 continue;
735
736 /* User hasn't requested to replicate STORED generated cols. */
737 if (include_gencols_type != PUBLISH_GENCOLS_STORED)
738 continue;
739 }
740
741 result = bms_add_member(result, att->attnum);
742 }
743
744 return result;
745}
FormData_pg_attribute * Form_pg_attribute

References bms_add_member(), fb(), i, TupleDescData::natts, RelationGetDescr, 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 485 of file pg_publication.c.

487{
488 Relation rel;
491 bool nulls[Natts_pg_publication_rel];
492 Relation targetrel = pri->relation;
495 Bitmapset *attnums;
496 Publication *pub = GetPublication(pubid);
499 List *relids = NIL;
500 int i;
502
504
505 /*
506 * Check for duplicates. Note that this does not really prevent
507 * duplicates, it's here just to provide nicer error message in common
508 * case. The real protection is the unique key on the catalog.
509 */
511 ObjectIdGetDatum(pubid)))
512 {
514
515 if (if_not_exists)
517
520 errmsg("relation \"%s\" is already member of publication \"%s\"",
522 }
523
525
526 /* Validate and translate column names into a Bitmapset of attnums. */
527 attnums = pub_collist_validate(pri->relation, pri->columns);
528
529 /* Form a tuple. */
530 memset(values, 0, sizeof(values));
531 memset(nulls, false, sizeof(nulls));
532
537 ObjectIdGetDatum(pubid);
539 ObjectIdGetDatum(relid);
541 BoolGetDatum(pri->except);
542
543 /* Add qualifications, if available */
544 if (pri->whereClause != NULL)
546 else
547 nulls[Anum_pg_publication_rel_prqual - 1] = true;
548
549 /* Add column list, if available */
550 if (pri->columns)
552 else
553 nulls[Anum_pg_publication_rel_prattrs - 1] = true;
554
556
557 /* Insert tuple into catalog. */
560
561 /* Register dependencies as needed */
563
564 /* Add dependency on the publication */
567
568 /* Add dependency on the relation */
571
572 /* Add dependency on the objects mentioned in the qualifications */
573 if (pri->whereClause)
574 recordDependencyOnSingleRelExpr(&myself, pri->whereClause, relid,
576 false);
577
578 /* Add dependency on the columns, if any are listed */
579 i = -1;
580 while ((i = bms_next_member(attnums, i)) >= 0)
581 {
584 }
585
586 /* Close the table. */
588
589 /*
590 * Determine whether EXCEPT tables require explicit relcache invalidation.
591 *
592 * For CREATE PUBLICATION with EXCEPT tables, invalidation is skipped
593 * here, as CreatePublication() function invalidates all relations as part
594 * of defining a FOR ALL TABLES publication.
595 *
596 * For ALTER PUBLICATION, invalidation is needed only when adding an
597 * EXCEPT table to a publication already marked as ALL TABLES. For
598 * publications that were originally empty or defined as ALL SEQUENCES and
599 * are being converted to ALL TABLES, invalidation is skipped here, as
600 * AlterPublicationAllFlags() function invalidates all relations while
601 * marking the publication as ALL TABLES publication.
602 */
604 (alter_stmt->for_all_tables && pri->except);
605
606 if (!pri->except || inval_except_table)
607 {
608 /*
609 * Invalidate relcache so that publication info is rebuilt.
610 *
611 * For the partitioned tables, we must invalidate all partitions
612 * contained in the respective partition hierarchies, not just the one
613 * explicitly mentioned in the publication. This is required because
614 * we implicitly publish the child tables when the parent table is
615 * published.
616 */
618 relid);
619
621 }
622
623 return myself;
624}
int bms_next_member(const Bitmapset *a, int prevbit)
Definition bitmapset.c:1290
static Datum values[MAXATTR]
Definition bootstrap.c:188
#define CStringGetTextDatum(s)
Definition builtins.h:98
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
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:1037
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1384
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:47
static int2vector * attnumstoint2vector(Bitmapset *attrs)
Bitmapset * pub_collist_validate(Relation targetrel, List *columns)
static void check_publication_add_relation(PublicationRelInfo *pri)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
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 751 of file pg_publication.c.

752{
753 Relation rel;
757 Oid psschid;
758 Publication *pub = GetPublication(pubid);
762
764
765 /*
766 * Check for duplicates. Note that this does not really prevent
767 * duplicates, it's here just to provide nicer error message in common
768 * case. The real protection is the unique key on the catalog.
769 */
772 ObjectIdGetDatum(pubid)))
773 {
775
776 if (if_not_exists)
778
781 errmsg("schema \"%s\" is already member of publication \"%s\"",
783 }
784
786
787 /* Form a tuple */
788 memset(values, 0, sizeof(values));
789 memset(nulls, false, sizeof(nulls));
790
795 ObjectIdGetDatum(pubid);
798
800
801 /* Insert tuple into catalog */
804
806
807 /* Add dependency on the publication */
810
811 /* Add dependency on the schema */
814
815 /* Close the table */
817
818 /*
819 * Invalidate relcache so that publication info is rebuilt. See
820 * publication_add_relation for why we need to consider all the
821 * partitions.
822 */
826
827 return myself;
828}
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3588
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.