@@ -393,21 +393,28 @@ AlterPublicationTables(AlterPublicationStmt *stmt, Relation rel,
393393
394394foreach (newlc ,rels )
395395{
396- Relation newrel = ( Relation ) lfirst ( newlc ) ;
396+ PublicationRelInfo * newpubrel ;
397397
398- if (RelationGetRelid (newrel )== oldrelid )
398+ newpubrel = (PublicationRelInfo * )lfirst (newlc );
399+ if (RelationGetRelid (newpubrel -> relation )== oldrelid )
399400{
400401found = true;
401402break ;
402403}
403404}
404-
405+ /* Not yet in the list, open it and add to the list */
405406if (!found )
406407{
407- Relation oldrel = table_open (oldrelid ,
408- ShareUpdateExclusiveLock );
408+ Relation oldrel ;
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- *The returnedtables are locked in ShareUpdateExclusiveLock mode in order to
503- * add them to a publication.
508+ * Open relations specified by aPublicationTable list.
509+ *In the returnedlist of PublicationRelInfo, tables are locked
510+ *in ShareUpdateExclusiveLock mode in order to add them to a publication.
504511 */
505512static List *
506513OpenTableList (List * tables )
@@ -514,15 +521,16 @@ OpenTableList(List *tables)
514521 */
515522foreach (lc ,tables )
516523{
517- RangeVar * rv = lfirst_node (RangeVar ,lc );
518- bool recurse = rv -> inh ;
524+ PublicationTable * t = lfirst_node (PublicationTable ,lc );
525+ bool recurse = t -> relation -> inh ;
519526Relation rel ;
520527Oid myrelid ;
528+ PublicationRelInfo * pub_rel ;
521529
522530/* Allow query cancel in case this takes a long time */
523531CHECK_FOR_INTERRUPTS ();
524532
525- rel = table_openrv (rv ,ShareUpdateExclusiveLock );
533+ rel = table_openrv (t -> relation ,ShareUpdateExclusiveLock );
526534myrelid = RelationGetRelid (rel );
527535
528536/*
@@ -538,7 +546,9 @@ OpenTableList(List *tables)
538546continue ;
539547}
540548
541- rels = lappend (rels ,rel );
549+ pub_rel = palloc (sizeof (PublicationRelInfo ));
550+ pub_rel -> relation = rel ;
551+ rels = lappend (rels ,pub_rel );
542552relids = lappend_oid (relids ,myrelid );
543553
544554/*
@@ -571,7 +581,9 @@ OpenTableList(List *tables)
571581
572582/* find_all_inheritors already got lock */
573583rel = 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 );
575587relids = lappend_oid (relids ,childrelid );
576588}
577589}
@@ -592,9 +604,10 @@ CloseTableList(List *rels)
592604
593605foreach (lc ,rels )
594606{
595- Relation rel = ( 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
612625foreach (lc ,rels )
613626{
614- Relation rel = (Relation )lfirst (lc );
627+ PublicationRelInfo * pub_rel = (PublicationRelInfo * )lfirst (lc );
628+ Relation rel = pub_rel -> relation ;
615629ObjectAddress obj ;
616630
617631/* Must be owner of the table or superuser. */
618632if (!pg_class_ownercheck (RelationGetRelid (rel ),GetUserId ()))
619633aclcheck_error (ACLCHECK_NOT_OWNER ,get_relkind_objtype (rel -> rd_rel -> relkind ),
620634RelationGetRelationName (rel ));
621635
622- obj = publication_add_relation (pubid ,rel ,if_not_exists );
636+ obj = publication_add_relation (pubid ,pub_rel ,if_not_exists );
623637if (stmt )
624638{
625639EventTriggerCollectSimpleCommand (obj ,InvalidObjectAddress ,
@@ -643,7 +657,8 @@ PublicationDropTables(Oid pubid, List *rels, bool missing_ok)
643657
644658foreach (lc ,rels )
645659{
646- Relation rel = (Relation )lfirst (lc );
660+ PublicationRelInfo * pubrel = (PublicationRelInfo * )lfirst (lc );
661+ Relation rel = pubrel -> relation ;
647662Oid relid = RelationGetRelid (rel );
648663
649664prid = GetSysCacheOid2 (PUBLICATIONRELMAP ,Anum_pg_publication_rel_oid ,