Skip to content

Commit 9286ef8

Browse files
committed
Clean up sloppy coding in publicationcmds.c's OpenTableList().
Remove dead code (which would be incorrect if it weren't dead), per report from Pan Bian. Add a CHECK_FOR_INTERRUPTS in the inner loop over child relations, because there's little point in having one in the outer loop if there's not one here too. Minor stylistic adjustments and comment improvements. Seems to be aboriginal to this code (cf commit 665d1fa). Back-patch to v10 where that came in, not because any of this is significant, but just to keep the branches looking similar. Discussion: https://postgr.es/m/15539-06d00ef6b1e2e1bb@postgresql.org
1 parent eeee62d commit 9286ef8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/backend/commands/publicationcmds.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ RemovePublicationRelById(Oid proid)
494494
}
495495

496496
/*
497-
* Open relations based on provided by RangeVar list.
497+
* Open relations specified by a RangeVar list.
498498
* The returned tables are locked in ShareUpdateExclusiveLock mode.
499499
*/
500500
static List *
@@ -509,11 +509,12 @@ OpenTableList(List *tables)
509509
*/
510510
foreach(lc, tables)
511511
{
512-
RangeVar *rv = lfirst(lc);
513-
Relation rel;
512+
RangeVar *rv = castNode(RangeVar, lfirst(lc));
514513
bool recurse = rv->inh;
514+
Relation rel;
515515
Oid myrelid;
516516

517+
/* Allow query cancel in case this takes a long time */
517518
CHECK_FOR_INTERRUPTS();
518519

519520
rel = heap_openrv(rv, ShareUpdateExclusiveLock);
@@ -531,13 +532,15 @@ OpenTableList(List *tables)
531532
heap_close(rel, ShareUpdateExclusiveLock);
532533
continue;
533534
}
535+
534536
rels = lappend(rels, rel);
535537
relids = lappend_oid(relids, myrelid);
536538

539+
/* Add children of this rel, if requested */
537540
if (recurse)
538541
{
539-
ListCell *child;
540542
List *children;
543+
ListCell *child;
541544

542545
children = find_all_inheritors(myrelid, ShareUpdateExclusiveLock,
543546
NULL);
@@ -546,18 +549,15 @@ OpenTableList(List *tables)
546549
{
547550
Oid childrelid = lfirst_oid(child);
548551

549-
if (list_member_oid(relids, childrelid))
550-
continue;
552+
/* Allow query cancel in case this takes a long time */
553+
CHECK_FOR_INTERRUPTS();
551554

552555
/*
553556
* Skip duplicates if user specified both parent and child
554557
* tables.
555558
*/
556559
if (list_member_oid(relids, childrelid))
557-
{
558-
heap_close(rel, ShareUpdateExclusiveLock);
559560
continue;
560-
}
561561

562562
/* find_all_inheritors already got lock */
563563
rel = heap_open(childrelid, NoLock);

0 commit comments

Comments
 (0)