From 8465584bc2cc85eb0f8303d22614446a04ec1921 Mon Sep 17 00:00:00 2001
From: Amit Kapila <akapila@postgresql.org>
Date: Sun, 26 Jul 2020 16:06:44 +0530
Subject: [PATCH v3] Fix comments in heapam.c.

After commits 85f6b49c2c and 3ba59ccc89, we can allow parallel inserts
which was earlier not possible as parallel group members won't conflict
for relation extension and page lock.  In those commits, we forgot to
update comments at few places.

Reviewed-by: Robert Haas and Dilip Kumar
Discussion: https://postgr.es/m/CAFiTN-tMrQh5FFMPx5aWJ+1gi1H6JxktEhq5mDwCHgnEO5oBkA@mail.gmail.com

diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index d881f4c..cb4090a 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2013,12 +2013,14 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid,
 					CommandId cid, int options)
 {
 	/*
-	 * Parallel operations are required to be strictly read-only in a parallel
-	 * worker.  Parallel inserts are not safe even in the leader in the
-	 * general case, because group locking means that heavyweight locks for
-	 * relation extension or GIN page locks will not conflict between members
-	 * of a lock group, but we don't prohibit that case here because there are
-	 * useful special cases that we can safely allow, such as CREATE TABLE AS.
+	 * For now, we don't allow parallel inserts of any form not even where the
+	 * leader can perform the insert.  This restriction can be uplifted once
+	 * we allow the planner to generate parallel plans for inserts.  We can
+	 * parallelize inserts unless they generate a new commandid (ex. inserts
+	 * into a table having foreign key column) or lock tuples (ex. statements
+	 * like Insert .. Select For Update).  We should be able to parallelize
+	 * the later case if we can ensure that no two parallel processes can ever
+	 * operate on the same page.
 	 */
 	if (IsParallelWorker())
 		ereport(ERROR,
@@ -5694,10 +5696,10 @@ heap_inplace_update(Relation relation, HeapTuple tuple)
 	uint32		newlen;
 
 	/*
-	 * For now, parallel operations are required to be strictly read-only.
-	 * Unlike a regular update, this should never create a combo CID, so it
-	 * might be possible to relax this restriction, but not without more
-	 * thought and testing.  It's not clear that it would be useful, anyway.
+	 * For now, we don't allow parallel updates.  Unlike a regular update,
+	 * this should never create a combo CID, so it might be possible to relax
+	 * this restriction, but not without more thought and testing.  It's not
+	 * clear that it would be useful, anyway.
 	 */
 	if (IsInParallelMode())
 		ereport(ERROR,
-- 
1.8.3.1

