@@ -393,21 +393,28 @@ AlterPublicationTables(AlterPublicationStmt *stmt, Relation rel,
393
393
394
394
foreach (newlc , rels )
395
395
{
396
- Relation newrel = ( Relation ) lfirst ( newlc ) ;
396
+ PublicationRelInfo * newpubrel ;
397
397
398
- if (RelationGetRelid (newrel ) == oldrelid )
398
+ newpubrel = (PublicationRelInfo * ) lfirst (newlc );
399
+ if (RelationGetRelid (newpubrel -> relation ) == oldrelid )
399
400
{
400
401
found = true;
401
402
break ;
402
403
}
403
404
}
404
-
405
+ /* Not yet in the list, open it and add to the list */
405
406
if (!found )
406
407
{
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 ;
409
416
410
- delrels = lappend (delrels , oldrel );
417
+ delrels = lappend (delrels , pubrel );
411
418
}
412
419
}
413
420
@@ -498,9 +505,9 @@ RemovePublicationRelById(Oid proid)
498
505
}
499
506
500
507
/*
501
- * Open relations specified by a RangeVar list.
502
- * The returned tables are locked in ShareUpdateExclusiveLock mode in order to
503
- * add them to a publication.
508
+ * Open relations specified by a PublicationTable list.
509
+ * In the returned list of PublicationRelInfo, tables are locked
510
+ * in ShareUpdateExclusiveLock mode in order to add them to a publication.
504
511
*/
505
512
static List *
506
513
OpenTableList (List * tables )
@@ -514,15 +521,16 @@ OpenTableList(List *tables)
514
521
*/
515
522
foreach (lc , tables )
516
523
{
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 ;
519
526
Relation rel ;
520
527
Oid myrelid ;
528
+ PublicationRelInfo * pub_rel ;
521
529
522
530
/* Allow query cancel in case this takes a long time */
523
531
CHECK_FOR_INTERRUPTS ();
524
532
525
- rel = table_openrv (rv , ShareUpdateExclusiveLock );
533
+ rel = table_openrv (t -> relation , ShareUpdateExclusiveLock );
526
534
myrelid = RelationGetRelid (rel );
527
535
528
536
/*
@@ -538,7 +546,9 @@ OpenTableList(List *tables)
538
546
continue ;
539
547
}
540
548
541
- rels = lappend (rels , rel );
549
+ pub_rel = palloc (sizeof (PublicationRelInfo ));
550
+ pub_rel -> relation = rel ;
551
+ rels = lappend (rels , pub_rel );
542
552
relids = lappend_oid (relids , myrelid );
543
553
544
554
/*
@@ -571,7 +581,9 @@ OpenTableList(List *tables)
571
581
572
582
/* find_all_inheritors already got lock */
573
583
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 );
575
587
relids = lappend_oid (relids , childrelid );
576
588
}
577
589
}
@@ -592,9 +604,10 @@ CloseTableList(List *rels)
592
604
593
605
foreach (lc , rels )
594
606
{
595
- Relation rel = ( Relation ) lfirst ( lc ) ;
607
+ PublicationRelInfo * pub_rel ;
596
608
597
- table_close (rel , NoLock );
609
+ pub_rel = (PublicationRelInfo * ) lfirst (lc );
610
+ table_close (pub_rel -> relation , NoLock );
598
611
}
599
612
}
600
613
@@ -611,15 +624,16 @@ PublicationAddTables(Oid pubid, List *rels, bool if_not_exists,
611
624
612
625
foreach (lc , rels )
613
626
{
614
- Relation rel = (Relation ) lfirst (lc );
627
+ PublicationRelInfo * pub_rel = (PublicationRelInfo * ) lfirst (lc );
628
+ Relation rel = pub_rel -> relation ;
615
629
ObjectAddress obj ;
616
630
617
631
/* Must be owner of the table or superuser. */
618
632
if (!pg_class_ownercheck (RelationGetRelid (rel ), GetUserId ()))
619
633
aclcheck_error (ACLCHECK_NOT_OWNER , get_relkind_objtype (rel -> rd_rel -> relkind ),
620
634
RelationGetRelationName (rel ));
621
635
622
- obj = publication_add_relation (pubid , rel , if_not_exists );
636
+ obj = publication_add_relation (pubid , pub_rel , if_not_exists );
623
637
if (stmt )
624
638
{
625
639
EventTriggerCollectSimpleCommand (obj , InvalidObjectAddress ,
@@ -643,7 +657,8 @@ PublicationDropTables(Oid pubid, List *rels, bool missing_ok)
643
657
644
658
foreach (lc , rels )
645
659
{
646
- Relation rel = (Relation ) lfirst (lc );
660
+ PublicationRelInfo * pubrel = (PublicationRelInfo * ) lfirst (lc );
661
+ Relation rel = pubrel -> relation ;
647
662
Oid relid = RelationGetRelid (rel );
648
663
649
664
prid = GetSysCacheOid2 (PUBLICATIONRELMAP , Anum_pg_publication_rel_oid ,
0 commit comments