Subject: [PATCH 1/5] Miscallaneous code and comment improvements.

From: amit <[email-masked]>
Date: Tue, 13 Dec 2016 15:06:08 +0900

---
 src/backend/catalog/heap.c                 |  4 ++++
 src/backend/catalog/partition.c            |  2 +-
 src/backend/commands/copy.c                | 27 ++++++++++++---------------
 src/backend/commands/tablecmds.c           | 20 ++++++++++----------
 src/backend/executor/nodeModifyTable.c     | 22 +++++++++++-----------
 src/include/catalog/pg_partitioned_table.h |  4 ++--
 6 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 5ffea74855..c09c9f28a7 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1887,6 +1887,10 @@ heap_drop_with_catalog(Oid relid)
 
 	if (parent)
 	{
+		/*
+		 * Invalidate the parent's relcache so that the partition is no longer
+		 * included in its partition descriptor.
+		 */
 		CacheInvalidateRelcache(parent);
 		heap_close(parent, NoLock);		/* keep the lock */
 	}
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 219d380cde..cc09fb3e55 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -1492,7 +1492,7 @@ generate_partition_qual(Relation rel, bool recurse)
  *			Construct values[] and isnull[] arrays for the partition key
  *			of a tuple.
  *
- *	pkinfo			partition key execution info
+ *	pd				Partition dispatch object of the partitioned table
  *	slot			Heap tuple from which to extract partition key
  *	estate			executor state for evaluating any partition key
  *					expressions (must be non-NULL)
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 270be0af18..e9177491e2 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1403,31 +1403,28 @@ BeginCopy(ParseState *pstate,
 					 errmsg("table \"%s\" does not have OIDs",
 							RelationGetRelationName(cstate->rel))));
 
-		/*
-		 * Initialize state for CopyFrom tuple routing.  Watch out for
-		 * any foreign partitions.
-		 */
+		/* Initialize state for CopyFrom tuple routing. */
 		if (is_from && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
 		{
-			PartitionDispatch *pd;
 			List		   *leaf_parts;
 			ListCell	   *cell;
 			int				i,
-							num_parted,
-							num_leaf_parts;
+							num_parted;
 			ResultRelInfo  *leaf_part_rri;
 
 			/* Get the tuple-routing information and lock partitions */
-			pd = RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
-												  &num_parted, &leaf_parts);
-			num_leaf_parts = list_length(leaf_parts);
-			cstate->partition_dispatch_info = pd;
+			cstate->partition_dispatch_info =
+					RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
+													 &num_parted,
+													 &leaf_parts);
 			cstate->num_dispatch = num_parted;
-			cstate->num_partitions = num_leaf_parts;
-			cstate->partitions = (ResultRelInfo *) palloc(num_leaf_parts *
-														sizeof(ResultRelInfo));
+			cstate->num_partitions = list_length(leaf_parts);
+			cstate->partitions = (ResultRelInfo *)
+									palloc(cstate->num_partitions *
+													sizeof(ResultRelInfo));
 			cstate->partition_tupconv_maps = (TupleConversionMap **)
-						palloc0(num_leaf_parts * sizeof(TupleConversionMap *));
+									palloc0(cstate->num_partitions *
+											sizeof(TupleConversionMap *));
 
 			leaf_part_rri = cstate->partitions;
 			i = 0;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 5856e72918..a9650114d4 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -1614,8 +1614,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
 
 	/*
 	 * In case of a partition, there are no new column definitions, only
-	 * dummy ColumnDefs created for column constraints.  We merge these
-	 * constraints inherited from the parent.
+	 * dummy ColumnDefs created for column constraints.  We merge them
+	 * with the constraints inherited from the parent.
 	 */
 	if (is_partition)
 	{
@@ -2030,8 +2030,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
 							newcollid;
 
 				/*
-				 * Partitions have only one parent, so conflict should never
-				 * occur
+				 * Partitions have only one parent and have no column
+				 * definitions of their own, so conflict should never occur.
 				 */
 				Assert(!is_partition);
 
@@ -2118,8 +2118,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
 
 	/*
 	 * Now that we have the column definition list for a partition, we can
-	 * check whether the columns referenced in column option specifications
-	 * actually exist.  Also, we merge the options into the corresponding
+	 * check whether the columns referenced in the column constraint specs
+	 * actually exist.  Also, we merge the constraints into the corresponding
 	 * column definitions.
 	 */
 	if (is_partition && list_length(saved_schema) > 0)
@@ -13351,8 +13351,8 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
 	}
 
 	/*
-	 * Invalidate the relcache so that the new partition is now included
-	 * in rel's partition descriptor.
+	 * Invalidate the parent's relcache so that the new partition is now
+	 * included its partition descriptor.
 	 */
 	CacheInvalidateRelcache(rel);
 
@@ -13414,8 +13414,8 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
 	heap_close(classRel, RowExclusiveLock);
 
 	/*
-	 * Invalidate the relcache so that the partition is no longer included
-	 * in our partition descriptor.
+	 * Invalidate the parent's relcache so that the partition is no longer
+	 * included in its partition descriptor.
 	 */
 	CacheInvalidateRelcache(rel);
 
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index c0b58d1841..ec440b353d 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1718,26 +1718,26 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
 	if (operation == CMD_INSERT &&
 		rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
 	{
-		PartitionDispatch  *pd;
 		int					i,
 							j,
-							num_parted,
-							num_leaf_parts;
+							num_parted;
 		List			   *leaf_parts;
 		ListCell		   *cell;
 		ResultRelInfo	   *leaf_part_rri;
 
-		/* Form the partition node tree and lock partitions */
-		pd = RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
-											  &num_parted, &leaf_parts);
-		mtstate->mt_partition_dispatch_info = pd;
+		/* Get the tuple-routing information and lock partitions */
+		mtstate->mt_partition_dispatch_info =
+					RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
+													 &num_parted,
+													 &leaf_parts);
 		mtstate->mt_num_dispatch = num_parted;
-		num_leaf_parts = list_length(leaf_parts);
-		mtstate->mt_num_partitions = num_leaf_parts;
+		mtstate->mt_num_partitions = list_length(leaf_parts);
 		mtstate->mt_partitions = (ResultRelInfo *)
-						palloc0(num_leaf_parts * sizeof(ResultRelInfo));
+						palloc0(mtstate->mt_num_partitions *
+												sizeof(ResultRelInfo));
 		mtstate->mt_partition_tupconv_maps = (TupleConversionMap **)
-					palloc0(num_leaf_parts * sizeof(TupleConversionMap *));
+						palloc0(mtstate->mt_num_partitions *
+												sizeof(TupleConversionMap *));
 
 		leaf_part_rri = mtstate->mt_partitions;
 		i = j = 0;
diff --git a/src/include/catalog/pg_partitioned_table.h b/src/include/catalog/pg_partitioned_table.h
index cec54ae62e..2c6b6cf3a0 100644
--- a/src/include/catalog/pg_partitioned_table.h
+++ b/src/include/catalog/pg_partitioned_table.h
@@ -7,7 +7,7 @@
  *
  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_partitioned_table.h $
+ * src/include/catalog/pg_partitioned_table.h
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -47,7 +47,7 @@ CATALOG(pg_partitioned_table,3350) BKI_WITHOUT_OIDS
 #ifdef CATALOG_VARLEN
 	oidvector		partclass;		/* operator class to compare keys */
 	oidvector		partcollation;	/* user-specified collation for keys */
-	pg_node_tree	partexprs;		/* list of expressions in the partitioning
+	pg_node_tree	partexprs;		/* list of expressions in the partition
 									 * key; one item for each zero entry in
 									 * partattrs[] */
 #endif
-- 
2.11.0

--------------87B7BEABA41A98E25D2BEF30
Content-Type: text/x-diff;
 name="0002-Miscallaneous-documentation-improvements.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0002-Miscallaneous-documentation-improvements.patch"