* could attempt to access the just-dropped relation as its partition. We
         * must therefore take a table lock strong enough to prevent all queries
         * on the table from proceeding until we commit and send out a
-        * shared-cache-inval notice that will make them update their index lists.
+        * shared-cache-inval notice that will make them update their partition
+        * descriptors.
         */
        tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
        if (!HeapTupleIsValid(tuple))
  *             Update pg_class tuple of rel to store the partition bound and set
  *             relispartition to true
  *
+ * If this is the default partition, also update the default partition OID in
+ * pg_partitioned_table.
+ *
  * Also, invalidate the parent's relcache, so that the next rebuild will load
  * the new partition's info into its partition descriptor.  If there is a
  * default partition, we must invalidate its relcache entry as well.
        heap_freetuple(newtuple);
        heap_close(classRel, RowExclusiveLock);
 
-       /* Make update visible */
+       /*
+        * If we're storing bounds for the default partition, update
+        * pg_partitioned_table too.
+        */
+       if (bound->is_default)
+               update_default_partition_oid(RelationGetRelid(parent),
+                                                                        RelationGetRelid(rel));
+
+       /* Make these updates visible */
        CommandCounterIncrement();
 
        /*
 
                /* Update the pg_class entry. */
                StorePartitionBound(rel, parent, bound);
 
-               /* Update the default partition oid */
-               if (bound->is_default)
-                       update_default_partition_oid(RelationGetRelid(parent), relationId);
-
                heap_close(parent, NoLock);
        }
 
        /* OK to create inheritance.  Rest of the checks performed there */
        CreateInheritance(attachrel, rel);
 
-       /* Update the default partition oid */
-       if (cmd->bound->is_default)
-               update_default_partition_oid(RelationGetRelid(rel),
-                                                                        RelationGetRelid(attachrel));
-
        /*
         * Check that the new partition's bound is valid and does not overlap any
         * of existing partitions of the parent - note that it does not return on
 
        /*
         * We must lock the default partition, because detaching this partition
-        * will changing its partition constrant.
+        * will change its partition constraint.
         */
        defaultPartOid =
                get_default_oid_from_partdesc(RelationGetPartitionDesc(rel));
        if (OidIsValid(defaultPartOid))
        {
                /*
-                * If the detach relation is the default partition itself, invalidate
-                * its entry in pg_partitioned_table.
+                * If the relation being detached is the default partition itself,
+                * remove it from the parent's pg_partitioned_table entry.
+                *
+                * If not, we must invalidate default partition's relcache entry, as
+                * in StorePartitionBound: its partition constraint depends on every
+                * other partition's partition constraint.
                 */
                if (RelationGetRelid(partRel) == defaultPartOid)
                        update_default_partition_oid(RelationGetRelid(rel), InvalidOid);
                else
-               {
-                       /*
-                        * We must invalidate default partition's relcache, for the same
-                        * reasons explained in StorePartitionBound().
-                        */
                        CacheInvalidateRelcacheByRelid(defaultPartOid);
-               }
        }
 
        /* detach indexes too */