]> granicus.if.org Git - postgresql/commitdiff
Clean up sloppy coding in publicationcmds.c's OpenTableList().
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Dec 2018 16:02:39 +0000 (11:02 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Dec 2018 16:02:39 +0000 (11:02 -0500)
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 665d1fad9).
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

src/backend/commands/publicationcmds.c

index 6f7762a906caa32c7fffd472f50083f30a5ce609..675ee96b0facf28df01f844711daca205dbd06a3 100644 (file)
@@ -484,7 +484,7 @@ RemovePublicationRelById(Oid proid)
 }
 
 /*
- * Open relations based on provided by RangeVar list.
+ * Open relations specified by a RangeVar list.
  * The returned tables are locked in ShareUpdateExclusiveLock mode.
  */
 static List *
@@ -499,11 +499,12 @@ OpenTableList(List *tables)
         */
        foreach(lc, tables)
        {
-               RangeVar   *rv = lfirst(lc);
-               Relation        rel;
+               RangeVar   *rv = castNode(RangeVar, lfirst(lc));
                bool            recurse = rv->inh;
+               Relation        rel;
                Oid                     myrelid;
 
+               /* Allow query cancel in case this takes a long time */
                CHECK_FOR_INTERRUPTS();
 
                rel = heap_openrv(rv, ShareUpdateExclusiveLock);
@@ -521,13 +522,15 @@ OpenTableList(List *tables)
                        heap_close(rel, ShareUpdateExclusiveLock);
                        continue;
                }
+
                rels = lappend(rels, rel);
                relids = lappend_oid(relids, myrelid);
 
+               /* Add children of this rel, if requested */
                if (recurse)
                {
-                       ListCell   *child;
                        List       *children;
+                       ListCell   *child;
 
                        children = find_all_inheritors(myrelid, ShareUpdateExclusiveLock,
                                                                                   NULL);
@@ -536,18 +539,15 @@ OpenTableList(List *tables)
                        {
                                Oid                     childrelid = lfirst_oid(child);
 
-                               if (list_member_oid(relids, childrelid))
-                                       continue;
+                               /* Allow query cancel in case this takes a long time */
+                               CHECK_FOR_INTERRUPTS();
 
                                /*
                                 * Skip duplicates if user specified both parent and child
                                 * tables.
                                 */
                                if (list_member_oid(relids, childrelid))
-                               {
-                                       heap_close(rel, ShareUpdateExclusiveLock);
                                        continue;
-                               }
 
                                /* find_all_inheritors already got lock */
                                rel = heap_open(childrelid, NoLock);