]> granicus.if.org Git - postgresql/commitdiff
Fix CommandCounterIncrement in partition-related DDL
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 20 Mar 2018 14:19:41 +0000 (11:19 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 20 Mar 2018 14:19:41 +0000 (11:19 -0300)
It makes sense to do the CCIs in the places that do catalog updates,
rather than before the places that error out because the former ones
fail to do it.  In particular, it looks like StorePartitionBound() and
IndexSetParentIndex() ought to make their own CCIs.

Per review comments from Peter Eisentraut for row-level triggers on
partitioned tables.

Discussion: https://postgr.es/m/20171229225319.ajltgss2ojkfd3kp@alvherre.pgsql

src/backend/catalog/heap.c
src/backend/commands/indexcmds.c
src/backend/commands/tablecmds.c

index 3d80ff9e5bb01fd462a9bc7f5e26b0d602b3384f..0497332e9d7fad01d4f676ed7d5a2184226bed0d 100644 (file)
@@ -3298,6 +3298,9 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
        heap_freetuple(newtuple);
        heap_close(classRel, RowExclusiveLock);
 
+       /* Make update visible */
+       CommandCounterIncrement();
+
        /*
         * The partition constraint for the default partition depends on the
         * partition bounds of every other partition, so we must invalidate the
index ff40683d06630059c88cb755f3089847c3d70983..0a2ab50023850abaff685a6609b36f3ea44d1bff 100644 (file)
@@ -2512,5 +2512,8 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
 
                        recordDependencyOn(&partIdx, &partitionTbl, DEPENDENCY_AUTO);
                }
+
+               /* make our updates visible */
+               CommandCounterIncrement();
        }
 }
index 218224a15639287899b9b9cdae7231bca0409bf3..8f83aa46753841df2f76cbbbac8482e49cfbc4cb 100644 (file)
@@ -864,13 +864,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
                        update_default_partition_oid(RelationGetRelid(parent), relationId);
 
                heap_close(parent, NoLock);
-
-               /*
-                * The code that follows may also update the pg_class tuple to update
-                * relnumchecks, so bump up the command counter to avoid the "already
-                * updated by self" error.
-                */
-               CommandCounterIncrement();
        }
 
        /*
@@ -14585,8 +14578,6 @@ ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name)
 
                pfree(attmap);
 
-               CommandCounterIncrement();
-
                validatePartitionedIndex(parentIdx, parentTbl);
        }