Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c6828f

Browse files
committed
Add PublicationTable and PublicationRelInfo structs
These encapsulate a relation when referred from replication DDL.Currently they don't do anything useful (they're just wrappers aroundRangeVar and Relation respectively) but in the future they'll be used tocarry column lists.Extracted from a larger patch by Rahila Syed.Author: Rahila Syed <rahilasyed90@gmail.com>Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>Discussion:https://postgr.es/m/CAH2L28vddB_NFdRVpuyRBJEBWjz4BSyTB=_ektNRH8NJ1jf95g@mail.gmail.com
1 parent89dba59 commit0c6828f

File tree

9 files changed

+95
-31
lines changed

9 files changed

+95
-31
lines changed

‎src/backend/catalog/pg_publication.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ pg_relation_is_publishable(PG_FUNCTION_ARGS)
141141
* Insert new publication / relation mapping.
142142
*/
143143
ObjectAddress
144-
publication_add_relation(Oidpubid,Relationtargetrel,
144+
publication_add_relation(Oidpubid,PublicationRelInfo*targetrel,
145145
boolif_not_exists)
146146
{
147147
Relationrel;
148148
HeapTupletup;
149149
Datumvalues[Natts_pg_publication_rel];
150150
boolnulls[Natts_pg_publication_rel];
151-
Oidrelid=RelationGetRelid(targetrel);
151+
Oidrelid=RelationGetRelid(targetrel->relation);
152152
Oidprrelid;
153153
Publication*pub=GetPublication(pubid);
154154
ObjectAddressmyself,
@@ -172,10 +172,10 @@ publication_add_relation(Oid pubid, Relation targetrel,
172172
ereport(ERROR,
173173
(errcode(ERRCODE_DUPLICATE_OBJECT),
174174
errmsg("relation \"%s\" is already member of publication \"%s\"",
175-
RelationGetRelationName(targetrel),pub->name)));
175+
RelationGetRelationName(targetrel->relation),pub->name)));
176176
}
177177

178-
check_publication_add_relation(targetrel);
178+
check_publication_add_relation(targetrel->relation);
179179

180180
/* Form a tuple. */
181181
memset(values,0,sizeof(values));
@@ -209,7 +209,7 @@ publication_add_relation(Oid pubid, Relation targetrel,
209209
table_close(rel,RowExclusiveLock);
210210

211211
/* Invalidate relcache so that publication info is rebuilt. */
212-
CacheInvalidateRelcache(targetrel);
212+
CacheInvalidateRelcache(targetrel->relation);
213213

214214
returnmyself;
215215
}

‎src/backend/commands/publicationcmds.c

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -393,21 +393,28 @@ AlterPublicationTables(AlterPublicationStmt *stmt, Relation rel,
393393

394394
foreach(newlc,rels)
395395
{
396-
Relationnewrel= (Relation)lfirst(newlc);
396+
PublicationRelInfo*newpubrel;
397397

398-
if (RelationGetRelid(newrel)==oldrelid)
398+
newpubrel= (PublicationRelInfo*)lfirst(newlc);
399+
if (RelationGetRelid(newpubrel->relation)==oldrelid)
399400
{
400401
found= true;
401402
break;
402403
}
403404
}
404-
405+
/* Not yet in the list, open it and add to the list */
405406
if (!found)
406407
{
407-
Relationoldrel=table_open(oldrelid,
408-
ShareUpdateExclusiveLock);
408+
Relationoldrel;
409+
PublicationRelInfo*pubrel;
410+
411+
/* Wrap relation into PublicationRelInfo */
412+
oldrel=table_open(oldrelid,ShareUpdateExclusiveLock);
413+
414+
pubrel=palloc(sizeof(PublicationRelInfo));
415+
pubrel->relation=oldrel;
409416

410-
delrels=lappend(delrels,oldrel);
417+
delrels=lappend(delrels,pubrel);
411418
}
412419
}
413420

@@ -498,9 +505,9 @@ RemovePublicationRelById(Oid proid)
498505
}
499506

500507
/*
501-
* Open relations specified by aRangeVar list.
502-
*Thereturnedtables are locked in ShareUpdateExclusiveLock mode in order to
503-
* add them to a publication.
508+
* Open relations specified by aPublicationTable list.
509+
*In thereturnedlist of PublicationRelInfo, tables are locked
510+
*in ShareUpdateExclusiveLock mode in order toadd them to a publication.
504511
*/
505512
staticList*
506513
OpenTableList(List*tables)
@@ -514,15 +521,16 @@ OpenTableList(List *tables)
514521
*/
515522
foreach(lc,tables)
516523
{
517-
RangeVar*rv=lfirst_node(RangeVar,lc);
518-
boolrecurse=rv->inh;
524+
PublicationTable*t=lfirst_node(PublicationTable,lc);
525+
boolrecurse=t->relation->inh;
519526
Relationrel;
520527
Oidmyrelid;
528+
PublicationRelInfo*pub_rel;
521529

522530
/* Allow query cancel in case this takes a long time */
523531
CHECK_FOR_INTERRUPTS();
524532

525-
rel=table_openrv(rv,ShareUpdateExclusiveLock);
533+
rel=table_openrv(t->relation,ShareUpdateExclusiveLock);
526534
myrelid=RelationGetRelid(rel);
527535

528536
/*
@@ -538,7 +546,9 @@ OpenTableList(List *tables)
538546
continue;
539547
}
540548

541-
rels=lappend(rels,rel);
549+
pub_rel=palloc(sizeof(PublicationRelInfo));
550+
pub_rel->relation=rel;
551+
rels=lappend(rels,pub_rel);
542552
relids=lappend_oid(relids,myrelid);
543553

544554
/*
@@ -571,7 +581,9 @@ OpenTableList(List *tables)
571581

572582
/* find_all_inheritors already got lock */
573583
rel=table_open(childrelid,NoLock);
574-
rels=lappend(rels,rel);
584+
pub_rel=palloc(sizeof(PublicationRelInfo));
585+
pub_rel->relation=rel;
586+
rels=lappend(rels,pub_rel);
575587
relids=lappend_oid(relids,childrelid);
576588
}
577589
}
@@ -592,9 +604,10 @@ CloseTableList(List *rels)
592604

593605
foreach(lc,rels)
594606
{
595-
Relationrel= (Relation)lfirst(lc);
607+
PublicationRelInfo*pub_rel;
596608

597-
table_close(rel,NoLock);
609+
pub_rel= (PublicationRelInfo*)lfirst(lc);
610+
table_close(pub_rel->relation,NoLock);
598611
}
599612
}
600613

@@ -611,15 +624,16 @@ PublicationAddTables(Oid pubid, List *rels, bool if_not_exists,
611624

612625
foreach(lc,rels)
613626
{
614-
Relationrel= (Relation)lfirst(lc);
627+
PublicationRelInfo*pub_rel= (PublicationRelInfo*)lfirst(lc);
628+
Relationrel=pub_rel->relation;
615629
ObjectAddressobj;
616630

617631
/* Must be owner of the table or superuser. */
618632
if (!pg_class_ownercheck(RelationGetRelid(rel),GetUserId()))
619633
aclcheck_error(ACLCHECK_NOT_OWNER,get_relkind_objtype(rel->rd_rel->relkind),
620634
RelationGetRelationName(rel));
621635

622-
obj=publication_add_relation(pubid,rel,if_not_exists);
636+
obj=publication_add_relation(pubid,pub_rel,if_not_exists);
623637
if (stmt)
624638
{
625639
EventTriggerCollectSimpleCommand(obj,InvalidObjectAddress,
@@ -643,7 +657,8 @@ PublicationDropTables(Oid pubid, List *rels, bool missing_ok)
643657

644658
foreach(lc,rels)
645659
{
646-
Relationrel= (Relation)lfirst(lc);
660+
PublicationRelInfo*pubrel= (PublicationRelInfo*)lfirst(lc);
661+
Relationrel=pubrel->relation;
647662
Oidrelid=RelationGetRelid(rel);
648663

649664
prid=GetSysCacheOid2(PUBLICATIONRELMAP,Anum_pg_publication_rel_oid,

‎src/backend/nodes/copyfuncs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4939,6 +4939,15 @@ _copyForeignKeyCacheInfo(const ForeignKeyCacheInfo *from)
49394939
returnnewnode;
49404940
}
49414941

4942+
staticPublicationTable*
4943+
_copyPublicationTable(constPublicationTable*from)
4944+
{
4945+
PublicationTable*newnode=makeNode(PublicationTable);
4946+
4947+
COPY_NODE_FIELD(relation);
4948+
4949+
returnnewnode;
4950+
}
49424951

49434952
/*
49444953
* copyObjectImpl -- implementation of copyObject(); see nodes/nodes.h
@@ -5854,6 +5863,9 @@ copyObjectImpl(const void *from)
58545863
caseT_PartitionCmd:
58555864
retval=_copyPartitionCmd(from);
58565865
break;
5866+
caseT_PublicationTable:
5867+
retval=_copyPublicationTable(from);
5868+
break;
58575869

58585870
/*
58595871
* MISCELLANEOUS NODES

‎src/backend/nodes/equalfuncs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,14 @@ _equalValue(const Value *a, const Value *b)
31143114
return true;
31153115
}
31163116

3117+
staticbool
3118+
_equalPublicationTable(constPublicationTable*a,constPublicationTable*b)
3119+
{
3120+
COMPARE_NODE_FIELD(relation);
3121+
3122+
return true;
3123+
}
3124+
31173125
/*
31183126
* equal
31193127
* returns whether two nodes are equal
@@ -3862,6 +3870,9 @@ equal(const void *a, const void *b)
38623870
caseT_PartitionCmd:
38633871
retval=_equalPartitionCmd(a,b);
38643872
break;
3873+
caseT_PublicationTable:
3874+
retval=_equalPublicationTable(a,b);
3875+
break;
38653876

38663877
default:
38673878
elog(ERROR,"unrecognized node type: %d",

‎src/backend/parser/gram.y

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
426426
transform_element_listtransform_type_list
427427
TriggerTransitionsTriggerReferencing
428428
vacuum_relation_listopt_vacuum_relation_list
429-
drop_option_list
429+
drop_option_listpublication_table_list
430430

431431
%type<node>opt_routine_body
432432
%type<groupclause>group_clause
433433
%type<list>group_by_list
434434
%type<node>group_by_itemempty_grouping_setrollup_clausecube_clause
435435
%type<node>grouping_sets_clause
436-
%type<node>opt_publication_for_tablespublication_for_tables
436+
%type<node>opt_publication_for_tablespublication_for_tablespublication_table
437437

438438
%type<list>opt_fdw_optionsfdw_options
439439
%type<defelt>fdw_option
@@ -9620,7 +9620,7 @@ opt_publication_for_tables:
96209620
;
96219621

96229622
publication_for_tables:
9623-
FORTABLErelation_expr_list
9623+
FORTABLEpublication_table_list
96249624
{
96259625
$$ = (Node *)$3;
96269626
}
@@ -9630,6 +9630,20 @@ publication_for_tables:
96309630
}
96319631
;
96329632

9633+
publication_table_list:
9634+
publication_table
9635+
{$$ = list_make1($1); }
9636+
|publication_table_list','publication_table
9637+
{$$ = lappend($1,$3); }
9638+
;
9639+
9640+
publication_table:relation_expr
9641+
{
9642+
PublicationTable *n = makeNode(PublicationTable);
9643+
n->relation =$1;
9644+
$$ = (Node *) n;
9645+
}
9646+
;
96339647

96349648
/*****************************************************************************
96359649
*
@@ -9651,23 +9665,23 @@ AlterPublicationStmt:
96519665
n->options =$5;
96529666
$$ = (Node *)n;
96539667
}
9654-
|ALTERPUBLICATIONnameADD_PTABLErelation_expr_list
9668+
|ALTERPUBLICATIONnameADD_PTABLEpublication_table_list
96559669
{
96569670
AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
96579671
n->pubname =$3;
96589672
n->tables =$6;
96599673
n->tableAction = DEFELEM_ADD;
96609674
$$ = (Node *)n;
96619675
}
9662-
|ALTERPUBLICATIONnameSETTABLErelation_expr_list
9676+
|ALTERPUBLICATIONnameSETTABLEpublication_table_list
96639677
{
96649678
AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
96659679
n->pubname =$3;
96669680
n->tables =$6;
96679681
n->tableAction = DEFELEM_SET;
96689682
$$ = (Node *)n;
96699683
}
9670-
|ALTERPUBLICATIONnameDROPTABLErelation_expr_list
9684+
|ALTERPUBLICATIONnameDROPTABLEpublication_table_list
96719685
{
96729686
AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
96739687
n->pubname =$3;

‎src/include/catalog/pg_publication.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ typedef struct Publication
8383
PublicationActionspubactions;
8484
}Publication;
8585

86+
typedefstructPublicationRelInfo
87+
{
88+
Relationrelation;
89+
}PublicationRelInfo;
90+
8691
externPublication*GetPublication(Oidpubid);
8792
externPublication*GetPublicationByName(constchar*pubname,boolmissing_ok);
8893
externList*GetRelationPublications(Oidrelid);
@@ -108,7 +113,7 @@ extern List *GetAllTablesPublications(void);
108113
externList*GetAllTablesPublicationRelations(boolpubviaroot);
109114

110115
externboolis_publishable_relation(Relationrel);
111-
externObjectAddresspublication_add_relation(Oidpubid,Relationtargetrel,
116+
externObjectAddresspublication_add_relation(Oidpubid,PublicationRelInfo*targetrel,
112117
boolif_not_exists);
113118

114119
externOidget_publication_oid(constchar*pubname,boolmissing_ok);

‎src/include/nodes/nodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ typedef enum NodeTag
490490
T_PartitionRangeDatum,
491491
T_PartitionCmd,
492492
T_VacuumRelation,
493+
T_PublicationTable,
493494

494495
/*
495496
* TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)

‎src/include/nodes/parsenodes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,11 @@ typedef struct AlterTSConfigurationStmt
36243624
boolmissing_ok;/* for DROP - skip error if missing? */
36253625
}AlterTSConfigurationStmt;
36263626

3627+
typedefstructPublicationTable
3628+
{
3629+
NodeTagtype;
3630+
RangeVar*relation;/* relation to be published */
3631+
}PublicationTable;
36273632

36283633
typedefstructCreatePublicationStmt
36293634
{

‎src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,7 @@ PublicationActions
20472047
PublicationInfo
20482048
PublicationPartOpt
20492049
PublicationRelInfo
2050+
PublicationTable
20502051
PullFilter
20512052
PullFilterOps
20522053
PushFilter

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp