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 FormData_pg_publicationForm_pg_publication
 
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

 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)
 
ListGetRelationPublications (Oid relid)
 
ListGetPublicationRelations (Oid pubid, PublicationPartOpt pub_partopt)
 
ListGetAllTablesPublications (void)
 
ListGetAllPublicationRelations (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 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)
 
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

 FormData_pg_publication
 

Typedef Documentation

◆ Form_pg_publication

◆ Publication

◆ PublicationActions

◆ PublicationDesc

◆ PublicationPartOpt

◆ PublicationRelInfo

Enumeration Type Documentation

◆ PublicationPartOpt

Enumerator
PUBLICATION_PART_ROOT 
PUBLICATION_PART_LEAF 
PUBLICATION_PART_ALL 

Definition at line 164 of file pg_publication.h.

165{
PublicationPartOpt
@ PUBLICATION_PART_LEAF
@ PUBLICATION_PART_ROOT
@ PUBLICATION_PART_ALL

Function Documentation

◆ CATALOG()

CATALOG ( pg_publication  ,
6104  ,
PublicationRelationId   
)

Definition at line 29 of file pg_publication.h.

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

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

273{
275 bool found = false;
276
277 if (pub->alltables)
278 return false;
279
281 ObjectIdGetDatum(relid),
282 ObjectIdGetDatum(pub->oid));
284 {
286 bool isnull;
287
288 /* Lookup the column list attribute. */
291
292 /* Was a column list found? */
293 if (!isnull)
294 {
295 /* Build the column list bitmap in the given memory context. */
296 if (cols)
297 *cols = pub_collist_to_bitmapset(*cols, cfdatum, mcxt);
298
299 found = true;
300 }
301
303 }
304
305 return found;
306}
#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:262
uint64_t Datum
Definition postgres.h:70
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition syscache.c:230

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 ( char  relkind,
bool  pubviaroot 
)
extern

Definition at line 869 of file pg_publication.c.

870{
872 ScanKeyData key[1];
873 TableScanDesc scan;
874 HeapTuple tuple;
875 List *result = NIL;
876
877 Assert(!(relkind == RELKIND_SEQUENCE && pubviaroot));
878
880
881 ScanKeyInit(&key[0],
884 CharGetDatum(relkind));
885
886 scan = table_beginscan_catalog(classRel, 1, key);
887
888 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
889 {
891 Oid relid = relForm->oid;
892
893 if (is_publishable_class(relid, relForm) &&
894 !(relForm->relispartition && pubviaroot))
895 result = lappend_oid(result, relid);
896 }
897
898 table_endscan(scan);
899
900 if (pubviaroot)
901 {
902 ScanKeyInit(&key[0],
906
907 scan = table_beginscan_catalog(classRel, 1, key);
908
909 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
910 {
912 Oid relid = relForm->oid;
913
914 if (is_publishable_class(relid, relForm) &&
915 !relForm->relispartition)
916 result = lappend_oid(result, relid);
917 }
918
919 table_endscan(scan);
920 }
921
923 return result;
924}
#define Assert(condition)
Definition c.h:873
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition heapam.c:1409
static void * GETSTRUCT(const HeapTupleData *tuple)
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
#define AccessShareLock
Definition lockdefs.h:36
FormData_pg_class * Form_pg_class
Definition pg_class.h:156
#define NIL
Definition pg_list.h:68
static bool is_publishable_class(Oid relid, Form_pg_class reltuple)
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:1005

References AccessShareLock, Assert, BTEqualStrategyNumber, CharGetDatum(), fb(), ForwardScanDirection, GETSTRUCT(), heap_getnext(), is_publishable_class(), lappend_oid(), NIL, 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 1053 of file pg_publication.c.

1054{
1055 List *result = NIL;
1057 ListCell *cell;
1058
1059 foreach(cell, pubschemalist)
1060 {
1061 Oid schemaid = lfirst_oid(cell);
1062 List *schemaRels = NIL;
1063
1065 result = list_concat(result, schemaRels);
1066 }
1067
1068 return result;
1069}
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 826 of file pg_publication.c.

827{
828 List *result;
829 Relation rel;
831 SysScanDesc scan;
833
834 /* Find all publications that are marked as for all tables. */
836
840 BoolGetDatum(true));
841
842 scan = systable_beginscan(rel, InvalidOid, false,
843 NULL, 1, &scankey);
844
845 result = NIL;
846 while (HeapTupleIsValid(tup = systable_getnext(scan)))
847 {
848 Oid oid = ((Form_pg_publication) GETSTRUCT(tup))->oid;
849
850 result = lappend_oid(result, oid);
851 }
852
853 systable_endscan(scan);
855
856 return result;
857}
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
FormData_pg_publication * Form_pg_publication
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
#define InvalidOid

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

Referenced by RelationBuildPublicationDesc().

◆ GetPublication()

Publication * GetPublication ( Oid  pubid)
extern

Definition at line 1077 of file pg_publication.c.

1078{
1079 HeapTuple tup;
1080 Publication *pub;
1082
1084 if (!HeapTupleIsValid(tup))
1085 elog(ERROR, "cache lookup failed for publication %u", pubid);
1086
1088
1090 pub->oid = pubid;
1091 pub->name = pstrdup(NameStr(pubform->pubname));
1092 pub->alltables = pubform->puballtables;
1093 pub->allsequences = pubform->puballsequences;
1094 pub->pubactions.pubinsert = pubform->pubinsert;
1095 pub->pubactions.pubupdate = pubform->pubupdate;
1096 pub->pubactions.pubdelete = pubform->pubdelete;
1097 pub->pubactions.pubtruncate = pubform->pubtruncate;
1098 pub->pubviaroot = pubform->pubviaroot;
1099 pub->pubgencols_type = pubform->pubgencols;
1100
1102
1103 return pub;
1104}
#define NameStr(name)
Definition c.h:765
#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(int cacheId, Datum key1)
Definition syscache.c:220

References Publication::allsequences, Publication::alltables, elog, ERROR, fb(), 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 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 1110 of file pg_publication.c.

1111{
1112 Oid oid;
1113
1114 oid = get_publication_oid(pubname, missing_ok);
1115
1116 return OidIsValid(oid) ? GetPublication(oid) : NULL;
1117}
#define OidIsValid(objectId)
Definition c.h:788
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition lsyscache.c:3775
Publication * GetPublication(Oid pubid)

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().

◆ GetPublicationRelations()

List * GetPublicationRelations ( Oid  pubid,
PublicationPartOpt  pub_partopt 
)
extern

Definition at line 783 of file pg_publication.c.

784{
785 List *result;
788 SysScanDesc scan;
790
791 /* Find all relations associated with the publication. */
793
797 ObjectIdGetDatum(pubid));
798
800 true, NULL, 1, &scankey);
801
802 result = NIL;
803 while (HeapTupleIsValid(tup = systable_getnext(scan)))
804 {
806
809 pubrel->prrelid);
810 }
811
812 systable_endscan(scan);
814
815 /* Now sort and de-duplicate the result list */
816 list_sort(result, list_oid_cmp);
817 list_deduplicate_oid(result);
818
819 return result;
820}
void list_sort(List *list, list_sort_comparator cmp)
Definition list.c:1674
void list_deduplicate_oid(List *list)
Definition list.c:1495
int list_oid_cmp(const ListCell *p1, const ListCell *p2)
Definition list.c:1703
List * GetPubPartitionOptionRelations(List *result, PublicationPartOpt pub_partopt, Oid relid)
FormData_pg_publication_rel * Form_pg_publication_rel

References AccessShareLock, BTEqualStrategyNumber, fb(), GetPubPartitionOptionRelations(), GETSTRUCT(), HeapTupleIsValid, list_deduplicate_oid(), list_oid_cmp(), list_sort(), NIL, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by AlterPublicationOptions(), AlterPublicationSchemas(), AlterPublicationTables(), InvalidatePubRelSyncCache(), 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 313 of file pg_publication.c.

315{
318 {
320 NULL);
321
323 result = list_concat(result, all_parts);
325 {
326 ListCell *lc;
327
328 foreach(lc, all_parts)
329 {
331
333 result = lappend_oid(result, partOid);
334 }
335 }
336 else
337 Assert(false);
338 }
339 else
340 result = lappend_oid(result, relid);
341
342 return result;
343}
#define NoLock
Definition lockdefs.h:34
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2153
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(), GetPublicationRelations(), GetSchemaPublicationRelations(), publication_add_relation(), and RemovePublicationRelById().

◆ GetRelationPublications()

List * GetRelationPublications ( Oid  relid)
extern

Definition at line 754 of file pg_publication.c.

755{
756 List *result = NIL;
758 int i;
759
760 /* Find all publications associated with the relation. */
762 ObjectIdGetDatum(relid));
763 for (i = 0; i < pubrellist->n_members; i++)
764 {
765 HeapTuple tup = &pubrellist->members[i]->tuple;
767
768 result = lappend_oid(result, pubid);
769 }
770
772
773 return result;
774}
int i
Definition isn.c:77
#define ReleaseSysCacheList(x)
Definition syscache.h:134
#define SearchSysCacheList1(cacheId, key1)
Definition syscache.h:127

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

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

◆ GetSchemaPublicationRelations()

List * GetSchemaPublicationRelations ( Oid  schemaid,
PublicationPartOpt  pub_partopt 
)
extern

Definition at line 996 of file pg_publication.c.

997{
999 ScanKeyData key[1];
1000 TableScanDesc scan;
1001 HeapTuple tuple;
1002 List *result = NIL;
1003
1005
1007
1008 ScanKeyInit(&key[0],
1012
1013 /* get all the relations present in the specified schema */
1014 scan = table_beginscan_catalog(classRel, 1, key);
1015 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
1016 {
1018 Oid relid = relForm->oid;
1019 char relkind;
1020
1021 if (!is_publishable_class(relid, relForm))
1022 continue;
1023
1024 relkind = get_rel_relkind(relid);
1025 if (relkind == RELKIND_RELATION)
1026 result = lappend_oid(result, relid);
1027 else if (relkind == RELKIND_PARTITIONED_TABLE)
1028 {
1030
1031 /*
1032 * It is quite possible that some of the partitions are in a
1033 * different schema than the parent table, so we need to get such
1034 * partitions separately.
1035 */
1038 relForm->oid);
1039 result = list_concat_unique_oid(result, partitionrels);
1040 }
1041 }
1042
1043 table_endscan(scan);
1045 return result;
1046}
List * list_concat_unique_oid(List *list1, const List *list2)
Definition list.c:1469

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

971{
972 List *result = NIL;
974 int i;
975
976 /* Find all publications associated with the schema */
979 for (i = 0; i < pubschlist->n_members; i++)
980 {
981 HeapTuple tup = &pubschlist->members[i]->tuple;
983
984 result = lappend_oid(result, pubid);
985 }
986
988
989 return result;
990}

References fb(), 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 357 of file pg_publication.c.

358{
359 ListCell *lc;
361 int level = 0;
362
363 /*
364 * Find the "topmost" ancestor that is in this publication.
365 */
366 foreach(lc, ancestors)
367 {
371
372 level++;
373
375 {
377
378 if (ancestor_level)
379 *ancestor_level = level;
380 }
381 else
382 {
385 {
387
388 if (ancestor_level)
389 *ancestor_level = level;
390 }
391 }
392
395 }
396
397 return topmost_relid;
398}
void list_free(List *list)
Definition list.c:1546
bool list_member_oid(const List *list, Oid datum)
Definition list.c:722
Oid get_rel_namespace(Oid relid)
Definition lsyscache.c:2102
List * GetRelationPublications(Oid relid)
List * GetSchemaPublications(Oid schemaid)

References fb(), get_rel_namespace(), GetRelationPublications(), 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 150 of file pg_publication.c.

151{
153}
#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()

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

609{
610 Bitmapset *result = columns;
611 ArrayType *arr;
612 int nelems;
613 int16 *elems;
615
617 nelems = ARR_DIMS(arr)[0];
618 elems = (int16 *) ARR_DATA_PTR(arr);
619
620 /* If a memory context was specified, switch to it. */
621 if (mcxt)
623
624 for (int i = 0; i < nelems; i++)
625 result = bms_add_member(result, elems[i]);
626
627 if (mcxt)
629
630 return result;
631}
#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:814
int16_t int16
Definition c.h:541
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 559 of file pg_publication.c.

560{
561 Bitmapset *set = NULL;
562 ListCell *lc;
564
565 foreach(lc, columns)
566 {
567 char *colname = strVal(lfirst(lc));
569
573 errmsg("column \"%s\" of relation \"%s\" does not exist",
575
579 errmsg("cannot use system column \"%s\" in publication column list",
580 colname));
581
582 if (TupleDescAttr(tupdesc, attnum - 1)->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
585 errmsg("cannot use virtual generated column \"%s\" in publication column list",
586 colname));
587
588 if (bms_is_member(attnum, set))
591 errmsg("duplicate column \"%s\" in publication column list",
592 colname));
593
594 set = bms_add_member(set, attnum);
595 }
596
597 return set;
598}
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:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
AttrNumber get_attnum(Oid relid, const char *attname)
Definition lsyscache.c:934
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:160
#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 640 of file pg_publication.c.

641{
642 Bitmapset *result = NULL;
643 TupleDesc desc = RelationGetDescr(relation);
644
645 for (int i = 0; i < desc->natts; i++)
646 {
648
649 if (att->attisdropped)
650 continue;
651
652 if (att->attgenerated)
653 {
654 /* We only support replication of STORED generated cols. */
655 if (att->attgenerated != ATTRIBUTE_GENERATED_STORED)
656 continue;
657
658 /* User hasn't requested to replicate STORED generated cols. */
659 if (include_gencols_type != PUBLISH_GENCOLS_STORED)
660 continue;
661 }
662
663 result = bms_add_member(result, att->attnum);
664 }
665
666 return result;
667}
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 
)
extern

Definition at line 431 of file pg_publication.c.

433{
434 Relation rel;
437 bool nulls[Natts_pg_publication_rel];
438 Relation targetrel = pri->relation;
441 Bitmapset *attnums;
442 Publication *pub = GetPublication(pubid);
445 List *relids = NIL;
446 int i;
447
449
450 /*
451 * Check for duplicates. Note that this does not really prevent
452 * duplicates, it's here just to provide nicer error message in common
453 * case. The real protection is the unique key on the catalog.
454 */
456 ObjectIdGetDatum(pubid)))
457 {
459
460 if (if_not_exists)
462
465 errmsg("relation \"%s\" is already member of publication \"%s\"",
467 }
468
470
471 /* Validate and translate column names into a Bitmapset of attnums. */
472 attnums = pub_collist_validate(pri->relation, pri->columns);
473
474 /* Form a tuple. */
475 memset(values, 0, sizeof(values));
476 memset(nulls, false, sizeof(nulls));
477
482 ObjectIdGetDatum(pubid);
484 ObjectIdGetDatum(relid);
485
486 /* Add qualifications, if available */
487 if (pri->whereClause != NULL)
489 else
490 nulls[Anum_pg_publication_rel_prqual - 1] = true;
491
492 /* Add column list, if available */
493 if (pri->columns)
495 else
496 nulls[Anum_pg_publication_rel_prattrs - 1] = true;
497
499
500 /* Insert tuple into catalog. */
503
504 /* Register dependencies as needed */
506
507 /* Add dependency on the publication */
510
511 /* Add dependency on the relation */
514
515 /* Add dependency on the objects mentioned in the qualifications */
516 if (pri->whereClause)
517 recordDependencyOnSingleRelExpr(&myself, pri->whereClause, relid,
519 false);
520
521 /* Add dependency on the columns, if any are listed */
522 i = -1;
523 while ((i = bms_next_member(attnums, i)) >= 0)
524 {
527 }
528
529 /* Close the table. */
531
532 /*
533 * Invalidate relcache so that publication info is rebuilt.
534 *
535 * For the partitioned tables, we must invalidate all partitions contained
536 * in the respective partition hierarchies, not just the one explicitly
537 * mentioned in the publication. This is required because we implicitly
538 * publish the child tables when the parent table is published.
539 */
541 relid);
542
544
545 return myself;
546}
int bms_next_member(const Bitmapset *a, int prevbit)
Definition bitmapset.c:1305
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:97
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:1117
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
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:802
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition pg_depend.c:45
static int2vector * attnumstoint2vector(Bitmapset *attrs)
Bitmapset * pub_collist_validate(Relation targetrel, List *columns)
static void check_publication_add_relation(Relation targetrel)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
void InvalidatePublicationRels(List *relids)
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition syscache.h:102

References attnumstoint2vector(), bms_next_member(), 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 673 of file pg_publication.c.

674{
675 Relation rel;
679 Oid psschid;
680 Publication *pub = GetPublication(pubid);
684
686
687 /*
688 * Check for duplicates. Note that this does not really prevent
689 * duplicates, it's here just to provide nicer error message in common
690 * case. The real protection is the unique key on the catalog.
691 */
694 ObjectIdGetDatum(pubid)))
695 {
697
698 if (if_not_exists)
700
703 errmsg("schema \"%s\" is already member of publication \"%s\"",
705 }
706
708
709 /* Form a tuple */
710 memset(values, 0, sizeof(values));
711 memset(nulls, false, sizeof(nulls));
712
717 ObjectIdGetDatum(pubid);
720
722
723 /* Insert tuple into catalog */
726
728
729 /* Add dependency on the publication */
732
733 /* Add dependency on the schema */
736
737 /* Close the table */
739
740 /*
741 * Invalidate relcache so that publication info is rebuilt. See
742 * publication_add_relation for why we need to consider all the
743 * partitions.
744 */
748
749 return myself;
750}
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516
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

◆ FormData_pg_publication

FormData_pg_publication

Definition at line 69 of file pg_publication.h.