public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages
58+ messages / 10 participants
[nested] [flat]

* [PATCH v10 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index c76849a98e..d85fee1e50 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2264,7 +2265,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index fe471a8a0c..076e1ff674 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -119,7 +119,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -298,14 +297,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 29387166c1..edc54ecffe 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -1994,15 +1996,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2013,7 +2017,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--3o7pc6dfau5a5hry
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v10-0012-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v10 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index c76849a98e..d85fee1e50 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2264,7 +2265,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index fe471a8a0c..076e1ff674 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -119,7 +119,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -298,14 +297,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 29387166c1..edc54ecffe 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -1994,15 +1996,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2013,7 +2017,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--3o7pc6dfau5a5hry
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v10-0012-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v11 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2d9e0e1a9f..81a7488007 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2172,7 +2172,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2322,7 +2323,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index fe471a8a0c..076e1ff674 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -119,7 +119,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -298,14 +297,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 459e123e92..bb2b79717c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -808,8 +808,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -826,8 +826,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2029,15 +2031,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2048,7 +2052,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--owzzsiozz6hgpp7e
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v11-0012-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2ad785e511..266b34fe6b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2267,7 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 7e73583fe5..96b55507a3 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -69,7 +69,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -267,14 +266,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index a820cc8c99..1d4b79a73f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2013,15 +2015,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2032,7 +2036,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--7mdtsjmrzitrgzgx
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v9-0011-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v8 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2ad785e511..266b34fe6b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2267,7 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 7e73583fe5..96b55507a3 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -69,7 +69,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -267,14 +266,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index a820cc8c99..1d4b79a73f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2013,15 +2015,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2032,7 +2036,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--xqq4defy3uncu6k6
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v8-0012-Separate-TBM-Shared-Iterator-and-TBMIterateResult.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v12 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 38c4fd5011c..46f1a374252 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2199,7 +2199,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2349,7 +2350,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 8b6f22bc3b6..fb79f57d7a6 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -119,7 +119,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -298,14 +297,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 592a8421bdf..a06ed271eb6 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -804,8 +804,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -822,8 +822,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2019,15 +2021,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2038,7 +2042,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--6jpz2j246qmht4bt
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v12-0012-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v8 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2ad785e511..266b34fe6b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2267,7 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 7e73583fe5..96b55507a3 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -69,7 +69,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -267,14 +266,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index a820cc8c99..1d4b79a73f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2013,15 +2015,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2032,7 +2036,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--xqq4defy3uncu6k6
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v8-0012-Separate-TBM-Shared-Iterator-and-TBMIterateResult.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v11 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2d9e0e1a9f..81a7488007 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2172,7 +2172,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2322,7 +2323,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index fe471a8a0c..076e1ff674 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -119,7 +119,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -298,14 +297,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 459e123e92..bb2b79717c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -808,8 +808,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -826,8 +826,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2029,15 +2031,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2048,7 +2052,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--owzzsiozz6hgpp7e
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v11-0012-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2ad785e511..266b34fe6b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2267,7 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 7e73583fe5..96b55507a3 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -69,7 +69,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -267,14 +266,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index a820cc8c99..1d4b79a73f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2013,15 +2015,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2032,7 +2036,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--7mdtsjmrzitrgzgx
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v9-0011-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2ad785e511..266b34fe6b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2267,7 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 7e73583fe5..96b55507a3 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -69,7 +69,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -267,14 +266,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index a820cc8c99..1d4b79a73f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2013,15 +2015,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2032,7 +2036,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--7mdtsjmrzitrgzgx
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v9-0011-Hard-code-TBMIterateResult-offsets-array-size.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* [PATCH v8 11/17] table_scan_bitmap_next_block counts lossy and exact pages
@ 2024-03-22 21:09 Melanie Plageman <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Melanie Plageman @ 2024-03-22 21:09 UTC (permalink / raw)

Now that the table_scan_bitmap_next_block() callback only returns false
when the bitmap is exhausted, it is simpler to move the management of
the lossy and exact page counters into it. We will eventually remove
this callback and table_scan_bitmap_next_tuple() will update those
counters when a new block is read in.
---
 src/backend/access/heap/heapam_handler.c  |  8 ++++++--
 src/backend/executor/nodeBitmapHeapscan.c |  9 ++-------
 src/include/access/tableam.h              | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2ad785e511..266b34fe6b 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2114,7 +2114,8 @@ heapam_estimate_rel_size(Relation rel, int32 *attr_widths,
 
 static bool
 heapam_scan_bitmap_next_block(TableScanDesc scan,
-							  bool *recheck, bool *lossy, BlockNumber *blockno)
+							  bool *recheck, BlockNumber *blockno,
+							  long *lossy_pages, long *exact_pages)
 {
 	HeapScanDesc hscan = (HeapScanDesc) scan;
 	BlockNumber block;
@@ -2267,7 +2268,10 @@ heapam_scan_bitmap_next_block(TableScanDesc scan,
 	Assert(ntup <= MaxHeapTuplesPerPage);
 	hscan->rs_ntuples = ntup;
 
-	*lossy = tbmres->ntuples < 0;
+	if (tbmres->ntuples < 0)
+		(*lossy_pages)++;
+	else
+		(*exact_pages)++;
 
 	/*
 	 * Return true to indicate that a valid block was found and the bitmap is
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 7e73583fe5..96b55507a3 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -69,7 +69,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
 {
 	ExprContext *econtext;
 	TableScanDesc scan;
-	bool		lossy;
 	TIDBitmap  *tbm;
 	TupleTableSlot *slot;
 	ParallelBitmapHeapState *pstate = node->pstate;
@@ -267,14 +266,10 @@ new_page:
 
 		BitmapAdjustPrefetchIterator(node);
 
-		if (!table_scan_bitmap_next_block(scan, &node->recheck, &lossy, &node->blockno))
+		if (!table_scan_bitmap_next_block(scan, &node->recheck, &node->blockno,
+										  &node->lossy_pages, &node->exact_pages))
 			break;
 
-		if (lossy)
-			node->lossy_pages++;
-		else
-			node->exact_pages++;
-
 		/*
 		 * If serial, we can error out if the the prefetch block doesn't stay
 		 * ahead of the current block.
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index a820cc8c99..1d4b79a73f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -797,8 +797,8 @@ typedef struct TableAmRoutine
 	 * work to allow scan_bitmap_next_tuple() to return tuples (e.g. it might
 	 * make sense to perform tuple visibility checks at this time).
 	 *
-	 * lossy indicates whether or not the block's representation in the bitmap
-	 * is lossy or exact.
+	 * lossy_pages is incremented if the block's representation in the bitmap
+	 * is lossy, otherwise, exact_pages is incremented.
 	 *
 	 * XXX: Currently this may only be implemented if the AM uses md.c as its
 	 * storage manager, and uses ItemPointer->ip_blkid in a manner that maps
@@ -815,8 +815,10 @@ typedef struct TableAmRoutine
 	 * scan_bitmap_next_tuple need to exist, or neither.
 	 */
 	bool		(*scan_bitmap_next_block) (TableScanDesc scan,
-										   bool *recheck, bool *lossy,
-										   BlockNumber *blockno);
+										   bool *recheck,
+										   BlockNumber *blockno,
+										   long *lossy_pages,
+										   long *exact_pages);
 
 	/*
 	 * Fetch the next tuple of a bitmap table scan into `slot` and return true
@@ -2013,15 +2015,17 @@ table_relation_estimate_size(Relation rel, int32 *attr_widths,
 /*
  * Prepare to fetch / check / return tuples as part of a bitmap table scan.
  * `scan` needs to have been started via table_beginscan_bm(). Returns false if
- * there are no more blocks in the bitmap, true otherwise. lossy is set to true
- * if bitmap is lossy for the selected block and false otherwise.
+ * there are no more blocks in the bitmap, true otherwise. lossy_pages is
+ * incremented if bitmap is lossy for the selected block and exact_pages is
+ * incremented otherwise.
  *
  * Note, this is an optionally implemented function, therefore should only be
  * used after verifying the presence (at plan time or such).
  */
 static inline bool
 table_scan_bitmap_next_block(TableScanDesc scan,
-							 bool *recheck, bool *lossy, BlockNumber *blockno)
+							 bool *recheck, BlockNumber *blockno,
+							 long *lossy_pages, long *exact_pages)
 {
 	/*
 	 * We don't expect direct calls to table_scan_bitmap_next_block with valid
@@ -2032,7 +2036,8 @@ table_scan_bitmap_next_block(TableScanDesc scan,
 		elog(ERROR, "unexpected table_scan_bitmap_next_block call during logical decoding");
 
 	return scan->rs_rd->rd_tableam->scan_bitmap_next_block(scan, recheck,
-														   lossy, blockno);
+														   blockno, lossy_pages,
+														   exact_pages);
 }
 
 /*
-- 
2.40.1


--xqq4defy3uncu6k6
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v8-0012-Separate-TBM-Shared-Iterator-and-TBMIterateResult.patch"



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
@ 2024-04-09 23:03 Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-09 23:03 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

On Mon, Apr 8, 2024 at 11:43 PM Dmitry Koval <[email protected]> wrote:
> Attached fix for the problems found by Alexander Lakhin.
>
> About grammar errors.
> Unfortunately, I don't know English well.
> Therefore, I plan (in the coming days) to show the text to specialists
> who perform technical translation of documentation.

Thank you.  I've pushed this fix with minor corrections from me.

------
Regards,
Alexander Korotkov






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-10 09:00 ` Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-10 09:00 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

Hello Alexander and Dmitry,

10.04.2024 02:03, Alexander Korotkov wrote:
> On Mon, Apr 8, 2024 at 11:43 PM Dmitry Koval <[email protected]> wrote:
>> Attached fix for the problems found by Alexander Lakhin.
>>
>> About grammar errors.
>> Unfortunately, I don't know English well.
>> Therefore, I plan (in the coming days) to show the text to specialists
>> who perform technical translation of documentation.
> Thank you.  I've pushed this fix with minor corrections from me.

Thank you for fixing that defect!

Please look at an error message emitted for foreign tables:
CREATE TABLE t (i int) PARTITION BY RANGE (i);
CREATE FOREIGN TABLE ftp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1)
   SERVER loopback OPTIONS (table_name 'lt_0_1');
CREATE FOREIGN TABLE ftp_1_2 PARTITION OF t
   FOR VALUES FROM (1) TO (2)
   SERVER loopback OPTIONS (table_name 'lt_1_2');
ALTER TABLE t MERGE PARTITIONS (ftp_0_1, ftp_1_2) INTO ftp_0_2;
ERROR:  "ftp_0_1" is not a table

Shouldn't it be more correct/precise?

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-10 12:00   ` Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-10 12:00 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Richard Guo <[email protected]>

10.04.2024 12:00, Alexander Lakhin wrote:
> Hello Alexander and Dmitry,
>
> 10.04.2024 02:03, Alexander Korotkov wrote:
>> Thank you.  I've pushed this fix with minor corrections from me.
>

Please look at another anomaly with MERGE.

CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
CREATE TABLE tp_0_2 PARTITION OF t
   FOR VALUES FROM (0) TO (2);
fails with
ERROR:  cannot create a permanent relation as partition of temporary relation "t"

But
CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
CREATE TEMP TABLE tp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1);
CREATE TEMP TABLE tp_1_2 PARTITION OF t
   FOR VALUES FROM (1) TO (2);
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
succeeds and we get:
regression=# \d+ t*
                                     Partitioned table "pg_temp_1.t"
  Column |  Type   | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
  i      | integer |           |          |         | plain |             |              |
Partition key: RANGE (i)
Partitions: tp_0_2 FOR VALUES FROM (0) TO (2)

                                          Table "public.tp_0_2"
  Column |  Type   | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
  i      | integer |           |          |         | plain |             |              |
Partition of: t FOR VALUES FROM (0) TO (2)
Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-10 17:22     ` Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-04-10 17:22 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Richard Guo <[email protected]>

Hi!

Alexander Korotkov, thanks for the commit of previous fix.
Alexander Lakhin, thanks for the problem you found.

There are two corrections attached to the letter:

1) v1-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch - fix 
for the problem [1].

2) v1-0002-Fixes-for-english-text.patch - fixes for English text 
(comments, error messages etc.).

Links:
[1] 
https://www.postgresql.org/message-id/dbc8b96c-3cf0-d1ee-860d-0e491da20485%40gmail.com

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
From 3c443a57c334c74e9218fd4e2f1ced45e6d4141d Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v1 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 11 ++++---
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 32 +++++++++++++++++--
 src/test/regress/expected/partition_split.out | 29 +++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 24 +++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++++++++++
 6 files changed, 113 insertions(+), 8 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..3da9f6389d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21491,7 +21493,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..ef1a2a97c0 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not a ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..c69a717aaa 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not a ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,32 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..cce5ffa29f 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,27 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1


From ecbcbf622ae54bfeee7b92759058a117169dca5b Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v1 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +--
 src/backend/commands/tablecmds.c              | 18 +++----
 src/backend/parser/parse_utilcmd.c            |  6 +--
 src/backend/partitioning/partbounds.c         | 28 +++++------
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 +++---
 src/test/regress/expected/partition_split.out | 50 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++---
 src/test/regress/sql/partition_split.sql      | 42 ++++++++--------
 10 files changed, 90 insertions(+), 90 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3da9f6389d..c44d9c1db6 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
@@ -21512,7 +21512,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 
 	/*
 	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
+	 * verification for each cloned constraint is not needed.
 	 */
 	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
 
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ef1a2a97c0..82b6ba7fc6 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..1c8396e83c 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition has",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index c69a717aaa..6e25365124 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not a ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..87417b7796 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -555,7 +555,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition has
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index cce5ffa29f..c96120a4ad 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..763699c5af 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -313,7 +313,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



Attachments:

  [text/plain] v1-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (10.7K, ../../[email protected]/2-v1-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch)
  download | inline diff:
From 3c443a57c334c74e9218fd4e2f1ced45e6d4141d Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v1 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 11 ++++---
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 32 +++++++++++++++++--
 src/test/regress/expected/partition_split.out | 29 +++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 24 +++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++++++++++
 6 files changed, 113 insertions(+), 8 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..3da9f6389d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21491,7 +21493,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..ef1a2a97c0 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not a ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..c69a717aaa 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not a ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,32 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..cce5ffa29f 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,27 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1



  [text/plain] v1-0002-Fixes-for-english-text.patch (41.9K, ../../[email protected]/3-v1-0002-Fixes-for-english-text.patch)
  download | inline diff:
From ecbcbf622ae54bfeee7b92759058a117169dca5b Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v1 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +--
 src/backend/commands/tablecmds.c              | 18 +++----
 src/backend/parser/parse_utilcmd.c            |  6 +--
 src/backend/partitioning/partbounds.c         | 28 +++++------
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 +++---
 src/test/regress/expected/partition_split.out | 50 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++---
 src/test/regress/sql/partition_split.sql      | 42 ++++++++--------
 10 files changed, 90 insertions(+), 90 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3da9f6389d..c44d9c1db6 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
@@ -21512,7 +21512,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 
 	/*
 	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
+	 * verification for each cloned constraint is not needed.
 	 */
 	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
 
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ef1a2a97c0..82b6ba7fc6 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..1c8396e83c 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition has",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index c69a717aaa..6e25365124 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not a ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..87417b7796 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -555,7 +555,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition has
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index cce5ffa29f..c96120a4ad 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not a ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..763699c5af 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -313,7 +313,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition has
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-11 07:57       ` Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Richard Guo @ 2024-04-11 07:57 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Alexander Korotkov <[email protected]>; PostgreSQL Hackers <[email protected]>

On Thu, Apr 11, 2024 at 1:22 AM Dmitry Koval <[email protected]> wrote:

> 2) v1-0002-Fixes-for-english-text.patch - fixes for English text
> (comments, error messages etc.).


FWIW, I also proposed a patch earlier that fixes error messages and
comments in the split partition code at
https://www.postgresql.org/message-id/flat/CAMbWs49DDsknxyoycBqiE72VxzL_sYHF6zqL8dSeNehKPJhkKg%40mai...

Thanks
Richard


^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
@ 2024-04-11 08:59         ` Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-04-11 08:59 UTC (permalink / raw)
  To: Richard Guo <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

> FWIW, I also proposed a patch earlier that fixes error messages and
> comments in the split partition code

Sorry, I thought all the fixes you suggested were already included in 
v1-0002-Fixes-for-english-text.patch (but they are not).
Added missing lines to v2-0002-Fixes-for-english-text.patch.

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
From cfd5a56d15e7ead6dd7ae66cd382de3fa38150d7 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v2 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 11 ++++---
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 32 +++++++++++++++++--
 src/test/regress/expected/partition_split.out | 29 +++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 24 +++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++++++++++
 6 files changed, 113 insertions(+), 8 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..3da9f6389d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21491,7 +21493,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..a3bbcc99c0 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..9fe97a801d 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,32 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..428b6cc88f 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,27 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1


From 83cd86343b8a75afe89e4177fc064e53fe821b01 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v2 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 18 +++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 98 insertions(+), 98 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3da9f6389d..c44d9c1db6 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
@@ -21512,7 +21512,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 
 	/*
 	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
+	 * verification for each cloned constraint is not needed.
 	 */
 	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
 
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index a3bbcc99c0..1f6e90cd47 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 9fe97a801d..26756faf38 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 428b6cc88f..99b8f11a18 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



Attachments:

  [text/plain] v2-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (10.7K, ../../[email protected]/2-v2-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch)
  download | inline diff:
From cfd5a56d15e7ead6dd7ae66cd382de3fa38150d7 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v2 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 11 ++++---
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 32 +++++++++++++++++--
 src/test/regress/expected/partition_split.out | 29 +++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 24 +++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++++++++++
 6 files changed, 113 insertions(+), 8 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..3da9f6389d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21491,7 +21493,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..a3bbcc99c0 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..9fe97a801d 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,32 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..428b6cc88f 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,27 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1



  [text/plain] v2-0002-Fixes-for-english-text.patch (46.4K, ../../[email protected]/3-v2-0002-Fixes-for-english-text.patch)
  download | inline diff:
From 83cd86343b8a75afe89e4177fc064e53fe821b01 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v2 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 18 +++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 98 insertions(+), 98 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3da9f6389d..c44d9c1db6 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
@@ -21512,7 +21512,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 
 	/*
 	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
+	 * verification for each cloned constraint is not needed.
 	 */
 	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
 
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index a3bbcc99c0..1f6e90cd47 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 9fe97a801d..26756faf38 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 428b6cc88f..99b8f11a18 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-11 12:00           ` Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-11 12:00 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; Richard Guo <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi Dmitry,

11.04.2024 11:59, Dmitry Koval wrote:
>
>> FWIW, I also proposed a patch earlier that fixes error messages and
>> comments in the split partition code
>
> Sorry, I thought all the fixes you suggested were already included in v1-0002-Fixes-for-english-text.patch (but they 
> are not).
> Added missing lines to v2-0002-Fixes-for-english-text.patch.
>

It seems to me that v2-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch
is not complete either.
Take a look, please:
CREATE TABLE t (i int) PARTITION BY RANGE (i);
SET search_path = pg_temp, public;
CREATE TABLE tp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1);
-- fails with:
ERROR:  cannot create a temporary relation as partition of permanent relation "t"

But:
CREATE TABLE t (i int) PARTITION BY RANGE (i);
CREATE TABLE tp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1_2 PARTITION OF t
   FOR VALUES FROM (1) TO (2);
INSERT INTO t VALUES(0), (1);
SELECT * FROM t;
-- the expected result is:
  i
---
  0
  1
(2 rows)

SET search_path = pg_temp, public;
ALTER TABLE t
MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
-- succeeds, and
\c -
SELECT * FROM t;
-- gives:
  i
---
(0 rows)

Please also ask your tech writers to check contents of src/test/sql/*, if
possible (perhaps, they'll fix "salesmans" and improve grammar).

Best regards,
Alexander

^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-11 13:27             ` Dmitry Koval <[email protected]>
  2024-04-11 14:21               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Dmitry Koval @ 2024-04-11 13:27 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

1.
Alexander Lakhin sent a question about index name after MERGE (partition 
name is the same as one of the merged partitions):

----start of quote----
I'm also confused by an index name after MERGE:
CREATE TABLE t (i int) PARTITION BY RANGE (i);

CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);

CREATE INDEX tidx ON t(i);
ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
\d+ t*

                                          Table "public.tp_1_2"
  Column |  Type   | Collation | Nullable | Default | Storage | 
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
  i      | integer |           |          |         | plain   | 
    |              |
Partition of: t FOR VALUES FROM (0) TO (2)
Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))
Indexes:
     "merge-16385-3A14B2-tmp_i_idx" btree (i)

Is the name "merge-16385-3A14B2-tmp_i_idx" valid or it's something 
temporary?
----end of quote----

Fix for this case added to file 
v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.

----

2.
 >It seems to me that v2-0001-Fix-for-SPLIT-MERGE-partitions-of-
 >temporary-table.patch is not complete either.

Added correction (and test), see 
v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
From 58eb4abd4f065b6aa423bbddf62acd1799eba22e Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v3 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 30 ++++---
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 87 ++++++++++++++++++-
 src/test/regress/expected/partition_split.out | 29 +++++++
 src/test/regress/sql/partition_merge.sql      | 70 ++++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++
 6 files changed, 227 insertions(+), 14 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..2769be55be 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,20 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+	newPartName->schemaname = modelRelName->schemaname;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21294,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21491,7 +21494,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21507,12 +21511,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21542,7 +21540,19 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..a3bbcc99c0 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..9d48262a82 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,87 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- Try creating a partition in the temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition tp_0_2 should be permanent (p).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | p
+(1 row)
+
+SET search_path = public, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..312f0e49d3 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,73 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- Try creating a partition in the temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition tp_0_2 should be permanent (p).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1


From f80a240209810749d64203fd469552aab1864d48 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v3 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 16 ++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 2769be55be..dff9ac9df1 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21246,7 +21246,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21313,7 +21313,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21387,7 +21387,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21489,7 +21489,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index a3bbcc99c0..1f6e90cd47 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 9d48262a82..39c3b90b9c 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 312f0e49d3..38cb60585d 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



Attachments:

  [text/plain] v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (15.9K, ../../[email protected]/2-v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch)
  download | inline diff:
From 58eb4abd4f065b6aa423bbddf62acd1799eba22e Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v3 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 30 ++++---
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 87 ++++++++++++++++++-
 src/test/regress/expected/partition_split.out | 29 +++++++
 src/test/regress/sql/partition_merge.sql      | 70 ++++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++
 6 files changed, 227 insertions(+), 14 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..2769be55be 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,20 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+	newPartName->schemaname = modelRelName->schemaname;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21294,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21491,7 +21494,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21507,12 +21511,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21542,7 +21540,19 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..a3bbcc99c0 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..9d48262a82 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,87 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- Try creating a partition in the temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition tp_0_2 should be permanent (p).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | p
+(1 row)
+
+SET search_path = public, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..312f0e49d3 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,73 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- Try creating a partition in the temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition tp_0_2 should be permanent (p).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1



  [text/plain] v3-0002-Fixes-for-english-text.patch (46.1K, ../../[email protected]/3-v3-0002-Fixes-for-english-text.patch)
  download | inline diff:
From f80a240209810749d64203fd469552aab1864d48 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v3 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 16 ++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 2769be55be..dff9ac9df1 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21246,7 +21246,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21313,7 +21313,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21387,7 +21387,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21489,7 +21489,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index a3bbcc99c0..1f6e90cd47 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 9d48262a82..39c3b90b9c 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 312f0e49d3..38cb60585d 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-11 14:21               ` Alexander Korotkov <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-11 14:21 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi, Dmitry!

On Thu, Apr 11, 2024 at 4:27 PM Dmitry Koval <[email protected]> wrote:
> 1.
> Alexander Lakhin sent a question about index name after MERGE (partition
> name is the same as one of the merged partitions):
>
> ----start of quote----
> I'm also confused by an index name after MERGE:
> CREATE TABLE t (i int) PARTITION BY RANGE (i);
>
> CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
> CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
>
> CREATE INDEX tidx ON t(i);
> ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
> \d+ t*
>
>                                           Table "public.tp_1_2"
>   Column |  Type   | Collation | Nullable | Default | Storage |
> Compression | Stats target | Description
> --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
>   i      | integer |           |          |         | plain   |
>     |              |
> Partition of: t FOR VALUES FROM (0) TO (2)
> Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))
> Indexes:
>      "merge-16385-3A14B2-tmp_i_idx" btree (i)
>
> Is the name "merge-16385-3A14B2-tmp_i_idx" valid or it's something
> temporary?
> ----end of quote----
>
> Fix for this case added to file
> v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.
>
> ----
>
> 2.
>  >It seems to me that v2-0001-Fix-for-SPLIT-MERGE-partitions-of-
>  >temporary-table.patch is not complete either.
>
> Added correction (and test), see
> v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.

Thank you, I'll review this later today.

------
Regards,
Alexander Korotkov






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-11 17:00               ` Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  1 sibling, 2 replies; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-11 17:00 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; PostgreSQL Hackers <[email protected]>


11.04.2024 16:27, Dmitry Koval wrote:
>
> Added correction (and test), see v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.
>

Thank you for the correction, but may be an attempt to merge into implicit
pg_temp should fail just like CREATE TABLE ... PARTITION OF ... does?

Please look also at another anomaly with schemas:
CREATE SCHEMA s1;
CREATE TABLE t (i int) PARTITION BY RANGE (i);
CREATE TABLE tp_0_2 PARTITION OF t
   FOR VALUES FROM (0) TO (2);
ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
   (PARTITION s1.tp0 FOR VALUES FROM (0) TO (1), PARTITION s1.tp1 FOR VALUES FROM (1) TO (2));
results in:
\d+ s1.*
Did not find any relation named "s1.*"
\d+ tp*
                                           Table "public.tp0"
...
                                            Table "public.tp1"
...

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-12 01:53                 ` Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-12 01:53 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Dmitry Koval <[email protected]>; PostgreSQL Hackers <[email protected]>

On Thu, Apr 11, 2024 at 8:00 PM Alexander Lakhin <[email protected]> wrote:
> 11.04.2024 16:27, Dmitry Koval wrote:
> >
> > Added correction (and test), see v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.
> >
>
> Thank you for the correction, but may be an attempt to merge into implicit
> pg_temp should fail just like CREATE TABLE ... PARTITION OF ... does?
>
> Please look also at another anomaly with schemas:
> CREATE SCHEMA s1;
> CREATE TABLE t (i int) PARTITION BY RANGE (i);
> CREATE TABLE tp_0_2 PARTITION OF t
>    FOR VALUES FROM (0) TO (2);
> ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
>    (PARTITION s1.tp0 FOR VALUES FROM (0) TO (1), PARTITION s1.tp1 FOR VALUES FROM (1) TO (2));
> results in:
> \d+ s1.*
> Did not find any relation named "s1.*"
> \d+ tp*
>                                            Table "public.tp0"
> ...
>                                             Table "public.tp1"

+1
I think we shouldn't unconditionally copy schema name and
relpersistence from the parent table.  Instead we should throw the
error on a mismatch like CREATE TABLE ... PARTITION OF ... does.  I'm
working on revising this fix.

------
Regards,
Alexander Korotkov






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-12 02:20                   ` Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 11:34                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Robert Haas @ 2024-04-12 02:20 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Dmitry Koval <[email protected]>; PostgreSQL Hackers <[email protected]>

On Thu, Apr 11, 2024 at 9:54 PM Alexander Korotkov <[email protected]> wrote:
> I think we shouldn't unconditionally copy schema name and
> relpersistence from the parent table.  Instead we should throw the
> error on a mismatch like CREATE TABLE ... PARTITION OF ... does.  I'm
> working on revising this fix.

We definitely shouldn't copy the schema name from the parent table. It
should be possible to schema-qualify the new partition names, and if
you don't, then the search_path should determine where they get
placed.

But I am inclined to think that relpersistence should be copied. It's
weird that you split an unlogged partition and you get logged
partitions.

One of the things I dislike about this type of feature -- not this
implementation specifically, but just this kind of idea in general --
is that the syntax mentions a whole bunch of tables but in a way where
you can't set their properties. Persistence, reloptions, whatever.
There's just no place to mention any of that stuff - and if you wanted
to create a place, you'd have to invent special syntax for each
separate thing. That's why I think it's good that the normal way of
creating a partition is CREATE TABLE .. PARTITION OF. Because that
way, we know that the full power of the CREATE TABLE statement is
always available, and you can set anything that you could set for a
table that is not a partition.

Of course, that is not to say that some people won't like to have a
feature of this sort. I expect they will. The approach does have some
drawbacks, though.

-- 
Robert Haas
EDB: http://www.enterprisedb.com






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
@ 2024-04-12 13:04                     ` Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-04-12 13:04 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

Attached is a patch with corrections based on comments in previous 
letters (I think these corrections are not final).
I'll be very grateful for feedbacks and bug reports.

11.04.2024 20:00, Alexander Lakhin wrote:
 > may be an attempt to merge into implicit
 > pg_temp should fail just like CREATE TABLE ... PARTITION OF ... does?

Corrected. Result is:

\d+ s1.*
Table "s1.tp0"
...
Table "s1.tp1"
...
\d+ tp*
Did not find any relation named "tp*".


12.04.2024 4:53, Alexander Korotkov wrote:
 > I think we shouldn't unconditionally copy schema name and
 > relpersistence from the parent table. Instead we should throw the
 > error on a mismatch like CREATE TABLE ... PARTITION OF ... does.
12.04.2024 5:20, Robert Haas wrote:
 > We definitely shouldn't copy the schema name from the parent table.

Fixed.

12.04.2024 5:20, Robert Haas wrote:
 > One of the things I dislike about this type of feature -- not this
 > implementation specifically, but just this kind of idea in general --
 > is that the syntax mentions a whole bunch of tables but in a way where
 > you can't set their properties. Persistence, reloptions, whatever.

In next releases I want to allow specifying options (probably, first of 
all, specifying tablespace of the partitions).
But before that, I would like to get a users reaction - what options 
they really need?

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
From 707d15cf9ee4673a1deed2825f48ffbc09a34e9d Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v4 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              |  32 +++--
 src/backend/parser/parse_utilcmd.c            |  19 ++-
 src/test/regress/expected/partition_merge.out | 118 +++++++++++++++++-
 src/test/regress/expected/partition_split.out |  29 +++++
 src/test/regress/sql/partition_merge.sql      |  95 +++++++++++++-
 src/test/regress/sql/partition_split.sql      |  23 ++++
 6 files changed, 297 insertions(+), 19 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..b59e1dda03 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21488,10 +21490,10 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temparary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21507,12 +21509,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21542,7 +21538,19 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..6b4dd81470 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3421,16 +3421,27 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString,
  *		Check that partRelOid is an oid of partition of the parent table rel
  */
 static void
-checkPartition(Relation rel, Oid partRelOid)
+checkPartition(Relation rel, RangeVar *partName, Oid partRelOid)
 {
 	Relation	partRel;
+	Oid			nspid;
+
+	nspid = RangeVarGetCreationNamespace(partName);
+
+	/* If the parent table is permanent, so must be all of its partitions. */
+	if (rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		isTempOrTempToastNamespace(nspid))
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(rel))));
 
 	partRel = relation_open(partRelOid, AccessShareLock);
 
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
@@ -3481,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 
 	splitPartOid = RangeVarGetRelid(partcmd->name, NoLock, false);
 
-	checkPartition(parent, splitPartOid);
+	checkPartition(parent, partcmd->name, splitPartOid);
 
 	/* Then we should check partitions with transformed bounds. */
 	check_partitions_for_split(parent, splitPartOid, partcmd->name, partcmd->partlist, cxt->pstate);
@@ -3546,7 +3557,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		if (partOid == defaultPartOid)
 			isDefaultPart = true;
 
-		checkPartition(parent, partOid);
+		checkPartition(parent, name, partOid);
 
 		partOids = lappend_oid(partOids, partOid);
 	}
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..23fe99ba28 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,118 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- Try creating a partition of the permanent relation in a temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+SET search_path = public, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = public, pg_temp;
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+SET search_path = pg_temp, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..98738e165b 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,98 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- Try creating a partition of the permanent relation in a temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = public, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1


From 1f34e2130bb836ef4cf847e8a40c79092fba77c7 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v4 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 16 ++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b59e1dda03..f58ff43699 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 6b4dd81470..361b31b7d3 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3503,7 +3503,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3548,7 +3548,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3562,7 +3562,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 23fe99ba28..94b3c59cac 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 98738e165b..af5c2dab6e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



Attachments:

  [text/plain] v4-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (20.0K, ../../[email protected]/2-v4-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch)
  download | inline diff:
From 707d15cf9ee4673a1deed2825f48ffbc09a34e9d Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v4 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              |  32 +++--
 src/backend/parser/parse_utilcmd.c            |  19 ++-
 src/test/regress/expected/partition_merge.out | 118 +++++++++++++++++-
 src/test/regress/expected/partition_split.out |  29 +++++
 src/test/regress/sql/partition_merge.sql      |  95 +++++++++++++-
 src/test/regress/sql/partition_split.sql      |  23 ++++
 6 files changed, 297 insertions(+), 19 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..b59e1dda03 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21488,10 +21490,10 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temparary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21507,12 +21509,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21542,7 +21538,19 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..6b4dd81470 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3421,16 +3421,27 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString,
  *		Check that partRelOid is an oid of partition of the parent table rel
  */
 static void
-checkPartition(Relation rel, Oid partRelOid)
+checkPartition(Relation rel, RangeVar *partName, Oid partRelOid)
 {
 	Relation	partRel;
+	Oid			nspid;
+
+	nspid = RangeVarGetCreationNamespace(partName);
+
+	/* If the parent table is permanent, so must be all of its partitions. */
+	if (rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		isTempOrTempToastNamespace(nspid))
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(rel))));
 
 	partRel = relation_open(partRelOid, AccessShareLock);
 
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
@@ -3481,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 
 	splitPartOid = RangeVarGetRelid(partcmd->name, NoLock, false);
 
-	checkPartition(parent, splitPartOid);
+	checkPartition(parent, partcmd->name, splitPartOid);
 
 	/* Then we should check partitions with transformed bounds. */
 	check_partitions_for_split(parent, splitPartOid, partcmd->name, partcmd->partlist, cxt->pstate);
@@ -3546,7 +3557,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		if (partOid == defaultPartOid)
 			isDefaultPart = true;
 
-		checkPartition(parent, partOid);
+		checkPartition(parent, name, partOid);
 
 		partOids = lappend_oid(partOids, partOid);
 	}
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..23fe99ba28 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,118 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- Try creating a partition of the permanent relation in a temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+SET search_path = public, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = public, pg_temp;
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+SET search_path = pg_temp, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..98738e165b 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,98 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- Try creating a partition of the permanent relation in a temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = public, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1



  [text/plain] v4-0002-Fixes-for-english-text.patch (46.0K, ../../[email protected]/3-v4-0002-Fixes-for-english-text.patch)
  download | inline diff:
From 1f34e2130bb836ef4cf847e8a40c79092fba77c7 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v4 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 16 ++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b59e1dda03..f58ff43699 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 6b4dd81470..361b31b7d3 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3503,7 +3503,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3548,7 +3548,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3562,7 +3562,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 23fe99ba28..94b3c59cac 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 98738e165b..af5c2dab6e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-12 17:00                       ` Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-12 17:00 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; Robert Haas <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

Hi Dmitry,

12.04.2024 16:04, Dmitry Koval wrote:
> Hi!
>
> Attached is a patch with corrections based on comments in previous letters (I think these corrections are not final).
> I'll be very grateful for feedbacks and bug reports.
>
> 11.04.2024 20:00, Alexander Lakhin wrote:
> > may be an attempt to merge into implicit
> > pg_temp should fail just like CREATE TABLE ... PARTITION OF ... does?
>
> Corrected. Result is:

Thank you!
Still now we're able to create a partition in the pg_temp schema
explicitly. Please try:
ALTER TABLE t
MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;

in the scenario [1] and you'll get the same empty table.

[1] https://www.postgresql.org/message-id/fdaa003e-919c-cbc9-4f0c-e4546e96bd65%40gmail.com

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-12 19:59                         ` Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-04-12 19:59 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

Thanks, Alexander!

> Still now we're able to create a partition in the pg_temp schema
> explicitly.

Attached patches with fix.

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
From 2b68bbdb068e881e8ca6e34dec735f7ce656374f Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v5 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              |  32 +++--
 src/backend/parser/parse_utilcmd.c            |  36 ++++-
 src/test/regress/expected/partition_merge.out | 124 +++++++++++++++++-
 src/test/regress/expected/partition_split.out |  29 ++++
 src/test/regress/sql/partition_merge.sql      | 101 +++++++++++++-
 src/test/regress/sql/partition_split.sql      |  23 ++++
 6 files changed, 324 insertions(+), 21 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..b59e1dda03 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21488,10 +21490,10 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temparary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21507,12 +21509,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21542,7 +21538,19 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..997f9bedf2 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3415,13 +3415,12 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString,
 	table_close(rel, NoLock);
 }
 
-
 /*
- * checkPartition
+ * checkOldPartition
  *		Check that partRelOid is an oid of partition of the parent table rel
  */
 static void
-checkPartition(Relation rel, Oid partRelOid)
+checkOldPartition(Relation rel, Oid partRelOid)
 {
 	Relation	partRel;
 
@@ -3430,7 +3429,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
@@ -3449,6 +3448,26 @@ checkPartition(Relation rel, Oid partRelOid)
 	relation_close(partRel, AccessShareLock);
 }
 
+/*
+ * checkNewPartition
+ *		Check that the new partition has the correct namespace.
+ */
+static void
+checkNewPartition(Relation rel, RangeVar *partName)
+{
+	Oid			nspid;
+
+	nspid = RangeVarGetCreationNamespace(partName);
+
+	/* If the parent table is permanent, so must be all of its partitions. */
+	if (rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		isTempOrTempToastNamespace(nspid))
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(rel))));
+}
+
 /*
  * transformPartitionCmdForSplit
  *		Analyze the ALTER TABLLE ... SPLIT PARTITION command
@@ -3477,11 +3496,13 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		transformPartitionCmd(cxt, sps->bound);
 		/* Assign transformed value of the partition bound. */
 		sps->bound = cxt->partbound;
+		/* Check that the new partition has the correct namespace. */
+		checkNewPartition(parent, sps->name);
 	}
 
 	splitPartOid = RangeVarGetRelid(partcmd->name, NoLock, false);
 
-	checkPartition(parent, splitPartOid);
+	checkOldPartition(parent, splitPartOid);
 
 	/* Then we should check partitions with transformed bounds. */
 	check_partitions_for_split(parent, splitPartOid, partcmd->name, partcmd->partlist, cxt->pstate);
@@ -3521,6 +3542,9 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 				 errmsg("partition of hash-partitioned table cannot be merged")));
 
+	/* Check that the new partition has the correct namespace. */
+	checkNewPartition(parent, partcmd->name);
+
 	/* Is current partition a DEFAULT partition? */
 	defaultPartOid = get_default_oid_from_partdesc(
 												   RelationGetPartitionDesc(parent, true));
@@ -3546,7 +3570,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		if (partOid == defaultPartOid)
 			isDefaultPart = true;
 
-		checkPartition(parent, partOid);
+		checkOldPartition(parent, partOid);
 
 		partOids = lappend_oid(partOids, partOid);
 	}
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..2d6a8474e7 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,124 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- 1. Try creating a partition of the permanent relation in a temporary schema.
+-- 2. Try to create a partition in the pg_temp schema explicitly.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+-- 1.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+SET search_path = public, pg_temp;
+-- 2.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+RESET search_path;
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = public, pg_temp;
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+SET search_path = pg_temp, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..8a3c3f4a4b 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,104 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- 1. Try creating a partition of the permanent relation in a temporary schema.
+-- 2. Try to create a partition in the pg_temp schema explicitly.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+-- 1.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = public, pg_temp;
+
+-- 2.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+
+DROP TABLE t;
+RESET search_path;
+
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1


From c4dccd827e769bd0ba03c65634235a8537bf30f4 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v5 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 16 ++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b59e1dda03..f58ff43699 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 997f9bedf2..75362df50a 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3513,7 +3513,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3561,7 +3561,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3575,7 +3575,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 2d6a8474e7..cb50229b87 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 8a3c3f4a4b..677d404647 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



Attachments:

  [text/plain] v5-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (21.7K, ../../[email protected]/2-v5-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch)
  download | inline diff:
From 2b68bbdb068e881e8ca6e34dec735f7ce656374f Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v5 1/2] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              |  32 +++--
 src/backend/parser/parse_utilcmd.c            |  36 ++++-
 src/test/regress/expected/partition_merge.out | 124 +++++++++++++++++-
 src/test/regress/expected/partition_split.out |  29 ++++
 src/test/regress/sql/partition_merge.sql      | 101 +++++++++++++-
 src/test/regress/sql/partition_split.sql      |  23 ++++
 6 files changed, 324 insertions(+), 21 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8a98a0af48..b59e1dda03 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
 static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
 
+	newPartName->relpersistence = rel->rd_rel->relpersistence;
+
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
 	createStmt->tableElts = NIL;
@@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
+		createPartitionTable(rel, sps->name, parentName, context);
 
 		/* Open the new partition and acquire exclusive lock on it. */
 		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
@@ -21488,10 +21490,10 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temparary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(rel,
+						 mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21507,12 +21509,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21542,7 +21538,19 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba069905..997f9bedf2 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3415,13 +3415,12 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString,
 	table_close(rel, NoLock);
 }
 
-
 /*
- * checkPartition
+ * checkOldPartition
  *		Check that partRelOid is an oid of partition of the parent table rel
  */
 static void
-checkPartition(Relation rel, Oid partRelOid)
+checkOldPartition(Relation rel, Oid partRelOid)
 {
 	Relation	partRel;
 
@@ -3430,7 +3429,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
@@ -3449,6 +3448,26 @@ checkPartition(Relation rel, Oid partRelOid)
 	relation_close(partRel, AccessShareLock);
 }
 
+/*
+ * checkNewPartition
+ *		Check that the new partition has the correct namespace.
+ */
+static void
+checkNewPartition(Relation rel, RangeVar *partName)
+{
+	Oid			nspid;
+
+	nspid = RangeVarGetCreationNamespace(partName);
+
+	/* If the parent table is permanent, so must be all of its partitions. */
+	if (rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		isTempOrTempToastNamespace(nspid))
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(rel))));
+}
+
 /*
  * transformPartitionCmdForSplit
  *		Analyze the ALTER TABLLE ... SPLIT PARTITION command
@@ -3477,11 +3496,13 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		transformPartitionCmd(cxt, sps->bound);
 		/* Assign transformed value of the partition bound. */
 		sps->bound = cxt->partbound;
+		/* Check that the new partition has the correct namespace. */
+		checkNewPartition(parent, sps->name);
 	}
 
 	splitPartOid = RangeVarGetRelid(partcmd->name, NoLock, false);
 
-	checkPartition(parent, splitPartOid);
+	checkOldPartition(parent, splitPartOid);
 
 	/* Then we should check partitions with transformed bounds. */
 	check_partitions_for_split(parent, splitPartOid, partcmd->name, partcmd->partlist, cxt->pstate);
@@ -3521,6 +3542,9 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 				 errmsg("partition of hash-partitioned table cannot be merged")));
 
+	/* Check that the new partition has the correct namespace. */
+	checkNewPartition(parent, partcmd->name);
+
 	/* Is current partition a DEFAULT partition? */
 	defaultPartOid = get_default_oid_from_partdesc(
 												   RelationGetPartitionDesc(parent, true));
@@ -3546,7 +3570,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		if (partOid == defaultPartOid)
 			isDefaultPart = true;
 
-		checkPartition(parent, partOid);
+		checkOldPartition(parent, partOid);
 
 		partOids = lappend_oid(partOids, partOid);
 	}
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf3..2d6a8474e7 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,124 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- 1. Try creating a partition of the permanent relation in a temporary schema.
+-- 2. Try to create a partition in the pg_temp schema explicitly.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+-- 1.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+SET search_path = public, pg_temp;
+-- 2.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+RESET search_path;
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = public, pg_temp;
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+SET search_path = pg_temp, pg_temp;
+DROP TABLE t;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d09969..3d22083e41 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365..8a3c3f4a4b 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,104 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- 1. Try creating a partition of the permanent relation in a temporary schema.
+-- 2. Try to create a partition in the pg_temp schema explicitly.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+-- 1.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = public, pg_temp;
+
+-- 2.
+-- ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+
+DROP TABLE t;
+RESET search_path;
+
+--
+-- Try creating a partition of the temporary relation in a permanent schema.
+--
+SET search_path = pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+-- There is no problem with creating a temporary partition in a permanent schema.
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition tp_0_2 should be temporary (t).
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, pg_temp;
+
+DROP TABLE t;
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1..5dc2fc39cd 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.40.1.windows.1



  [text/plain] v5-0002-Fixes-for-english-text.patch (46.0K, ../../[email protected]/3-v5-0002-Fixes-for-english-text.patch)
  download | inline diff:
From c4dccd827e769bd0ba03c65634235a8537bf30f4 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 19:55:18 +0300
Subject: [PATCH v5 2/2] Fixes for english text

---
 doc/src/sgml/ddl.sgml                         |  2 +-
 doc/src/sgml/ref/alter_table.sgml             |  6 +-
 src/backend/commands/tablecmds.c              | 16 ++---
 src/backend/parser/parse_utilcmd.c            |  6 +-
 src/backend/partitioning/partbounds.c         | 30 +++++-----
 src/test/isolation/specs/partition-merge.spec |  2 +-
 src/test/regress/expected/partition_merge.out | 14 ++---
 src/test/regress/expected/partition_split.out | 58 +++++++++----------
 src/test/regress/sql/partition_merge.sql      | 12 ++--
 src/test/regress/sql/partition_split.sql      | 48 +++++++--------
 10 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 00f44f56fa..026bfff70f 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key
      a single partition using the
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
-     administrators to combine partitions that are no longer needed as
+     users to combine partitions that are no longer needed as
      separate entities.  It's important to note that this operation is not
      supported for hash-partitioned tables and acquires an
      <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8f5bf185dd..fe36ff82e5 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables is necessary that the ranges
+         For range-partitioned tables it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
          be merged into one range without spaces and overlaps (otherwise an error
@@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the values lists of all partitions
+         For list-partitioned tables the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
-         combined and form a list of values of partition
+         combined and form the list of values of partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b59e1dda03..f58ff43699 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode)
 }
 
 /*
- * Struct with context of new partition for insert rows from splited partition
+ * Struct with context of new partition for inserting rows from split partition
  */
 typedef struct SplitPartitionContext
 {
@@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options)
  *
  * New partitions description:
  * partlist: list of pointers to SinglePartitionSpec structures.
- * newPartRels: list of Relation's.
+ * newPartRels: list of Relations.
  * defaultPartOid: oid of DEFAULT partition, for table rel.
  */
 static void
@@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 	/*
 	 * Map computing for moving attributes of split partition to new partition
-	 * (for first new partition but other new partitions can use the same
+	 * (for first new partition, but other new partitions can use the same
 	 * map).
 	 */
 	pc = (SplitPartitionContext *) lfirst(list_head(partContexts));
@@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 		if (tuple_map)
 		{
-			/* Need to use map for copy attributes. */
+			/* Need to use map to copy attributes. */
 			insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot);
 		}
 		else
@@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 			RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL);
 
 		/*
-		 * This would fail later on anyway, if the relation already exists.
+		 * This would fail later on anyway if the relation already exists.
 		 * But by catching it here we can emit a nicer error message.
 		 */
 		existing_relid = get_relname_relid(relname, namespaceId);
@@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel = (Relation) lfirst(listptr2);
 
-		/* wqueue = NULL: verification for each cloned constraint is not need. */
+		/* wqueue = NULL: verification for each cloned constraint is not needed. */
 		attachPartitionTable(NULL, rel, newPartRel, sps->bound);
 		/* Keep the lock until commit. */
 		table_close(newPartRel, NoLock);
@@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
 
 			if (tuple_map)
 			{
-				/* Need to use map for copy attributes. */
+				/* Need to use map to copy attributes. */
 				insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot);
 			}
 			else
@@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Create table for new partition, use partitioned table as model. */
 	if (isSameName)
 	{
-		/* Create partition table with generated temparary name. */
+		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
 		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 997f9bedf2..75362df50a 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3513,7 +3513,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
  * transformPartitionCmdForMerge
  *		Analyze the ALTER TABLLE ... MERGE PARTITIONS command
  *
- * Does simple checks for merged partitions. Calculates bound of result
+ * Does simple checks for merged partitions. Calculates bound of resulting
  * partition.
  */
 static void
@@ -3561,7 +3561,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 			if (equal(name, name2))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("partition with name \"%s\" already used", name->relname)),
+						 errmsg("partition with name \"%s\" is already used", name->relname)),
 						parser_errposition(cxt->pstate, name2->location));
 		}
 
@@ -3575,7 +3575,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
 		partOids = lappend_oid(partOids, partOid);
 	}
 
-	/* Allocate bound of result partition. */
+	/* Allocate bound of resulting partition. */
 	Assert(partcmd->bound == NULL);
 	partcmd->bound = makeNode(PartitionBoundSpec);
 
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index c0c49b0a0b..f89bdb3c86 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent,
 						PartitionRangeDatum *datum;
 
 						/*
-						 * Point to problematic key in the lower datums list;
+						 * Point to problematic key in the list of lower datums;
 						 * if we have equality, point to the first one.
 						 */
 						datum = cmpval == 0 ? linitial(spec->lowerdatums) :
@@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * This is a helper function for check_partitions_for_split() and
  * calculate_partition_bound_for_merge().
  * This function compares upper bound of first_bound and lower bound of
- * second_bound. These bounds should be equal except case
+ * second_bound. These bounds should be equal except when
  * "defaultPart == true" (this means that one of split partitions is DEFAULT).
  * In this case upper bound of first_bound can be less than lower bound of
- * second_bound because space between of these bounds will be included in
+ * second_bound because space between these bounds will be included in
  * DEFAULT partition.
  *
  * parent:			partitioned table
@@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
  * second_name:		name of second partition
  * second_bound:	bound of second partition
  * defaultPart:		true if one of split partitions is DEFAULT
- * pstate:			pointer to ParseState struct for determine error position
+ * pstate:			pointer to ParseState struct for determining error position
  */
 static void
 check_two_partitions_bounds_range(Relation parent,
@@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent,
 	second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true);
 
 	/*
-	 * lower1=false (the second to last argument) for correct comparison lower
+	 * lower1=false (the second to last argument) for correct comparison of lower
 	 * and upper bounds.
 	 */
 	cmpval = partition_rbound_cmp(key->partnatts,
@@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name)
  *
  * (function for BY RANGE partitioning)
  *
- * Checks that bounds of new partition "spec" is inside bounds of split
+ * Checks that bounds of new partition "spec" are inside bounds of split
  * partition (with Oid splitPartOid). If first=true (this means that "spec" is
  * the first of new partitions) then lower bound of "spec" should be equal (or
  * greater than or equal in case defaultPart=true) to lower bound of split
@@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent,
  *
  * (function for BY LIST partitioning)
  *
- * Checks that bounds of new partition is inside bounds of split partition
+ * Checks that bounds of new partition are inside bounds of split partition
  * (with Oid splitPartOid).
  *
  * parent:			partitioned table
@@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent,
 	Assert(key->strategy == PARTITION_STRATEGY_LIST);
 
 	/*
-	 * Special processing for NULL value. Search NULL-value if it contains
-	 * split partition (partOid).
+	 * Special processing for NULL value. Search NULL value if the split
+	 * partition (partOid) contains it.
 	 */
 	if (partition_bound_accepts_nulls(boundinfo) &&
 		partdesc->oids[boundinfo->null_index] == partOid)
@@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 	/*
 	 * Search all values of split partition with partOid in PartitionDesc of
-	 * partitionde table.
+	 * partitioned table.
 	 */
 	for (i = 0; i < boundinfo->ndatums; i++)
 	{
@@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent,
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("new partitions not have value %s but split partition has",
+				 errmsg("new partitions do not have value %s but split partition does",
 						searchNull ? "NULL" : get_list_partvalue_string(notFoundVal))));
 	}
 }
@@ -5645,7 +5645,7 @@ check_partitions_for_split(Relation parent,
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				 errmsg("any partition in the list should be DEFAULT because split partition is DEFAULT")),
+				 errmsg("all partitions in the list should be DEFAULT because split partition is DEFAULT")),
 				parser_errposition(pstate, ((SinglePartitionSpec *) linitial(partlist))->name->location));
 	}
 	else if (!isSplitPartDefault && (default_index >= 0) && OidIsValid(defaultPartOid))
@@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent,
 			if (equal(sps->name, sps2->name))
 				ereport(ERROR,
 						(errcode(ERRCODE_DUPLICATE_TABLE),
-						 errmsg("name \"%s\" already used", sps2->name->relname)),
+						 errmsg("name \"%s\" is already used", sps2->name->relname)),
 						parser_errposition(pstate, sps2->name->location));
 		}
 	}
@@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent,
 				}
 
 				/*
-				 * Lower bound of first partition is a lower bound of merged
+				 * Lower bound of first partition is the lower bound of merged
 				 * partition.
 				 */
 				spec->lowerdatums =
 					((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums;
 
 				/*
-				 * Upper bound of last partition is a upper bound of merged
+				 * Upper bound of last partition is the upper bound of merged
 				 * partition.
 				 */
 				spec->upperdatums =
diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec
index ec48732c58..dc2b9d3445 100644
--- a/src/test/isolation/specs/partition-merge.spec
+++ b/src/test/isolation/specs/partition-merge.spec
@@ -38,7 +38,7 @@ step s2s	{ SELECT * FROM tpart; }
 
 
 # s2 inserts row into table. s1 starts MERGE PARTITIONS then
-# s2 trying to update inserted row and waits until s1 finished
+# s2 is trying to update inserted row and waits until s1 finishes
 # MERGE operation.
 
 permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 2d6a8474e7..cb50229b87 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
-ERROR:  partition with name "sales_feb2022" already used
+ERROR:  partition with name "sales_feb2022" is already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 ERROR:  "sales_apr2022" is not an ordinary table
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
 ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
@@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 
 DROP TABLE sales_range;
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -162,7 +162,7 @@ SELECT * FROM sales_others;
           14 | Smith         |          510 | 05-04-2022
 (1 row)
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
@@ -704,7 +704,7 @@ SELECT * FROM sales_all;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
  salesman_id | salesman_name | sales_state | sales_amount | sales_date 
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 3d22083e41..46f02013be 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -43,7 +43,7 @@ ERROR:  empty range bound specified for partition "sales_mar2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO...
                                                     ^
 DETAIL:  Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022').
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 ERROR:  list of new partitions should contain at least two items
@@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is less than lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO...
                                                     ^
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb_mar_apr2022" already used
+ERROR:  name "sales_feb_mar_apr2022" is already used
 LINE 3:    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03...
                      ^
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  name "sales_feb2022" already used
+ERROR:  name "sales_feb2022" is already used
 LINE 3:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO...
                      ^
 -- ERROR:  "sales_feb_mar_apr2022" is not a partitioned table
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
 LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
                                                              ^
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -96,7 +96,7 @@ LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -191,7 +191,7 @@ SELECT * FROM sales_others;
 
 DROP TABLE sales_range CASCADE;
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022;
                       ^
 DROP TABLE sales_date CASCADE;
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
@@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 
 DROP TABLE sales_range CASCADE;
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211210) TO (2021...
                                                   ^
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -547,15 +547,15 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 LINE 3:    PARTITION sales_error FOR VALUES FROM (20211201) TO (2022...
                                                   ^
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
-ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 LINE 2:   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20...
                      ^
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -616,7 +616,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
  FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
@@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
@@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
  salesman_name |             | 
 (2 rows)
 
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
@@ -1036,7 +1036,7 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL),
 DROP TABLE sales_list;
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -1075,18 +1075,18 @@ CREATE TABLE sales_list
 PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
-ERROR:  new partitions not have value NULL but split partition has
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value NULL but split partition does
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL));
-ERROR:  new partitions not have value 'Kyiv' but split partition has
+ERROR:  new partitions do not have value 'Kyiv' but split partition does
 DROP TABLE sales_list;
 --
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
@@ -1174,7 +1174,7 @@ SELECT * FROM sales_central;
           13 | Gandi         | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 8a3c3f4a4b..677d404647 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04
 
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- ERROR:  partition with name "sales_feb2022" already used
+-- ERROR:  partition with name "sales_feb2022" is already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
--- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022"
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
--- ERROR:  invalid partitions order, partition "sales_jan2022" can not be merged
+-- ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
@@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 DROP TABLE sales_range;
 
 --
--- Add rows into partitioned table then merge partitions
+-- Add rows into partitioned table, then merge partitions
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
@@ -415,7 +415,7 @@ SELECT * FROM sales_list;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_all;
 
--- Use indexscan for test indexes after merge partitions
+-- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 5dc2fc39cd..576f9f0f63 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
---ERROR:  list of split partitions should contains at least two items
+--ERROR:  list of split partitions should contain at least two items
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01'));
 
@@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb_mar_apr2022" already used
+-- ERROR:  name "sales_feb_mar_apr2022" is already used
 -- (We can create partition with the same name as split partition, but can't create two partitions with the same name)
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
--- ERROR:  name "sales_feb2022" already used
+-- ERROR:  name "sales_feb2022" is already used
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 
--- ERROR:  lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition
+-- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
@@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
 
--- ERROR:  lower bound of partition "sales_feb2022" is not equals to lower bound of split partition
+-- ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
@@ -133,7 +133,7 @@ SELECT * FROM sales_others;
 DROP TABLE sales_range CASCADE;
 
 --
--- Add split partition then add rows into partitioned table
+-- Add split partition, then add rows into partitioned table
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022;
 DROP TABLE sales_date CASCADE;
 
 --
--- Test: split DEFAULT partition; using a index on partition key; check index after split
+-- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
@@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'),
    PARTITION sales_others DEFAULT);
 
--- Use indexscan for test indexes
+-- Use indexscan for testing indexes
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
@@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part
 DROP TABLE sales_range CASCADE;
 
 --
--- Test: some cases for split DEFAULT partition (different bounds)
+-- Test: some cases for splitting DEFAULT partition (different bounds)
 --
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- sales_error intersects with sales_dec2022 (exact the same bounds)
+-- sales_error intersects with sales_dec2022 (exactly the same bounds)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
@@ -307,13 +307,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 
--- ERROR:  any partition in the list should be DEFAULT because split partition is DEFAULT
+-- ERROR:  all partitions in the list should be DEFAULT because split partition is DEFAULT
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201),
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301));
 
--- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120),
@@ -325,7 +325,7 @@ DROP TABLE sales_range;
 CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
--- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022
+-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101),
    PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201),
@@ -361,7 +361,7 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
 
--- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_salesman_id_check"
+-- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
@@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE;
 DROP TABLE salesmans CASCADE;
 
 --
--- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table
+-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
 CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
@@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
--- If split partition column is identity-column, columns of new partitions are identity-columns too.
+-- If split partition column is identity column, columns of new partitions are identity columns too.
 --
 CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
 CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
--- Create new partition with identity-column:
+-- Create new partition with identity column:
 CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
 ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
 
@@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
 
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
--- Split partition has identity-column:
+-- Split partition has identity column:
 SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
 
 ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
@@ -609,7 +609,7 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
--- ERROR:  partition "sales_east" would overlap partition "sales_nord"
+-- ERROR:  new partition "sales_east" would overlap with another (not split) partition "sales_nord"
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok', 'Helsinki'),
@@ -631,8 +631,8 @@ DROP TABLE sales_list;
 
 --
 -- Test: two specific errors for BY LIST partitioning:
---   * new partitions not has NULL value that split partition has.
---   * new partitions not has a value that split partition has.
+--   * new partitions do not have NULL value, which split partition has.
+--   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
 (salesman_id INT,
@@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);
 
--- ERROR:  new partitions not have value NULL but split partition has
+-- ERROR:  new partitions do not have value NULL but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 
--- ERROR:  new partitions not have value 'Kyiv' but split partition has
+-- ERROR:  new partitions do not have value 'Kyiv' but split partition does
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
@@ -703,7 +703,7 @@ SELECT * FROM sales_east;
 SELECT * FROM sales_nord;
 SELECT * FROM sales_central;
 
--- Use indexscan for test indexes after split partition
+-- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 
-- 
2.40.1.windows.1



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-13 10:04                           ` Alexander Korotkov <[email protected]>
  2024-04-15 14:30                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-13 10:04 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi, Dmitry!

On Fri, Apr 12, 2024 at 10:59 PM Dmitry Koval <[email protected]> wrote:
>
> Thanks, Alexander!
>
> > Still now we're able to create a partition in the pg_temp schema
> > explicitly.
>
> Attached patches with fix.

Please, find a my version of this fix attached.  I think we need to
check relpersistence in a similar way ATTACH PARTITION or CREATE TABLE
... PARTITION OF do.  I'm going to polish this a little bit more.

------
Regards,
Alexander Korotkov


Attachments:

  [application/octet-stream] v6-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (17.0K, ../../CAPpHfdv-uR663BO6G2kRuLEQjob+UBHuD3iyXF+qGHXQFRN0-Q@mail.gmail.com/2-v6-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch)
  download | inline diff:
From abfbd47c4d5ae6cc6ff538688fe2b85601912e18 Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Wed, 10 Apr 2024 18:54:05 +0300
Subject: [PATCH v6] Fix for SPLIT/MERGE partitions of temporary table

---
 src/backend/commands/tablecmds.c              | 84 +++++++++++++------
 src/backend/parser/parse_utilcmd.c            |  2 +-
 src/test/regress/expected/partition_merge.out | 75 ++++++++++++++++-
 src/test/regress/expected/partition_split.out | 29 +++++++
 src/test/regress/sql/partition_merge.sql      | 69 ++++++++++++++-
 src/test/regress/sql/partition_split.sql      | 23 +++++
 6 files changed, 253 insertions(+), 29 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 000212f24c4..d38eb51002f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21124,16 +21124,24 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
  */
-static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+static Relation
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
+	Relation	newRel;
+
+	/* If existing rel is temp, it must belong to this session */
+	if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
+		!rel->rd_islocaltemp)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create as partition of temporary relation of another session")));
 
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
@@ -21172,6 +21180,35 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 				   NULL,
 				   None_Receiver,
 				   NULL);
+
+	/*
+	 * Open the new partition and acquire exclusive lock on it.  This will
+	 * stop all the operations with partitioned table.  This might seem
+	 * excessive, but this is the way we make sure nobody is planning queries
+	 * involving merging partitions.
+	 */
+	newRel = table_openrv(newPartName, AccessExclusiveLock);
+
+	/*
+	 * If the parent is permanent, so must be all of its partitions.  Note
+	 * that inheritance allows that case.
+	 */
+	if (rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		newRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(rel))));
+
+	/* Permanent rels cannot inherit from temporary ones */
+	if (newRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a permanent relation as partition of temporary relation \"%s\"",
+						RelationGetRelationName(rel))));
+
+	return newRel;
 }
 
 /*
@@ -21270,11 +21307,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
-
-		/* Open the new partition and acquire exclusive lock on it. */
-		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
-
+		newPartRel = createPartitionTable(rel, sps->name, parentName, context);
 		newPartRels = lappend(newPartRels, newPartRel);
 	}
 
@@ -21466,28 +21499,16 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									 tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
-						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									  RelationGetRelationName(rel), -1),
-						 context);
 
-	/*
-	 * Open the new partition and acquire exclusive lock on it.  This will
-	 * stop all the operations with partitioned table.  This might seem
-	 * excessive, but this is the way we make sure nobody is planning queries
-	 * involving merging partitions.
-	 */
-	newPartRel = table_openrv(mergePartName, AccessExclusiveLock);
+	newPartRel = createPartitionTable(rel,
+									  mergePartName,
+									  makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
+												   RelationGetRelationName(rel), -1),
+									  context);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21517,7 +21538,20 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ceba0699050..a3bbcc99c02 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid)
 	if (partRel->rd_rel->relkind != RELKIND_RELATION)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a table",
+				 errmsg("\"%s\" is not an ordinary table",
 						RelationGetRelationName(partRel))));
 
 	if (!partRel->rd_rel->relispartition)
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 60eacf6bf39..b1d0b50b0b4 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe
 ERROR:  partition with name "sales_feb2022" already used
 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2...
                                                              ^
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
-ERROR:  "sales_apr2022" is not a table
+ERROR:  "sales_apr2022" is not an ordinary table
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
@@ -746,4 +746,75 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
+-- Try creating a partition in the temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SET search_path = pg_temp, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+DROP TAble tp_0_2;
+ERROR:  table "tp_0_2" does not exist
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SET search_path = public, pg_temp;
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+ROLLBACK;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 26a0d099696..46cd82ce191 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9afed70365f..2d55e0f5a38 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- ERROR:  partition with name "sales_feb2022" already used
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- ERROR:  "sales_apr2022" is not a table
+-- ERROR:  "sales_apr2022" is not an ordinary table
 ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
 -- ERROR:  invalid partitions order, partition "sales_mar2022" can not be merged
 -- (space between sections sales_jan2022 and sales_mar2022)
@@ -444,5 +444,72 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
+
+DROP TABLE t;
+
+--
+-- Try creating a partition in the temporary schema.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SET search_path = pg_temp, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+DROP TABLE t;
+DROP TAble tp_0_2;
+
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SET search_path = public, pg_temp;
+
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 625b01ddd1f..5dc2fc39cd5 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.39.3 (Apple Git-145)



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-15 14:30                             ` Robert Haas <[email protected]>
  2024-04-15 15:00                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Robert Haas @ 2024-04-15 14:30 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; PostgreSQL Hackers <[email protected]>

On Sat, Apr 13, 2024 at 6:05 AM Alexander Korotkov <[email protected]> wrote:
> Please, find a my version of this fix attached.  I think we need to
> check relpersistence in a similar way ATTACH PARTITION or CREATE TABLE
> ... PARTITION OF do.  I'm going to polish this a little bit more.

+ errmsg("\"%s\" is not an ordinary table",

This is not a phrasing that we use in any other error message. We
always just say "is not a table".

+ * Open the new partition and acquire exclusive lock on it.  This will

A minor nitpick is that this should probably say access exclusive
rather than exclusive. But the bigger thing that confuses me here is
that if we just created the partition, surely we must *already* hold
AccessExclusiveLoc on it. No?

-- 
Robert Haas
EDB: http://www.enterprisedb.com






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 14:30                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
@ 2024-04-15 15:00                               ` Alexander Lakhin <[email protected]>
  2024-04-15 15:38                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-15 15:00 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; PostgreSQL Hackers <[email protected]>

Hello Robert,

15.04.2024 17:30, Robert Haas wrote:
> On Sat, Apr 13, 2024 at 6:05 AM Alexander Korotkov <[email protected]> wrote:
>> Please, find a my version of this fix attached.  I think we need to
>> check relpersistence in a similar way ATTACH PARTITION or CREATE TABLE
>> ... PARTITION OF do.  I'm going to polish this a little bit more.
> + errmsg("\"%s\" is not an ordinary table",
>
> This is not a phrasing that we use in any other error message. We
> always just say "is not a table".

Initially I was confused by that message, because of:
CREATE TABLE t (i int) PARTITION BY RANGE (i);
CREATE FOREIGN TABLE ftp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1)
   SERVER loopback OPTIONS (table_name 'lt_0_1');
CREATE FOREIGN TABLE ftp_1_2 PARTITION OF t
   FOR VALUES FROM (1) TO (2)
   SERVER loopback OPTIONS (table_name 'lt_1_2');
ALTER TABLE t MERGE PARTITIONS (ftp_0_1, ftp_1_2) INTO ftp_0_2;
ERROR:  "ftp_0_1" is not a table
(Isn't a foreign table a table?)

And also:
CREATE TABLE t (i int) PARTITION BY RANGE (i);
CREATE TABLE tp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1);
CREATE TABLE t2 (i int) PARTITION BY RANGE (i);
ALTER TABLE t MERGE PARTITIONS (tp_0_1, t2) INTO tpn;
ERROR:  "t2" is not a table
(Isn't a partitioned table a table?)

And in fact, an ordinary table is not suitable for MERGE anyway:
CREATE TABLE t (i int) PARTITION BY RANGE (i);
CREATE TABLE tp_0_1 PARTITION OF t
   FOR VALUES FROM (0) TO (1);
CREATE TABLE t2 (i int);
ALTER TABLE t MERGE PARTITIONS (tp_0_1, t2) INTO tpn;
ERROR:  "t2" is not a partition

So I don't think that "an ordinary table" is a good (unambiguous) term
either.

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 14:30                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-15 15:00                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-15 15:38                                 ` Robert Haas <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Robert Haas @ 2024-04-15 15:38 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; PostgreSQL Hackers <[email protected]>

On Mon, Apr 15, 2024 at 11:00 AM Alexander Lakhin <[email protected]> wrote:
> Initially I was confused by that message, because of:
> CREATE TABLE t (i int) PARTITION BY RANGE (i);
> CREATE FOREIGN TABLE ftp_0_1 PARTITION OF t
>    FOR VALUES FROM (0) TO (1)
>    SERVER loopback OPTIONS (table_name 'lt_0_1');
> CREATE FOREIGN TABLE ftp_1_2 PARTITION OF t
>    FOR VALUES FROM (1) TO (2)
>    SERVER loopback OPTIONS (table_name 'lt_1_2');
> ALTER TABLE t MERGE PARTITIONS (ftp_0_1, ftp_1_2) INTO ftp_0_2;
> ERROR:  "ftp_0_1" is not a table
> (Isn't a foreign table a table?)

I agree that this can be confusing, but a patch that is about adding
SPLIT and MERGE PARTITION operations cannot decide to also invent a
new error message phraseology and use it only in one place. We need to
maintain consistency across the whole code base.

-- 
Robert Haas
EDB: http://www.enterprisedb.com






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-15 15:26                             ` Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-04-15 15:26 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

> Please, find a my version of this fix attached.

Is it possible to make a small addition to the file v6-0001 ... .patch 
(see attachment)?

Most important:
1) Line 19:

+ mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);

(temporary table should use the same schema as the partition);

2) Lines 116-123:

+RESET search_path;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+
+SET search_path = pg_temp, public;

(Alexandr Lakhin's test for using of pg_temp schema explicitly).


The rest of the changes in v6_afterfix.diff are not very important and 
can be ignored.

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index c6ce7b94d9..bce5e39b64 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21130,6 +21130,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  *
  * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * Function locks created relation in AccessExclusiveLock mode and returns it.
  */
 static Relation
 createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
@@ -21500,8 +21501,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temparary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
 
 	newPartRel = createPartitionTable(rel,
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index b1d0b50b0b..0a4022f714 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -793,23 +793,58 @@ SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
 
 DROP TABLE t;
 --
--- Try creating a partition in the temporary schema.
+-- Try mixing permanent and temporary partitions.
 --
 SET search_path = public, pg_temp;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
 SET search_path = pg_temp, public;
 -- Can't merge persistent partitions into a temporary partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+RESET search_path;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
 DROP TABLE t;
-DROP TAble tp_0_2;
-ERROR:  table "tp_0_2" does not exist
+SET search_path = pg_temp, public;
 BEGIN;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
 SET search_path = public, pg_temp;
 -- Can't merge temporary partitions into a persistent partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 2d55e0f5a3..56adcf4bfc 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -484,25 +484,43 @@ SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
 DROP TABLE t;
 
 --
--- Try creating a partition in the temporary schema.
+-- Try mixing permanent and temporary partitions.
 --
 SET search_path = public, pg_temp;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
 SET search_path = pg_temp, public;
 
 -- Can't merge persistent partitions into a temporary partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+RESET search_path;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
 DROP TABLE t;
-DROP TAble tp_0_2;
+
+SET search_path = pg_temp, public;
 
 BEGIN;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
 SET search_path = public, pg_temp;
 
 -- Can't merge temporary partitions into a persistent partition


Attachments:

  [text/plain] v6_afterfix.diff (6.2K, ../../[email protected]/2-v6_afterfix.diff)
  download | inline diff:
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index c6ce7b94d9..bce5e39b64 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21130,6 +21130,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  *
  * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * Function locks created relation in AccessExclusiveLock mode and returns it.
  */
 static Relation
 createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
@@ -21500,8 +21501,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temparary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
 
 	newPartRel = createPartitionTable(rel,
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index b1d0b50b0b..0a4022f714 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -793,23 +793,58 @@ SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
 
 DROP TABLE t;
 --
--- Try creating a partition in the temporary schema.
+-- Try mixing permanent and temporary partitions.
 --
 SET search_path = public, pg_temp;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
 SET search_path = pg_temp, public;
 -- Can't merge persistent partitions into a temporary partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+RESET search_path;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
 DROP TABLE t;
-DROP TAble tp_0_2;
-ERROR:  table "tp_0_2" does not exist
+SET search_path = pg_temp, public;
 BEGIN;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
 SET search_path = public, pg_temp;
 -- Can't merge temporary partitions into a persistent partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 2d55e0f5a3..56adcf4bfc 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -484,25 +484,43 @@ SELECT indexname FROM pg_indexes WHERE tablename = 'tp_1_2';
 DROP TABLE t;
 
 --
--- Try creating a partition in the temporary schema.
+-- Try mixing permanent and temporary partitions.
 --
 SET search_path = public, pg_temp;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
 SET search_path = pg_temp, public;
 
 -- Can't merge persistent partitions into a temporary partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+RESET search_path;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
 DROP TABLE t;
-DROP TAble tp_0_2;
+
+SET search_path = pg_temp, public;
 
 BEGIN;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
 SET search_path = public, pg_temp;
 
 -- Can't merge temporary partitions into a persistent partition


^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-18 10:35                               ` Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 19:59                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-18 10:35 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi, Dmitry!

On Mon, Apr 15, 2024 at 6:26 PM Dmitry Koval <[email protected]> wrote:
>
> Hi!
>
> > Please, find a my version of this fix attached.
>
> Is it possible to make a small addition to the file v6-0001 ... .patch
> (see attachment)?
>
> Most important:
> 1) Line 19:
>
> + mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
>
> (temporary table should use the same schema as the partition);
>
> 2) Lines 116-123:
>
> +RESET search_path;
> +
> +-- Can't merge persistent partitions into a temporary partition
> +ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
> +
> +SET search_path = pg_temp, public;
>
> (Alexandr Lakhin's test for using of pg_temp schema explicitly).
>
>
> The rest of the changes in v6_afterfix.diff are not very important and
> can be ignored.

Thank you.  I've integrated your changes.

The revised patchset is attached.
1) I've split the fix for the CommandCounterIncrement() issue and the
fix for relation persistence issue into a separate patch.
2) I've validated that the lock on the new partition is held in
createPartitionTable() after ProcessUtility() as pointed out by
Robert.  So, no need to place the lock again.
3) Added fix for problematic error message as a separate patch [1].
4) Added rename "salemans" => "salesmen" for tests as a separate patch.

I think these fixes are reaching committable shape, but I'd like
someone to check it before I push.

Links.
1. https://postgr.es/m/20240408.152402.1485994009160660141.horikyota.ntt%40gmail.com

------
Regards,
Alexander Korotkov


Attachments:

  [application/octet-stream] v6-0002-Verify-persistence-of-new-partitions-during-MERGE.patch (16.8K, ../../CAPpHfdvShLh5txtQdh6=ZMCnzGZHv8W+RHAe8pY94rfzghWTAg@mail.gmail.com/2-v6-0002-Verify-persistence-of-new-partitions-during-MERGE.patch)
  download | inline diff:
From 57d38e20b28ade963bd33273c2fc2d8c032f549c Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:41:09 +0300
Subject: [PATCH v6 2/4] Verify persistence of new partitions during
 MERGE/SPLIT operations

The createPartitionTable() function is responsible for creating new partitions
for ALTER TABLE ... MERGE PARTITIONS, and ALTER TABLE ... SPLIT PARTITION
commands.  It emulates the behavious of CREATE TABLE ... (LIKE ...), but
lacks of check for the result relation persistence.  This commit adds
corresponsing check similarly to what we have for CREATE TABLE ...
PARTITION OF command.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/dbc8b96c-3cf0-d1ee-860d-0e491da20485%40gmail.com
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas
---
 src/backend/commands/tablecmds.c              | 67 +++++++++-----
 src/test/regress/expected/partition_merge.out | 89 +++++++++++++++++++
 src/test/regress/expected/partition_split.out | 29 ++++++
 src/test/regress/sql/partition_merge.sql      | 68 ++++++++++++++
 src/test/regress/sql/partition_split.sql      | 23 +++++
 5 files changed, 255 insertions(+), 21 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 87427ad7d2e..d894d5a73fd 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21133,16 +21133,25 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * createPartitionTable: create table for a new partition with given name
  * (newPartName) like table (modelRelName)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
-static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+static Relation
+createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
+	Relation	newRel;
+
+	/* If existing rel is temp, it must belong to this session */
+	if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
+		!rel->rd_islocaltemp)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create as partition of temporary relation of another session")));
 
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
@@ -21181,6 +21190,33 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 				   NULL,
 				   None_Receiver,
 				   NULL);
+
+	/*
+	 * Open the new partition with no lock, because we already have
+	 * AccessExclusiveLock placed there after creation.
+	 */
+	newRel = table_openrv(newPartName, NoLock);
+
+	/*
+	 * If the parent is permanent, so must be all of its partitions.  Note
+	 * that inheritance allows that case.
+	 */
+	if (rel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		newRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(rel))));
+
+	/* Permanent rels cannot inherit from temporary ones */
+	if (newRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a permanent relation as partition of temporary relation \"%s\"",
+						RelationGetRelationName(rel))));
+
+	return newRel;
 }
 
 /*
@@ -21279,11 +21315,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
-
-		/* Open the new partition and acquire exclusive lock on it. */
-		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
-
+		newPartRel = createPartitionTable(rel, sps->name, parentName, context);
 		newPartRels = lappend(newPartRels, newPartRel);
 	}
 
@@ -21475,21 +21507,14 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
 	}
-	createPartitionTable(mergePartName,
-						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									  RelationGetRelationName(rel), -1),
-						 context);
 
-	/*
-	 * Open the new partition and acquire exclusive lock on it.  This will
-	 * stop all the operations with partitioned table.  This might seem
-	 * excessive, but this is the way we make sure nobody is planning queries
-	 * involving merging partitions.
-	 */
-	newPartRel = table_openrv(mergePartName, AccessExclusiveLock);
+	newPartRel = createPartitionTable(rel,
+									  mergePartName,
+									  makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
+												   RelationGetRelationName(rel), -1),
+									  context);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 3593720731c..748c8c7a89b 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -746,6 +746,36 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
@@ -764,4 +794,63 @@ WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
 
 DROP TABLE t;
 --
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+RESET search_path;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+SET search_path = pg_temp, public;
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = public, pg_temp;
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+ROLLBACK;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 419d169f036..660361cd20e 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 940e6b5a9e5..6faac959a7c 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -444,6 +444,28 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
@@ -462,5 +484,51 @@ WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
 
 DROP TABLE t;
 
+--
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+RESET search_path;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+DROP TABLE t;
+
+SET search_path = pg_temp, public;
+
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = public, pg_temp;
+
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index b63532ee562..576f9f0f63c 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v6-0004-Grammar-fix-for-tests-of-partition-MERGE-SPLIT-op.patch (50.9K, ../../CAPpHfdvShLh5txtQdh6=ZMCnzGZHv8W+RHAe8pY94rfzghWTAg@mail.gmail.com/3-v6-0004-Grammar-fix-for-tests-of-partition-MERGE-SPLIT-op.patch)
  download | inline diff:
From 5032cdf6dd9905fe16b15890e822bef88c2f6142 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 13:27:11 +0300
Subject: [PATCH v6 4/4] Grammar fix for tests of partition MERGE/SPLIT
 operations

Replace "salesmans" with "salesmen".

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/fdaa003e-919c-cbc9-4f0c-e4546e96bd65%40gmail.com
---
 src/test/regress/expected/partition_merge.out |  96 +++----
 src/test/regress/expected/partition_split.out | 238 +++++++++---------
 src/test/regress/sql/partition_merge.sql      |  84 +++----
 src/test/regress/sql/partition_split.sql      | 186 +++++++-------
 4 files changed, 302 insertions(+), 302 deletions(-)

diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 748c8c7a89b..b5744ed4986 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -349,50 +349,50 @@ DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen10_20 PARTITION OF salesmen FOR VALUES FROM (10) TO (20);
+CREATE TABLE salesmen20_30 PARTITION OF salesmen FOR VALUES FROM (20) TO (30);
+CREATE TABLE salesmen30_40 PARTITION OF salesmen FOR VALUES FROM (30) TO (40);
+INSERT INTO salesmen VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salesmen_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
+CREATE TRIGGER salesmen_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salesmen VALUES (10, 'May');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+INSERT INTO salesmen10_20 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salesmen MERGE PARTITIONS (salesmen10_20, salesmen20_30, salesmen30_40) INTO salesmen10_40;
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salesmen VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
+INSERT INTO salesmen10_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salesmen01_10;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
+SELECT * FROM salesmen10_40;
  salesman_id | salesman_name 
 -------------+---------------
           10 | May
@@ -401,31 +401,31 @@ SELECT * FROM salesmans10_40;
           30 | Ford
 (4 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salesmen;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
-select * from salesmans;
+CREATE TABLE salesmen10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
+CREATE TABLE salesmen20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
+CREATE TABLE salesmen30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
+INSERT INTO salesmen10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salesmen20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salesmen30_40 VALUES (31, now(), 'Popov');
+ALTER TABLE salesmen10_20 DROP COLUMN d1;
+ALTER TABLE salesmen20_30 DROP COLUMN d2;
+ALTER TABLE salesmen30_40 DROP COLUMN d3;
+ALTER TABLE salesmen ATTACH PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salesmen ATTACH PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salesmen ATTACH PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40);
+INSERT INTO salesmen VALUES (1, 'Poirot');
+INSERT INTO salesmen VALUES (10, 'May');
+INSERT INTO salesmen VALUES (30, 'Ford');
+ALTER TABLE salesmen MERGE PARTITIONS (salesmen10_20, salesmen20_30, salesmen30_40) INTO salesmen10_40;
+select * from salesmen;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
@@ -436,13 +436,13 @@ select * from salesmans;
           30 | Ford
 (6 rows)
 
-select * from salesmans01_10;
+select * from salesmen01_10;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-select * from salesmans10_40;
+select * from salesmen10_40;
  salesman_id | salesman_name 
 -------------+---------------
           19 | Ivanov
@@ -452,7 +452,7 @@ select * from salesmans10_40;
           30 | Ford
 (5 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salesmen;
 --
 -- Test: merge sub-partitions
 --
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 660361cd20e..217e9ba54bb 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -84,8 +84,8 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
-LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
-                                                             ^
+LINE 4:    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO...
+                                                    ^
 -- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
@@ -574,20 +574,20 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
+INSERT INTO salesmen VALUES (1,  'Poirot');
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesman_id INT REFERENCES salesmen(salesman_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb_mar_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                    pg_get_constraintdef                    |            conname             | conkey 
+------------------------------------------------------------+--------------------------------+--------
+ CHECK ((sales_amount > 1))                                 | sales_range_sales_amount_check | {2}
+ FOREIGN KEY (salesman_id) REFERENCES salesmen(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
@@ -596,24 +596,24 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 -- We should see the same CONSTRAINTs as on sales_feb_mar_apr2022 partition
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                    pg_get_constraintdef                    |            conname             | conkey 
+------------------------------------------------------------+--------------------------------+--------
+ CHECK ((sales_amount > 1))                                 | sales_range_sales_amount_check | {2}
+ FOREIGN KEY (salesman_id) REFERENCES salesmen(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                    pg_get_constraintdef                    |            conname             | conkey 
+------------------------------------------------------------+--------------------------------+--------
+ CHECK ((sales_amount > 1))                                 | sales_range_sales_amount_check | {2}
+ FOREIGN KEY (salesman_id) REFERENCES salesmen(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                    pg_get_constraintdef                    |            conname             | conkey 
+------------------------------------------------------------+--------------------------------+--------
+ CHECK ((sales_amount > 1))                                 | sales_range_sales_amount_check | {2}
+ FOREIGN KEY (salesman_id) REFERENCES salesmen(salesman_id) | sales_range_salesman_id_fkey   | {1}
 (2 rows)
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
@@ -623,23 +623,23 @@ DETAIL:  Failing row contains (1, 0, 03-11-2022).
 -- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
 ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(-1) is not present in table "salesmans".
+DETAIL:  Key (salesman_id)=(-1) is not present in table "salesmen".
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE sales (salesman_id INT REFERENCES salesmen(salesman_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen10_40 PARTITION OF salesmen FOR VALUES FROM (10) TO (40);
+INSERT INTO salesmen VALUES (1,  'Poirot');
+INSERT INTO salesmen VALUES (10, 'May');
+INSERT INTO salesmen VALUES (19, 'Ivanov');
+INSERT INTO salesmen VALUES (20, 'Smirnoff');
+INSERT INTO salesmen VALUES (30, 'Ford');
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
 INSERT INTO sales VALUES (10, 150, '2022-03-01');
@@ -648,13 +648,13 @@ INSERT INTO sales VALUES (19, 200, '2022-03-04');
 INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
-SELECT * FROM salesmans01_10;
+SELECT * FROM salesmen01_10;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
+SELECT * FROM salesmen10_40;
  salesman_id | salesman_name 
 -------------+---------------
           10 | May
@@ -663,30 +663,30 @@ SELECT * FROM salesmans10_40;
           30 | Ford
 (4 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-SELECT * FROM salesmans01_10;
+ALTER TABLE salesmen SPLIT PARTITION salesmen10_40 INTO
+  (PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40));
+SELECT * FROM salesmen01_10;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
+SELECT * FROM salesmen10_20;
  salesman_id | salesman_name 
 -------------+---------------
           10 | May
           19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
+SELECT * FROM salesmen20_30;
  salesman_id | salesman_name 
 -------------+---------------
           20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
+SELECT * FROM salesmen30_40;
  salesman_id | salesman_name 
 -------------+---------------
           30 | Ford
@@ -695,98 +695,98 @@ SELECT * FROM salesmans30_40;
 -- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
 ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(40) is not present in table "salesmans".
+DETAIL:  Key (salesman_id)=(40) is not present in table "salesmen".
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen10_40 PARTITION OF salesmen FOR VALUES FROM (10) TO (40);
+INSERT INTO salesmen VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salesmen_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
+CREATE TRIGGER salesmen_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salesmen VALUES (10, 'May');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+INSERT INTO salesmen10_40 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salesmen SPLIT PARTITION salesmen10_40 INTO
+  (PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40));
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salesmen VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
+INSERT INTO salesmen30_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salesmen) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salesmen01_10;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
+SELECT * FROM salesmen10_20;
  salesman_id | salesman_name 
 -------------+---------------
           10 | May
           19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
+SELECT * FROM salesmen20_30;
  salesman_id | salesman_name 
 -------------+---------------
           20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
+SELECT * FROM salesmen30_40;
  salesman_id | salesman_name 
 -------------+---------------
           30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salesmen(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen1_2 PARTITION OF salesmen FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
+CREATE TABLE salesmen2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
+ALTER TABLE salesmen ATTACH PARTITION salesmen2_5 FOR VALUES FROM (2) TO (5);
+INSERT INTO salesmen (salesman_name) VALUES ('Poirot');
+INSERT INTO salesmen (salesman_name) VALUES ('Ivanov');
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
  salesman_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen1_2'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
@@ -794,51 +794,51 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
 (2 rows)
 
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen2_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
  salesman_name |             | 
 (2 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
-SELECT * FROM salesmans1_2;
+ALTER TABLE salesmen SPLIT PARTITION salesmen2_5 INTO
+  (PARTITION salesmen2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salesmen3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salesmen4_5 FOR VALUES FROM (4) TO (5));
+INSERT INTO salesmen (salesman_name) VALUES ('May');
+INSERT INTO salesmen (salesman_name) VALUES ('Ford');
+SELECT * FROM salesmen1_2;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans2_3;
+SELECT * FROM salesmen2_3;
  salesman_id | salesman_name 
 -------------+---------------
            2 | Ivanov
 (1 row)
 
-SELECT * FROM salesmans3_4;
+SELECT * FROM salesmen3_4;
  salesman_id | salesman_name 
 -------------+---------------
            3 | May
 (1 row)
 
-SELECT * FROM salesmans4_5;
+SELECT * FROM salesmen4_5;
  salesman_id | salesman_name 
 -------------+---------------
            4 | Ford
 (1 row)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
  salesman_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen1_2'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
@@ -846,74 +846,74 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND
 (2 rows)
 
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen2_3'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
  salesman_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen3_4'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
  salesman_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen4_5'::regclass::oid;
     attname    | attidentity | attgenerated 
 ---------------+-------------+--------------
  salesman_id   | a           | 
  salesman_name |             | 
 (2 rows)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-select * from salesmans01_10;
+CREATE TABLE salesmen10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
+INSERT INTO salesmen10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salesmen10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+ALTER TABLE salesmen10_40 DROP COLUMN d1;
+ALTER TABLE salesmen10_40 DROP COLUMN d2;
+ALTER TABLE salesmen10_40 DROP COLUMN d3;
+ALTER TABLE salesmen ATTACH PARTITION salesmen10_40 FOR VALUES FROM (10) TO (40);
+INSERT INTO salesmen VALUES (1, 'Poirot');
+INSERT INTO salesmen VALUES (10, 'May');
+INSERT INTO salesmen VALUES (30, 'Ford');
+ALTER TABLE salesmen SPLIT PARTITION salesmen10_40 INTO
+  (PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40));
+select * from salesmen01_10;
  salesman_id | salesman_name 
 -------------+---------------
            1 | Poirot
 (1 row)
 
-select * from salesmans10_20;
+select * from salesmen10_20;
  salesman_id | salesman_name 
 -------------+---------------
           19 | Ivanov
           10 | May
 (2 rows)
 
-select * from salesmans20_30;
+select * from salesmen20_30;
  salesman_id | salesman_name 
 -------------+---------------
           20 | Smirnoff
 (1 row)
 
-select * from salesmans30_40;
+select * from salesmen30_40;
  salesman_id | salesman_name 
 -------------+---------------
           30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 --
 -- Test: split sub-partition
 --
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 6faac959a7c..df737e214ee 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -193,14 +193,14 @@ DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen10_20 PARTITION OF salesmen FOR VALUES FROM (10) TO (20);
+CREATE TABLE salesmen20_30 PARTITION OF salesmen FOR VALUES FROM (20) TO (30);
+CREATE TABLE salesmen30_40 PARTITION OF salesmen FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salesmen VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -209,70 +209,70 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salesmen_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salesmen_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salesmen VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
+INSERT INTO salesmen10_20 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salesmen MERGE PARTITIONS (salesmen10_20, salesmen20_30, salesmen30_40) INTO salesmen10_40;
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salesmen VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
+INSERT INTO salesmen10_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salesmen01_10;
+SELECT * FROM salesmen10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salesmen;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salesmen10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
+CREATE TABLE salesmen20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
+CREATE TABLE salesmen30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
 
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
+INSERT INTO salesmen10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salesmen20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salesmen30_40 VALUES (31, now(), 'Popov');
 
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
+ALTER TABLE salesmen10_20 DROP COLUMN d1;
+ALTER TABLE salesmen20_30 DROP COLUMN d2;
+ALTER TABLE salesmen30_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
+ALTER TABLE salesmen ATTACH PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salesmen ATTACH PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salesmen ATTACH PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salesmen VALUES (1, 'Poirot');
+INSERT INTO salesmen VALUES (10, 'May');
+INSERT INTO salesmen VALUES (30, 'Ford');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salesmen MERGE PARTITIONS (salesmen10_20, salesmen20_30, salesmen30_40) INTO salesmen10_40;
 
-select * from salesmans;
-select * from salesmans01_10;
-select * from salesmans10_40;
+select * from salesmen;
+select * from salesmen01_10;
+select * from salesmen10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salesmen;
 
 --
 -- Test: merge sub-partitions
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 576f9f0f63c..12def95d1d5 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -337,11 +337,11 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
+INSERT INTO salesmen VALUES (1,  'Poirot');
 
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesman_id INT REFERENCES salesmen(salesman_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 
@@ -369,22 +369,22 @@ INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE sales (salesman_id INT REFERENCES salesmen(salesman_id), sales_amount INT, sales_date DATE);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen10_40 PARTITION OF salesmen FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salesmen VALUES (1,  'Poirot');
+INSERT INTO salesmen VALUES (10, 'May');
+INSERT INTO salesmen VALUES (19, 'Ivanov');
+INSERT INTO salesmen VALUES (20, 'Smirnoff');
+INSERT INTO salesmen VALUES (30, 'Ford');
 
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
@@ -395,18 +395,18 @@ INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salesmen01_10;
+SELECT * FROM salesmen10_40;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salesmen SPLIT PARTITION salesmen10_40 INTO
+  (PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40));
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salesmen01_10;
+SELECT * FROM salesmen10_20;
+SELECT * FROM salesmen20_30;
+SELECT * FROM salesmen30_40;
 
 -- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
@@ -414,17 +414,17 @@ INSERT INTO sales VALUES (40, 50,  '2022-03-04');
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen10_40 PARTITION OF salesmen FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salesmen VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -433,115 +433,115 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salesmen_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salesmen_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salesmen
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salesmen');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salesmen VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
+INSERT INTO salesmen10_40 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salesmen SPLIT PARTITION salesmen10_40 INTO
+  (PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40));
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salesmen VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
+INSERT INTO salesmen30_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salesmen01_10;
+SELECT * FROM salesmen10_20;
+SELECT * FROM salesmen20_30;
+SELECT * FROM salesmen30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salesmen1_2 PARTITION OF salesmen FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
+CREATE TABLE salesmen2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
+ALTER TABLE salesmen ATTACH PARTITION salesmen2_5 FOR VALUES FROM (2) TO (5);
 
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
+INSERT INTO salesmen (salesman_name) VALUES ('Poirot');
+INSERT INTO salesmen (salesman_name) VALUES ('Ivanov');
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen1_2'::regclass::oid;
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen2_5'::regclass::oid;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
+ALTER TABLE salesmen SPLIT PARTITION salesmen2_5 INTO
+  (PARTITION salesmen2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salesmen3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salesmen4_5 FOR VALUES FROM (4) TO (5));
 
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
+INSERT INTO salesmen (salesman_name) VALUES ('May');
+INSERT INTO salesmen (salesman_name) VALUES ('Ford');
 
-SELECT * FROM salesmans1_2;
-SELECT * FROM salesmans2_3;
-SELECT * FROM salesmans3_4;
-SELECT * FROM salesmans4_5;
+SELECT * FROM salesmen1_2;
+SELECT * FROM salesmen2_3;
+SELECT * FROM salesmen3_4;
+SELECT * FROM salesmen4_5;
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen1_2'::regclass::oid;
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen2_3'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen3_4'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmen4_5'::regclass::oid;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salesmen(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salesmen01_10 PARTITION OF salesmen FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salesmen10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
 
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+INSERT INTO salesmen10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salesmen10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
 
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
+ALTER TABLE salesmen10_40 DROP COLUMN d1;
+ALTER TABLE salesmen10_40 DROP COLUMN d2;
+ALTER TABLE salesmen10_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
+ALTER TABLE salesmen ATTACH PARTITION salesmen10_40 FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salesmen VALUES (1, 'Poirot');
+INSERT INTO salesmen VALUES (10, 'May');
+INSERT INTO salesmen VALUES (30, 'Ford');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salesmen SPLIT PARTITION salesmen10_40 INTO
+  (PARTITION salesmen10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salesmen20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salesmen30_40 FOR VALUES FROM (30) TO (40));
 
-select * from salesmans01_10;
-select * from salesmans10_20;
-select * from salesmans20_30;
-select * from salesmans30_40;
+select * from salesmen01_10;
+select * from salesmen10_20;
+select * from salesmen20_30;
+select * from salesmen30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salesmen CASCADE;
 
 --
 -- Test: split sub-partition
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v6-0003-Fix-error-message-in-check_partition_bounds_for_s.patch (3.9K, ../../CAPpHfdvShLh5txtQdh6=ZMCnzGZHv8W+RHAe8pY94rfzghWTAg@mail.gmail.com/4-v6-0003-Fix-error-message-in-check_partition_bounds_for_s.patch)
  download | inline diff:
From 2a2742ca3d99e6ce3471e43e9062144e12bd8ecc Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:56:51 +0300
Subject: [PATCH v6 3/4] Fix error message in
 check_partition_bounds_for_split_range()

Currently, the error message is produced by a system of complex substitutions
making it quite untranslatable and hard to read.  This commit splits this into
4 plain error messages suitable for translation.

Reported-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20240408.152402.1485994009160660141.horikyota.ntt%40gmail.com
---
 src/backend/partitioning/partbounds.c | 60 +++++++++++++++++----------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 0dbacf39c05..bfb965fb2c6 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5211,7 +5211,7 @@ check_partition_bounds_for_split_range(Relation parent,
 	if (first || last)
 	{
 		PartitionBoundSpec *split_spec = get_partition_bound_spec(splitPartOid, splitPartName);
-		bool		overlap = false;
+		PartitionRangeDatum *datum;
 
 		if (first)
 		{
@@ -5224,13 +5224,30 @@ check_partition_bounds_for_split_range(Relation parent,
 										  key->partcollation,
 										  lower->datums, lower->kind,
 										  true, split_lower);
+			datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) - 1) : NULL;
 
 			/*
 			 * Lower bound of "spec" should be equal (or greater than or equal
 			 * in case defaultPart=true) to lower bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval < 0))
-				overlap = true;
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is not equal to lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
+			else
+			{
+				if (cmpval < 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is less than lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
 		}
 		else
 		{
@@ -5243,29 +5260,30 @@ check_partition_bounds_for_split_range(Relation parent,
 										  key->partcollation,
 										  upper->datums, upper->kind,
 										  false, split_upper);
+			datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) - 1) : NULL;
 
 			/*
 			 * Upper bound of of "spec" should be equal (or less than or equal
 			 * in case defaultPart=true) to upper bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval > 0))
-				overlap = true;
-		}
-
-		if (overlap)
-		{
-			PartitionRangeDatum *datum;
-
-			datum = list_nth(first ? spec->lowerdatums : spec->upperdatums, abs(cmpval) - 1);
-
-			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-					 errmsg("%s bound of partition \"%s\" is %s %s bound of split partition",
-							first ? "lower" : "upper",
-							relname,
-							defaultPart ? (first ? "less than" : "greater than") : "not equal to",
-							first ? "lower" : "upper"),
-					 parser_errposition(pstate, datum->location)));
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is not equal to upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
+			else
+			{
+				if (cmpval > 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is greater than upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
 		}
 	}
 }
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v6-0001-Add-missing-CommandCounterIncrement-to-ATExecMerg.patch (4.2K, ../../CAPpHfdvShLh5txtQdh6=ZMCnzGZHv8W+RHAe8pY94rfzghWTAg@mail.gmail.com/5-v6-0001-Add-missing-CommandCounterIncrement-to-ATExecMerg.patch)
  download | inline diff:
From 31a493af6a3a7788adea207ede7a63c9192a45a6 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:27:39 +0300
Subject: [PATCH v6 1/4] Add missing CommandCounterIncrement() to
 ATExecMergePartitions()

During the MERGE PARTITIONS operation, increment the command counter before
attaching the new partition to the parent.  Otherwise, the new catalog tuple
wouldn't be visible.  In turn, that could lead to inappropriate index names.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/edfbd846-dcc1-42d1-ac26-715691b687d3%40postgrespro.ru
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas
---
 src/backend/commands/tablecmds.c              | 20 +++++++++++++------
 src/test/regress/expected/partition_merge.out | 18 +++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 18 +++++++++++++++++
 3 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 027d68e5d2a..87427ad7d2e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21494,12 +21494,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21526,10 +21520,24 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		 * visible for rename.
 		 */
 		CommandCounterIncrement();
+
 		/* Rename partition. */
 		RenameRelationInternal(RelationGetRelid(newPartRel),
 							   cmd->name->relname, false, false);
+
+		/*
+		 * Bump the command counter to make the tuple of renamed partition
+		 * visible for attach partition operation.
+		 */
+		CommandCounterIncrement();
 	}
+
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 373d32948ca..3593720731c 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -746,4 +746,22 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes
+WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
+  indexname   
+--------------
+ tp_1_2_i_idx
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 6a0b35b1799..940e6b5a9e5 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -444,5 +444,23 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname value should be 'tp_1_2_i_idx'.
+SELECT indexname FROM pg_indexes
+WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
-- 
2.39.3 (Apple Git-145)



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-18 16:00                                 ` Alexander Lakhin <[email protected]>
  2024-04-18 17:03                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dagfinn Ilmari Mannsåker <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  1 sibling, 2 replies; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-18 16:00 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; +Cc: Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi Alexander,

18.04.2024 13:35, Alexander Korotkov wrote:
>
> The revised patchset is attached.
> 1) I've split the fix for the CommandCounterIncrement() issue and the
> fix for relation persistence issue into a separate patch.
> 2) I've validated that the lock on the new partition is held in
> createPartitionTable() after ProcessUtility() as pointed out by
> Robert.  So, no need to place the lock again.
> 3) Added fix for problematic error message as a separate patch [1].
> 4) Added rename "salemans" => "salesmen" for tests as a separate patch.
>
> I think these fixes are reaching committable shape, but I'd like
> someone to check it before I push.

I think the feature implementation should also provide tab completion for
SPLIT/MERGE.
(ALTER TABLE t S<Tab>
fills in only SET now.)

Also, the following MERGE operation:
CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
CREATE TABLE tp_0 PARTITION OF t FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1 PARTITION OF t FOR VALUES FROM (1) TO (2);
ALTER TABLE t MERGE PARTITIONS (tp_0, tp_1) INTO tp_0;

leaves a strange constraint:
\d+ t*
                                           Table "public.tp_0"
...
Not-null constraints:
     "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-18 17:03                                   ` Dagfinn Ilmari Mannsåker <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: Dagfinn Ilmari Mannsåker @ 2024-04-18 17:03 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Alexander Lakhin <[email protected]> writes:

> Hi Alexander,
>
> 18.04.2024 13:35, Alexander Korotkov wrote:
>>
>> The revised patchset is attached.
>> 1) I've split the fix for the CommandCounterIncrement() issue and the
>> fix for relation persistence issue into a separate patch.
>> 2) I've validated that the lock on the new partition is held in
>> createPartitionTable() after ProcessUtility() as pointed out by
>> Robert.  So, no need to place the lock again.
>> 3) Added fix for problematic error message as a separate patch [1].
>> 4) Added rename "salemans" => "salesmen" for tests as a separate patch.
>>
>> I think these fixes are reaching committable shape, but I'd like
>> someone to check it before I push.
>
> I think the feature implementation should also provide tab completion for
> SPLIT/MERGE.
> (ALTER TABLE t S<Tab>
> fills in only SET now.)

Here's a patch for that.  One thing I noticed while testing it was that
the tab completeion for partitions (Query_for_partition_of_table) shows
all the schemas in the DB, even ones that don't contain any partitions
of the table being altered.

- ilmari



Attachments:

  [text/x-diff] 0001-Add-tab-completion-for-ALTER-TABLE-SPLIT-MERGE-PARTI.patch (2.5K, ../../[email protected]/2-0001-Add-tab-completion-for-ALTER-TABLE-SPLIT-MERGE-PARTI.patch)
  download | inline diff:
From 26db03b7a7675aa7dbff1f18ee084296caa1e181 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <[email protected]>
Date: Thu, 18 Apr 2024 17:47:22 +0100
Subject: [PATCH] =?UTF-8?q?Add=20tab=20completion=20for=20ALTER=20TABLE=20?=
 =?UTF-8?q?=E2=80=A6=20SPLIT|MERGE=20PARTITION(S)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/bin/psql/tab-complete.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 6fee3160f0..97cd5d9f62 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2353,6 +2353,7 @@ psql_completion(const char *text, int start, int end)
 					  "OWNER TO", "SET", "VALIDATE CONSTRAINT",
 					  "REPLICA IDENTITY", "ATTACH PARTITION",
 					  "DETACH PARTITION", "FORCE ROW LEVEL SECURITY",
+					  "SPLIT PARTITION", "MERGE PARTITIONS (",
 					  "OF", "NOT OF");
 	/* ALTER TABLE xxx ADD */
 	else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
@@ -2609,10 +2610,10 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH("FROM (", "IN (", "WITH (");
 
 	/*
-	 * If we have ALTER TABLE <foo> DETACH PARTITION, provide a list of
+	 * If we have ALTER TABLE <foo> DETACH|SPLIT PARTITION, provide a list of
 	 * partitions of <foo>.
 	 */
-	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION"))
+	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH|SPLIT", "PARTITION"))
 	{
 		set_completion_reference(prev3_wd);
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
@@ -2620,6 +2621,19 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION", MatchAny))
 		COMPLETE_WITH("CONCURRENTLY", "FINALIZE");
 
+	/* ALTER TABLE <name> SPLIT PARTITION <name> */
+	else if (Matches("ALTER", "TABLE", MatchAny, "SPLIT", "PARTITION", MatchAny))
+		COMPLETE_WITH("INTO ( PARTITION");
+
+	/* ALTER TABLE <name> MERGE PARTITIONS ( */
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "("))
+	{
+		set_completion_reference(prev4_wd);
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
+	}
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "(*)"))
+		COMPLETE_WITH("INTO");
+
 	/* ALTER TABLE <name> OF */
 	else if (Matches("ALTER", "TABLE", MatchAny, "OF"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
-- 
2.39.2



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-18 23:26                                   ` Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-29 18:00                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  1 sibling, 2 replies; 58+ messages in thread

From: Dmitry Koval @ 2024-04-18 23:26 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

18.04.2024 19:00, Alexander Lakhin wrote:
> leaves a strange constraint:
> \d+ t*
>                                            Table "public.tp_0"
> ...
> Not-null constraints:
>      "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"

Thanks!
Attached fix (with test) for this case.
The patch should be applied after patches
v6-0001- ... .patch ... v6-0004- ... .patch

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
From 58e4b7fb1d3b15cdf1c742c28690392dda34915d Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Fri, 19 Apr 2024 01:57:49 +0300
Subject: [PATCH v6] Fix

---
 src/backend/commands/tablecmds.c              | 49 ++++++-------------
 src/test/regress/expected/partition_merge.out | 13 ++++-
 src/test/regress/sql/partition_merge.sql      |  8 ++-
 3 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 72874295cb..8985747180 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21508,9 +21508,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	ListCell   *listptr;
 	List	   *mergingPartitionsList = NIL;
 	Oid			defaultPartOid;
-	char		tmpRelName[NAMEDATALEN];
-	RangeVar   *mergePartName = cmd->name;
-	bool		isSameName = false;
 
 	/*
 	 * Lock all merged partitions, check them and create list with partitions
@@ -21532,8 +21529,22 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		 * function transformPartitionCmdForMerge().
 		 */
 		if (equal(name, cmd->name))
+		{
 			/* One new partition can have the same name as merged partition. */
-			isSameName = true;
+			char		tmpRelName[NAMEDATALEN];
+
+			/* Generate temporary name. */
+			sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
+
+			/* Rename partition. */
+			RenameRelationInternal(RelationGetRelid(mergingPartition),
+								   tmpRelName, false, false);
+			/*
+			 * We must bump the command counter to make the new partition tuple
+			 * visible for rename.
+			 */
+			CommandCounterIncrement();
+		}
 
 		/* Store a next merging partition into the list. */
 		mergingPartitionsList = lappend(mergingPartitionsList,
@@ -21553,16 +21564,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	/* Create table for new partition, use partitioned table as model. */
-	if (isSameName)
-	{
-		/* Create partition table with generated temporary name. */
-		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
-	}
-
 	newPartRel = createPartitionTable(rel,
-									  mergePartName,
+									  cmd->name,
 									  makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 												   RelationGetRelationName(rel), -1),
 									  context);
@@ -21588,26 +21591,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 	list_free(mergingPartitionsList);
 
-	/* Rename new partition if it is needed. */
-	if (isSameName)
-	{
-		/*
-		 * We must bump the command counter to make the new partition tuple
-		 * visible for rename.
-		 */
-		CommandCounterIncrement();
-
-		/* Rename partition. */
-		RenameRelationInternal(RelationGetRelid(newPartRel),
-							   cmd->name->relname, false, false);
-
-		/*
-		 * Bump the command counter to make the tuple of renamed partition
-		 * visible for attach partition operation.
-		 */
-		CommandCounterIncrement();
-	}
-
 	/*
 	 * Attach a new partition to the partitioned table. wqueue = NULL:
 	 * verification for each cloned constraint is not needed.
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index b5744ed498..2499a314fb 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -779,17 +779,26 @@ DROP TABLE t;
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
-CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 CREATE INDEX tidx ON t(i);
 ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
--- Indexname value should be 'tp_1_2_i_idx'.
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
 SELECT indexname FROM pg_indexes
 WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
   indexname   
 --------------
+ tp_1_2_pkey
  tp_1_2_i_idx
+(2 rows)
+
+-- Conname value should be 'tp_1_2_i_not_null'.
+SELECT conname FROM pg_constraint
+WHERE conrelid='tp_1_2'::regclass AND contype='n';
+      conname      
+-------------------
+ tp_1_2_i_not_null
 (1 row)
 
 DROP TABLE t;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index df737e214e..6614512f69 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -470,7 +470,7 @@ DROP TABLE t;
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
-CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
 
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
@@ -478,10 +478,14 @@ CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 CREATE INDEX tidx ON t(i);
 ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
 
--- Indexname value should be 'tp_1_2_i_idx'.
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
 SELECT indexname FROM pg_indexes
 WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
 
+-- Conname value should be 'tp_1_2_i_not_null'.
+SELECT conname FROM pg_constraint
+WHERE conrelid='tp_1_2'::regclass AND contype='n';
+
 DROP TABLE t;
 
 --
-- 
2.40.1.windows.1



Attachments:

  [text/plain] v6-0005-Fix.patch (5.6K, ../../[email protected]/2-v6-0005-Fix.patch)
  download | inline diff:
From 58e4b7fb1d3b15cdf1c742c28690392dda34915d Mon Sep 17 00:00:00 2001
From: Koval Dmitry <[email protected]>
Date: Fri, 19 Apr 2024 01:57:49 +0300
Subject: [PATCH v6] Fix

---
 src/backend/commands/tablecmds.c              | 49 ++++++-------------
 src/test/regress/expected/partition_merge.out | 13 ++++-
 src/test/regress/sql/partition_merge.sql      |  8 ++-
 3 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 72874295cb..8985747180 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21508,9 +21508,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	ListCell   *listptr;
 	List	   *mergingPartitionsList = NIL;
 	Oid			defaultPartOid;
-	char		tmpRelName[NAMEDATALEN];
-	RangeVar   *mergePartName = cmd->name;
-	bool		isSameName = false;
 
 	/*
 	 * Lock all merged partitions, check them and create list with partitions
@@ -21532,8 +21529,22 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		 * function transformPartitionCmdForMerge().
 		 */
 		if (equal(name, cmd->name))
+		{
 			/* One new partition can have the same name as merged partition. */
-			isSameName = true;
+			char		tmpRelName[NAMEDATALEN];
+
+			/* Generate temporary name. */
+			sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
+
+			/* Rename partition. */
+			RenameRelationInternal(RelationGetRelid(mergingPartition),
+								   tmpRelName, false, false);
+			/*
+			 * We must bump the command counter to make the new partition tuple
+			 * visible for rename.
+			 */
+			CommandCounterIncrement();
+		}
 
 		/* Store a next merging partition into the list. */
 		mergingPartitionsList = lappend(mergingPartitionsList,
@@ -21553,16 +21564,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	/* Create table for new partition, use partitioned table as model. */
-	if (isSameName)
-	{
-		/* Create partition table with generated temporary name. */
-		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(cmd->name->schemaname, tmpRelName, -1);
-	}
-
 	newPartRel = createPartitionTable(rel,
-									  mergePartName,
+									  cmd->name,
 									  makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 												   RelationGetRelationName(rel), -1),
 									  context);
@@ -21588,26 +21591,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 	list_free(mergingPartitionsList);
 
-	/* Rename new partition if it is needed. */
-	if (isSameName)
-	{
-		/*
-		 * We must bump the command counter to make the new partition tuple
-		 * visible for rename.
-		 */
-		CommandCounterIncrement();
-
-		/* Rename partition. */
-		RenameRelationInternal(RelationGetRelid(newPartRel),
-							   cmd->name->relname, false, false);
-
-		/*
-		 * Bump the command counter to make the tuple of renamed partition
-		 * visible for attach partition operation.
-		 */
-		CommandCounterIncrement();
-	}
-
 	/*
 	 * Attach a new partition to the partitioned table. wqueue = NULL:
 	 * verification for each cloned constraint is not needed.
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index b5744ed498..2499a314fb 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -779,17 +779,26 @@ DROP TABLE t;
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
-CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 CREATE INDEX tidx ON t(i);
 ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
--- Indexname value should be 'tp_1_2_i_idx'.
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
 SELECT indexname FROM pg_indexes
 WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
   indexname   
 --------------
+ tp_1_2_pkey
  tp_1_2_i_idx
+(2 rows)
+
+-- Conname value should be 'tp_1_2_i_not_null'.
+SELECT conname FROM pg_constraint
+WHERE conrelid='tp_1_2'::regclass AND contype='n';
+      conname      
+-------------------
+ tp_1_2_i_not_null
 (1 row)
 
 DROP TABLE t;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index df737e214e..6614512f69 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -470,7 +470,7 @@ DROP TABLE t;
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
-CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
 
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
@@ -478,10 +478,14 @@ CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
 CREATE INDEX tidx ON t(i);
 ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
 
--- Indexname value should be 'tp_1_2_i_idx'.
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
 SELECT indexname FROM pg_indexes
 WHERE tablename = 'tp_1_2' AND schemaname = 'partitions_merge_schema';
 
+-- Conname value should be 'tp_1_2_i_not_null'.
+SELECT conname FROM pg_constraint
+WHERE conrelid='tp_1_2'::regclass AND contype='n';
+
 DROP TABLE t;
 
 --
-- 
2.40.1.windows.1



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-19 13:29                                     ` Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-19 13:29 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

On Fri, Apr 19, 2024 at 2:26 AM Dmitry Koval <[email protected]> wrote:
>
> Hi!
>
> 18.04.2024 19:00, Alexander Lakhin wrote:
> > leaves a strange constraint:
> > \d+ t*
> >                                            Table "public.tp_0"
> > ...
> > Not-null constraints:
> >      "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"
>
> Thanks!
> Attached fix (with test) for this case.
> The patch should be applied after patches
> v6-0001- ... .patch ... v6-0004- ... .patch

I've incorporated this fix with 0001 patch.

Also added to the patchset
005 – tab completion by Dagfinn [1]
006 – draft fix for table AM issue spotted by Alexander Lakhin [2]
007 – doc review by Justin [3]

I'm continuing work on this.

Links
1. https://www.postgresql.org/message-id/87plumiox2.fsf%40wibble.ilmari.org
2. https://www.postgresql.org/message-id/84ada05b-be5c-473e-6d1c-ebe5dd21b190%40gmail.com
3. https://www.postgresql.org/message-id/ZiGH0xc1lxJ71ZfB%40pryzbyj2023

------
Regards,
Alexander Korotkov


Attachments:

  [application/octet-stream] v7-0001-Change-the-way-ATExecMergePartitions-handles-the-.patch (7.4K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/2-v7-0001-Change-the-way-ATExecMergePartitions-handles-the-.patch)
  download | inline diff:
From be331b8793b92fed797b76b48acb231c405c4a1a Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Fri, 19 Apr 2024 13:39:45 +0300
Subject: [PATCH v7 1/7] Change the way ATExecMergePartitions() handles the
 name collision

The name collision happens when the name of the new partition is the same as
the name of one of the merging partitions.  Currently, ATExecMergePartitions()
first gives the new partition a temporary name and then renames it when old
partitions are deleted.  That negatively influences the naming of related
objects like indexes and constrains, which could inherit a temporary name.

This commit changes the implementation in the following way.  A merging
partition gets renamed first, then the new partition is created with the
right name immediately.  This resolves the issue of the naming of related
objects.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/edfbd846-dcc1-42d1-ac26-715691b687d3%40postgrespro.ru
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas
---
 src/backend/commands/tablecmds.c              | 61 +++++++++----------
 src/test/regress/expected/partition_merge.out | 25 ++++++++
 src/test/regress/sql/partition_merge.sql      | 18 ++++++
 3 files changed, 72 insertions(+), 32 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index fbffaef1966..0f72ffa9abc 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21476,9 +21476,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	ListCell   *listptr;
 	List	   *mergingPartitionsList = NIL;
 	Oid			defaultPartOid;
-	char		tmpRelName[NAMEDATALEN];
-	RangeVar   *mergePartName = cmd->name;
-	bool		isSameName = false;
 
 	/*
 	 * Lock all merged partitions, check them and create list with partitions
@@ -21500,8 +21497,28 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		 * function transformPartitionCmdForMerge().
 		 */
 		if (equal(name, cmd->name))
+		{
 			/* One new partition can have the same name as merged partition. */
-			isSameName = true;
+			char		tmpRelName[NAMEDATALEN];
+
+			/* Generate temporary name. */
+			sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
+
+			/*
+			 * Rename the existing partition with a temporary name, leaving it
+			 * free for the new partition.  We don't need to care about this
+			 * in the future because we're going to eventually drop the
+			 * existing partition anyway.
+			 */
+			RenameRelationInternal(RelationGetRelid(mergingPartition),
+								   tmpRelName, false, false);
+
+			/*
+			 * We must bump the command counter to make the new partition
+			 * tuple visible for rename.
+			 */
+			CommandCounterIncrement();
+		}
 
 		/* Store a next merging partition into the list. */
 		mergingPartitionsList = lappend(mergingPartitionsList,
@@ -21521,15 +21538,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	/* Create table for new partition, use partitioned table as model. */
-	if (isSameName)
-	{
-		/* Create partition table with generated temporary name. */
-		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
-	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(cmd->name,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21540,17 +21549,11 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	 * excessive, but this is the way we make sure nobody is planning queries
 	 * involving merging partitions.
 	 */
-	newPartRel = table_openrv(mergePartName, AccessExclusiveLock);
+	newPartRel = table_openrv(cmd->name, AccessExclusiveLock);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
 	/* Unlock and drop merged partitions. */
 	foreach(listptr, mergingPartitionsList)
 	{
@@ -21569,18 +21572,12 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 	list_free(mergingPartitionsList);
 
-	/* Rename new partition if it is needed. */
-	if (isSameName)
-	{
-		/*
-		 * We must bump the command counter to make the new partition tuple
-		 * visible for rename.
-		 */
-		CommandCounterIncrement();
-		/* Rename partition. */
-		RenameRelationInternal(RelationGetRelid(newPartRel),
-							   cmd->name->relname, false, false);
-	}
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 373d32948ca..2e0bfdc705d 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -746,4 +746,29 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
+-- Not-null constraint name should be 'tp_1_2_i_not_null'.
+\d+ tp_1_2
+                          Table "partitions_merge_schema.tp_1_2"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           | not null |         | plain   |              | 
+Partition of: t FOR VALUES FROM (0) TO (2)
+Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))
+Indexes:
+    "tp_1_2_pkey" PRIMARY KEY, btree (i)
+    "tp_1_2_i_idx" btree (i)
+Not-null constraints:
+    "tp_1_2_i_not_null" NOT NULL "i"
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 6a0b35b1799..72b1cb0b35e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -444,5 +444,23 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
+-- Not-null constraint name should be 'tp_1_2_i_not_null'.
+\d+ tp_1_2
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v7-0002-Verify-persistence-of-new-partitions-during-MERGE.patch (17.8K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/3-v7-0002-Verify-persistence-of-new-partitions-during-MERGE.patch)
  download | inline diff:
From ca4d010f40b1c10cfb72d72e41fda3c992f66235 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:41:09 +0300
Subject: [PATCH v7 2/7] Verify persistence of new partitions during
 MERGE/SPLIT operations

The createPartitionTable() function is responsible for creating new partitions
for ALTER TABLE ... MERGE PARTITIONS, and ALTER TABLE ... SPLIT PARTITION
commands.  It emulates the behaviour of CREATE TABLE ... (LIKE ...), but
lacks of check for the result relation persistence.  This commit adds
corresponding check similarly to what we have for CREATE TABLE ...
PARTITION OF command.

This commit also changes the signature of createPartitionTable() making it
take the parent's Relation itself instead of the name of the parent relation,
and return the Relation of new partition.  That doesn't lead to
complications, because both callers have the parent table open and need to
open the new partition.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/dbc8b96c-3cf0-d1ee-860d-0e491da20485%40gmail.com
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas
---
 src/backend/commands/tablecmds.c              | 70 +++++++++------
 src/test/regress/expected/partition_merge.out | 89 +++++++++++++++++++
 src/test/regress/expected/partition_split.out | 29 ++++++
 src/test/regress/sql/partition_merge.sql      | 68 ++++++++++++++
 src/test/regress/sql/partition_split.sql      | 23 +++++
 5 files changed, 254 insertions(+), 25 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 0f72ffa9abc..2025e68bdae 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21182,18 +21182,27 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 /*
  * createPartitionTable: create table for a new partition with given name
- * (newPartName) like table (modelRelName)
+ * (newPartName) like table (modelRel)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
-static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+static Relation
+createPartitionTable(RangeVar *newPartName, Relation modelRel,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
+	Relation	newRel;
+
+	/* If existing rel is temp, it must belong to this session */
+	if (modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
+		!modelRel->rd_islocaltemp)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create as partition of temporary relation of another session")));
 
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
@@ -21206,7 +21215,8 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 	createStmt->if_not_exists = false;
 
 	tlc = makeNode(TableLikeClause);
-	tlc->relation = modelRelName;
+	tlc->relation = makeRangeVar(get_namespace_name(RelationGetNamespace(modelRel)),
+								 RelationGetRelationName(modelRel), -1);
 
 	/*
 	 * Indexes will be inherited on "attach new partitions" stage, after data
@@ -21232,6 +21242,33 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 				   NULL,
 				   None_Receiver,
 				   NULL);
+
+	/*
+	 * Open the new partition with no lock, because we already have
+	 * AccessExclusiveLock placed there after creation.
+	 */
+	newRel = table_openrv(newPartName, NoLock);
+
+	/*
+	 * If the parent is permanent, so must be all of its partitions.  Note
+	 * that inheritance allows that case.
+	 */
+	if (modelRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		newRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(modelRel))));
+
+	/* Permanent rels cannot inherit from temporary ones */
+	if (newRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a permanent relation as partition of temporary relation \"%s\"",
+						RelationGetRelationName(modelRel))));
+
+	return newRel;
 }
 
 /*
@@ -21251,7 +21288,6 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	char		tmpRelName[NAMEDATALEN];
 	List	   *newPartRels = NIL;
 	ObjectAddress object;
-	RangeVar   *parentName;
 	Oid			defaultPartOid;
 
 	defaultPartOid = get_default_oid_from_partdesc(RelationGetPartitionDesc(rel, true));
@@ -21323,18 +21359,12 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 
 	/* Create new partitions (like split partition), without indexes. */
-	parentName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-							  RelationGetRelationName(rel), -1);
 	foreach(listptr, cmd->partlist)
 	{
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
-
-		/* Open the new partition and acquire exclusive lock on it. */
-		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
-
+		newPartRel = createPartitionTable(sps->name, rel, context);
 		newPartRels = lappend(newPartRels, newPartRel);
 	}
 
@@ -21538,18 +21568,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	createPartitionTable(cmd->name,
-						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									  RelationGetRelationName(rel), -1),
-						 context);
-
-	/*
-	 * Open the new partition and acquire exclusive lock on it.  This will
-	 * stop all the operations with partitioned table.  This might seem
-	 * excessive, but this is the way we make sure nobody is planning queries
-	 * involving merging partitions.
-	 */
-	newPartRel = table_openrv(cmd->name, AccessExclusiveLock);
+	/* Create table for new partition, use partitioned table as model. */
+	newPartRel = createPartitionTable(cmd->name, rel, context);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 2e0bfdc705d..cf961b041fb 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -746,6 +746,36 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
@@ -771,4 +801,63 @@ Not-null constraints:
 
 DROP TABLE t;
 --
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = public, pg_temp;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+RESET search_path;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+SET search_path = pg_temp, public;
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = public, pg_temp;
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+ROLLBACK;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 419d169f036..660361cd20e 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1427,4 +1427,33 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+ERROR:  cannot create a permanent relation as partition of temporary relation "t"
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 72b1cb0b35e..29ae6a09f13 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -444,6 +444,28 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
@@ -462,5 +484,51 @@ ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
 
 DROP TABLE t;
 
+--
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = partitions_merge_schema, pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = partitions_merge_schema, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+DROP TABLE t;
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = partitions_merge_schema, pg_temp, public;
+
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index b63532ee562..576f9f0f63c 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v7-0005-Add-tab-completion-for-ALTER-TABLE-SPLIT-MERGE-PA.patch (2.5K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/4-v7-0005-Add-tab-completion-for-ALTER-TABLE-SPLIT-MERGE-PA.patch)
  download | inline diff:
From f20d063f436b126da5ef0b78f0fb90b698c965eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <[email protected]>
Date: Thu, 18 Apr 2024 17:47:22 +0100
Subject: [PATCH v7 5/7] =?UTF-8?q?Add=20tab=20completion=20for=20ALTER=20T?=
 =?UTF-8?q?ABLE=20=E2=80=A6=20SPLIT|MERGE=20PARTITION(S)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/bin/psql/tab-complete.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 6fee3160f02..97cd5d9f628 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2353,6 +2353,7 @@ psql_completion(const char *text, int start, int end)
 					  "OWNER TO", "SET", "VALIDATE CONSTRAINT",
 					  "REPLICA IDENTITY", "ATTACH PARTITION",
 					  "DETACH PARTITION", "FORCE ROW LEVEL SECURITY",
+					  "SPLIT PARTITION", "MERGE PARTITIONS (",
 					  "OF", "NOT OF");
 	/* ALTER TABLE xxx ADD */
 	else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
@@ -2609,10 +2610,10 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH("FROM (", "IN (", "WITH (");
 
 	/*
-	 * If we have ALTER TABLE <foo> DETACH PARTITION, provide a list of
+	 * If we have ALTER TABLE <foo> DETACH|SPLIT PARTITION, provide a list of
 	 * partitions of <foo>.
 	 */
-	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION"))
+	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH|SPLIT", "PARTITION"))
 	{
 		set_completion_reference(prev3_wd);
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
@@ -2620,6 +2621,19 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION", MatchAny))
 		COMPLETE_WITH("CONCURRENTLY", "FINALIZE");
 
+	/* ALTER TABLE <name> SPLIT PARTITION <name> */
+	else if (Matches("ALTER", "TABLE", MatchAny, "SPLIT", "PARTITION", MatchAny))
+		COMPLETE_WITH("INTO ( PARTITION");
+
+	/* ALTER TABLE <name> MERGE PARTITIONS ( */
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "("))
+	{
+		set_completion_reference(prev4_wd);
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
+	}
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "(*)"))
+		COMPLETE_WITH("INTO");
+
 	/* ALTER TABLE <name> OF */
 	else if (Matches("ALTER", "TABLE", MatchAny, "OF"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v7-0003-Fix-error-message-in-check_partition_bounds_for_s.patch (3.9K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/5-v7-0003-Fix-error-message-in-check_partition_bounds_for_s.patch)
  download | inline diff:
From 204321a37aa69273a6438e26163eb769d49cac47 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:56:51 +0300
Subject: [PATCH v7 3/7] Fix error message in
 check_partition_bounds_for_split_range()

Currently, the error message is produced by a system of complex substitutions
making it quite untranslatable and hard to read.  This commit splits this into
4 plain error messages suitable for translation.

Reported-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20240408.152402.1485994009160660141.horikyota.ntt%40gmail.com
---
 src/backend/partitioning/partbounds.c | 60 +++++++++++++++++----------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index b08edf87a69..6c04d8bef5b 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5211,7 +5211,7 @@ check_partition_bounds_for_split_range(Relation parent,
 	if (first || last)
 	{
 		PartitionBoundSpec *split_spec = get_partition_bound_spec(splitPartOid, splitPartName);
-		bool		overlap = false;
+		PartitionRangeDatum *datum;
 
 		if (first)
 		{
@@ -5224,13 +5224,30 @@ check_partition_bounds_for_split_range(Relation parent,
 										  key->partcollation,
 										  lower->datums, lower->kind,
 										  true, split_lower);
+			datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) - 1) : NULL;
 
 			/*
 			 * Lower bound of "spec" should be equal (or greater than or equal
 			 * in case defaultPart=true) to lower bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval < 0))
-				overlap = true;
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is not equal to lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
+			else
+			{
+				if (cmpval < 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is less than lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
 		}
 		else
 		{
@@ -5243,29 +5260,30 @@ check_partition_bounds_for_split_range(Relation parent,
 										  key->partcollation,
 										  upper->datums, upper->kind,
 										  false, split_upper);
+			datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) - 1) : NULL;
 
 			/*
 			 * Upper bound of "spec" should be equal (or less than or equal in
 			 * case defaultPart=true) to upper bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval > 0))
-				overlap = true;
-		}
-
-		if (overlap)
-		{
-			PartitionRangeDatum *datum;
-
-			datum = list_nth(first ? spec->lowerdatums : spec->upperdatums, abs(cmpval) - 1);
-
-			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-					 errmsg("%s bound of partition \"%s\" is %s %s bound of split partition",
-							first ? "lower" : "upper",
-							relname,
-							defaultPart ? (first ? "less than" : "greater than") : "not equal to",
-							first ? "lower" : "upper"),
-					 parser_errposition(pstate, datum->location)));
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is not equal to upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
+			else
+			{
+				if (cmpval > 0)
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is greater than upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+			}
 		}
 	}
 }
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v7-0004-Rename-tables-in-tests-of-partition-MERGE-SPLIT-o.patch (202.8K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/6-v7-0004-Rename-tables-in-tests-of-partition-MERGE-SPLIT-o.patch)
  download | inline diff:
From e985c103b43cd6d31da294d8541407dc0c8dc131 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Fri, 19 Apr 2024 16:03:06 +0300
Subject: [PATCH v7 4/7] Rename tables in  tests of partition MERGE/SPLIT
 operations

Replace "salesman" with "salesperson", "salesmen" with "salespeople".  The
names are both gramatically correct and gender-neutral.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/fdaa003e-919c-cbc9-4f0c-e4546e96bd65%40gmail.com
Reviewed-by: Robert Haas
---
 src/test/regress/expected/partition_merge.out |  676 ++++-----
 src/test/regress/expected/partition_split.out | 1238 ++++++++---------
 src/test/regress/sql/partition_merge.sql      |  160 +--
 src/test/regress/sql/partition_split.sql      |  280 ++--
 4 files changed, 1177 insertions(+), 1177 deletions(-)

diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index cf961b041fb..acacd81767c 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -10,12 +10,12 @@ SET search_path = partitions_merge_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_dec2021 PARTITION OF sales_range FOR VALUES FROM ('2021-12-01') TO ('2021-12-31');
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-15');
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
@@ -54,7 +54,7 @@ DROP TABLE sales_range;
 --
 -- Add rows into partitioned table, then merge partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -115,68 +115,68 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemanam
 (1 row)
 
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb_mar_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (10 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          11 | Trump         |          380 | 04-06-2022
-           5 | Deev          |          250 | 04-07-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             11 | Trump            |          380 | 04-06-2022
+              5 | Deev             |          250 | 04-07-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (10 rows)
 
 RESET enable_seqscan;
@@ -184,7 +184,7 @@ DROP TABLE sales_range;
 --
 -- Merge some partitions into DEFAULT partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -209,15 +209,15 @@ INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 -- name
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022, sales_others) INTO sales_others;
 select * from sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (7 rows)
 
 -- show partitions with conditions:
@@ -239,7 +239,7 @@ DROP TABLE sales_range;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -248,219 +248,219 @@ CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1)
 CREATE TABLE sales_jan2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1);
 CREATE TABLE sales_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (9 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
 (2 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
 (2 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 ALTER TABLE sales_date MERGE PARTITIONS (sales_jan2022, sales_feb2022) INTO sales_jan_feb2022;
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (11 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
 (6 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_20 PARTITION OF salespeople FOR VALUES FROM (10) TO (20);
+CREATE TABLE salespeople20_30 PARTITION OF salespeople FOR VALUES FROM (20) TO (30);
+CREATE TABLE salespeople30_40 PARTITION OF salespeople FOR VALUES FROM (30) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (10, 'May');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+INSERT INTO salespeople10_20 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+INSERT INTO salespeople10_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
-          20 | Smirnoff
-          30 | Ford
+SELECT * FROM salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
+             20 | Smirnoff
+             30 | Ford
 (4 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
-select * from salesmans;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
-          19 | Ivanov
-          10 | May
-          20 | Smirnoff
-          31 | Popov
-          30 | Ford
+CREATE TABLE salespeople10_20(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+CREATE TABLE salespeople20_30(salesperson_id INT PRIMARY KEY, d2 INT,  salesperson_name VARCHAR(30));
+CREATE TABLE salespeople30_40(salesperson_id INT PRIMARY KEY, d3 DATE, salesperson_name VARCHAR(30));
+INSERT INTO salespeople10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salespeople20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salespeople30_40 VALUES (31, now(), 'Popov');
+ALTER TABLE salespeople10_20 DROP COLUMN d1;
+ALTER TABLE salespeople20_30 DROP COLUMN d2;
+ALTER TABLE salespeople30_40 DROP COLUMN d3;
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salespeople ATTACH PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salespeople ATTACH PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40);
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
+select * from salespeople;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
+             19 | Ivanov
+             10 | May
+             20 | Smirnoff
+             31 | Popov
+             30 | Ford
 (6 rows)
 
-select * from salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+select * from salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-select * from salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          19 | Ivanov
-          10 | May
-          20 | Smirnoff
-          31 | Popov
-          30 | Ford
+select * from salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             19 | Ivanov
+             10 | May
+             20 | Smirnoff
+             31 | Popov
+             30 | Ford
 (5 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 --
 -- Test: merge sub-partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr2022_01_10 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-10');
 CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');
 CREATE TABLE sales_apr2022_20_30 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01');
@@ -482,88 +482,88 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr2022_01_10;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_apr2022_10_20;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           4 | Ivanov        |          750 | 04-13-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              4 | Ivanov           |          750 | 04-13-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_20_30;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
 (1 row)
 
 ALTER TABLE sales_apr2022 MERGE PARTITIONS (sales_apr2022_01_10, sales_apr2022_10_20, sales_apr2022_20_30) INTO sales_apr_all;
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr_all;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 DROP TABLE sales_range;
@@ -574,8 +574,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -607,33 +607,33 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, MERGE PARTITIONS with data
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_west PARTITION OF sales_list FOR VALUES IN ('Lisbon', 'New York', 'Madrid');
 CREATE TABLE sales_east PARTITION OF sales_list FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok');
 CREATE TABLE sales_central PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
@@ -662,68 +662,68 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 (3 rows)
 
 SELECT * FROM sales_list;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           2 | Smirnoff      | New York       |          500 | 03-03-2022
-           5 | Deev          | Lisbon         |          250 | 03-07-2022
-          11 | Muller        | Madrid         |          650 | 03-05-2022
-          14 | Plato         | Lisbon         |          950 | 03-05-2022
-           1 | Trump         | Bejing         |         1000 | 03-01-2022
-           8 | Li            | Vladivostok    |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw         |          750 | 03-04-2022
-           6 | Poirot        | Berlin         |         1000 | 03-01-2022
-          12 | Smith         | Kyiv           |          350 | 03-10-2022
-          13 | Gandi         | Warsaw         |          150 | 03-08-2022
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Helsinki       |         1200 | 03-06-2022
-           9 | May           | Helsinki       |         1200 | 03-11-2022
-          10 | Halder        | Oslo           |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              2 | Smirnoff         | New York       |          500 | 03-03-2022
+              5 | Deev             | Lisbon         |          250 | 03-07-2022
+             11 | Muller           | Madrid         |          650 | 03-05-2022
+             14 | Plato            | Lisbon         |          950 | 03-05-2022
+              1 | Trump            | Bejing         |         1000 | 03-01-2022
+              8 | Li               | Vladivostok    |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw         |          750 | 03-04-2022
+              6 | Poirot           | Berlin         |         1000 | 03-01-2022
+             12 | Smith            | Kyiv           |          350 | 03-10-2022
+             13 | Gandi            | Warsaw         |          150 | 03-08-2022
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Helsinki       |         1200 | 03-06-2022
+              9 | May              | Helsinki       |         1200 | 03-11-2022
+             10 | Halder           | Oslo           |          800 | 03-02-2022
 (14 rows)
 
 SELECT * FROM sales_nord;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Helsinki       |         1200 | 03-06-2022
-           9 | May           | Helsinki       |         1200 | 03-11-2022
-          10 | Halder        | Oslo           |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Helsinki       |         1200 | 03-06-2022
+              9 | May              | Helsinki       |         1200 | 03-11-2022
+             10 | Halder           | Oslo           |          800 | 03-02-2022
 (4 rows)
 
 SELECT * FROM sales_all;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           2 | Smirnoff      | New York    |          500 | 03-03-2022
-           5 | Deev          | Lisbon      |          250 | 03-07-2022
-          11 | Muller        | Madrid      |          650 | 03-05-2022
-          14 | Plato         | Lisbon      |          950 | 03-05-2022
-           1 | Trump         | Bejing      |         1000 | 03-01-2022
-           8 | Li            | Vladivostok |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-           6 | Poirot        | Berlin      |         1000 | 03-01-2022
-          12 | Smith         | Kyiv        |          350 | 03-10-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              2 | Smirnoff         | New York    |          500 | 03-03-2022
+              5 | Deev             | Lisbon      |          250 | 03-07-2022
+             11 | Muller           | Madrid      |          650 | 03-05-2022
+             14 | Plato            | Lisbon      |          950 | 03-05-2022
+              1 | Trump            | Bejing      |         1000 | 03-01-2022
+              8 | Li               | Vladivostok |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+              6 | Poirot           | Berlin      |         1000 | 03-01-2022
+             12 | Smith            | Kyiv        |          350 | 03-10-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
 -- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
 (1 row)
 
 RESET enable_seqscan;
@@ -803,7 +803,7 @@ DROP TABLE t;
 --
 -- Try mixing permanent and temporary partitions.
 --
-SET search_path = public, pg_temp;
+SET search_path = partitions_merge_schema, pg_temp, public;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
 CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
@@ -823,16 +823,16 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
  tp_1_2 | FOR VALUES FROM (1) TO (2) | p
 (2 rows)
 
-SET search_path = pg_temp, public;
+SET search_path = pg_temp, partitions_merge_schema, public;
 -- Can't merge persistent partitions into a temporary partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ERROR:  cannot create a temporary relation as partition of permanent relation "t"
-RESET search_path;
+SET search_path = partitions_merge_schema, public;
 -- Can't merge persistent partitions into a temporary partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
 ERROR:  cannot create a temporary relation as partition of permanent relation "t"
 DROP TABLE t;
-SET search_path = pg_temp, public;
+SET search_path = pg_temp, partitions_merge_schema, public;
 BEGIN;
 CREATE TABLE t (i int) PARTITION BY RANGE (i);
 CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
@@ -853,7 +853,7 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
  tp_1_2 | FOR VALUES FROM (1) TO (2) | t
 (2 rows)
 
-SET search_path = public, pg_temp;
+SET search_path = partitions_merge_schema, pg_temp, public;
 -- Can't merge temporary partitions into a persistent partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ERROR:  cannot create a permanent relation as partition of temporary relation "t"
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 660361cd20e..ed25ff08d9f 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -10,7 +10,7 @@ SET search_path = partition_split_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id int, salesman_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id int, salesperson_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -84,8 +84,8 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
-LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
-                                                             ^
+LINE 4:    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO...
+                                                    ^
 -- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
@@ -109,7 +109,7 @@ DROP TABLE sales_others;
 --
 -- Add rows into partitioned table then split partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -132,68 +132,68 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 DROP TABLE sales_range CASCADE;
 --
 -- Add split partition, then add rows into partitioned table
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -216,61 +216,61 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 DROP TABLE sales_range CASCADE;
@@ -280,7 +280,7 @@ DROP TABLE sales_range CASCADE;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -288,103 +288,103 @@ CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month
 CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1) TO (2022, 1, 1);
 CREATE TABLE sales_jan_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (9 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
 (4 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 ALTER TABLE sales_date SPLIT PARTITION sales_jan_feb2022 INTO
   (PARTITION sales_jan2022 FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1),
    PARTITION sales_feb2022 FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1));
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (11 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
 (3 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 --ERROR:  relation "sales_jan_feb2022" does not exist
@@ -396,7 +396,7 @@ DROP TABLE sales_date CASCADE;
 --
 -- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date);
@@ -415,19 +415,19 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-           6 | Poirot        |          150 | 02-11-2022
-           7 | Li            |          175 | 03-08-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          11 | Trump         |          380 | 04-06-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+              6 | Poirot           |          150 | 02-11-2022
+              7 | Li               |          175 | 03-08-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             11 | Trump            |          380 | 04-06-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (11 rows)
 
 SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'partition_split_schema';
@@ -445,34 +445,34 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          11 | Trump         |          380 | 04-06-2022
-           5 | Deev          |          250 | 04-07-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             11 | Trump            |          380 | 04-06-2022
+              5 | Deev             |          250 | 04-07-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_others where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 SET enable_indexscan = ON;
@@ -505,7 +505,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Test: some cases for splitting DEFAULT partition (different bounds)
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 -- sales_error intersects with sales_dec2022 (lower bound)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
@@ -562,7 +562,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 DROP TABLE sales_range;
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 -- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
@@ -574,20 +574,20 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesperson_id INT REFERENCES salespeople(salesperson_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb_mar_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
@@ -596,50 +596,50 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 -- We should see the same CONSTRAINTs as on sales_feb_mar_apr2022 partition
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
--- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
-ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(-1) is not present in table "salesmans".
+ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
+DETAIL:  Key (salesperson_id)=(-1) is not present in table "salespeople".
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (19, 'Ivanov');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (30, 'Ford');
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
 INSERT INTO sales VALUES (10, 150, '2022-03-01');
@@ -648,280 +648,280 @@ INSERT INTO sales VALUES (19, 200, '2022-03-04');
 INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
-          20 | Smirnoff
-          30 | Ford
+SELECT * FROM salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
+             20 | Smirnoff
+             30 | Ford
 (4 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
+SELECT * FROM salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+SELECT * FROM salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+SELECT * FROM salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
--- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
-ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(40) is not present in table "salesmans".
+ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
+DETAIL:  Key (salesperson_id)=(40) is not present in table "salespeople".
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (10, 'May');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+INSERT INTO salespeople10_40 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+INSERT INTO salespeople30_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
+SELECT * FROM salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+SELECT * FROM salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+SELECT * FROM salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salespeople(salesperson_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople1_2 PARTITION OF salespeople FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+CREATE TABLE salespeople2_5(salesperson_id INT NOT NULL, salesperson_name VARCHAR(30));
+ALTER TABLE salespeople ATTACH PARTITION salespeople2_5 FOR VALUES FROM (2) TO (5);
+INSERT INTO salespeople (salesperson_name) VALUES ('Poirot');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ivanov');
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_5'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
-SELECT * FROM salesmans1_2;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+ALTER TABLE salespeople SPLIT PARTITION salespeople2_5 INTO
+  (PARTITION salespeople2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salespeople3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salespeople4_5 FOR VALUES FROM (4) TO (5));
+INSERT INTO salespeople (salesperson_name) VALUES ('May');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ford');
+SELECT * FROM salespeople1_2;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans2_3;
- salesman_id | salesman_name 
--------------+---------------
-           2 | Ivanov
+SELECT * FROM salespeople2_3;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              2 | Ivanov
 (1 row)
 
-SELECT * FROM salesmans3_4;
- salesman_id | salesman_name 
--------------+---------------
-           3 | May
+SELECT * FROM salespeople3_4;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              3 | May
 (1 row)
 
-SELECT * FROM salesmans4_5;
- salesman_id | salesman_name 
--------------+---------------
-           4 | Ford
+SELECT * FROM salespeople4_5;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              4 | Ford
 (1 row)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_3'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople3_4'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople4_5'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-select * from salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+CREATE TABLE salespeople10_40(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, d2 INT, d3 DATE, salesperson_name VARCHAR(30));
+INSERT INTO salespeople10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salespeople10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+ALTER TABLE salespeople10_40 DROP COLUMN d1;
+ALTER TABLE salespeople10_40 DROP COLUMN d2;
+ALTER TABLE salespeople10_40 DROP COLUMN d3;
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_40 FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
+select * from salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-select * from salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          19 | Ivanov
-          10 | May
+select * from salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             19 | Ivanov
+             10 | May
 (2 rows)
 
-select * from salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+select * from salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-select * from salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+select * from salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split sub-partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_all PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -941,31 +941,31 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 ALTER TABLE sales_apr2022 SPLIT PARTITION sales_apr_all INTO
@@ -973,50 +973,50 @@ ALTER TABLE sales_apr2022 SPLIT PARTITION sales_apr_all INTO
    PARTITION sales_apr2022_10_20 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20'),
    PARTITION sales_apr2022_20_30 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01'));
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr2022_01_10;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_apr2022_10_20;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           4 | Ivanov        |          750 | 04-13-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              4 | Ivanov           |          750 | 04-13-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_20_30;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
 (1 row)
 
 DROP TABLE sales_range;
@@ -1027,8 +1027,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -1067,8 +1067,8 @@ DROP TABLE sales_list;
 --   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -1092,109 +1092,109 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
 --
 CREATE TABLE sales_list
-(salesman_id SERIAL,
- salesman_name VARCHAR(30),
+(salesperson_id SERIAL,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 SELECT * FROM sales_list;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           1 | Trump         | Bejing         |         1000 | 03-01-2022
-           8 | Li            | Vladivostok    |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw         |          750 | 03-04-2022
-           6 | Poirot        | Berlin         |         1000 | 03-01-2022
-          12 | Smith         | Kyiv           |          350 | 03-10-2022
-          13 | Gandi         | Warsaw         |          150 | 03-08-2022
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Oslo           |         1200 | 03-06-2022
-           9 | May           | Oslo           |         1200 | 03-11-2022
-          10 | Halder        | Helsinki       |          800 | 03-02-2022
-           2 | Smirnoff      | New York       |          500 | 03-03-2022
-           5 | Deev          | Lisbon         |          250 | 03-07-2022
-          11 | Muller        | Madrid         |          650 | 03-05-2022
-          14 | Plato         | Lisbon         |          950 | 03-05-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              1 | Trump            | Bejing         |         1000 | 03-01-2022
+              8 | Li               | Vladivostok    |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw         |          750 | 03-04-2022
+              6 | Poirot           | Berlin         |         1000 | 03-01-2022
+             12 | Smith            | Kyiv           |          350 | 03-10-2022
+             13 | Gandi            | Warsaw         |          150 | 03-08-2022
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Oslo           |         1200 | 03-06-2022
+              9 | May              | Oslo           |         1200 | 03-11-2022
+             10 | Halder           | Helsinki       |          800 | 03-02-2022
+              2 | Smirnoff         | New York       |          500 | 03-03-2022
+              5 | Deev             | Lisbon         |          250 | 03-07-2022
+             11 | Muller           | Madrid         |          650 | 03-05-2022
+             14 | Plato            | Lisbon         |          950 | 03-05-2022
 (14 rows)
 
 SELECT * FROM sales_west;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           2 | Smirnoff      | New York    |          500 | 03-03-2022
-           5 | Deev          | Lisbon      |          250 | 03-07-2022
-          11 | Muller        | Madrid      |          650 | 03-05-2022
-          14 | Plato         | Lisbon      |          950 | 03-05-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              2 | Smirnoff         | New York    |          500 | 03-03-2022
+              5 | Deev             | Lisbon      |          250 | 03-07-2022
+             11 | Muller           | Madrid      |          650 | 03-05-2022
+             14 | Plato            | Lisbon      |          950 | 03-05-2022
 (4 rows)
 
 SELECT * FROM sales_east;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           1 | Trump         | Bejing      |         1000 | 03-01-2022
-           8 | Li            | Vladivostok |         1150 | 03-09-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              1 | Trump            | Bejing      |         1000 | 03-01-2022
+              8 | Li               | Vladivostok |         1150 | 03-09-2022
 (2 rows)
 
 SELECT * FROM sales_nord;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Oslo           |         1200 | 03-06-2022
-           9 | May           | Oslo           |         1200 | 03-11-2022
-          10 | Halder        | Helsinki       |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Oslo           |         1200 | 03-06-2022
+              9 | May              | Oslo           |         1200 | 03-11-2022
+             10 | Halder           | Helsinki       |          800 | 03-02-2022
 (4 rows)
 
 SELECT * FROM sales_central;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-           6 | Poirot        | Berlin      |         1000 | 03-01-2022
-          12 | Smith         | Kyiv        |          350 | 03-10-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+              6 | Poirot           | Berlin      |         1000 | 03-01-2022
+             12 | Smith            | Kyiv        |          350 | 03-10-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
 -- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
 (1 row)
 
 SET enable_indexscan = ON;
@@ -1205,7 +1205,7 @@ DROP TABLE sales_list;
 --   * split DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-09');
@@ -1228,42 +1228,42 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022_1decade FOR VALUES FROM ('2022-02-01') TO ('2022-02-10'),
    PARTITION sales_apr2022_1decade FOR VALUES FROM ('2022-04-01') TO ('2022-04-10'));
 SELECT * FROM sales_jan2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             13 | Gandi            |          377 | 01-09-2022
 (1 row)
 
 SELECT * FROM sales_feb2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-09-2022
-           6 | Poirot        |          150 | 02-07-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-09-2022
+              6 | Poirot           |          150 | 02-07-2022
 (2 rows)
 
 SELECT * FROM sales_mar2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          10 | Halder        |          350 | 01-28-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             10 | Halder           |          350 | 01-28-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (8 rows)
 
 DROP TABLE sales_range;
@@ -1272,7 +1272,7 @@ DROP TABLE sales_range;
 --   * split non-DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -1295,42 +1295,42 @@ ALTER TABLE sales_range SPLIT PARTITION sales_all INTO
    PARTITION sales_feb2022_1decade FOR VALUES FROM ('2022-02-01') TO ('2022-02-10'),
    PARTITION sales_apr2022_1decade FOR VALUES FROM ('2022-04-01') TO ('2022-04-10'));
 SELECT * FROM sales_jan2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             13 | Gandi            |          377 | 01-09-2022
 (1 row)
 
 SELECT * FROM sales_feb2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-09-2022
-           6 | Poirot        |          150 | 02-07-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-09-2022
+              6 | Poirot           |          150 | 02-07-2022
 (2 rows)
 
 SELECT * FROM sales_mar2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
-           1 | May           |         1000 | 01-31-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          10 | Halder        |          350 | 01-28-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
+              1 | May              |         1000 | 01-31-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             10 | Halder           |          350 | 01-28-2022
+             12 | Plato            |          350 | 03-19-2022
 (8 rows)
 
 DROP TABLE sales_range;
@@ -1338,7 +1338,7 @@ DROP TABLE sales_range;
 -- Test for split non-DEFAULT partition to DEFAULT partition + partitions
 -- with spaces between bounds.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -1360,56 +1360,56 @@ ALTER TABLE sales_range SPLIT PARTITION sales_all INTO
    PARTITION sales_others DEFAULT);
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (4 rows)
 
 DROP TABLE sales_range;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 29ae6a09f13..9e21d8b163f 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -13,13 +13,13 @@ SET search_path = partitions_merge_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_dec2021 PARTITION OF sales_range FOR VALUES FROM ('2021-12-01') TO ('2021-12-31');
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-15');
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
@@ -50,7 +50,7 @@ DROP TABLE sales_range;
 --
 -- Add rows into partitioned table, then merge partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -108,7 +108,7 @@ DROP TABLE sales_range;
 --
 -- Merge some partitions into DEFAULT partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -151,7 +151,7 @@ DROP TABLE sales_range;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -162,15 +162,15 @@ CREATE TABLE sales_jan2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1)
 CREATE TABLE sales_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -180,8 +180,8 @@ SELECT * FROM sales_other;
 
 ALTER TABLE sales_date MERGE PARTITIONS (sales_jan2022, sales_feb2022) INTO sales_jan_feb2022;
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -193,14 +193,14 @@ DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_20 PARTITION OF salespeople FOR VALUES FROM (10) TO (20);
+CREATE TABLE salespeople20_30 PARTITION OF salespeople FOR VALUES FROM (20) TO (30);
+CREATE TABLE salespeople30_40 PARTITION OF salespeople FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -209,80 +209,80 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salespeople VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
+INSERT INTO salespeople10_20 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
+INSERT INTO salespeople10_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salespeople10_20(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+CREATE TABLE salespeople20_30(salesperson_id INT PRIMARY KEY, d2 INT,  salesperson_name VARCHAR(30));
+CREATE TABLE salespeople30_40(salesperson_id INT PRIMARY KEY, d3 DATE, salesperson_name VARCHAR(30));
 
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
+INSERT INTO salespeople10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salespeople20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salespeople30_40 VALUES (31, now(), 'Popov');
 
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
+ALTER TABLE salespeople10_20 DROP COLUMN d1;
+ALTER TABLE salespeople20_30 DROP COLUMN d2;
+ALTER TABLE salespeople30_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salespeople ATTACH PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salespeople ATTACH PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 
-select * from salesmans;
-select * from salesmans01_10;
-select * from salesmans10_40;
+select * from salespeople;
+select * from salespeople01_10;
+select * from salespeople10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 
 --
 -- Test: merge sub-partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr2022_01_10 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-10');
 CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');
 CREATE TABLE sales_apr2022_20_30 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01');
@@ -329,8 +329,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -366,14 +366,14 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, MERGE PARTITIONS with data
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
 
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
@@ -382,20 +382,20 @@ CREATE TABLE sales_east PARTITION OF sales_list FOR VALUES IN ('Bejing', 'Delhi'
 CREATE TABLE sales_central PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
@@ -420,7 +420,7 @@ SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
 
 RESET enable_seqscan;
 
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 576f9f0f63c..4228917654c 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -13,7 +13,7 @@ SET search_path = partition_split_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id int, salesman_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id int, salesperson_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -98,7 +98,7 @@ DROP TABLE sales_others;
 --
 -- Add rows into partitioned table then split partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -135,7 +135,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Add split partition, then add rows into partitioned table
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -175,7 +175,7 @@ DROP TABLE sales_range CASCADE;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -185,15 +185,15 @@ CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1)
 CREATE TABLE sales_jan_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -204,8 +204,8 @@ ALTER TABLE sales_date SPLIT PARTITION sales_jan_feb2022 INTO
   (PARTITION sales_jan2022 FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1),
    PARTITION sales_feb2022 FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1));
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -221,7 +221,7 @@ DROP TABLE sales_date CASCADE;
 --
 -- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date);
@@ -272,7 +272,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Test: some cases for splitting DEFAULT partition (different bounds)
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- sales_error intersects with sales_dec2022 (lower bound)
@@ -322,7 +322,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 
 DROP TABLE sales_range;
 
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
@@ -337,11 +337,11 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesperson_id INT REFERENCES salespeople(salesperson_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 
@@ -363,28 +363,28 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
--- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (19, 'Ivanov');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
@@ -395,36 +395,36 @@ INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_40;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_20;
+SELECT * FROM salespeople20_30;
+SELECT * FROM salespeople30_40;
 
--- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -433,125 +433,125 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salespeople VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
+INSERT INTO salespeople10_40 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
+INSERT INTO salespeople30_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_20;
+SELECT * FROM salespeople20_30;
+SELECT * FROM salespeople30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salespeople1_2 PARTITION OF salespeople FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
+CREATE TABLE salespeople2_5(salesperson_id INT NOT NULL, salesperson_name VARCHAR(30));
+ALTER TABLE salespeople ATTACH PARTITION salespeople2_5 FOR VALUES FROM (2) TO (5);
 
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
+INSERT INTO salespeople (salesperson_name) VALUES ('Poirot');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ivanov');
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_5'::regclass::oid;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
+ALTER TABLE salespeople SPLIT PARTITION salespeople2_5 INTO
+  (PARTITION salespeople2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salespeople3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salespeople4_5 FOR VALUES FROM (4) TO (5));
 
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
+INSERT INTO salespeople (salesperson_name) VALUES ('May');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ford');
 
-SELECT * FROM salesmans1_2;
-SELECT * FROM salesmans2_3;
-SELECT * FROM salesmans3_4;
-SELECT * FROM salesmans4_5;
+SELECT * FROM salespeople1_2;
+SELECT * FROM salespeople2_3;
+SELECT * FROM salespeople3_4;
+SELECT * FROM salespeople4_5;
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_3'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople3_4'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople4_5'::regclass::oid;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salespeople10_40(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, d2 INT, d3 DATE, salesperson_name VARCHAR(30));
 
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+INSERT INTO salespeople10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salespeople10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
 
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
+ALTER TABLE salespeople10_40 DROP COLUMN d1;
+ALTER TABLE salespeople10_40 DROP COLUMN d2;
+ALTER TABLE salespeople10_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_40 FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
-select * from salesmans01_10;
-select * from salesmans10_20;
-select * from salesmans20_30;
-select * from salesmans30_40;
+select * from salespeople01_10;
+select * from salespeople10_20;
+select * from salespeople20_30;
+select * from salespeople30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split sub-partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_all PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 
@@ -598,8 +598,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -635,8 +635,8 @@ DROP TABLE sales_list;
 --   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -663,34 +663,34 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
 --
 CREATE TABLE sales_list
-(salesman_id SERIAL,
- salesman_name VARCHAR(30),
+(salesperson_id SERIAL,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
 
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
@@ -709,7 +709,7 @@ SET enable_seqscan = OFF;
 
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
 
 SET enable_indexscan = ON;
 SET enable_seqscan = ON;
@@ -721,7 +721,7 @@ DROP TABLE sales_list;
 --   * split DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -759,7 +759,7 @@ DROP TABLE sales_range;
 --   * split non-DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
@@ -796,7 +796,7 @@ DROP TABLE sales_range;
 -- Test for split non-DEFAULT partition to DEFAULT partition + partitions
 -- with spaces between bounds.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v7-0006-ALTER-TABLE-.-MERGE-PARTITIONS-.-make-inherit-par.patch (1.6K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/7-v7-0006-ALTER-TABLE-.-MERGE-PARTITIONS-.-make-inherit-par.patch)
  download | inline diff:
From 11f4b57db9e381745a107d3f49e796afd5e8924e Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Fri, 19 Apr 2024 14:55:24 +0300
Subject: [PATCH v7 6/7] ALTER TABLE ... MERGE PARTITIONS ... make inherit
 parent's am

Reported-by:
Bug:
Discussion:
Author:
Reviewed-by:
Tested-by:
Backpatch-through:
---
 src/backend/commands/tablecmds.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 2025e68bdae..575e99509d8 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21186,6 +21186,11 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  *
  * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ *
+ * Also, this function sets the new partition access method same as parent
+ * table access methods (similarly to CREATE TABLE ... PARTITION OF).  It
+ * checks that parent and child tables have compatible persistence.
+ *
  * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
 static Relation
@@ -21213,6 +21218,7 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
 	createStmt->oncommit = ONCOMMIT_NOOP;
 	createStmt->tablespacename = NULL;
 	createStmt->if_not_exists = false;
+	createStmt->accessMethod = get_am_name(modelRel->rd_rel->relam);
 
 	tlc = makeNode(TableLikeClause);
 	tlc->relation = makeRangeVar(get_namespace_name(RelationGetNamespace(modelRel)),
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v7-0007-doc-review-for-ALTER-TABLE-.-SPLIT-MERGE-PARTITIO.patch (6.0K, ../../CAPpHfdtLk5M4FV6C33DnBusWpsbwwmrQ83mpu7N8PZMupbftyw@mail.gmail.com/8-v7-0007-doc-review-for-ALTER-TABLE-.-SPLIT-MERGE-PARTITIO.patch)
  download | inline diff:
From 9be4d11f85fd4adac924b40eded963e74bb55171 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <[email protected]>
Date: Thu, 18 Apr 2024 15:40:44 -0500
Subject: [PATCH v7 7/7] doc review for ALTER TABLE ... SPLIT/MERGE PARTITION

---
 doc/src/sgml/ddl.sgml             |  4 ++--
 doc/src/sgml/ref/alter_table.sgml | 22 +++++++++++-----------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 026bfff70f3..01277b1d327 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4384,7 +4384,7 @@ ALTER INDEX measurement_city_id_logdate_key
 
     <para>
      There is also an option for merging multiple table partitions into
-     a single partition using the
+     a single partition using
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
      users to combine partitions that are no longer needed as
@@ -4403,7 +4403,7 @@ ALTER TABLE measurement
 
     <para>
      Similarly to merging multiple table partitions, there is an option for
-     splitting a single partition into multiple using the
+     splitting a single partition into multiple partitions using
      <link linkend="sql-altertable-split-partition"><command>ALTER TABLE ... SPLIT PARTITION</command></link>.
      This feature could come in handy when one partition grows too big
      and needs to be split into multiple.  It's important to note that
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index fe36ff82e52..e52cfee840c 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1136,16 +1136,16 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       If the split partition is a DEFAULT partition, one of the new partitions must be DEFAULT.
       In case one of the new partitions or one of existing partitions is DEFAULT,
       new partitions <replaceable class="parameter">partition_name1</replaceable>,
-      <replaceable class="parameter">partition_name2</replaceable>, ... can have spaces
+      <replaceable class="parameter">partition_name2</replaceable>, ... can have gaps
       between partitions bounds.  If the partitioned table does not have a DEFAULT
       partition, the DEFAULT partition can be defined as one of the new partitions.
      </para>
      <para>
       In case new partitions do not contain a DEFAULT partition and the partitioned table
-      does not have a DEFAULT partition, the following must be true: sum bounds of
+      does not have a DEFAULT partition, the following must be true: the sum bounds of
       new partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable>, ... should be
-      equal to bound of split partition <replaceable class="parameter">partition_name</replaceable>.
+      equal to the bounds of split partition <replaceable class="parameter">partition_name</replaceable>.
       One of the new partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable>, ... can have
       the same name as split partition <replaceable class="parameter">partition_name</replaceable>
@@ -1168,24 +1168,24 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
     <listitem>
      <para>
-      This form merges several partitions into the one partition of the target table.
-      Hash-partitioning is not supported.  If DEFAULT partition is not in the
+      This form merges several partitions of the target table into a single partition.
+      Hash-partitioning is not supported.  If a DEFAULT partition is not in the
       list of partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable> [, ...]:
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables it is necessary that the ranges
+         For range-partitioned tables, it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
-         be merged into one range without spaces and overlaps (otherwise an error
+         be merged into one range with neither gaps nor overlaps (otherwise an error
          will be generated).  The combined range will be the range for the partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the value lists of all partitions
+         For list-partitioned tables, the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
          combined and form the list of values of partition
@@ -1193,7 +1193,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
         </para>
        </listitem>
       </itemizedlist>
-      If DEFAULT partition is in the list of partitions <replaceable class="parameter">partition_name1</replaceable>,
+      If a DEFAULT partition is in the list of partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable> [, ...]:
       <itemizedlist>
        <listitem>
@@ -1204,8 +1204,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For range- and list-partitioned tables the ranges and lists of values
-         of the merged partitions can be any.
+         For range- and list-partitioned tables, the ranges and lists of values
+         of the merged partitions can be anything.
         </para>
        </listitem>
       </itemizedlist>
-- 
2.39.3 (Apple Git-145)



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-22 10:31                                       ` Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-22 10:31 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

On Fri, Apr 19, 2024 at 4:29 PM Alexander Korotkov <[email protected]> wrote:
> On Fri, Apr 19, 2024 at 2:26 AM Dmitry Koval <[email protected]> wrote:
> > 18.04.2024 19:00, Alexander Lakhin wrote:
> > > leaves a strange constraint:
> > > \d+ t*
> > >                                            Table "public.tp_0"
> > > ...
> > > Not-null constraints:
> > >      "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"
> >
> > Thanks!
> > Attached fix (with test) for this case.
> > The patch should be applied after patches
> > v6-0001- ... .patch ... v6-0004- ... .patch
>
> I've incorporated this fix with 0001 patch.
>
> Also added to the patchset
> 005 – tab completion by Dagfinn [1]
> 006 – draft fix for table AM issue spotted by Alexander Lakhin [2]
> 007 – doc review by Justin [3]
>
> I'm continuing work on this.
>
> Links
> 1. https://www.postgresql.org/message-id/87plumiox2.fsf%40wibble.ilmari.org
> 2. https://www.postgresql.org/message-id/84ada05b-be5c-473e-6d1c-ebe5dd21b190%40gmail.com
> 3. https://www.postgresql.org/message-id/ZiGH0xc1lxJ71ZfB%40pryzbyj2023

0001
The way we handle name collisions during MERGE PARTITIONS operation is
reworked by integration of patch [3].  This makes note about commit in
[2] not relevant.

0002
The persistence of the new partition is copied as suggested in [1].
But the checks are in-place, because search_path could influence new
table persistence.  Per review [2], commit message typos are fixed,
documentation is revised, revised tests to cover schema-qualification,
usage of search_path.

0003
Making code more clear that we're not going to dereference the NULL
datum per note in [2].

0004
Gender-neutral terms are used per suggestions in [2].

0005
Commit message revised

0006
Revise documentation mentioning we're going to copy the parent's table
AM.  Regression tests are added.  Commit message revised.

0007
Commit message revised

Links
1. https://www.postgresql.org/message-id/CA%2BTgmoYcjL%2Bw2BQzku5iNXKR5fyxJMSP3avQta8xngioTX7D7A%40mail...
2. https://www.postgresql.org/message-id/CA%2BTgmoY_4r6BeeSCTim04nAiCmmXg-1pG1toxQovZOP2qaFJ0A%40mail.g...
3. https://www.postgresql.org/message-id/f8b5cbf5-965e-4e5b-b506-33bbf41b0d50%40postgrespro.ru

------
Regards,
Alexander Korotkov


Attachments:

  [application/octet-stream] v8-0003-Fix-error-message-in-check_partition_bounds_for_s.patch (4.0K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/2-v8-0003-Fix-error-message-in-check_partition_bounds_for_s.patch)
  download | inline diff:
From f1b75b45cb6c7f0070344f4d4e3d7b14b7792733 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:56:51 +0300
Subject: [PATCH v8 3/7] Fix error message in
 check_partition_bounds_for_split_range()

Currently, the error message is produced by a system of complex substitutions
making it quite untranslatable and hard to read.  This commit splits this into
4 plain error messages suitable for translation.

Reported-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20240408.152402.1485994009160660141.horikyota.ntt%40gmail.com
---
 src/backend/partitioning/partbounds.c | 71 +++++++++++++++++++--------
 1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index b08edf87a69..2fb39e3d006 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5211,7 +5211,7 @@ check_partition_bounds_for_split_range(Relation parent,
 	if (first || last)
 	{
 		PartitionBoundSpec *split_spec = get_partition_bound_spec(splitPartOid, splitPartName);
-		bool		overlap = false;
+		PartitionRangeDatum *datum;
 
 		if (first)
 		{
@@ -5229,8 +5229,30 @@ check_partition_bounds_for_split_range(Relation parent,
 			 * Lower bound of "spec" should be equal (or greater than or equal
 			 * in case defaultPart=true) to lower bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval < 0))
-				overlap = true;
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+				{
+					datum = list_nth(spec->lowerdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is not equal to lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
+			else
+			{
+				if (cmpval < 0)
+				{
+					datum = list_nth(spec->lowerdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is less than lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
 		}
 		else
 		{
@@ -5243,29 +5265,36 @@ check_partition_bounds_for_split_range(Relation parent,
 										  key->partcollation,
 										  upper->datums, upper->kind,
 										  false, split_upper);
+			datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) - 1) : NULL;
 
 			/*
 			 * Upper bound of "spec" should be equal (or less than or equal in
 			 * case defaultPart=true) to upper bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval > 0))
-				overlap = true;
-		}
-
-		if (overlap)
-		{
-			PartitionRangeDatum *datum;
-
-			datum = list_nth(first ? spec->lowerdatums : spec->upperdatums, abs(cmpval) - 1);
-
-			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-					 errmsg("%s bound of partition \"%s\" is %s %s bound of split partition",
-							first ? "lower" : "upper",
-							relname,
-							defaultPart ? (first ? "less than" : "greater than") : "not equal to",
-							first ? "lower" : "upper"),
-					 parser_errposition(pstate, datum->location)));
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+				{
+					datum = list_nth(spec->upperdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is not equal to upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
+			else
+			{
+				if (cmpval > 0)
+				{
+					datum = list_nth(spec->upperdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is greater than upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
 		}
 	}
 }
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v8-0004-Rename-tables-in-tests-of-partition-MERGE-SPLIT-o.patch (205.0K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/3-v8-0004-Rename-tables-in-tests-of-partition-MERGE-SPLIT-o.patch)
  download | inline diff:
From 3b0d557c29c15ded94908114ed7ab1fe7cc1ab75 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 11:31:57 +0300
Subject: [PATCH v8 4/7] Rename tables in tests of partition MERGE/SPLIT
 operations

Replace "salesman" with "salesperson", "salesmen" with "salespeople".  The
names are both gramatically correct and gender-neutral.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/fdaa003e-919c-cbc9-4f0c-e4546e96bd65%40gmail.com
Reviewed-by: Robert Haas
---
 src/test/regress/expected/partition_merge.out |  666 ++++-----
 src/test/regress/expected/partition_split.out | 1266 ++++++++---------
 src/test/regress/sql/partition_merge.sql      |  160 +--
 src/test/regress/sql/partition_split.sql      |  280 ++--
 4 files changed, 1186 insertions(+), 1186 deletions(-)

diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 3aae5f89e80..a92a270c591 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -11,12 +11,12 @@ SET search_path = partitions_merge_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_dec2021 PARTITION OF sales_range FOR VALUES FROM ('2021-12-01') TO ('2021-12-31');
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-15');
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
@@ -60,7 +60,7 @@ DROP TABLE sales_range;
 --
 -- Add rows into partitioned table, then merge partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -122,68 +122,68 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemanam
 (1 row)
 
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (10 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          11 | Trump         |          380 | 04-06-2022
-           5 | Deev          |          250 | 04-07-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             11 | Trump            |          380 | 04-06-2022
+              5 | Deev             |          250 | 04-07-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (10 rows)
 
 RESET enable_seqscan;
@@ -191,7 +191,7 @@ DROP TABLE sales_range;
 --
 -- Merge some partitions into DEFAULT partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -216,15 +216,15 @@ INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 -- name
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022, sales_others) INTO sales_others;
 select * from sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (7 rows)
 
 -- show partitions with conditions:
@@ -246,7 +246,7 @@ DROP TABLE sales_range;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -255,219 +255,219 @@ CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1)
 CREATE TABLE sales_jan2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1);
 CREATE TABLE sales_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (9 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
 (2 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
 (2 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 ALTER TABLE sales_date MERGE PARTITIONS (sales_jan2022, sales_feb2022) INTO sales_jan_feb2022;
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (11 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
 (6 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_20 PARTITION OF salespeople FOR VALUES FROM (10) TO (20);
+CREATE TABLE salespeople20_30 PARTITION OF salespeople FOR VALUES FROM (20) TO (30);
+CREATE TABLE salespeople30_40 PARTITION OF salespeople FOR VALUES FROM (30) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (10, 'May');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+INSERT INTO salespeople10_20 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+INSERT INTO salespeople10_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
-          20 | Smirnoff
-          30 | Ford
+SELECT * FROM salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
+             20 | Smirnoff
+             30 | Ford
 (4 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
-select * from salesmans;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
-          19 | Ivanov
-          10 | May
-          20 | Smirnoff
-          31 | Popov
-          30 | Ford
+CREATE TABLE salespeople10_20(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+CREATE TABLE salespeople20_30(salesperson_id INT PRIMARY KEY, d2 INT,  salesperson_name VARCHAR(30));
+CREATE TABLE salespeople30_40(salesperson_id INT PRIMARY KEY, d3 DATE, salesperson_name VARCHAR(30));
+INSERT INTO salespeople10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salespeople20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salespeople30_40 VALUES (31, now(), 'Popov');
+ALTER TABLE salespeople10_20 DROP COLUMN d1;
+ALTER TABLE salespeople20_30 DROP COLUMN d2;
+ALTER TABLE salespeople30_40 DROP COLUMN d3;
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salespeople ATTACH PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salespeople ATTACH PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40);
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
+select * from salespeople;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
+             19 | Ivanov
+             10 | May
+             20 | Smirnoff
+             31 | Popov
+             30 | Ford
 (6 rows)
 
-select * from salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+select * from salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-select * from salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          19 | Ivanov
-          10 | May
-          20 | Smirnoff
-          31 | Popov
-          30 | Ford
+select * from salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             19 | Ivanov
+             10 | May
+             20 | Smirnoff
+             31 | Popov
+             30 | Ford
 (5 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 --
 -- Test: merge sub-partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr2022_01_10 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-10');
 CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');
 CREATE TABLE sales_apr2022_20_30 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01');
@@ -489,88 +489,88 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr2022_01_10;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_apr2022_10_20;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           4 | Ivanov        |          750 | 04-13-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              4 | Ivanov           |          750 | 04-13-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_20_30;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
 (1 row)
 
 ALTER TABLE sales_apr2022 MERGE PARTITIONS (sales_apr2022_01_10, sales_apr2022_10_20, sales_apr2022_20_30) INTO sales_apr_all;
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr_all;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 DROP TABLE sales_range;
@@ -581,8 +581,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -614,33 +614,33 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, MERGE PARTITIONS with data
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_west PARTITION OF sales_list FOR VALUES IN ('Lisbon', 'New York', 'Madrid');
 CREATE TABLE sales_east PARTITION OF sales_list FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok');
 CREATE TABLE sales_central PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
@@ -669,68 +669,68 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 (3 rows)
 
 SELECT * FROM sales_list;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           2 | Smirnoff      | New York       |          500 | 03-03-2022
-           5 | Deev          | Lisbon         |          250 | 03-07-2022
-          11 | Muller        | Madrid         |          650 | 03-05-2022
-          14 | Plato         | Lisbon         |          950 | 03-05-2022
-           1 | Trump         | Bejing         |         1000 | 03-01-2022
-           8 | Li            | Vladivostok    |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw         |          750 | 03-04-2022
-           6 | Poirot        | Berlin         |         1000 | 03-01-2022
-          12 | Smith         | Kyiv           |          350 | 03-10-2022
-          13 | Gandi         | Warsaw         |          150 | 03-08-2022
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Helsinki       |         1200 | 03-06-2022
-           9 | May           | Helsinki       |         1200 | 03-11-2022
-          10 | Halder        | Oslo           |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              2 | Smirnoff         | New York       |          500 | 03-03-2022
+              5 | Deev             | Lisbon         |          250 | 03-07-2022
+             11 | Muller           | Madrid         |          650 | 03-05-2022
+             14 | Plato            | Lisbon         |          950 | 03-05-2022
+              1 | Trump            | Bejing         |         1000 | 03-01-2022
+              8 | Li               | Vladivostok    |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw         |          750 | 03-04-2022
+              6 | Poirot           | Berlin         |         1000 | 03-01-2022
+             12 | Smith            | Kyiv           |          350 | 03-10-2022
+             13 | Gandi            | Warsaw         |          150 | 03-08-2022
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Helsinki       |         1200 | 03-06-2022
+              9 | May              | Helsinki       |         1200 | 03-11-2022
+             10 | Halder           | Oslo           |          800 | 03-02-2022
 (14 rows)
 
 SELECT * FROM sales_nord;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Helsinki       |         1200 | 03-06-2022
-           9 | May           | Helsinki       |         1200 | 03-11-2022
-          10 | Halder        | Oslo           |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Helsinki       |         1200 | 03-06-2022
+              9 | May              | Helsinki       |         1200 | 03-11-2022
+             10 | Halder           | Oslo           |          800 | 03-02-2022
 (4 rows)
 
 SELECT * FROM sales_all;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           2 | Smirnoff      | New York    |          500 | 03-03-2022
-           5 | Deev          | Lisbon      |          250 | 03-07-2022
-          11 | Muller        | Madrid      |          650 | 03-05-2022
-          14 | Plato         | Lisbon      |          950 | 03-05-2022
-           1 | Trump         | Bejing      |         1000 | 03-01-2022
-           8 | Li            | Vladivostok |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-           6 | Poirot        | Berlin      |         1000 | 03-01-2022
-          12 | Smith         | Kyiv        |          350 | 03-10-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              2 | Smirnoff         | New York    |          500 | 03-03-2022
+              5 | Deev             | Lisbon      |          250 | 03-07-2022
+             11 | Muller           | Madrid      |          650 | 03-05-2022
+             14 | Plato            | Lisbon      |          950 | 03-05-2022
+              1 | Trump            | Bejing      |         1000 | 03-01-2022
+              8 | Li               | Vladivostok |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+              6 | Poirot           | Berlin      |         1000 | 03-01-2022
+             12 | Smith            | Kyiv        |          350 | 03-10-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
 -- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
 (1 row)
 
 RESET enable_seqscan;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index e2a362ffafd..55ae37ad370 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -11,7 +11,7 @@ SET search_path = partition_split_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id int, salesman_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id int, salesperson_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -85,8 +85,8 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
-LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
-                                                             ^
+LINE 4:    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO...
+                                                    ^
 -- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
@@ -114,13 +114,13 @@ SPLIT PARTITION partition_split_schema.sales_feb_mar_apr2022 INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 SET search_path = partition_split_schema, public;
 \d+ sales_range
-                             Partitioned table "partition_split_schema.sales_range"
-    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
----------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
- salesman_id   | integer               |           |          |         | plain    |              | 
- salesman_name | character varying(30) |           |          |         | extended |              | 
- sales_amount  | integer               |           |          |         | plain    |              | 
- sales_date    | date                  |           |          |         | plain    |              | 
+                              Partitioned table "partition_split_schema.sales_range"
+      Column      |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+------------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesperson_id   | integer               |           |          |         | plain    |              | 
+ salesperson_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount     | integer               |           |          |         | plain    |              | 
+ sales_date       | date                  |           |          |         | plain    |              | 
 Partition key: RANGE (sales_date)
 Partitions: partition_split_schema2.sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
             partition_split_schema2.sales_feb2022 FOR VALUES FROM ('02-01-2022') TO ('03-01-2022'),
@@ -132,7 +132,7 @@ DROP TABLE sales_others;
 --
 -- Add rows into partitioned table then split partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -155,68 +155,68 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 DROP TABLE sales_range CASCADE;
 --
 -- Add split partition, then add rows into partitioned table
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -226,13 +226,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION partition_split_schema2.sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 \d+ sales_range
-                             Partitioned table "partition_split_schema.sales_range"
-    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
----------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
- salesman_id   | integer               |           |          |         | plain    |              | 
- salesman_name | character varying(30) |           |          |         | extended |              | 
- sales_amount  | integer               |           |          |         | plain    |              | 
- sales_date    | date                  |           |          |         | plain    |              | 
+                              Partitioned table "partition_split_schema.sales_range"
+      Column      |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+------------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesperson_id   | integer               |           |          |         | plain    |              | 
+ salesperson_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount     | integer               |           |          |         | plain    |              | 
+ sales_date       | date                  |           |          |         | plain    |              | 
 Partition key: RANGE (sales_date)
 Partitions: partition_split_schema2.sales_mar2022 FOR VALUES FROM ('03-01-2022') TO ('04-01-2022'),
             sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
@@ -255,61 +255,61 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM partition_split_schema2.sales_mar2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 DROP TABLE sales_range CASCADE;
@@ -319,7 +319,7 @@ DROP TABLE sales_range CASCADE;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -327,103 +327,103 @@ CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month
 CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1) TO (2022, 1, 1);
 CREATE TABLE sales_jan_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (9 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
 (4 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 ALTER TABLE sales_date SPLIT PARTITION sales_jan_feb2022 INTO
   (PARTITION sales_jan2022 FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1),
    PARTITION sales_feb2022 FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1));
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (11 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
 (3 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 --ERROR:  relation "sales_jan_feb2022" does not exist
@@ -435,7 +435,7 @@ DROP TABLE sales_date CASCADE;
 --
 -- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date);
@@ -454,19 +454,19 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-           6 | Poirot        |          150 | 02-11-2022
-           7 | Li            |          175 | 03-08-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          11 | Trump         |          380 | 04-06-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+              6 | Poirot           |          150 | 02-11-2022
+              7 | Li               |          175 | 03-08-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             11 | Trump            |          380 | 04-06-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (11 rows)
 
 SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'partition_split_schema';
@@ -484,34 +484,34 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          11 | Trump         |          380 | 04-06-2022
-           5 | Deev          |          250 | 04-07-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             11 | Trump            |          380 | 04-06-2022
+              5 | Deev             |          250 | 04-07-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_others where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 SET enable_indexscan = ON;
@@ -544,7 +544,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Test: some cases for splitting DEFAULT partition (different bounds)
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 -- sales_error intersects with sales_dec2022 (lower bound)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
@@ -601,7 +601,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 DROP TABLE sales_range;
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 -- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
@@ -613,20 +613,20 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesperson_id INT REFERENCES salespeople(salesperson_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb_mar_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
@@ -635,50 +635,50 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 -- We should see the same CONSTRAINTs as on sales_feb_mar_apr2022 partition
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
--- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
-ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(-1) is not present in table "salesmans".
+ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
+DETAIL:  Key (salesperson_id)=(-1) is not present in table "salespeople".
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (19, 'Ivanov');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (30, 'Ford');
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
 INSERT INTO sales VALUES (10, 150, '2022-03-01');
@@ -687,280 +687,280 @@ INSERT INTO sales VALUES (19, 200, '2022-03-04');
 INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
-          20 | Smirnoff
-          30 | Ford
+SELECT * FROM salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
+             20 | Smirnoff
+             30 | Ford
 (4 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
+SELECT * FROM salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+SELECT * FROM salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+SELECT * FROM salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
--- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
-ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(40) is not present in table "salesmans".
+ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
+DETAIL:  Key (salesperson_id)=(40) is not present in table "salespeople".
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (10, 'May');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+INSERT INTO salespeople10_40 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+INSERT INTO salespeople30_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
+SELECT * FROM salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+SELECT * FROM salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+SELECT * FROM salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salespeople(salesperson_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople1_2 PARTITION OF salespeople FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+CREATE TABLE salespeople2_5(salesperson_id INT NOT NULL, salesperson_name VARCHAR(30));
+ALTER TABLE salespeople ATTACH PARTITION salespeople2_5 FOR VALUES FROM (2) TO (5);
+INSERT INTO salespeople (salesperson_name) VALUES ('Poirot');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ivanov');
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_5'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
-SELECT * FROM salesmans1_2;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+ALTER TABLE salespeople SPLIT PARTITION salespeople2_5 INTO
+  (PARTITION salespeople2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salespeople3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salespeople4_5 FOR VALUES FROM (4) TO (5));
+INSERT INTO salespeople (salesperson_name) VALUES ('May');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ford');
+SELECT * FROM salespeople1_2;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans2_3;
- salesman_id | salesman_name 
--------------+---------------
-           2 | Ivanov
+SELECT * FROM salespeople2_3;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              2 | Ivanov
 (1 row)
 
-SELECT * FROM salesmans3_4;
- salesman_id | salesman_name 
--------------+---------------
-           3 | May
+SELECT * FROM salespeople3_4;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              3 | May
 (1 row)
 
-SELECT * FROM salesmans4_5;
- salesman_id | salesman_name 
--------------+---------------
-           4 | Ford
+SELECT * FROM salespeople4_5;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              4 | Ford
 (1 row)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_3'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople3_4'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople4_5'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-select * from salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+CREATE TABLE salespeople10_40(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, d2 INT, d3 DATE, salesperson_name VARCHAR(30));
+INSERT INTO salespeople10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salespeople10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+ALTER TABLE salespeople10_40 DROP COLUMN d1;
+ALTER TABLE salespeople10_40 DROP COLUMN d2;
+ALTER TABLE salespeople10_40 DROP COLUMN d3;
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_40 FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
+select * from salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-select * from salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          19 | Ivanov
-          10 | May
+select * from salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             19 | Ivanov
+             10 | May
 (2 rows)
 
-select * from salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+select * from salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-select * from salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+select * from salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split sub-partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_all PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -980,31 +980,31 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 ALTER TABLE sales_apr2022 SPLIT PARTITION sales_apr_all INTO
@@ -1012,50 +1012,50 @@ ALTER TABLE sales_apr2022 SPLIT PARTITION sales_apr_all INTO
    PARTITION sales_apr2022_10_20 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20'),
    PARTITION sales_apr2022_20_30 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01'));
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr2022_01_10;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_apr2022_10_20;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           4 | Ivanov        |          750 | 04-13-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              4 | Ivanov           |          750 | 04-13-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_20_30;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
 (1 row)
 
 DROP TABLE sales_range;
@@ -1066,8 +1066,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -1106,8 +1106,8 @@ DROP TABLE sales_list;
 --   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -1131,109 +1131,109 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
 --
 CREATE TABLE sales_list
-(salesman_id SERIAL,
- salesman_name VARCHAR(30),
+(salesperson_id SERIAL,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 SELECT * FROM sales_list;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           1 | Trump         | Bejing         |         1000 | 03-01-2022
-           8 | Li            | Vladivostok    |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw         |          750 | 03-04-2022
-           6 | Poirot        | Berlin         |         1000 | 03-01-2022
-          12 | Smith         | Kyiv           |          350 | 03-10-2022
-          13 | Gandi         | Warsaw         |          150 | 03-08-2022
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Oslo           |         1200 | 03-06-2022
-           9 | May           | Oslo           |         1200 | 03-11-2022
-          10 | Halder        | Helsinki       |          800 | 03-02-2022
-           2 | Smirnoff      | New York       |          500 | 03-03-2022
-           5 | Deev          | Lisbon         |          250 | 03-07-2022
-          11 | Muller        | Madrid         |          650 | 03-05-2022
-          14 | Plato         | Lisbon         |          950 | 03-05-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              1 | Trump            | Bejing         |         1000 | 03-01-2022
+              8 | Li               | Vladivostok    |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw         |          750 | 03-04-2022
+              6 | Poirot           | Berlin         |         1000 | 03-01-2022
+             12 | Smith            | Kyiv           |          350 | 03-10-2022
+             13 | Gandi            | Warsaw         |          150 | 03-08-2022
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Oslo           |         1200 | 03-06-2022
+              9 | May              | Oslo           |         1200 | 03-11-2022
+             10 | Halder           | Helsinki       |          800 | 03-02-2022
+              2 | Smirnoff         | New York       |          500 | 03-03-2022
+              5 | Deev             | Lisbon         |          250 | 03-07-2022
+             11 | Muller           | Madrid         |          650 | 03-05-2022
+             14 | Plato            | Lisbon         |          950 | 03-05-2022
 (14 rows)
 
 SELECT * FROM sales_west;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           2 | Smirnoff      | New York    |          500 | 03-03-2022
-           5 | Deev          | Lisbon      |          250 | 03-07-2022
-          11 | Muller        | Madrid      |          650 | 03-05-2022
-          14 | Plato         | Lisbon      |          950 | 03-05-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              2 | Smirnoff         | New York    |          500 | 03-03-2022
+              5 | Deev             | Lisbon      |          250 | 03-07-2022
+             11 | Muller           | Madrid      |          650 | 03-05-2022
+             14 | Plato            | Lisbon      |          950 | 03-05-2022
 (4 rows)
 
 SELECT * FROM sales_east;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           1 | Trump         | Bejing      |         1000 | 03-01-2022
-           8 | Li            | Vladivostok |         1150 | 03-09-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              1 | Trump            | Bejing      |         1000 | 03-01-2022
+              8 | Li               | Vladivostok |         1150 | 03-09-2022
 (2 rows)
 
 SELECT * FROM sales_nord;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Oslo           |         1200 | 03-06-2022
-           9 | May           | Oslo           |         1200 | 03-11-2022
-          10 | Halder        | Helsinki       |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Oslo           |         1200 | 03-06-2022
+              9 | May              | Oslo           |         1200 | 03-11-2022
+             10 | Halder           | Helsinki       |          800 | 03-02-2022
 (4 rows)
 
 SELECT * FROM sales_central;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-           6 | Poirot        | Berlin      |         1000 | 03-01-2022
-          12 | Smith         | Kyiv        |          350 | 03-10-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+              6 | Poirot           | Berlin      |         1000 | 03-01-2022
+             12 | Smith            | Kyiv        |          350 | 03-10-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
 -- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
 (1 row)
 
 SET enable_indexscan = ON;
@@ -1244,7 +1244,7 @@ DROP TABLE sales_list;
 --   * split DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-09');
@@ -1267,42 +1267,42 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022_1decade FOR VALUES FROM ('2022-02-01') TO ('2022-02-10'),
    PARTITION sales_apr2022_1decade FOR VALUES FROM ('2022-04-01') TO ('2022-04-10'));
 SELECT * FROM sales_jan2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             13 | Gandi            |          377 | 01-09-2022
 (1 row)
 
 SELECT * FROM sales_feb2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-09-2022
-           6 | Poirot        |          150 | 02-07-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-09-2022
+              6 | Poirot           |          150 | 02-07-2022
 (2 rows)
 
 SELECT * FROM sales_mar2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          10 | Halder        |          350 | 01-28-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             10 | Halder           |          350 | 01-28-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (8 rows)
 
 DROP TABLE sales_range;
@@ -1311,7 +1311,7 @@ DROP TABLE sales_range;
 --   * split non-DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -1334,42 +1334,42 @@ ALTER TABLE sales_range SPLIT PARTITION sales_all INTO
    PARTITION sales_feb2022_1decade FOR VALUES FROM ('2022-02-01') TO ('2022-02-10'),
    PARTITION sales_apr2022_1decade FOR VALUES FROM ('2022-04-01') TO ('2022-04-10'));
 SELECT * FROM sales_jan2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             13 | Gandi            |          377 | 01-09-2022
 (1 row)
 
 SELECT * FROM sales_feb2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-09-2022
-           6 | Poirot        |          150 | 02-07-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-09-2022
+              6 | Poirot           |          150 | 02-07-2022
 (2 rows)
 
 SELECT * FROM sales_mar2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
-           1 | May           |         1000 | 01-31-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          10 | Halder        |          350 | 01-28-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
+              1 | May              |         1000 | 01-31-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             10 | Halder           |          350 | 01-28-2022
+             12 | Plato            |          350 | 03-19-2022
 (8 rows)
 
 DROP TABLE sales_range;
@@ -1377,7 +1377,7 @@ DROP TABLE sales_range;
 -- Test for split non-DEFAULT partition to DEFAULT partition + partitions
 -- with spaces between bounds.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -1399,56 +1399,56 @@ ALTER TABLE sales_range SPLIT PARTITION sales_all INTO
    PARTITION sales_others DEFAULT);
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (4 rows)
 
 DROP TABLE sales_range;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 5a69425d96e..085c422d540 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -14,13 +14,13 @@ SET search_path = partitions_merge_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_dec2021 PARTITION OF sales_range FOR VALUES FROM ('2021-12-01') TO ('2021-12-31');
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-15');
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
@@ -56,7 +56,7 @@ DROP TABLE sales_range;
 --
 -- Add rows into partitioned table, then merge partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -115,7 +115,7 @@ DROP TABLE sales_range;
 --
 -- Merge some partitions into DEFAULT partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -158,7 +158,7 @@ DROP TABLE sales_range;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -169,15 +169,15 @@ CREATE TABLE sales_jan2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1)
 CREATE TABLE sales_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -187,8 +187,8 @@ SELECT * FROM sales_other;
 
 ALTER TABLE sales_date MERGE PARTITIONS (sales_jan2022, sales_feb2022) INTO sales_jan_feb2022;
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -200,14 +200,14 @@ DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_20 PARTITION OF salespeople FOR VALUES FROM (10) TO (20);
+CREATE TABLE salespeople20_30 PARTITION OF salespeople FOR VALUES FROM (20) TO (30);
+CREATE TABLE salespeople30_40 PARTITION OF salespeople FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -216,80 +216,80 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salespeople VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
+INSERT INTO salespeople10_20 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
+INSERT INTO salespeople10_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salespeople10_20(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+CREATE TABLE salespeople20_30(salesperson_id INT PRIMARY KEY, d2 INT,  salesperson_name VARCHAR(30));
+CREATE TABLE salespeople30_40(salesperson_id INT PRIMARY KEY, d3 DATE, salesperson_name VARCHAR(30));
 
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
+INSERT INTO salespeople10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salespeople20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salespeople30_40 VALUES (31, now(), 'Popov');
 
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
+ALTER TABLE salespeople10_20 DROP COLUMN d1;
+ALTER TABLE salespeople20_30 DROP COLUMN d2;
+ALTER TABLE salespeople30_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salespeople ATTACH PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salespeople ATTACH PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 
-select * from salesmans;
-select * from salesmans01_10;
-select * from salesmans10_40;
+select * from salespeople;
+select * from salespeople01_10;
+select * from salespeople10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 
 --
 -- Test: merge sub-partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr2022_01_10 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-10');
 CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');
 CREATE TABLE sales_apr2022_20_30 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01');
@@ -336,8 +336,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -373,14 +373,14 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, MERGE PARTITIONS with data
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
 
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
@@ -389,20 +389,20 @@ CREATE TABLE sales_east PARTITION OF sales_list FOR VALUES IN ('Bejing', 'Delhi'
 CREATE TABLE sales_central PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
@@ -427,7 +427,7 @@ SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
 
 RESET enable_seqscan;
 
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index b4430133522..3a7f2f9c294 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -14,7 +14,7 @@ SET search_path = partition_split_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id int, salesman_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id int, salesperson_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -109,7 +109,7 @@ DROP TABLE sales_others;
 --
 -- Add rows into partitioned table then split partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -146,7 +146,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Add split partition, then add rows into partitioned table
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -188,7 +188,7 @@ DROP TABLE sales_range CASCADE;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -198,15 +198,15 @@ CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1)
 CREATE TABLE sales_jan_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -217,8 +217,8 @@ ALTER TABLE sales_date SPLIT PARTITION sales_jan_feb2022 INTO
   (PARTITION sales_jan2022 FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1),
    PARTITION sales_feb2022 FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1));
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -234,7 +234,7 @@ DROP TABLE sales_date CASCADE;
 --
 -- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date);
@@ -285,7 +285,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Test: some cases for splitting DEFAULT partition (different bounds)
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- sales_error intersects with sales_dec2022 (lower bound)
@@ -335,7 +335,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 
 DROP TABLE sales_range;
 
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
@@ -350,11 +350,11 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesperson_id INT REFERENCES salespeople(salesperson_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 
@@ -376,28 +376,28 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
--- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (19, 'Ivanov');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
@@ -408,36 +408,36 @@ INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_40;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_20;
+SELECT * FROM salespeople20_30;
+SELECT * FROM salespeople30_40;
 
--- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -446,125 +446,125 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salespeople VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
+INSERT INTO salespeople10_40 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
+INSERT INTO salespeople30_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_20;
+SELECT * FROM salespeople20_30;
+SELECT * FROM salespeople30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salespeople1_2 PARTITION OF salespeople FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
+CREATE TABLE salespeople2_5(salesperson_id INT NOT NULL, salesperson_name VARCHAR(30));
+ALTER TABLE salespeople ATTACH PARTITION salespeople2_5 FOR VALUES FROM (2) TO (5);
 
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
+INSERT INTO salespeople (salesperson_name) VALUES ('Poirot');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ivanov');
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_5'::regclass::oid;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
+ALTER TABLE salespeople SPLIT PARTITION salespeople2_5 INTO
+  (PARTITION salespeople2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salespeople3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salespeople4_5 FOR VALUES FROM (4) TO (5));
 
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
+INSERT INTO salespeople (salesperson_name) VALUES ('May');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ford');
 
-SELECT * FROM salesmans1_2;
-SELECT * FROM salesmans2_3;
-SELECT * FROM salesmans3_4;
-SELECT * FROM salesmans4_5;
+SELECT * FROM salespeople1_2;
+SELECT * FROM salespeople2_3;
+SELECT * FROM salespeople3_4;
+SELECT * FROM salespeople4_5;
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_3'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople3_4'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople4_5'::regclass::oid;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salespeople10_40(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, d2 INT, d3 DATE, salesperson_name VARCHAR(30));
 
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+INSERT INTO salespeople10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salespeople10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
 
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
+ALTER TABLE salespeople10_40 DROP COLUMN d1;
+ALTER TABLE salespeople10_40 DROP COLUMN d2;
+ALTER TABLE salespeople10_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_40 FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
-select * from salesmans01_10;
-select * from salesmans10_20;
-select * from salesmans20_30;
-select * from salesmans30_40;
+select * from salespeople01_10;
+select * from salespeople10_20;
+select * from salespeople20_30;
+select * from salespeople30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split sub-partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_all PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 
@@ -611,8 +611,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -648,8 +648,8 @@ DROP TABLE sales_list;
 --   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -676,34 +676,34 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
 --
 CREATE TABLE sales_list
-(salesman_id SERIAL,
- salesman_name VARCHAR(30),
+(salesperson_id SERIAL,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
 
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
@@ -722,7 +722,7 @@ SET enable_seqscan = OFF;
 
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
 
 SET enable_indexscan = ON;
 SET enable_seqscan = ON;
@@ -734,7 +734,7 @@ DROP TABLE sales_list;
 --   * split DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -772,7 +772,7 @@ DROP TABLE sales_range;
 --   * split non-DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
@@ -809,7 +809,7 @@ DROP TABLE sales_range;
 -- Test for split non-DEFAULT partition to DEFAULT partition + partitions
 -- with spaces between bounds.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v8-0002-Make-new-partitions-with-parent-s-persistence-dur.patch (37.6K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/4-v8-0002-Make-new-partitions-with-parent-s-persistence-dur.patch)
  download | inline diff:
From f10a3a01abbd782d5ae49b4da819c0100490fb90 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:41:09 +0300
Subject: [PATCH v8 2/7] Make new partitions with parent's persistence during
 MERGE/SPLIT operations

The createPartitionTable() function is responsible for creating new partitions
for ALTER TABLE ... MERGE PARTITIONS, and ALTER TABLE ... SPLIT PARTITION
commands.  It emulates the behaviour of CREATE TABLE ... (LIKE ...), where
new table persistence should be specified by the user.  In the table
partitioning persistent of the partition and its parent must match.  So, this
commit makes createPartitionTable() copy the persistence of the parent
partition.

Also, this commit makes createPartitionTable() recheck the persistence after
the new table creation.  This is needed because persistence might be affected
by pg_temp in search_path.

This commit also changes the signature of createPartitionTable() making it
take the parent's Relation itself instead of the name of the parent relation,
and return the Relation of new partition.  That doesn't lead to
complications, because both callers have the parent table open and need to
open the new partition.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/dbc8b96c-3cf0-d1ee-860d-0e491da20485%40gmail.com
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas
---
 doc/src/sgml/ref/alter_table.sgml             |  21 +++
 src/backend/commands/tablecmds.c              |  75 ++++++----
 src/test/regress/expected/partition_merge.out | 134 +++++++++++++++---
 src/test/regress/expected/partition_split.out |  75 +++++++++-
 src/test/regress/sql/partition_merge.sql      |  88 +++++++++++-
 src/test/regress/sql/partition_split.sql      |  43 +++++-
 6 files changed, 379 insertions(+), 57 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index fe36ff82e52..a793899b69b 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1153,6 +1153,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       splitting we have a partition with the same name).
       Only simple, non-partitioned partition can be split.
      </para>
+     <para>
+      Any indexes, constraints and user-defined row-level triggers that exist
+      in the parent table are cloned on new partitions
+      <replaceable class="parameter">partition_name1</replaceable>,
+      <replaceable class="parameter">partition_name2</replaceable>, ... .
+      New partitions will have the same column names and types as the
+      partitioned table to which they belong.
+      If the parent table is persistent then new partitions are created
+      persistent.  If the parent table is temporary then new partitions
+      are also created temporary.
+     </para>
      <note>
       <para>
        This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
@@ -1213,6 +1224,16 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       can have the same name as one of the merged partitions.  Only simple,
       non-partitioned partitions can be merged.
      </para>
+     <para>
+      Any indexes, constraints and user-defined row-level triggers that exist
+      in the parent table are cloned on the new partition
+      <replaceable class="parameter">partition_name</replaceable>.
+      The new partition will have the same column names and types as the
+      partitioned table to which it belongs.
+      If the parent table is persistent then the new partition is created
+      persistent.  If the parent table is temporary then the new partition
+      is also created temporary.
+     </para>
      <note>
       <para>
        This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index dbb6ee356bb..1b89e18eb7e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21183,18 +21183,30 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 /*
  * createPartitionTable: create table for a new partition with given name
- * (newPartName) like table (modelRelName)
+ * (newPartName) like table (modelRel)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
-static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+static Relation
+createPartitionTable(RangeVar *newPartName, Relation modelRel,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
+	Relation	newRel;
+
+	/* If existing rel is temp, it must belong to this session */
+	if (modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
+		!modelRel->rd_islocaltemp)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create as partition of temporary relation of another session")));
+
+	/* New partition should have the same persistence as modelRel */
+	newPartName->relpersistence = modelRel->rd_rel->relpersistence;
 
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
@@ -21207,7 +21219,8 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 	createStmt->if_not_exists = false;
 
 	tlc = makeNode(TableLikeClause);
-	tlc->relation = modelRelName;
+	tlc->relation = makeRangeVar(get_namespace_name(RelationGetNamespace(modelRel)),
+								 RelationGetRelationName(modelRel), -1);
 
 	/*
 	 * Indexes will be inherited on "attach new partitions" stage, after data
@@ -21233,6 +21246,35 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 				   NULL,
 				   None_Receiver,
 				   NULL);
+
+	/*
+	 * Open the new partition with no lock, because we already have
+	 * AccessExclusiveLock placed there after creation.
+	 */
+	newRel = table_openrv(newPartName, NoLock);
+
+	/*
+	 * We intended to create the partition with the same persistence as the
+	 * parent table, but we still need to recheck because that might be
+	 * affected by the search_path.  If the parent is permanent, so must be
+	 * all of its partitions.
+	 */
+	if (modelRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		newRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(modelRel))));
+
+	/* Permanent rels cannot be partitions belonging to temporary parent */
+	if (newRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a permanent relation as partition of temporary relation \"%s\"",
+						RelationGetRelationName(modelRel))));
+
+	return newRel;
 }
 
 /*
@@ -21252,7 +21294,6 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	char		tmpRelName[NAMEDATALEN];
 	List	   *newPartRels = NIL;
 	ObjectAddress object;
-	RangeVar   *parentName;
 	Oid			defaultPartOid;
 
 	defaultPartOid = get_default_oid_from_partdesc(RelationGetPartitionDesc(rel, true));
@@ -21324,18 +21365,12 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 
 	/* Create new partitions (like split partition), without indexes. */
-	parentName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-							  RelationGetRelationName(rel), -1);
 	foreach(listptr, cmd->partlist)
 	{
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
-
-		/* Open the new partition and acquire exclusive lock on it. */
-		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
-
+		newPartRel = createPartitionTable(sps->name, rel, context);
 		newPartRels = lappend(newPartRels, newPartRel);
 	}
 
@@ -21539,18 +21574,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	createPartitionTable(cmd->name,
-						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									  RelationGetRelationName(rel), -1),
-						 context);
-
-	/*
-	 * Open the new partition and acquire exclusive lock on it.  This will
-	 * stop all the operations with partitioned table.  This might seem
-	 * excessive, but this is the way we make sure nobody is planning queries
-	 * involving merging partitions.
-	 */
-	newPartRel = table_openrv(cmd->name, AccessExclusiveLock);
+	/* Create table for new partition, use partitioned table as model. */
+	newPartRel = createPartitionTable(cmd->name, rel, context);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 2e0bfdc705d..3aae5f89e80 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -3,6 +3,7 @@
 -- Tests for "ALTER TABLE ... MERGE PARTITIONS ..." command
 --
 CREATE SCHEMA partitions_merge_schema;
+CREATE SCHEMA partitions_merge_schema2;
 SET search_path = partitions_merge_schema, public;
 --
 -- BY RANGE partitioning
@@ -36,18 +37,23 @@ ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of p
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
--- NO ERROR: test for custom partitions order
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_jan2022) INTO sales_jan_feb_mar2022;
+-- NO ERROR: test for custom partitions order, source partitions not in the search_path
+SET search_path = partitions_merge_schema2, public;
+ALTER TABLE partitions_merge_schema.sales_range MERGE PARTITIONS (
+  partitions_merge_schema.sales_feb2022,
+  partitions_merge_schema.sales_mar2022,
+  partitions_merge_schema.sales_jan2022) INTO sales_jan_feb_mar2022;
+SET search_path = partitions_merge_schema, public;
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
-          oid          | relkind | inhdetachpending |                   pg_get_expr                    
------------------------+---------+------------------+--------------------------------------------------
- sales_apr2022         | p       | f                | FOR VALUES FROM ('04-01-2022') TO ('05-01-2022')
- sales_dec2021         | r       | f                | FOR VALUES FROM ('12-01-2021') TO ('12-31-2021')
- sales_jan_feb_mar2022 | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('04-01-2022')
- sales_others          | r       | f                | DEFAULT
+                      oid                       | relkind | inhdetachpending |                   pg_get_expr                    
+------------------------------------------------+---------+------------------+--------------------------------------------------
+ partitions_merge_schema2.sales_jan_feb_mar2022 | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('04-01-2022')
+ sales_apr2022                                  | p       | f                | FOR VALUES FROM ('04-01-2022') TO ('05-01-2022')
+ sales_dec2021                                  | r       | f                | FOR VALUES FROM ('12-01-2021') TO ('12-31-2021')
+ sales_others                                   | r       | f                | DEFAULT
 (4 rows)
 
 DROP TABLE sales_range;
@@ -95,23 +101,24 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
  sales_others  | r       | f                | DEFAULT
 (5 rows)
 
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
+-- check schema-qualified name of the new partition
+ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO partitions_merge_schema2.sales_feb_mar_apr2022;
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
-          oid          | relkind | inhdetachpending |                   pg_get_expr                    
------------------------+---------+------------------+--------------------------------------------------
- sales_feb_mar_apr2022 | r       | f                | FOR VALUES FROM ('02-01-2022') TO ('05-01-2022')
- sales_jan2022         | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('02-01-2022')
- sales_others          | r       | f                | DEFAULT
+                      oid                       | relkind | inhdetachpending |                   pg_get_expr                    
+------------------------------------------------+---------+------------------+--------------------------------------------------
+ partitions_merge_schema2.sales_feb_mar_apr2022 | r       | f                | FOR VALUES FROM ('02-01-2022') TO ('05-01-2022')
+ sales_jan2022                                  | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('02-01-2022')
+ sales_others                                   | r       | f                | DEFAULT
 (3 rows)
 
-SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema';
-       schemaname        |       tablename       |              indexname               | tablespace |                                                          indexdef                                                           
--------------------------+-----------------------+--------------------------------------+------------+-----------------------------------------------------------------------------------------------------------------------------
- partitions_merge_schema | sales_feb_mar_apr2022 | sales_feb_mar_apr2022_sales_date_idx |            | CREATE INDEX sales_feb_mar_apr2022_sales_date_idx ON partitions_merge_schema.sales_feb_mar_apr2022 USING btree (sales_date)
+SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema2';
+        schemaname        |       tablename       |              indexname               | tablespace |                                                           indexdef                                                           
+--------------------------+-----------------------+--------------------------------------+------------+------------------------------------------------------------------------------------------------------------------------------
+ partitions_merge_schema2 | sales_feb_mar_apr2022 | sales_feb_mar_apr2022_sales_date_idx |            | CREATE INDEX sales_feb_mar_apr2022_sales_date_idx ON partitions_merge_schema2.sales_feb_mar_apr2022 USING btree (sales_date)
 (1 row)
 
 SELECT * FROM sales_range;
@@ -141,7 +148,7 @@ SELECT * FROM sales_jan2022;
           13 | Gandi         |          377 | 01-09-2022
 (3 rows)
 
-SELECT * FROM sales_feb_mar_apr2022;
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
  salesman_id | salesman_name | sales_amount | sales_date 
 -------------+---------------+--------------+------------
            2 | Smirnoff      |          500 | 02-10-2022
@@ -164,7 +171,7 @@ SELECT * FROM sales_others;
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
-SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
 -------------+---------------+--------------+------------
            2 | Smirnoff      |          500 | 02-10-2022
@@ -746,6 +753,34 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
@@ -771,4 +806,63 @@ Not-null constraints:
 
 DROP TABLE t;
 --
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = partitions_merge_schema, pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+SET search_path = partitions_merge_schema, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+SET search_path = pg_temp, partitions_merge_schema, public;
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = partitions_merge_schema, pg_temp, public;
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
+DROP SCHEMA partitions_merge_schema2;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 419d169f036..e2a362ffafd 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -3,6 +3,7 @@
 -- Tests for "ALTER TABLE ... SPLIT PARTITION ..." command
 --
 CREATE SCHEMA partition_split_schema;
+CREATE SCHEMA partition_split_schema2;
 SET search_path = partition_split_schema, public;
 --
 -- BY RANGE partitioning
@@ -104,6 +105,28 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO...
                                                     ^
+-- Check the source partition not in the search path
+SET search_path = partition_split_schema2, public;
+ALTER TABLE partition_split_schema.sales_range
+SPLIT PARTITION partition_split_schema.sales_feb_mar_apr2022 INTO
+  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+   PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+SET search_path = partition_split_schema, public;
+\d+ sales_range
+                             Partitioned table "partition_split_schema.sales_range"
+    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+---------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesman_id   | integer               |           |          |         | plain    |              | 
+ salesman_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount  | integer               |           |          |         | plain    |              | 
+ sales_date    | date                  |           |          |         | plain    |              | 
+Partition key: RANGE (sales_date)
+Partitions: partition_split_schema2.sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
+            partition_split_schema2.sales_feb2022 FOR VALUES FROM ('02-01-2022') TO ('03-01-2022'),
+            partition_split_schema2.sales_mar2022 FOR VALUES FROM ('03-01-2022') TO ('04-01-2022'),
+            sales_jan2022 FOR VALUES FROM ('01-01-2022') TO ('02-01-2022')
+
 DROP TABLE sales_range;
 DROP TABLE sales_others;
 --
@@ -197,10 +220,26 @@ CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amou
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
+-- Split partition, also check schema qualification of new partitions
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
-  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
-   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+  (PARTITION partition_split_schema.sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION partition_split_schema2.sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+\d+ sales_range
+                             Partitioned table "partition_split_schema.sales_range"
+    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+---------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesman_id   | integer               |           |          |         | plain    |              | 
+ salesman_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount  | integer               |           |          |         | plain    |              | 
+ sales_date    | date                  |           |          |         | plain    |              | 
+Partition key: RANGE (sales_date)
+Partitions: partition_split_schema2.sales_mar2022 FOR VALUES FROM ('03-01-2022') TO ('04-01-2022'),
+            sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
+            sales_feb2022 FOR VALUES FROM ('02-01-2022') TO ('03-01-2022'),
+            sales_jan2022 FOR VALUES FROM ('01-01-2022') TO ('02-01-2022'),
+            sales_others DEFAULT
+
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-10');
 INSERT INTO sales_range VALUES (3,  'Ford',     2000, '2022-04-30');
@@ -250,7 +289,7 @@ SELECT * FROM sales_feb2022;
            8 | Ericsson      |          185 | 02-23-2022
 (3 rows)
 
-SELECT * FROM sales_mar2022;
+SELECT * FROM partition_split_schema2.sales_mar2022;
  salesman_id | salesman_name | sales_amount | sales_date 
 -------------+---------------+--------------+------------
            7 | Li            |          175 | 03-08-2022
@@ -1427,4 +1466,34 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
+DROP SCHEMA partition_split_schema2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 72b1cb0b35e..5a69425d96e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -4,6 +4,7 @@
 --
 
 CREATE SCHEMA partitions_merge_schema;
+CREATE SCHEMA partitions_merge_schema2;
 SET search_path = partitions_merge_schema, public;
 
 --
@@ -37,8 +38,13 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sal
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
--- NO ERROR: test for custom partitions order
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_jan2022) INTO sales_jan_feb_mar2022;
+-- NO ERROR: test for custom partitions order, source partitions not in the search_path
+SET search_path = partitions_merge_schema2, public;
+ALTER TABLE partitions_merge_schema.sales_range MERGE PARTITIONS (
+  partitions_merge_schema.sales_feb2022,
+  partitions_merge_schema.sales_mar2022,
+  partitions_merge_schema.sales_jan2022) INTO sales_jan_feb_mar2022;
+SET search_path = partitions_merge_schema, public;
 
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
@@ -81,7 +87,8 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
 
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
+-- check schema-qualified name of the new partition
+ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO partitions_merge_schema2.sales_feb_mar_apr2022;
 
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
@@ -89,17 +96,17 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
 
-SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema';
+SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema2';
 
 SELECT * FROM sales_range;
 SELECT * FROM sales_jan2022;
-SELECT * FROM sales_feb_mar_apr2022;
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
-SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022 where sales_date > '2022-01-01';
 
 RESET enable_seqscan;
 
@@ -444,6 +451,28 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
@@ -462,5 +491,52 @@ ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
 
 DROP TABLE t;
 
+--
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = partitions_merge_schema, pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = partitions_merge_schema, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+DROP TABLE t;
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = partitions_merge_schema, pg_temp, public;
+
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
+DROP SCHEMA partitions_merge_schema2;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index b63532ee562..b4430133522 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -4,6 +4,7 @@
 --
 
 CREATE SCHEMA partition_split_schema;
+CREATE SCHEMA partition_split_schema2;
 SET search_path = partition_split_schema, public;
 
 --
@@ -92,6 +93,16 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
+-- Check the source partition not in the search path
+SET search_path = partition_split_schema2, public;
+ALTER TABLE partition_split_schema.sales_range
+SPLIT PARTITION partition_split_schema.sales_feb_mar_apr2022 INTO
+  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+   PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+SET search_path = partition_split_schema, public;
+\d+ sales_range
+
 DROP TABLE sales_range;
 DROP TABLE sales_others;
 
@@ -140,10 +151,12 @@ CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
+-- Split partition, also check schema qualification of new partitions
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
-  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
-   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+  (PARTITION partition_split_schema.sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION partition_split_schema2.sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+\d+ sales_range
 
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-10');
@@ -163,7 +176,7 @@ INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
 SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb2022;
-SELECT * FROM sales_mar2022;
+SELECT * FROM partition_split_schema2.sales_mar2022;
 SELECT * FROM sales_apr2022;
 SELECT * FROM sales_others;
 
@@ -844,5 +857,29 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
+DROP SCHEMA partition_split_schema2;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v8-0005-Add-tab-completion-for-partition-MERGE-SPLIT-oper.patch (2.7K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/5-v8-0005-Add-tab-completion-for-partition-MERGE-SPLIT-oper.patch)
  download | inline diff:
From c86c051eb0fd187f82f0c8111421ccb33f9cceb5 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 13:20:11 +0300
Subject: [PATCH v8 5/7] Add tab completion for partition MERGE/SPLIT
 operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This commit implements psql tab completion for ALTER TABLE ... SPLIT PARTITION
and ALTER TABLE ... MERGE PARTITIONS commands.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/5dee3937-8e9f-cca4-11fb-737709a92b37%40gmail.com
Author: Dagfinn Ilmari Mannsåker
---
 src/bin/psql/tab-complete.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 6fee3160f02..97cd5d9f628 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2353,6 +2353,7 @@ psql_completion(const char *text, int start, int end)
 					  "OWNER TO", "SET", "VALIDATE CONSTRAINT",
 					  "REPLICA IDENTITY", "ATTACH PARTITION",
 					  "DETACH PARTITION", "FORCE ROW LEVEL SECURITY",
+					  "SPLIT PARTITION", "MERGE PARTITIONS (",
 					  "OF", "NOT OF");
 	/* ALTER TABLE xxx ADD */
 	else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
@@ -2609,10 +2610,10 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH("FROM (", "IN (", "WITH (");
 
 	/*
-	 * If we have ALTER TABLE <foo> DETACH PARTITION, provide a list of
+	 * If we have ALTER TABLE <foo> DETACH|SPLIT PARTITION, provide a list of
 	 * partitions of <foo>.
 	 */
-	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION"))
+	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH|SPLIT", "PARTITION"))
 	{
 		set_completion_reference(prev3_wd);
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
@@ -2620,6 +2621,19 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION", MatchAny))
 		COMPLETE_WITH("CONCURRENTLY", "FINALIZE");
 
+	/* ALTER TABLE <name> SPLIT PARTITION <name> */
+	else if (Matches("ALTER", "TABLE", MatchAny, "SPLIT", "PARTITION", MatchAny))
+		COMPLETE_WITH("INTO ( PARTITION");
+
+	/* ALTER TABLE <name> MERGE PARTITIONS ( */
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "("))
+	{
+		set_completion_reference(prev4_wd);
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
+	}
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "(*)"))
+		COMPLETE_WITH("INTO");
+
 	/* ALTER TABLE <name> OF */
 	else if (Matches("ALTER", "TABLE", MatchAny, "OF"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v8-0001-Change-the-way-ATExecMergePartitions-handles-the-.patch (7.5K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/6-v8-0001-Change-the-way-ATExecMergePartitions-handles-the-.patch)
  download | inline diff:
From f17c461ea4e054950ee4e4f423ea223d20382477 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Fri, 19 Apr 2024 13:39:45 +0300
Subject: [PATCH v8 1/7] Change the way ATExecMergePartitions() handles the
 name collision

The name collision happens when the name of the new partition is the same as
the name of one of the merging partitions.  Currently, ATExecMergePartitions()
first gives the new partition a temporary name and then renames it when old
partitions are deleted.  That negatively influences the naming of related
objects like indexes and constrains, which could inherit a temporary name.

This commit changes the implementation in the following way.  A merging
partition gets renamed first, then the new partition is created with the
right name immediately.  This resolves the issue of the naming of related
objects.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/edfbd846-dcc1-42d1-ac26-715691b687d3%40postgrespro.ru
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas
---
 src/backend/commands/tablecmds.c              | 63 +++++++++----------
 src/test/regress/expected/partition_merge.out | 25 ++++++++
 src/test/regress/sql/partition_merge.sql      | 18 ++++++
 3 files changed, 73 insertions(+), 33 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3556240c8ed..dbb6ee356bb 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21477,9 +21477,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	ListCell   *listptr;
 	List	   *mergingPartitionsList = NIL;
 	Oid			defaultPartOid;
-	char		tmpRelName[NAMEDATALEN];
-	RangeVar   *mergePartName = cmd->name;
-	bool		isSameName = false;
 
 	/*
 	 * Lock all merged partitions, check them and create list with partitions
@@ -21501,8 +21498,28 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		 * function transformPartitionCmdForMerge().
 		 */
 		if (equal(name, cmd->name))
+		{
 			/* One new partition can have the same name as merged partition. */
-			isSameName = true;
+			char		tmpRelName[NAMEDATALEN];
+
+			/* Generate temporary name. */
+			sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
+
+			/*
+			 * Rename the existing partition with a temporary name, leaving it
+			 * free for the new partition.  We don't need to care about this
+			 * in the future because we're going to eventually drop the
+			 * existing partition anyway.
+			 */
+			RenameRelationInternal(RelationGetRelid(mergingPartition),
+								   tmpRelName, false, false);
+
+			/*
+			 * We must bump the command counter to make the new partition
+			 * tuple visible for rename.
+			 */
+			CommandCounterIncrement();
+		}
 
 		/* Store a next merging partition into the list. */
 		mergingPartitionsList = lappend(mergingPartitionsList,
@@ -21522,15 +21539,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	/* Create table for new partition, use partitioned table as model. */
-	if (isSameName)
-	{
-		/* Create partition table with generated temporary name. */
-		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
-	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(cmd->name,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21541,18 +21550,12 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	 * excessive, but this is the way we make sure nobody is planning queries
 	 * involving merging partitions.
 	 */
-	newPartRel = table_openrv(mergePartName, AccessExclusiveLock);
+	newPartRel = table_openrv(cmd->name, AccessExclusiveLock);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
-	/* Unlock and drop merged partitions. */
+	/* Drop the current partitions before attaching the new one. */
 	foreach(listptr, mergingPartitionsList)
 	{
 		ObjectAddress object;
@@ -21570,18 +21573,12 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 	list_free(mergingPartitionsList);
 
-	/* Rename new partition if it is needed. */
-	if (isSameName)
-	{
-		/*
-		 * We must bump the command counter to make the new partition tuple
-		 * visible for rename.
-		 */
-		CommandCounterIncrement();
-		/* Rename partition. */
-		RenameRelationInternal(RelationGetRelid(newPartRel),
-							   cmd->name->relname, false, false);
-	}
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 373d32948ca..2e0bfdc705d 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -746,4 +746,29 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
+-- Not-null constraint name should be 'tp_1_2_i_not_null'.
+\d+ tp_1_2
+                          Table "partitions_merge_schema.tp_1_2"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           | not null |         | plain   |              | 
+Partition of: t FOR VALUES FROM (0) TO (2)
+Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))
+Indexes:
+    "tp_1_2_pkey" PRIMARY KEY, btree (i)
+    "tp_1_2_i_idx" btree (i)
+Not-null constraints:
+    "tp_1_2_i_not_null" NOT NULL "i"
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 6a0b35b1799..72b1cb0b35e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -444,5 +444,23 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
+-- Not-null constraint name should be 'tp_1_2_i_not_null'.
+\d+ tp_1_2
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v8-0006-Inherit-parent-s-AM-for-partition-MERGE-SPLIT-ope.patch (9.3K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/7-v8-0006-Inherit-parent-s-AM-for-partition-MERGE-SPLIT-ope.patch)
  download | inline diff:
From 5fc0bcb59f1f40a2d10dd191d208b074145bd4c4 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 13:21:14 +0300
Subject: [PATCH v8 6/7] Inherit parent's AM for partition MERGE/SPLIT
 operations

This commit makes new partitions created by ALTER TABLE ... SPLIT PARTITION
and ALTER TABLE ... MERGE PARTITIONS commands inherit the paret table access
method.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/84ada05b-be5c-473e-6d1c-ebe5dd21b190%40gmail.com
---
 doc/src/sgml/ref/alter_table.sgml             |  8 +++----
 src/backend/commands/tablecmds.c              |  6 +++++
 src/test/regress/expected/partition_merge.out | 18 +++++++++++++++
 src/test/regress/expected/partition_split.out | 23 +++++++++++++++++--
 src/test/regress/sql/partition_merge.sql      | 13 +++++++++++
 src/test/regress/sql/partition_split.sql      | 14 +++++++++++
 6 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index a793899b69b..dba49a7ac8f 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1158,8 +1158,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       in the parent table are cloned on new partitions
       <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable>, ... .
-      New partitions will have the same column names and types as the
-      partitioned table to which they belong.
+      New partitions will have the same table access method,
+      same column names and types as the partitioned table to which they belong.
       If the parent table is persistent then new partitions are created
       persistent.  If the parent table is temporary then new partitions
       are also created temporary.
@@ -1228,8 +1228,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       Any indexes, constraints and user-defined row-level triggers that exist
       in the parent table are cloned on the new partition
       <replaceable class="parameter">partition_name</replaceable>.
-      The new partition will have the same column names and types as the
-      partitioned table to which it belongs.
+      The new partition will have the same table access method,
+      same column names and types as the partitioned table to which it belongs.
       If the parent table is persistent then the new partition is created
       persistent.  If the parent table is temporary then the new partition
       is also created temporary.
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 1b89e18eb7e..fd0812cd649 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21187,6 +21187,11 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  *
  * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ *
+ * Also, this function sets the new partition access method same as parent
+ * table access methods (similarly to CREATE TABLE ... PARTITION OF).  It
+ * checks that parent and child tables have compatible persistence.
+ *
  * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
 static Relation
@@ -21217,6 +21222,7 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
 	createStmt->oncommit = ONCOMMIT_NOOP;
 	createStmt->tablespacename = NULL;
 	createStmt->if_not_exists = false;
+	createStmt->accessMethod = get_am_name(modelRel->rd_rel->relam);
 
 	tlc = makeNode(TableLikeClause);
 	tlc->relation = makeRangeVar(get_namespace_name(RelationGetNamespace(modelRel)),
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index a92a270c591..92999703217 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -862,6 +862,24 @@ SET search_path = partitions_merge_schema, pg_temp, public;
 -- Can't merge temporary partitions into a persistent partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ROLLBACK;
+-- Check the new partition inherits parent's table access method
+SET search_path = partitions_merge_schema, public;
+CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partitions_merge_heap;
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_2'::regclass);
+ relname |        amname         
+---------+-----------------------
+ tp_0_2  | partitions_merge_heap
+ t       | partitions_merge_heap
+(2 rows)
+
+DROP TABLE t;
+DROP ACCESS METHOD partitions_merge_heap;
 RESET search_path;
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 55ae37ad370..326fa1bd400 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -85,8 +85,8 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
-LINE 4:    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO...
-                                                    ^
+LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
+                                                             ^
 -- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
@@ -1494,6 +1494,25 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
 (2 rows)
 
 DROP TABLE t;
+-- Check new partitions inherits parent's table access method
+CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partition_split_heap;
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_1'::regclass, 'tp_1_2'::regclass);
+ relname |        amname        
+---------+----------------------
+ t       | partition_split_heap
+ tp_0_1  | partition_split_heap
+ tp_1_2  | partition_split_heap
+(3 rows)
+
+DROP TABLE t;
+DROP ACCESS METHOD partition_split_heap;
 --
 DROP SCHEMA partition_split_schema;
 DROP SCHEMA partition_split_schema2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 085c422d540..23795cf9d94 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -535,6 +535,19 @@ SET search_path = partitions_merge_schema, pg_temp, public;
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ROLLBACK;
 
+-- Check the new partition inherits parent's table access method
+SET search_path = partitions_merge_schema, public;
+CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partitions_merge_heap;
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_2'::regclass);
+DROP TABLE t;
+DROP ACCESS METHOD partitions_merge_heap;
+
 RESET search_path;
 
 --
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 3a7f2f9c294..73e8c2fbeb9 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -880,6 +880,20 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
 
 DROP TABLE t;
 
+-- Check new partitions inherits parent's table access method
+CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partition_split_heap;
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_1'::regclass, 'tp_1_2'::regclass);
+DROP TABLE t;
+DROP ACCESS METHOD partition_split_heap;
+
+
 --
 DROP SCHEMA partition_split_schema;
 DROP SCHEMA partition_split_schema2;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v8-0007-Grammar-fixes-for-documentation-of-partition-MERG.patch (6.2K, ../../CAPpHfdtB9L1C7HLE30WDQfQQgUZo5P+5=9kLr5vQSpDZ-2AV_A@mail.gmail.com/8-v8-0007-Grammar-fixes-for-documentation-of-partition-MERG.patch)
  download | inline diff:
From 146d6946d7ff58dda8c32e048d9b8cf30c8278de Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 13:18:31 +0300
Subject: [PATCH v8 7/7] Grammar fixes for documentation of partition
 MERGE/SPLIT operations

Discussion: https://postgr.es/m/ZiGH0xc1lxJ71ZfB%40pryzbyj2023
Author: Justin Pryzby
---
 doc/src/sgml/ddl.sgml             |  4 ++--
 doc/src/sgml/ref/alter_table.sgml | 22 +++++++++++-----------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 026bfff70f3..01277b1d327 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -4384,7 +4384,7 @@ ALTER INDEX measurement_city_id_logdate_key
 
     <para>
      There is also an option for merging multiple table partitions into
-     a single partition using the
+     a single partition using
      <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>.
      This feature simplifies the management of partitioned tables by allowing
      users to combine partitions that are no longer needed as
@@ -4403,7 +4403,7 @@ ALTER TABLE measurement
 
     <para>
      Similarly to merging multiple table partitions, there is an option for
-     splitting a single partition into multiple using the
+     splitting a single partition into multiple partitions using
      <link linkend="sql-altertable-split-partition"><command>ALTER TABLE ... SPLIT PARTITION</command></link>.
      This feature could come in handy when one partition grows too big
      and needs to be split into multiple.  It's important to note that
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index dba49a7ac8f..db477856395 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1136,16 +1136,16 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       If the split partition is a DEFAULT partition, one of the new partitions must be DEFAULT.
       In case one of the new partitions or one of existing partitions is DEFAULT,
       new partitions <replaceable class="parameter">partition_name1</replaceable>,
-      <replaceable class="parameter">partition_name2</replaceable>, ... can have spaces
+      <replaceable class="parameter">partition_name2</replaceable>, ... can have gaps
       between partitions bounds.  If the partitioned table does not have a DEFAULT
       partition, the DEFAULT partition can be defined as one of the new partitions.
      </para>
      <para>
       In case new partitions do not contain a DEFAULT partition and the partitioned table
-      does not have a DEFAULT partition, the following must be true: sum bounds of
+      does not have a DEFAULT partition, the following must be true: the sum bounds of
       new partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable>, ... should be
-      equal to bound of split partition <replaceable class="parameter">partition_name</replaceable>.
+      equal to the bounds of split partition <replaceable class="parameter">partition_name</replaceable>.
       One of the new partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable>, ... can have
       the same name as split partition <replaceable class="parameter">partition_name</replaceable>
@@ -1179,24 +1179,24 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
 
     <listitem>
      <para>
-      This form merges several partitions into the one partition of the target table.
-      Hash-partitioning is not supported.  If DEFAULT partition is not in the
+      This form merges several partitions of the target table into a single partition.
+      Hash-partitioning is not supported.  If a DEFAULT partition is not in the
       list of partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable> [, ...]:
       <itemizedlist>
        <listitem>
         <para>
-         For range-partitioned tables it is necessary that the ranges
+         For range-partitioned tables, it is necessary that the ranges
          of the partitions <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] can
-         be merged into one range without spaces and overlaps (otherwise an error
+         be merged into one range with neither gaps nor overlaps (otherwise an error
          will be generated).  The combined range will be the range for the partition
          <replaceable class="parameter">partition_name</replaceable>.
         </para>
        </listitem>
        <listitem>
         <para>
-         For list-partitioned tables the value lists of all partitions
+         For list-partitioned tables, the value lists of all partitions
          <replaceable class="parameter">partition_name1</replaceable>,
          <replaceable class="parameter">partition_name2</replaceable> [, ...] are
          combined and form the list of values of partition
@@ -1204,7 +1204,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
         </para>
        </listitem>
       </itemizedlist>
-      If DEFAULT partition is in the list of partitions <replaceable class="parameter">partition_name1</replaceable>,
+      If a DEFAULT partition is in the list of partitions <replaceable class="parameter">partition_name1</replaceable>,
       <replaceable class="parameter">partition_name2</replaceable> [, ...]:
       <itemizedlist>
        <listitem>
@@ -1215,8 +1215,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
        </listitem>
        <listitem>
         <para>
-         For range- and list-partitioned tables the ranges and lists of values
-         of the merged partitions can be any.
+         For range- and list-partitioned tables, the ranges and lists of values
+         of the merged partitions can be anything.
         </para>
        </listitem>
       </itemizedlist>
-- 
2.39.3 (Apple Git-145)



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-24 20:26                                         ` Justin Pryzby <[email protected]>
  2024-04-26 13:33                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Pavel Borisov <[email protected]>
  2024-04-28 01:04                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Justin Pryzby @ 2024-04-24 20:26 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; [email protected]

On Mon, Apr 22, 2024 at 01:31:48PM +0300, Alexander Korotkov wrote:
> Hi!
> 
> On Fri, Apr 19, 2024 at 4:29 PM Alexander Korotkov <[email protected]> wrote:
> > On Fri, Apr 19, 2024 at 2:26 AM Dmitry Koval <[email protected]> wrote:
> > > 18.04.2024 19:00, Alexander Lakhin wrote:
> > > > leaves a strange constraint:
> > > > \d+ t*
> > > >                                            Table "public.tp_0"
> > > > ...
> > > > Not-null constraints:
> > > >      "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"
> > >
> > > Thanks!
> > > Attached fix (with test) for this case.
> > > The patch should be applied after patches
> > > v6-0001- ... .patch ... v6-0004- ... .patch
> >
> > I've incorporated this fix with 0001 patch.
> >
> > Also added to the patchset
> > 005 – tab completion by Dagfinn [1]
> > 006 – draft fix for table AM issue spotted by Alexander Lakhin [2]
> > 007 – doc review by Justin [3]
> >
> > I'm continuing work on this.
> >
> > Links
> > 1. https://www.postgresql.org/message-id/87plumiox2.fsf%40wibble.ilmari.org
> > 2. https://www.postgresql.org/message-id/84ada05b-be5c-473e-6d1c-ebe5dd21b190%40gmail.com
> > 3. https://www.postgresql.org/message-id/ZiGH0xc1lxJ71ZfB%40pryzbyj2023
> 
> 0001
> The way we handle name collisions during MERGE PARTITIONS operation is
> reworked by integration of patch [3].  This makes note about commit in
> [2] not relevant.

This patch also/already fixes the schema issue I reported.  Thanks.

If you wanted to include a test case for that:

begin;
CREATE SCHEMA s;
CREATE SCHEMA t;
CREATE TABLE p(i int) PARTITION BY RANGE(i);
CREATE TABLE s.c1 PARTITION OF p FOR VALUES FROM (1)TO(2);
CREATE TABLE s.c2 PARTITION OF p FOR VALUES FROM (2)TO(3);
ALTER TABLE p MERGE PARTITIONS (s.c1, s.c2) INTO s.c1; -- misbehaves if merging into the same name as an existing partition
\d+ p
...
Partitions: c1 FOR VALUES FROM (1) TO (3)

> 0002
> The persistence of the new partition is copied as suggested in [1].
> But the checks are in-place, because search_path could influence new
> table persistence.  Per review [2], commit message typos are fixed,
> documentation is revised, revised tests to cover schema-qualification,
> usage of search_path.

Subject: [PATCH v8 2/7] Make new partitions with parent's persistence during MERGE/SPLIT operations

This patch adds documentation saying:
+      Any indexes, constraints and user-defined row-level triggers that exist
+      in the parent table are cloned on new partitions [...]

Which is good to say, and addresses part of my message [0]
[0] ZiJW1g2nbQs9ekwK@pryzbyj2023

But it doesn't have anything to do with "creating new partitions with
parent's persistence".  Maybe there was a merge conflict and the docs
ended up in the wrong patch ?

Also, defaults, storage options, compression are also copied.  As will
be anything else from LIKE.  And since anything added in the future will
also be copied, maybe it's better to just say that the tables will be
created the same way as "LIKE .. INCLUDING ALL EXCLUDING ..", or
similar.  Otherwise, the next person who adds a new option for LIKE
would have to remember to update this paragraph...

Also, extended stats objects are currently cloned to new child tables.
But I suggested in [0] that they probably shouldn't be.

> 007 – doc review by Justin [3]

I suggest to drop this patch for now.  I'll send some more minor fixes to
docs and code comments once the other patches are settled.

-- 
Justin






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
@ 2024-04-26 13:33                                           ` Pavel Borisov <[email protected]>
  2024-04-28 00:59                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Pavel Borisov @ 2024-04-26 13:33 UTC (permalink / raw)
  To: Justin Pryzby <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; [email protected]

Hi, Hackers!

On Thu, 25 Apr 2024 at 00:26, Justin Pryzby <[email protected]> wrote:

> On Mon, Apr 22, 2024 at 01:31:48PM +0300, Alexander Korotkov wrote:
> > Hi!
> >
> > On Fri, Apr 19, 2024 at 4:29 PM Alexander Korotkov <[email protected]>
> wrote:
> > > On Fri, Apr 19, 2024 at 2:26 AM Dmitry Koval <[email protected]>
> wrote:
> > > > 18.04.2024 19:00, Alexander Lakhin wrote:
> > > > > leaves a strange constraint:
> > > > > \d+ t*
> > > > >                                            Table "public.tp_0"
> > > > > ...
> > > > > Not-null constraints:
> > > > >      "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"
> > > >
> > > > Thanks!
> > > > Attached fix (with test) for this case.
> > > > The patch should be applied after patches
> > > > v6-0001- ... .patch ... v6-0004- ... .patch
> > >
> > > I've incorporated this fix with 0001 patch.
> > >
> > > Also added to the patchset
> > > 005 – tab completion by Dagfinn [1]
> > > 006 – draft fix for table AM issue spotted by Alexander Lakhin [2]
> > > 007 – doc review by Justin [3]
> > >
> > > I'm continuing work on this.
> > >
> > > Links
> > > 1.
> https://www.postgresql.org/message-id/87plumiox2.fsf%40wibble.ilmari.org
> > > 2.
> https://www.postgresql.org/message-id/84ada05b-be5c-473e-6d1c-ebe5dd21b190%40gmail.com
> > > 3.
> https://www.postgresql.org/message-id/ZiGH0xc1lxJ71ZfB%40pryzbyj2023
> >
> > 0001
> > The way we handle name collisions during MERGE PARTITIONS operation is
> > reworked by integration of patch [3].  This makes note about commit in
> > [2] not relevant.
>
> This patch also/already fixes the schema issue I reported.  Thanks.
>
> If you wanted to include a test case for that:
>
> begin;
> CREATE SCHEMA s;
> CREATE SCHEMA t;
> CREATE TABLE p(i int) PARTITION BY RANGE(i);
> CREATE TABLE s.c1 PARTITION OF p FOR VALUES FROM (1)TO(2);
> CREATE TABLE s.c2 PARTITION OF p FOR VALUES FROM (2)TO(3);
> ALTER TABLE p MERGE PARTITIONS (s.c1, s.c2) INTO s.c1; -- misbehaves if
> merging into the same name as an existing partition
> \d+ p
> ...
> Partitions: c1 FOR VALUES FROM (1) TO (3)
>
> > 0002
> > The persistence of the new partition is copied as suggested in [1].
> > But the checks are in-place, because search_path could influence new
> > table persistence.  Per review [2], commit message typos are fixed,
> > documentation is revised, revised tests to cover schema-qualification,
> > usage of search_path.
>
> Subject: [PATCH v8 2/7] Make new partitions with parent's persistence
> during MERGE/SPLIT operations
>
> This patch adds documentation saying:
> +      Any indexes, constraints and user-defined row-level triggers that
> exist
> +      in the parent table are cloned on new partitions [...]
>
> Which is good to say, and addresses part of my message [0]
> [0] ZiJW1g2nbQs9ekwK@pryzbyj2023
>
> But it doesn't have anything to do with "creating new partitions with
> parent's persistence".  Maybe there was a merge conflict and the docs
> ended up in the wrong patch ?
>
> Also, defaults, storage options, compression are also copied.  As will
> be anything else from LIKE.  And since anything added in the future will
> also be copied, maybe it's better to just say that the tables will be
> created the same way as "LIKE .. INCLUDING ALL EXCLUDING ..", or
> similar.  Otherwise, the next person who adds a new option for LIKE
> would have to remember to update this paragraph...
>
> Also, extended stats objects are currently cloned to new child tables.
> But I suggested in [0] that they probably shouldn't be.
>
> > 007 – doc review by Justin [3]
>
> I suggest to drop this patch for now.  I'll send some more minor fixes to
> docs and code comments once the other patches are settled.
>
I've looked at the patchset:

0001 Look good.
0002 Also right with docs modification proposed by Justin.
0003:
Looks like unused code
5268             datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) -
1) : NULL;
overridden by
5278                     datum = list_nth(spec->upperdatums, abs(cmpval) -
1);
and
5290                     datum = list_nth(spec->upperdatums, abs(cmpval) -
1);

Otherwise - good.

0004:
I suggest also getting rid of thee-noun compound words like:
salesperson_name. Maybe salesperson -> clerk? Or maybe use the same terms
like in pgbench: branches, tellers, accounts, balance.

0005: Good
0006: Patch is right
In comments:
+      New partitions will have the same table access method,
+      same column names and types as the partitioned table to which they
belong.
(I'd suggest to remove second "same")

Tests are passed. I suppose that it's better to add similar tests for
SPLIT/MERGE PARTITION(S)  to those covering ATTACH/DETACH PARTITION (e.g.:
subscription/t/013_partition.pl and regression tests)

Overall, great work! Thanks!

Regards,
Pavel Borisov,
Supabase.


^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-04-26 13:33                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Pavel Borisov <[email protected]>
@ 2024-04-28 00:59                                             ` Alexander Korotkov <[email protected]>
  2024-04-28 11:00                                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-28 00:59 UTC (permalink / raw)
  To: Pavel Borisov <[email protected]>; +Cc: Justin Pryzby <[email protected]>; Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; [email protected]

Hi, Pavel.

Thank you for the review.

On Fri, Apr 26, 2024 at 4:33 PM Pavel Borisov <[email protected]> wrote:
> I've looked at the patchset:
>
> 0001 Look good.
> 0002 Also right with docs modification proposed by Justin.

Modified as proposed by Justin.  The documentation for the way new
partitions are created is now in separate patch.

> 0003:
> Looks like unused code
> 5268             datum = cmpval ? list_nth(spec->lowerdatums, abs(cmpval) - 1) : NULL;
> overridden by
> 5278                     datum = list_nth(spec->upperdatums, abs(cmpval) - 1);
> and
> 5290                     datum = list_nth(spec->upperdatums, abs(cmpval) - 1);
>
> Otherwise - good.

Fixed, thanks.

> 0004:
> I suggest also getting rid of thee-noun compound words like: salesperson_name. Maybe salesperson -> clerk? Or maybe use the same terms like in pgbench: branches, tellers, accounts, balance.

Thank you, but I'd like to prefer keeping these modifications simple.
It's just regression tests, we don't need to have perfect naming here.
My intention is to fix just obvious errors.

> 0005: Good
> 0006: Patch is right
> In comments:
> +      New partitions will have the same table access method,
> +      same column names and types as the partitioned table to which they belong.
> (I'd suggest to remove second "same")

Documentation is modified per proposal by Justin.  Thus double "same"
is already gone.

> Tests are passed. I suppose that it's better to add similar tests for SPLIT/MERGE PARTITION(S)  to those covering ATTACH/DETACH PARTITION (e.g.: subscription/t/013_partition.pl and regression tests)

The revised patchset is attached.  I'm going to push it if there are
no objections.

Thank you for your suggestions about adding tests similar to
subscription/t/013_partition.pl.  I will work on this after pushing
this patchset.

------
Regards,
Alexander Korotkov
Supabase


Attachments:

  [application/octet-stream] v9-0001-Change-the-way-ATExecMergePartitions-handles-the-.patch (7.5K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/2-v9-0001-Change-the-way-ATExecMergePartitions-handles-the-.patch)
  download | inline diff:
From a6d5687a942e8f8f1f6863f9b76c009a97130d03 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Fri, 19 Apr 2024 13:39:45 +0300
Subject: [PATCH v9 1/7] Change the way ATExecMergePartitions() handles the
 name collision

The name collision happens when the name of the new partition is the same as
the name of one of the merging partitions.  Currently, ATExecMergePartitions()
first gives the new partition a temporary name and then renames it when old
partitions are deleted.  That negatively influences the naming of related
objects like indexes and constrains, which could inherit a temporary name.

This commit changes the implementation in the following way.  A merging
partition gets renamed first, then the new partition is created with the
right name immediately.  This resolves the issue of the naming of related
objects.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/edfbd846-dcc1-42d1-ac26-715691b687d3%40postgrespro.ru
Author: Dmitry Koval, Alexander Korotkov
Reviewed-by: Robert Haas, Justin Pryzby, Pavel Borisov
---
 src/backend/commands/tablecmds.c              | 63 +++++++++----------
 src/test/regress/expected/partition_merge.out | 25 ++++++++
 src/test/regress/sql/partition_merge.sql      | 18 ++++++
 3 files changed, 73 insertions(+), 33 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3556240c8ed..dbb6ee356bb 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21477,9 +21477,6 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	ListCell   *listptr;
 	List	   *mergingPartitionsList = NIL;
 	Oid			defaultPartOid;
-	char		tmpRelName[NAMEDATALEN];
-	RangeVar   *mergePartName = cmd->name;
-	bool		isSameName = false;
 
 	/*
 	 * Lock all merged partitions, check them and create list with partitions
@@ -21501,8 +21498,28 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		 * function transformPartitionCmdForMerge().
 		 */
 		if (equal(name, cmd->name))
+		{
 			/* One new partition can have the same name as merged partition. */
-			isSameName = true;
+			char		tmpRelName[NAMEDATALEN];
+
+			/* Generate temporary name. */
+			sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
+
+			/*
+			 * Rename the existing partition with a temporary name, leaving it
+			 * free for the new partition.  We don't need to care about this
+			 * in the future because we're going to eventually drop the
+			 * existing partition anyway.
+			 */
+			RenameRelationInternal(RelationGetRelid(mergingPartition),
+								   tmpRelName, false, false);
+
+			/*
+			 * We must bump the command counter to make the new partition
+			 * tuple visible for rename.
+			 */
+			CommandCounterIncrement();
+		}
 
 		/* Store a next merging partition into the list. */
 		mergingPartitionsList = lappend(mergingPartitionsList,
@@ -21522,15 +21539,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	/* Create table for new partition, use partitioned table as model. */
-	if (isSameName)
-	{
-		/* Create partition table with generated temporary name. */
-		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
-	}
-	createPartitionTable(mergePartName,
+	createPartitionTable(cmd->name,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
 									  RelationGetRelationName(rel), -1),
 						 context);
@@ -21541,18 +21550,12 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	 * excessive, but this is the way we make sure nobody is planning queries
 	 * involving merging partitions.
 	 */
-	newPartRel = table_openrv(mergePartName, AccessExclusiveLock);
+	newPartRel = table_openrv(cmd->name, AccessExclusiveLock);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
 
-	/*
-	 * Attach a new partition to the partitioned table. wqueue = NULL:
-	 * verification for each cloned constraint is not need.
-	 */
-	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
-
-	/* Unlock and drop merged partitions. */
+	/* Drop the current partitions before attaching the new one. */
 	foreach(listptr, mergingPartitionsList)
 	{
 		ObjectAddress object;
@@ -21570,18 +21573,12 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 	list_free(mergingPartitionsList);
 
-	/* Rename new partition if it is needed. */
-	if (isSameName)
-	{
-		/*
-		 * We must bump the command counter to make the new partition tuple
-		 * visible for rename.
-		 */
-		CommandCounterIncrement();
-		/* Rename partition. */
-		RenameRelationInternal(RelationGetRelid(newPartRel),
-							   cmd->name->relname, false, false);
-	}
+	/*
+	 * Attach a new partition to the partitioned table. wqueue = NULL:
+	 * verification for each cloned constraint is not needed.
+	 */
+	attachPartitionTable(NULL, rel, newPartRel, cmd->bound);
+
 	/* Keep the lock until commit. */
 	table_close(newPartRel, NoLock);
 }
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 373d32948ca..2e0bfdc705d 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -746,4 +746,29 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
+-- Not-null constraint name should be 'tp_1_2_i_not_null'.
+\d+ tp_1_2
+                          Table "partitions_merge_schema.tp_1_2"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           | not null |         | plain   |              | 
+Partition of: t FOR VALUES FROM (0) TO (2)
+Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))
+Indexes:
+    "tp_1_2_pkey" PRIMARY KEY, btree (i)
+    "tp_1_2_i_idx" btree (i)
+Not-null constraints:
+    "tp_1_2_i_not_null" NOT NULL "i"
+
+DROP TABLE t;
+--
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 6a0b35b1799..72b1cb0b35e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -444,5 +444,23 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Check the partition index name if the partition name is the same as one
+-- of the merged partitions.
+--
+CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
+
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+CREATE INDEX tidx ON t(i);
+ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
+
+-- Indexname values should be 'tp_1_2_pkey' and 'tp_1_2_i_idx'.
+-- Not-null constraint name should be 'tp_1_2_i_not_null'.
+\d+ tp_1_2
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partitions_merge_schema;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v9-0003-Make-new-partitions-with-parent-s-persistence-dur.patch (37.1K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/3-v9-0003-Make-new-partitions-with-parent-s-persistence-dur.patch)
  download | inline diff:
From f69c80850a8bd8e79313ca8c4ccff9a49c53615f Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:41:09 +0300
Subject: [PATCH v9 3/7] Make new partitions with parent's persistence during
 MERGE/SPLIT operations

The createPartitionTable() function is responsible for creating new partitions
for ALTER TABLE ... MERGE PARTITIONS, and ALTER TABLE ... SPLIT PARTITION
commands.  It emulates the behaviour of CREATE TABLE ... (LIKE ...), where
new table persistence should be specified by the user.  In the table
partitioning persistent of the partition and its parent must match.  So, this
commit makes createPartitionTable() copy the persistence of the parent
partition.

Also, this commit makes createPartitionTable() recheck the persistence after
the new table creation.  This is needed because persistence might be affected
by pg_temp in search_path.

This commit also changes the signature of createPartitionTable() making it
take the parent's Relation itself instead of the name of the parent relation,
and return the Relation of new partition.  That doesn't lead to
complications, because both callers have the parent table open and need to
open the new partition.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/dbc8b96c-3cf0-d1ee-860d-0e491da20485%40gmail.com
Author: Dmitry Koval
Reviewed-by: Alexander Korotkov, Robert Haas, Justin Pryzby, Pavel Borisov
---
 doc/src/sgml/ref/alter_table.sgml             |   6 +
 src/backend/commands/tablecmds.c              |  75 ++++++----
 src/test/regress/expected/partition_merge.out | 134 +++++++++++++++---
 src/test/regress/expected/partition_split.out |  75 +++++++++-
 src/test/regress/sql/partition_merge.sql      |  88 +++++++++++-
 src/test/regress/sql/partition_split.sql      |  43 +++++-
 6 files changed, 364 insertions(+), 57 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 8a10a8bd79b..0f546357863 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1158,6 +1158,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name1</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
       The indexes and identity are created later after moving the data
       while attaching new partitions.
+      If the parent table is persistent then new partitions are created
+      persistent.  If the parent table is temporary then new partitions
+      are also created temporary.
      </para>
      <note>
       <para>
@@ -1224,6 +1227,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
       The indexes and identity are created later after moving the data
       while attaching the new partition.
+      If the parent table is persistent then the new partition is created
+      persistent.  If the parent table is temporary then the new partition
+      is also created temporary.
      </para>
      <note>
       <para>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index dbb6ee356bb..1b89e18eb7e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21183,18 +21183,30 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
 
 /*
  * createPartitionTable: create table for a new partition with given name
- * (newPartName) like table (modelRelName)
+ * (newPartName) like table (modelRel)
  *
- * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName>
+ * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
-static void
-createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
+static Relation
+createPartitionTable(RangeVar *newPartName, Relation modelRel,
 					 AlterTableUtilityContext *context)
 {
 	CreateStmt *createStmt;
 	TableLikeClause *tlc;
 	PlannedStmt *wrapper;
+	Relation	newRel;
+
+	/* If existing rel is temp, it must belong to this session */
+	if (modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
+		!modelRel->rd_islocaltemp)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create as partition of temporary relation of another session")));
+
+	/* New partition should have the same persistence as modelRel */
+	newPartName->relpersistence = modelRel->rd_rel->relpersistence;
 
 	createStmt = makeNode(CreateStmt);
 	createStmt->relation = newPartName;
@@ -21207,7 +21219,8 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 	createStmt->if_not_exists = false;
 
 	tlc = makeNode(TableLikeClause);
-	tlc->relation = modelRelName;
+	tlc->relation = makeRangeVar(get_namespace_name(RelationGetNamespace(modelRel)),
+								 RelationGetRelationName(modelRel), -1);
 
 	/*
 	 * Indexes will be inherited on "attach new partitions" stage, after data
@@ -21233,6 +21246,35 @@ createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName,
 				   NULL,
 				   None_Receiver,
 				   NULL);
+
+	/*
+	 * Open the new partition with no lock, because we already have
+	 * AccessExclusiveLock placed there after creation.
+	 */
+	newRel = table_openrv(newPartName, NoLock);
+
+	/*
+	 * We intended to create the partition with the same persistence as the
+	 * parent table, but we still need to recheck because that might be
+	 * affected by the search_path.  If the parent is permanent, so must be
+	 * all of its partitions.
+	 */
+	if (modelRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		newRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"",
+						RelationGetRelationName(modelRel))));
+
+	/* Permanent rels cannot be partitions belonging to temporary parent */
+	if (newRel->rd_rel->relpersistence != RELPERSISTENCE_TEMP &&
+		modelRel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("cannot create a permanent relation as partition of temporary relation \"%s\"",
+						RelationGetRelationName(modelRel))));
+
+	return newRel;
 }
 
 /*
@@ -21252,7 +21294,6 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	char		tmpRelName[NAMEDATALEN];
 	List	   *newPartRels = NIL;
 	ObjectAddress object;
-	RangeVar   *parentName;
 	Oid			defaultPartOid;
 
 	defaultPartOid = get_default_oid_from_partdesc(RelationGetPartitionDesc(rel, true));
@@ -21324,18 +21365,12 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	}
 
 	/* Create new partitions (like split partition), without indexes. */
-	parentName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-							  RelationGetRelationName(rel), -1);
 	foreach(listptr, cmd->partlist)
 	{
 		SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr);
 		Relation	newPartRel;
 
-		createPartitionTable(sps->name, parentName, context);
-
-		/* Open the new partition and acquire exclusive lock on it. */
-		newPartRel = table_openrv(sps->name, AccessExclusiveLock);
-
+		newPartRel = createPartitionTable(sps->name, rel, context);
 		newPartRels = lappend(newPartRels, newPartRel);
 	}
 
@@ -21539,18 +21574,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 		DetachPartitionFinalize(rel, mergingPartition, false, defaultPartOid);
 	}
 
-	createPartitionTable(cmd->name,
-						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									  RelationGetRelationName(rel), -1),
-						 context);
-
-	/*
-	 * Open the new partition and acquire exclusive lock on it.  This will
-	 * stop all the operations with partitioned table.  This might seem
-	 * excessive, but this is the way we make sure nobody is planning queries
-	 * involving merging partitions.
-	 */
-	newPartRel = table_openrv(cmd->name, AccessExclusiveLock);
+	/* Create table for new partition, use partitioned table as model. */
+	newPartRel = createPartitionTable(cmd->name, rel, context);
 
 	/* Copy data from merged partitions to new partition. */
 	moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 2e0bfdc705d..3aae5f89e80 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -3,6 +3,7 @@
 -- Tests for "ALTER TABLE ... MERGE PARTITIONS ..." command
 --
 CREATE SCHEMA partitions_merge_schema;
+CREATE SCHEMA partitions_merge_schema2;
 SET search_path = partitions_merge_schema, public;
 --
 -- BY RANGE partitioning
@@ -36,18 +37,23 @@ ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of p
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 ERROR:  lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021"
--- NO ERROR: test for custom partitions order
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_jan2022) INTO sales_jan_feb_mar2022;
+-- NO ERROR: test for custom partitions order, source partitions not in the search_path
+SET search_path = partitions_merge_schema2, public;
+ALTER TABLE partitions_merge_schema.sales_range MERGE PARTITIONS (
+  partitions_merge_schema.sales_feb2022,
+  partitions_merge_schema.sales_mar2022,
+  partitions_merge_schema.sales_jan2022) INTO sales_jan_feb_mar2022;
+SET search_path = partitions_merge_schema, public;
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
-          oid          | relkind | inhdetachpending |                   pg_get_expr                    
------------------------+---------+------------------+--------------------------------------------------
- sales_apr2022         | p       | f                | FOR VALUES FROM ('04-01-2022') TO ('05-01-2022')
- sales_dec2021         | r       | f                | FOR VALUES FROM ('12-01-2021') TO ('12-31-2021')
- sales_jan_feb_mar2022 | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('04-01-2022')
- sales_others          | r       | f                | DEFAULT
+                      oid                       | relkind | inhdetachpending |                   pg_get_expr                    
+------------------------------------------------+---------+------------------+--------------------------------------------------
+ partitions_merge_schema2.sales_jan_feb_mar2022 | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('04-01-2022')
+ sales_apr2022                                  | p       | f                | FOR VALUES FROM ('04-01-2022') TO ('05-01-2022')
+ sales_dec2021                                  | r       | f                | FOR VALUES FROM ('12-01-2021') TO ('12-31-2021')
+ sales_others                                   | r       | f                | DEFAULT
 (4 rows)
 
 DROP TABLE sales_range;
@@ -95,23 +101,24 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
  sales_others  | r       | f                | DEFAULT
 (5 rows)
 
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
+-- check schema-qualified name of the new partition
+ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO partitions_merge_schema2.sales_feb_mar_apr2022;
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
-          oid          | relkind | inhdetachpending |                   pg_get_expr                    
------------------------+---------+------------------+--------------------------------------------------
- sales_feb_mar_apr2022 | r       | f                | FOR VALUES FROM ('02-01-2022') TO ('05-01-2022')
- sales_jan2022         | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('02-01-2022')
- sales_others          | r       | f                | DEFAULT
+                      oid                       | relkind | inhdetachpending |                   pg_get_expr                    
+------------------------------------------------+---------+------------------+--------------------------------------------------
+ partitions_merge_schema2.sales_feb_mar_apr2022 | r       | f                | FOR VALUES FROM ('02-01-2022') TO ('05-01-2022')
+ sales_jan2022                                  | r       | f                | FOR VALUES FROM ('01-01-2022') TO ('02-01-2022')
+ sales_others                                   | r       | f                | DEFAULT
 (3 rows)
 
-SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema';
-       schemaname        |       tablename       |              indexname               | tablespace |                                                          indexdef                                                           
--------------------------+-----------------------+--------------------------------------+------------+-----------------------------------------------------------------------------------------------------------------------------
- partitions_merge_schema | sales_feb_mar_apr2022 | sales_feb_mar_apr2022_sales_date_idx |            | CREATE INDEX sales_feb_mar_apr2022_sales_date_idx ON partitions_merge_schema.sales_feb_mar_apr2022 USING btree (sales_date)
+SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema2';
+        schemaname        |       tablename       |              indexname               | tablespace |                                                           indexdef                                                           
+--------------------------+-----------------------+--------------------------------------+------------+------------------------------------------------------------------------------------------------------------------------------
+ partitions_merge_schema2 | sales_feb_mar_apr2022 | sales_feb_mar_apr2022_sales_date_idx |            | CREATE INDEX sales_feb_mar_apr2022_sales_date_idx ON partitions_merge_schema2.sales_feb_mar_apr2022 USING btree (sales_date)
 (1 row)
 
 SELECT * FROM sales_range;
@@ -141,7 +148,7 @@ SELECT * FROM sales_jan2022;
           13 | Gandi         |          377 | 01-09-2022
 (3 rows)
 
-SELECT * FROM sales_feb_mar_apr2022;
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
  salesman_id | salesman_name | sales_amount | sales_date 
 -------------+---------------+--------------+------------
            2 | Smirnoff      |          500 | 02-10-2022
@@ -164,7 +171,7 @@ SELECT * FROM sales_others;
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
-SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022 where sales_date > '2022-01-01';
  salesman_id | salesman_name | sales_amount | sales_date 
 -------------+---------------+--------------+------------
            2 | Smirnoff      |          500 | 02-10-2022
@@ -746,6 +753,34 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+DROP TABLE t;
+--
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
 --
@@ -771,4 +806,63 @@ Not-null constraints:
 
 DROP TABLE t;
 --
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = partitions_merge_schema, pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | p
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | p
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | p
+(2 rows)
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+SET search_path = partitions_merge_schema, public;
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+ERROR:  cannot create a temporary relation as partition of permanent relation "t"
+DROP TABLE t;
+SET search_path = pg_temp, partitions_merge_schema, public;
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+ oid | relpersistence 
+-----+----------------
+ t   | t
+(1 row)
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+SET search_path = partitions_merge_schema, pg_temp, public;
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+RESET search_path;
+--
 DROP SCHEMA partitions_merge_schema;
+DROP SCHEMA partitions_merge_schema2;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 419d169f036..e2a362ffafd 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -3,6 +3,7 @@
 -- Tests for "ALTER TABLE ... SPLIT PARTITION ..." command
 --
 CREATE SCHEMA partition_split_schema;
+CREATE SCHEMA partition_split_schema2;
 SET search_path = partition_split_schema, public;
 --
 -- BY RANGE partitioning
@@ -104,6 +105,28 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
 ERROR:  lower bound of partition "sales_feb2022" is not equal to lower bound of split partition
 LINE 2:   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO...
                                                     ^
+-- Check the source partition not in the search path
+SET search_path = partition_split_schema2, public;
+ALTER TABLE partition_split_schema.sales_range
+SPLIT PARTITION partition_split_schema.sales_feb_mar_apr2022 INTO
+  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+   PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+SET search_path = partition_split_schema, public;
+\d+ sales_range
+                             Partitioned table "partition_split_schema.sales_range"
+    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+---------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesman_id   | integer               |           |          |         | plain    |              | 
+ salesman_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount  | integer               |           |          |         | plain    |              | 
+ sales_date    | date                  |           |          |         | plain    |              | 
+Partition key: RANGE (sales_date)
+Partitions: partition_split_schema2.sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
+            partition_split_schema2.sales_feb2022 FOR VALUES FROM ('02-01-2022') TO ('03-01-2022'),
+            partition_split_schema2.sales_mar2022 FOR VALUES FROM ('03-01-2022') TO ('04-01-2022'),
+            sales_jan2022 FOR VALUES FROM ('01-01-2022') TO ('02-01-2022')
+
 DROP TABLE sales_range;
 DROP TABLE sales_others;
 --
@@ -197,10 +220,26 @@ CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amou
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
+-- Split partition, also check schema qualification of new partitions
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
-  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
-   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+  (PARTITION partition_split_schema.sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION partition_split_schema2.sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+\d+ sales_range
+                             Partitioned table "partition_split_schema.sales_range"
+    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+---------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesman_id   | integer               |           |          |         | plain    |              | 
+ salesman_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount  | integer               |           |          |         | plain    |              | 
+ sales_date    | date                  |           |          |         | plain    |              | 
+Partition key: RANGE (sales_date)
+Partitions: partition_split_schema2.sales_mar2022 FOR VALUES FROM ('03-01-2022') TO ('04-01-2022'),
+            sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
+            sales_feb2022 FOR VALUES FROM ('02-01-2022') TO ('03-01-2022'),
+            sales_jan2022 FOR VALUES FROM ('01-01-2022') TO ('02-01-2022'),
+            sales_others DEFAULT
+
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-10');
 INSERT INTO sales_range VALUES (3,  'Ford',     2000, '2022-04-30');
@@ -250,7 +289,7 @@ SELECT * FROM sales_feb2022;
            8 | Ericsson      |          185 | 02-23-2022
 (3 rows)
 
-SELECT * FROM sales_mar2022;
+SELECT * FROM partition_split_schema2.sales_mar2022;
  salesman_id | salesman_name | sales_amount | sales_date 
 -------------+---------------+--------------+------------
            7 | Li            |          175 | 03-08-2022
@@ -1427,4 +1466,34 @@ ERROR:  relation "t1pa" is not a partition of relation "t2"
 DROP TABLE t2;
 DROP TABLE t1;
 --
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_2 | FOR VALUES FROM (0) TO (2) | t
+(1 row)
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+  oid   |        pg_get_expr         | relpersistence 
+--------+----------------------------+----------------
+ tp_0_1 | FOR VALUES FROM (0) TO (1) | t
+ tp_1_2 | FOR VALUES FROM (1) TO (2) | t
+(2 rows)
+
+DROP TABLE t;
+--
 DROP SCHEMA partition_split_schema;
+DROP SCHEMA partition_split_schema2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 72b1cb0b35e..5a69425d96e 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -4,6 +4,7 @@
 --
 
 CREATE SCHEMA partitions_merge_schema;
+CREATE SCHEMA partitions_merge_schema2;
 SET search_path = partitions_merge_schema, public;
 
 --
@@ -37,8 +38,13 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sal
 -- (space between sections sales_dec2021 and sales_jan2022)
 ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022;
 
--- NO ERROR: test for custom partitions order
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_jan2022) INTO sales_jan_feb_mar2022;
+-- NO ERROR: test for custom partitions order, source partitions not in the search_path
+SET search_path = partitions_merge_schema2, public;
+ALTER TABLE partitions_merge_schema.sales_range MERGE PARTITIONS (
+  partitions_merge_schema.sales_feb2022,
+  partitions_merge_schema.sales_mar2022,
+  partitions_merge_schema.sales_jan2022) INTO sales_jan_feb_mar2022;
+SET search_path = partitions_merge_schema, public;
 
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
@@ -81,7 +87,8 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
 
-ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022;
+-- check schema-qualified name of the new partition
+ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO partitions_merge_schema2.sales_feb_mar_apr2022;
 
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
@@ -89,17 +96,17 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
   WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
   ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
 
-SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema';
+SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemaname = 'partitions_merge_schema2';
 
 SELECT * FROM sales_range;
 SELECT * FROM sales_jan2022;
-SELECT * FROM sales_feb_mar_apr2022;
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
 SELECT * FROM sales_others;
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 
-SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01';
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022 where sales_date > '2022-01-01';
 
 RESET enable_seqscan;
 
@@ -444,6 +451,28 @@ DROP TABLE t3;
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to MERGE partitions of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+-- Partition should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 -- Check the partition index name if the partition name is the same as one
 -- of the merged partitions.
@@ -462,5 +491,52 @@ ALTER TABLE t MERGE PARTITIONS (tp_1_2, tp_0_1) INTO tp_1_2;
 
 DROP TABLE t;
 
+--
+-- Try mixing permanent and temporary partitions.
+--
+SET search_path = partitions_merge_schema, pg_temp, public;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+
+SET search_path = partitions_merge_schema, public;
+
+-- Can't merge persistent partitions into a temporary partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO pg_temp.tp_0_2;
+DROP TABLE t;
+
+SET search_path = pg_temp, partitions_merge_schema, public;
+
+BEGIN;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, c.relpersistence FROM pg_catalog.pg_class c WHERE c.oid = 't'::regclass;
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+SET search_path = partitions_merge_schema, pg_temp, public;
+
+-- Can't merge temporary partitions into a persistent partition
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ROLLBACK;
+
+RESET search_path;
+
 --
 DROP SCHEMA partitions_merge_schema;
+DROP SCHEMA partitions_merge_schema2;
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index b63532ee562..b4430133522 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -4,6 +4,7 @@
 --
 
 CREATE SCHEMA partition_split_schema;
+CREATE SCHEMA partition_split_schema2;
 SET search_path = partition_split_schema, public;
 
 --
@@ -92,6 +93,16 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 
+-- Check the source partition not in the search path
+SET search_path = partition_split_schema2, public;
+ALTER TABLE partition_split_schema.sales_range
+SPLIT PARTITION partition_split_schema.sales_feb_mar_apr2022 INTO
+  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+   PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+SET search_path = partition_split_schema, public;
+\d+ sales_range
+
 DROP TABLE sales_range;
 DROP TABLE sales_others;
 
@@ -140,10 +151,12 @@ CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
+-- Split partition, also check schema qualification of new partitions
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
-  (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
-   PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
+  (PARTITION partition_split_schema.sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
+   PARTITION partition_split_schema2.sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
+\d+ sales_range
 
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-10');
@@ -163,7 +176,7 @@ INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
 SELECT * FROM sales_jan2022;
 SELECT * FROM sales_feb2022;
-SELECT * FROM sales_mar2022;
+SELECT * FROM partition_split_schema2.sales_mar2022;
 SELECT * FROM sales_apr2022;
 SELECT * FROM sales_others;
 
@@ -844,5 +857,29 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO
 DROP TABLE t2;
 DROP TABLE t1;
 
+--
+-- Try to SPLIT partition of temporary table.
+--
+CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+
+-- Partitions should be temporary.
+SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence
+  FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
+  WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass
+  ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text;
+
+DROP TABLE t;
+
 --
 DROP SCHEMA partition_split_schema;
+DROP SCHEMA partition_split_schema2;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v9-0004-Fix-error-message-in-check_partition_bounds_for_s.patch (3.8K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/4-v9-0004-Fix-error-message-in-check_partition_bounds_for_s.patch)
  download | inline diff:
From dbf49badfd1f0556958f212f8bf53cbfd46998a7 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Thu, 18 Apr 2024 12:56:51 +0300
Subject: [PATCH v9 4/7] Fix error message in
 check_partition_bounds_for_split_range()

Currently, the error message is produced by a system of complex substitutions
making it quite untranslatable and hard to read.  This commit splits this into
4 plain error messages suitable for translation.

Reported-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20240408.152402.1485994009160660141.horikyota.ntt%40gmail.com
Reviewed-by: Pavel Borisov
---
 src/backend/partitioning/partbounds.c | 70 +++++++++++++++++++--------
 1 file changed, 49 insertions(+), 21 deletions(-)

diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index b08edf87a69..4eda59767ce 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5211,7 +5211,7 @@ check_partition_bounds_for_split_range(Relation parent,
 	if (first || last)
 	{
 		PartitionBoundSpec *split_spec = get_partition_bound_spec(splitPartOid, splitPartName);
-		bool		overlap = false;
+		PartitionRangeDatum *datum;
 
 		if (first)
 		{
@@ -5229,8 +5229,30 @@ check_partition_bounds_for_split_range(Relation parent,
 			 * Lower bound of "spec" should be equal (or greater than or equal
 			 * in case defaultPart=true) to lower bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval < 0))
-				overlap = true;
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+				{
+					datum = list_nth(spec->lowerdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is not equal to lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
+			else
+			{
+				if (cmpval < 0)
+				{
+					datum = list_nth(spec->lowerdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("lower bound of partition \"%s\" is less than lower bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
 		}
 		else
 		{
@@ -5248,24 +5270,30 @@ check_partition_bounds_for_split_range(Relation parent,
 			 * Upper bound of "spec" should be equal (or less than or equal in
 			 * case defaultPart=true) to upper bound of split partition.
 			 */
-			if ((!defaultPart && cmpval) || (defaultPart && cmpval > 0))
-				overlap = true;
-		}
-
-		if (overlap)
-		{
-			PartitionRangeDatum *datum;
-
-			datum = list_nth(first ? spec->lowerdatums : spec->upperdatums, abs(cmpval) - 1);
-
-			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-					 errmsg("%s bound of partition \"%s\" is %s %s bound of split partition",
-							first ? "lower" : "upper",
-							relname,
-							defaultPart ? (first ? "less than" : "greater than") : "not equal to",
-							first ? "lower" : "upper"),
-					 parser_errposition(pstate, datum->location)));
+			if (!defaultPart)
+			{
+				if (cmpval != 0)
+				{
+					datum = list_nth(spec->upperdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is not equal to upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
+			else
+			{
+				if (cmpval > 0)
+				{
+					datum = list_nth(spec->upperdatums, abs(cmpval) - 1);
+					ereport(ERROR,
+							(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+							 errmsg("upper bound of partition \"%s\" is greater than upper bound of split partition",
+									relname),
+							 parser_errposition(pstate, datum->location)));
+				}
+			}
 		}
 	}
 }
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v9-0002-Document-the-way-parition-MERGE-SPLIT-operations-.patch (2.2K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/5-v9-0002-Document-the-way-parition-MERGE-SPLIT-operations-.patch)
  download | inline diff:
From 337fe9ee0288df424ac15cef3e68fba096525af7 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Sun, 28 Apr 2024 03:39:30 +0300
Subject: [PATCH v9 2/7] Document the way parition MERGE/SPLIT operations
 create new partitions

Reported-by: Justin Pryzby
Discussion: https://postgr.es/m/ZilrByTp-pbz6Mvf%40pryzbyj2023
---
 doc/src/sgml/ref/alter_table.sgml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index fe36ff82e52..8a10a8bd79b 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1153,6 +1153,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       splitting we have a partition with the same name).
       Only simple, non-partitioned partition can be split.
      </para>
+     <para>
+      New partitions are created the same way as they get created with an
+      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name1</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
+      The indexes and identity are created later after moving the data
+      while attaching new partitions.
+     </para>
      <note>
       <para>
        This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
@@ -1213,6 +1219,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       can have the same name as one of the merged partitions.  Only simple,
       non-partitioned partitions can be merged.
      </para>
+     <para>
+      The new partition are created the same way as it gets created with an
+      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
+      The indexes and identity are created later after moving the data
+      while attaching the new partition.
+     </para>
      <note>
       <para>
        This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v9-0005-Rename-tables-in-tests-of-partition-MERGE-SPLIT-o.patch (205.0K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/6-v9-0005-Rename-tables-in-tests-of-partition-MERGE-SPLIT-o.patch)
  download | inline diff:
From 4dab981213713687849edab924e45211904fab89 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 11:31:57 +0300
Subject: [PATCH v9 5/7] Rename tables in tests of partition MERGE/SPLIT
 operations

Replace "salesman" with "salesperson", "salesmen" with "salespeople".  The
names are both gramatically correct and gender-neutral.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/fdaa003e-919c-cbc9-4f0c-e4546e96bd65%40gmail.com
Reviewed-by: Robert Haas, Pavel Borisov
---
 src/test/regress/expected/partition_merge.out |  666 ++++-----
 src/test/regress/expected/partition_split.out | 1266 ++++++++---------
 src/test/regress/sql/partition_merge.sql      |  160 +--
 src/test/regress/sql/partition_split.sql      |  280 ++--
 4 files changed, 1186 insertions(+), 1186 deletions(-)

diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 3aae5f89e80..a92a270c591 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -11,12 +11,12 @@ SET search_path = partitions_merge_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_dec2021 PARTITION OF sales_range FOR VALUES FROM ('2021-12-01') TO ('2021-12-31');
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-15');
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
@@ -60,7 +60,7 @@ DROP TABLE sales_range;
 --
 -- Add rows into partitioned table, then merge partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -122,68 +122,68 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_feb_mar_apr2022' and schemanam
 (1 row)
 
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (10 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 -- Use indexscan for testing indexes
 SET enable_seqscan = OFF;
 SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          11 | Trump         |          380 | 04-06-2022
-           5 | Deev          |          250 | 04-07-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             11 | Trump            |          380 | 04-06-2022
+              5 | Deev             |          250 | 04-07-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (10 rows)
 
 RESET enable_seqscan;
@@ -191,7 +191,7 @@ DROP TABLE sales_range;
 --
 -- Merge some partitions into DEFAULT partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -216,15 +216,15 @@ INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 -- name
 ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022, sales_others) INTO sales_others;
 select * from sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (7 rows)
 
 -- show partitions with conditions:
@@ -246,7 +246,7 @@ DROP TABLE sales_range;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -255,219 +255,219 @@ CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1)
 CREATE TABLE sales_jan2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1);
 CREATE TABLE sales_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (9 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
 (2 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
 (2 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 ALTER TABLE sales_date MERGE PARTITIONS (sales_jan2022, sales_feb2022) INTO sales_jan_feb2022;
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (11 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
 (6 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_20 PARTITION OF salespeople FOR VALUES FROM (10) TO (20);
+CREATE TABLE salespeople20_30 PARTITION OF salespeople FOR VALUES FROM (20) TO (30);
+CREATE TABLE salespeople30_40 PARTITION OF salespeople FOR VALUES FROM (30) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (10, 'May');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+INSERT INTO salespeople10_20 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+INSERT INTO salespeople10_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
-          20 | Smirnoff
-          30 | Ford
+SELECT * FROM salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
+             20 | Smirnoff
+             30 | Ford
 (4 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
-select * from salesmans;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
-          19 | Ivanov
-          10 | May
-          20 | Smirnoff
-          31 | Popov
-          30 | Ford
+CREATE TABLE salespeople10_20(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+CREATE TABLE salespeople20_30(salesperson_id INT PRIMARY KEY, d2 INT,  salesperson_name VARCHAR(30));
+CREATE TABLE salespeople30_40(salesperson_id INT PRIMARY KEY, d3 DATE, salesperson_name VARCHAR(30));
+INSERT INTO salespeople10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salespeople20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salespeople30_40 VALUES (31, now(), 'Popov');
+ALTER TABLE salespeople10_20 DROP COLUMN d1;
+ALTER TABLE salespeople20_30 DROP COLUMN d2;
+ALTER TABLE salespeople30_40 DROP COLUMN d3;
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salespeople ATTACH PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salespeople ATTACH PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40);
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
+select * from salespeople;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
+             19 | Ivanov
+             10 | May
+             20 | Smirnoff
+             31 | Popov
+             30 | Ford
 (6 rows)
 
-select * from salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+select * from salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-select * from salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          19 | Ivanov
-          10 | May
-          20 | Smirnoff
-          31 | Popov
-          30 | Ford
+select * from salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             19 | Ivanov
+             10 | May
+             20 | Smirnoff
+             31 | Popov
+             30 | Ford
 (5 rows)
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 --
 -- Test: merge sub-partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr2022_01_10 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-10');
 CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');
 CREATE TABLE sales_apr2022_20_30 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01');
@@ -489,88 +489,88 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr2022_01_10;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_apr2022_10_20;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           4 | Ivanov        |          750 | 04-13-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              4 | Ivanov           |          750 | 04-13-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_20_30;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
 (1 row)
 
 ALTER TABLE sales_apr2022 MERGE PARTITIONS (sales_apr2022_01_10, sales_apr2022_10_20, sales_apr2022_20_30) INTO sales_apr_all;
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr_all;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 DROP TABLE sales_range;
@@ -581,8 +581,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -614,33 +614,33 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, MERGE PARTITIONS with data
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
 CREATE TABLE sales_west PARTITION OF sales_list FOR VALUES IN ('Lisbon', 'New York', 'Madrid');
 CREATE TABLE sales_east PARTITION OF sales_list FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok');
 CREATE TABLE sales_central PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
   FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
@@ -669,68 +669,68 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge
 (3 rows)
 
 SELECT * FROM sales_list;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           2 | Smirnoff      | New York       |          500 | 03-03-2022
-           5 | Deev          | Lisbon         |          250 | 03-07-2022
-          11 | Muller        | Madrid         |          650 | 03-05-2022
-          14 | Plato         | Lisbon         |          950 | 03-05-2022
-           1 | Trump         | Bejing         |         1000 | 03-01-2022
-           8 | Li            | Vladivostok    |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw         |          750 | 03-04-2022
-           6 | Poirot        | Berlin         |         1000 | 03-01-2022
-          12 | Smith         | Kyiv           |          350 | 03-10-2022
-          13 | Gandi         | Warsaw         |          150 | 03-08-2022
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Helsinki       |         1200 | 03-06-2022
-           9 | May           | Helsinki       |         1200 | 03-11-2022
-          10 | Halder        | Oslo           |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              2 | Smirnoff         | New York       |          500 | 03-03-2022
+              5 | Deev             | Lisbon         |          250 | 03-07-2022
+             11 | Muller           | Madrid         |          650 | 03-05-2022
+             14 | Plato            | Lisbon         |          950 | 03-05-2022
+              1 | Trump            | Bejing         |         1000 | 03-01-2022
+              8 | Li               | Vladivostok    |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw         |          750 | 03-04-2022
+              6 | Poirot           | Berlin         |         1000 | 03-01-2022
+             12 | Smith            | Kyiv           |          350 | 03-10-2022
+             13 | Gandi            | Warsaw         |          150 | 03-08-2022
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Helsinki       |         1200 | 03-06-2022
+              9 | May              | Helsinki       |         1200 | 03-11-2022
+             10 | Halder           | Oslo           |          800 | 03-02-2022
 (14 rows)
 
 SELECT * FROM sales_nord;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Helsinki       |         1200 | 03-06-2022
-           9 | May           | Helsinki       |         1200 | 03-11-2022
-          10 | Halder        | Oslo           |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Helsinki       |         1200 | 03-06-2022
+              9 | May              | Helsinki       |         1200 | 03-11-2022
+             10 | Halder           | Oslo           |          800 | 03-02-2022
 (4 rows)
 
 SELECT * FROM sales_all;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           2 | Smirnoff      | New York    |          500 | 03-03-2022
-           5 | Deev          | Lisbon      |          250 | 03-07-2022
-          11 | Muller        | Madrid      |          650 | 03-05-2022
-          14 | Plato         | Lisbon      |          950 | 03-05-2022
-           1 | Trump         | Bejing      |         1000 | 03-01-2022
-           8 | Li            | Vladivostok |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-           6 | Poirot        | Berlin      |         1000 | 03-01-2022
-          12 | Smith         | Kyiv        |          350 | 03-10-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              2 | Smirnoff         | New York    |          500 | 03-03-2022
+              5 | Deev             | Lisbon      |          250 | 03-07-2022
+             11 | Muller           | Madrid      |          650 | 03-05-2022
+             14 | Plato            | Lisbon      |          950 | 03-05-2022
+              1 | Trump            | Bejing      |         1000 | 03-01-2022
+              8 | Li               | Vladivostok |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+              6 | Poirot           | Berlin      |         1000 | 03-01-2022
+             12 | Smith            | Kyiv        |          350 | 03-10-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (10 rows)
 
 -- Use indexscan for testing indexes after merging partitions
 SET enable_seqscan = OFF;
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
 (1 row)
 
 RESET enable_seqscan;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index e2a362ffafd..55ae37ad370 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -11,7 +11,7 @@ SET search_path = partition_split_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id int, salesman_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id int, salesperson_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -85,8 +85,8 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
-LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
-                                                             ^
+LINE 4:    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO...
+                                                    ^
 -- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
@@ -114,13 +114,13 @@ SPLIT PARTITION partition_split_schema.sales_feb_mar_apr2022 INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 SET search_path = partition_split_schema, public;
 \d+ sales_range
-                             Partitioned table "partition_split_schema.sales_range"
-    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
----------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
- salesman_id   | integer               |           |          |         | plain    |              | 
- salesman_name | character varying(30) |           |          |         | extended |              | 
- sales_amount  | integer               |           |          |         | plain    |              | 
- sales_date    | date                  |           |          |         | plain    |              | 
+                              Partitioned table "partition_split_schema.sales_range"
+      Column      |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+------------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesperson_id   | integer               |           |          |         | plain    |              | 
+ salesperson_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount     | integer               |           |          |         | plain    |              | 
+ sales_date       | date                  |           |          |         | plain    |              | 
 Partition key: RANGE (sales_date)
 Partitions: partition_split_schema2.sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
             partition_split_schema2.sales_feb2022 FOR VALUES FROM ('02-01-2022') TO ('03-01-2022'),
@@ -132,7 +132,7 @@ DROP TABLE sales_others;
 --
 -- Add rows into partitioned table then split partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -155,68 +155,68 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 DROP TABLE sales_range CASCADE;
 --
 -- Add split partition, then add rows into partitioned table
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -226,13 +226,13 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION partition_split_schema2.sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 \d+ sales_range
-                             Partitioned table "partition_split_schema.sales_range"
-    Column     |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
----------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
- salesman_id   | integer               |           |          |         | plain    |              | 
- salesman_name | character varying(30) |           |          |         | extended |              | 
- sales_amount  | integer               |           |          |         | plain    |              | 
- sales_date    | date                  |           |          |         | plain    |              | 
+                              Partitioned table "partition_split_schema.sales_range"
+      Column      |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description 
+------------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
+ salesperson_id   | integer               |           |          |         | plain    |              | 
+ salesperson_name | character varying(30) |           |          |         | extended |              | 
+ sales_amount     | integer               |           |          |         | plain    |              | 
+ sales_date       | date                  |           |          |         | plain    |              | 
 Partition key: RANGE (sales_date)
 Partitions: partition_split_schema2.sales_mar2022 FOR VALUES FROM ('03-01-2022') TO ('04-01-2022'),
             sales_apr2022 FOR VALUES FROM ('04-01-2022') TO ('05-01-2022'),
@@ -255,61 +255,61 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM partition_split_schema2.sales_mar2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 DROP TABLE sales_range CASCADE;
@@ -319,7 +319,7 @@ DROP TABLE sales_range CASCADE;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -327,103 +327,103 @@ CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month
 CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1) TO (2022, 1, 1);
 CREATE TABLE sales_jan_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (9 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
 (4 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 ALTER TABLE sales_date SPLIT PARTITION sales_jan_feb2022 INTO
   (PARTITION sales_jan2022 FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1),
    PARTITION sales_feb2022 FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1));
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 SELECT * FROM sales_date;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (11 rows)
 
 SELECT * FROM sales_dec2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2021 |          12 |         7 | 2021.12.07 | Sales department
- Manager2      |       2021 |          12 |         8 | 2021.12.08 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2021 |          12 |         7 | 2021.12.07 | Sales department
+ Manager2         |       2021 |          12 |         8 | 2021.12.08 | Sales department
 (2 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager3      |       2022 |           1 |         1 | 2022.01.01 | Sales department
- Manager2      |       2022 |           1 |         2 | 2022.01.02 | Sales department
- Manager1      |       2022 |           1 |        10 | 2022.01.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager3         |       2022 |           1 |         1 | 2022.01.01 | Sales department
+ Manager2         |       2022 |           1 |         2 | 2022.01.02 | Sales department
+ Manager1         |       2022 |           1 |        10 | 2022.01.10 | Sales department
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           2 |         4 | 2022.02.04 | Sales department
- Manager3      |       2022 |           2 |         1 | 2022.02.01 | Sales department
- Manager2      |       2022 |           2 |        10 | 2022.02.10 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           2 |         4 | 2022.02.04 | Sales department
+ Manager3         |       2022 |           2 |         1 | 2022.02.01 | Sales department
+ Manager2         |       2022 |           2 |        10 | 2022.02.10 | Sales department
 (3 rows)
 
 SELECT * FROM sales_other;
- salesman_name | sales_year | sales_month | sales_day | sales_date | sales_department 
----------------+------------+-------------+-----------+------------+------------------
- Manager1      |       2022 |           3 |         3 | 2022.03.03 | Sales department
- Manager2      |       2022 |           3 |         4 | 2022.03.04 | Sales department
- Manager3      |       2022 |           5 |         1 | 2022.05.01 | Sales department
+ salesperson_name | sales_year | sales_month | sales_day | sales_date | sales_department 
+------------------+------------+-------------+-----------+------------+------------------
+ Manager1         |       2022 |           3 |         3 | 2022.03.03 | Sales department
+ Manager2         |       2022 |           3 |         4 | 2022.03.04 | Sales department
+ Manager3         |       2022 |           5 |         1 | 2022.05.01 | Sales department
 (3 rows)
 
 --ERROR:  relation "sales_jan_feb2022" does not exist
@@ -435,7 +435,7 @@ DROP TABLE sales_date CASCADE;
 --
 -- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date);
@@ -454,19 +454,19 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-           6 | Poirot        |          150 | 02-11-2022
-           7 | Li            |          175 | 03-08-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          11 | Trump         |          380 | 04-06-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+              6 | Poirot           |          150 | 02-11-2022
+              7 | Li               |          175 | 03-08-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             11 | Trump            |          380 | 04-06-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (11 rows)
 
 SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'partition_split_schema';
@@ -484,34 +484,34 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_feb2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_mar2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022 where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          11 | Trump         |          380 | 04-06-2022
-           5 | Deev          |          250 | 04-07-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             11 | Trump            |          380 | 04-06-2022
+              5 | Deev             |          250 | 04-07-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_others where sales_date > '2022-01-01';
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
 (1 row)
 
 SET enable_indexscan = ON;
@@ -544,7 +544,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Test: some cases for splitting DEFAULT partition (different bounds)
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 -- sales_error intersects with sales_dec2022 (lower bound)
 -- ERROR:  lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022"
@@ -601,7 +601,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301),
    PARTITION sales_others DEFAULT);
 DROP TABLE sales_range;
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 -- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
@@ -613,20 +613,20 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesperson_id INT REFERENCES salespeople(salesperson_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb_mar_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
@@ -635,50 +635,50 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
 -- We should see the same CONSTRAINTs as on sales_feb_mar_apr2022 partition
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_feb2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid;
-                    pg_get_constraintdef                     |            conname             | conkey 
--------------------------------------------------------------+--------------------------------+--------
- CHECK ((sales_amount > 1))                                  | sales_range_sales_amount_check | {2}
- FOREIGN KEY (salesman_id) REFERENCES salesmans(salesman_id) | sales_range_salesman_id_fkey   | {1}
+                        pg_get_constraintdef                         |             conname             | conkey 
+---------------------------------------------------------------------+---------------------------------+--------
+ CHECK ((sales_amount > 1))                                          | sales_range_sales_amount_check  | {2}
+ FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1}
 (2 rows)
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
 ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 DETAIL:  Failing row contains (1, 0, 03-11-2022).
--- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
-ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(-1) is not present in table "salesmans".
+ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
+DETAIL:  Key (salesperson_id)=(-1) is not present in table "salespeople".
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (19, 'Ivanov');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (30, 'Ford');
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
 INSERT INTO sales VALUES (10, 150, '2022-03-01');
@@ -687,280 +687,280 @@ INSERT INTO sales VALUES (19, 200, '2022-03-04');
 INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_40;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
-          20 | Smirnoff
-          30 | Ford
+SELECT * FROM salespeople10_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
+             20 | Smirnoff
+             30 | Ford
 (4 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
+SELECT * FROM salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+SELECT * FROM salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+SELECT * FROM salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
--- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
-ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
-DETAIL:  Key (salesman_id)=(40) is not present in table "salesmans".
+ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
+DETAIL:  Key (salesperson_id)=(40) is not present in table "salespeople".
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1,  'Poirot');
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
 	RAISE NOTICE 'trigger(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL;
     RETURN NULL;
 END;
 $BODY$;
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
-CREATE TRIGGER salesmans_after_insert_row_trigger
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (10, 'May');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+INSERT INTO salespeople10_40 VALUES (19, 'Ivanov');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = STATEMENT
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = STATEMENT
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
-NOTICE:  trigger(salesmans) called: action = INSERT, when = AFTER, level = ROW
-SELECT * FROM salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+INSERT INTO salespeople30_40 VALUES (30, 'Ford');
+NOTICE:  trigger(salespeople) called: action = INSERT, when = AFTER, level = ROW
+SELECT * FROM salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          10 | May
-          19 | Ivanov
+SELECT * FROM salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             10 | May
+             19 | Ivanov
 (2 rows)
 
-SELECT * FROM salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+SELECT * FROM salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-SELECT * FROM salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+SELECT * FROM salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salespeople(salesperson_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople1_2 PARTITION OF salespeople FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+CREATE TABLE salespeople2_5(salesperson_id INT NOT NULL, salesperson_name VARCHAR(30));
+ALTER TABLE salespeople ATTACH PARTITION salespeople2_5 FOR VALUES FROM (2) TO (5);
+INSERT INTO salespeople (salesperson_name) VALUES ('Poirot');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ivanov');
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_5'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
-SELECT * FROM salesmans1_2;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+ALTER TABLE salespeople SPLIT PARTITION salespeople2_5 INTO
+  (PARTITION salespeople2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salespeople3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salespeople4_5 FOR VALUES FROM (4) TO (5));
+INSERT INTO salespeople (salesperson_name) VALUES ('May');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ford');
+SELECT * FROM salespeople1_2;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-SELECT * FROM salesmans2_3;
- salesman_id | salesman_name 
--------------+---------------
-           2 | Ivanov
+SELECT * FROM salespeople2_3;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              2 | Ivanov
 (1 row)
 
-SELECT * FROM salesmans3_4;
- salesman_id | salesman_name 
--------------+---------------
-           3 | May
+SELECT * FROM salespeople3_4;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              3 | May
 (1 row)
 
-SELECT * FROM salesmans4_5;
- salesman_id | salesman_name 
--------------+---------------
-           4 | Ford
+SELECT * FROM salespeople4_5;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              4 | Ford
 (1 row)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_3'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople3_4'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
-    attname    | attidentity | attgenerated 
----------------+-------------+--------------
- salesman_id   | a           | 
- salesman_name |             | 
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople4_5'::regclass::oid;
+     attname      | attidentity | attgenerated 
+------------------+-------------+--------------
+ salesperson_id   | a           | 
+ salesperson_name |             | 
 (2 rows)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
-select * from salesmans01_10;
- salesman_id | salesman_name 
--------------+---------------
-           1 | Poirot
+CREATE TABLE salespeople10_40(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, d2 INT, d3 DATE, salesperson_name VARCHAR(30));
+INSERT INTO salespeople10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salespeople10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+ALTER TABLE salespeople10_40 DROP COLUMN d1;
+ALTER TABLE salespeople10_40 DROP COLUMN d2;
+ALTER TABLE salespeople10_40 DROP COLUMN d3;
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_40 FOR VALUES FROM (10) TO (40);
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
+select * from salespeople01_10;
+ salesperson_id | salesperson_name 
+----------------+------------------
+              1 | Poirot
 (1 row)
 
-select * from salesmans10_20;
- salesman_id | salesman_name 
--------------+---------------
-          19 | Ivanov
-          10 | May
+select * from salespeople10_20;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             19 | Ivanov
+             10 | May
 (2 rows)
 
-select * from salesmans20_30;
- salesman_id | salesman_name 
--------------+---------------
-          20 | Smirnoff
+select * from salespeople20_30;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             20 | Smirnoff
 (1 row)
 
-select * from salesmans30_40;
- salesman_id | salesman_name 
--------------+---------------
-          30 | Ford
+select * from salespeople30_40;
+ salesperson_id | salesperson_name 
+----------------+------------------
+             30 | Ford
 (1 row)
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 --
 -- Test: split sub-partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_all PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -980,31 +980,31 @@ INSERT INTO sales_range VALUES (12, 'Plato',    350,  '2022-03-19');
 INSERT INTO sales_range VALUES (13, 'Gandi',    377,  '2022-01-09');
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 ALTER TABLE sales_apr2022 SPLIT PARTITION sales_apr_all INTO
@@ -1012,50 +1012,50 @@ ALTER TABLE sales_apr2022 SPLIT PARTITION sales_apr_all INTO
    PARTITION sales_apr2022_10_20 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20'),
    PARTITION sales_apr2022_20_30 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01'));
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              3 | Ford             |         2000 | 04-30-2022
 (4 rows)
 
 SELECT * FROM sales_apr2022_01_10;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_apr2022_10_20;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           4 | Ivanov        |          750 | 04-13-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              4 | Ivanov           |          750 | 04-13-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_20_30;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
 (1 row)
 
 DROP TABLE sales_range;
@@ -1066,8 +1066,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -1106,8 +1106,8 @@ DROP TABLE sales_list;
 --   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -1131,109 +1131,109 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
 --
 CREATE TABLE sales_list
-(salesman_id SERIAL,
- salesman_name VARCHAR(30),
+(salesperson_id SERIAL,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
    PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
 SELECT * FROM sales_list;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           1 | Trump         | Bejing         |         1000 | 03-01-2022
-           8 | Li            | Vladivostok    |         1150 | 03-09-2022
-           4 | Ivanov        | Warsaw         |          750 | 03-04-2022
-           6 | Poirot        | Berlin         |         1000 | 03-01-2022
-          12 | Smith         | Kyiv           |          350 | 03-10-2022
-          13 | Gandi         | Warsaw         |          150 | 03-08-2022
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Oslo           |         1200 | 03-06-2022
-           9 | May           | Oslo           |         1200 | 03-11-2022
-          10 | Halder        | Helsinki       |          800 | 03-02-2022
-           2 | Smirnoff      | New York       |          500 | 03-03-2022
-           5 | Deev          | Lisbon         |          250 | 03-07-2022
-          11 | Muller        | Madrid         |          650 | 03-05-2022
-          14 | Plato         | Lisbon         |          950 | 03-05-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              1 | Trump            | Bejing         |         1000 | 03-01-2022
+              8 | Li               | Vladivostok    |         1150 | 03-09-2022
+              4 | Ivanov           | Warsaw         |          750 | 03-04-2022
+              6 | Poirot           | Berlin         |         1000 | 03-01-2022
+             12 | Smith            | Kyiv           |          350 | 03-10-2022
+             13 | Gandi            | Warsaw         |          150 | 03-08-2022
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Oslo           |         1200 | 03-06-2022
+              9 | May              | Oslo           |         1200 | 03-11-2022
+             10 | Halder           | Helsinki       |          800 | 03-02-2022
+              2 | Smirnoff         | New York       |          500 | 03-03-2022
+              5 | Deev             | Lisbon         |          250 | 03-07-2022
+             11 | Muller           | Madrid         |          650 | 03-05-2022
+             14 | Plato            | Lisbon         |          950 | 03-05-2022
 (14 rows)
 
 SELECT * FROM sales_west;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           2 | Smirnoff      | New York    |          500 | 03-03-2022
-           5 | Deev          | Lisbon      |          250 | 03-07-2022
-          11 | Muller        | Madrid      |          650 | 03-05-2022
-          14 | Plato         | Lisbon      |          950 | 03-05-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              2 | Smirnoff         | New York    |          500 | 03-03-2022
+              5 | Deev             | Lisbon      |          250 | 03-07-2022
+             11 | Muller           | Madrid      |          650 | 03-05-2022
+             14 | Plato            | Lisbon      |          950 | 03-05-2022
 (4 rows)
 
 SELECT * FROM sales_east;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           1 | Trump         | Bejing      |         1000 | 03-01-2022
-           8 | Li            | Vladivostok |         1150 | 03-09-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              1 | Trump            | Bejing      |         1000 | 03-01-2022
+              8 | Li               | Vladivostok |         1150 | 03-09-2022
 (2 rows)
 
 SELECT * FROM sales_nord;
- salesman_id | salesman_name |  sales_state   | sales_amount | sales_date 
--------------+---------------+----------------+--------------+------------
-           3 | Ford          | St. Petersburg |         2000 | 03-05-2022
-           7 | May           | Oslo           |         1200 | 03-06-2022
-           9 | May           | Oslo           |         1200 | 03-11-2022
-          10 | Halder        | Helsinki       |          800 | 03-02-2022
+ salesperson_id | salesperson_name |  sales_state   | sales_amount | sales_date 
+----------------+------------------+----------------+--------------+------------
+              3 | Ford             | St. Petersburg |         2000 | 03-05-2022
+              7 | May              | Oslo           |         1200 | 03-06-2022
+              9 | May              | Oslo           |         1200 | 03-11-2022
+             10 | Halder           | Helsinki       |          800 | 03-02-2022
 (4 rows)
 
 SELECT * FROM sales_central;
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-           6 | Poirot        | Berlin      |         1000 | 03-01-2022
-          12 | Smith         | Kyiv        |          350 | 03-10-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+              6 | Poirot           | Berlin      |         1000 | 03-01-2022
+             12 | Smith            | Kyiv        |          350 | 03-10-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (4 rows)
 
 -- Use indexscan for testing indexes after splitting partition
 SET enable_indexscan = ON;
 SET enable_seqscan = OFF;
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
-          13 | Gandi         | Warsaw      |          150 | 03-08-2022
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
+             13 | Gandi            | Warsaw      |          150 | 03-08-2022
 (2 rows)
 
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
- salesman_id | salesman_name | sales_state | sales_amount | sales_date 
--------------+---------------+-------------+--------------+------------
-           4 | Ivanov        | Warsaw      |          750 | 03-04-2022
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
+ salesperson_id | salesperson_name | sales_state | sales_amount | sales_date 
+----------------+------------------+-------------+--------------+------------
+              4 | Ivanov           | Warsaw      |          750 | 03-04-2022
 (1 row)
 
 SET enable_indexscan = ON;
@@ -1244,7 +1244,7 @@ DROP TABLE sales_list;
 --   * split DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
 INSERT INTO sales_range VALUES (2,  'Smirnoff', 500,  '2022-02-09');
@@ -1267,42 +1267,42 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_feb2022_1decade FOR VALUES FROM ('2022-02-01') TO ('2022-02-10'),
    PARTITION sales_apr2022_1decade FOR VALUES FROM ('2022-04-01') TO ('2022-04-10'));
 SELECT * FROM sales_jan2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             13 | Gandi            |          377 | 01-09-2022
 (1 row)
 
 SELECT * FROM sales_feb2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-09-2022
-           6 | Poirot        |          150 | 02-07-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-09-2022
+              6 | Poirot           |          150 | 02-07-2022
 (2 rows)
 
 SELECT * FROM sales_mar2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          10 | Halder        |          350 | 01-28-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             10 | Halder           |          350 | 01-28-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (8 rows)
 
 DROP TABLE sales_range;
@@ -1311,7 +1311,7 @@ DROP TABLE sales_range;
 --   * split non-DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -1334,42 +1334,42 @@ ALTER TABLE sales_range SPLIT PARTITION sales_all INTO
    PARTITION sales_feb2022_1decade FOR VALUES FROM ('2022-02-01') TO ('2022-02-10'),
    PARTITION sales_apr2022_1decade FOR VALUES FROM ('2022-04-01') TO ('2022-04-10'));
 SELECT * FROM sales_jan2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             13 | Gandi            |          377 | 01-09-2022
 (1 row)
 
 SELECT * FROM sales_feb2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-09-2022
-           6 | Poirot        |          150 | 02-07-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-09-2022
+              6 | Poirot           |          150 | 02-07-2022
 (2 rows)
 
 SELECT * FROM sales_mar2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
 (1 row)
 
 SELECT * FROM sales_apr2022_1decade;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (2 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-          14 | Smith         |          510 | 05-04-2022
-           1 | May           |         1000 | 01-31-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           9 | Muller        |          250 | 03-11-2022
-          10 | Halder        |          350 | 01-28-2022
-          12 | Plato         |          350 | 03-19-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+             14 | Smith            |          510 | 05-04-2022
+              1 | May              |         1000 | 01-31-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              9 | Muller           |          250 | 03-11-2022
+             10 | Halder           |          350 | 01-28-2022
+             12 | Plato            |          350 | 03-19-2022
 (8 rows)
 
 DROP TABLE sales_range;
@@ -1377,7 +1377,7 @@ DROP TABLE sales_range;
 -- Test for split non-DEFAULT partition to DEFAULT partition + partitions
 -- with spaces between bounds.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -1399,56 +1399,56 @@ ALTER TABLE sales_range SPLIT PARTITION sales_all INTO
    PARTITION sales_others DEFAULT);
 INSERT INTO sales_range VALUES (14, 'Smith',    510,  '2022-05-04');
 SELECT * FROM sales_range;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (14 rows)
 
 SELECT * FROM sales_jan2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           1 | May           |         1000 | 01-31-2022
-          10 | Halder        |          350 | 01-28-2022
-          13 | Gandi         |          377 | 01-09-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              1 | May              |         1000 | 01-31-2022
+             10 | Halder           |          350 | 01-28-2022
+             13 | Gandi            |          377 | 01-09-2022
 (3 rows)
 
 SELECT * FROM sales_feb2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           2 | Smirnoff      |          500 | 02-10-2022
-           6 | Poirot        |          150 | 02-11-2022
-           8 | Ericsson      |          185 | 02-23-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              2 | Smirnoff         |          500 | 02-10-2022
+              6 | Poirot           |          150 | 02-11-2022
+              8 | Ericsson         |          185 | 02-23-2022
 (3 rows)
 
 SELECT * FROM sales_apr2022;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           3 | Ford          |         2000 | 04-30-2022
-           4 | Ivanov        |          750 | 04-13-2022
-           5 | Deev          |          250 | 04-07-2022
-          11 | Trump         |          380 | 04-06-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              3 | Ford             |         2000 | 04-30-2022
+              4 | Ivanov           |          750 | 04-13-2022
+              5 | Deev             |          250 | 04-07-2022
+             11 | Trump            |          380 | 04-06-2022
 (4 rows)
 
 SELECT * FROM sales_others;
- salesman_id | salesman_name | sales_amount | sales_date 
--------------+---------------+--------------+------------
-           7 | Li            |          175 | 03-08-2022
-           9 | Muller        |          250 | 03-11-2022
-          12 | Plato         |          350 | 03-19-2022
-          14 | Smith         |          510 | 05-04-2022
+ salesperson_id | salesperson_name | sales_amount | sales_date 
+----------------+------------------+--------------+------------
+              7 | Li               |          175 | 03-08-2022
+              9 | Muller           |          250 | 03-11-2022
+             12 | Plato            |          350 | 03-19-2022
+             14 | Smith            |          510 | 05-04-2022
 (4 rows)
 
 DROP TABLE sales_range;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 5a69425d96e..085c422d540 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -14,13 +14,13 @@ SET search_path = partitions_merge_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_dec2021 PARTITION OF sales_range FOR VALUES FROM ('2021-12-01') TO ('2021-12-31');
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-15');
 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
@@ -56,7 +56,7 @@ DROP TABLE sales_range;
 --
 -- Add rows into partitioned table, then merge partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -115,7 +115,7 @@ DROP TABLE sales_range;
 --
 -- Merge some partitions into DEFAULT partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
@@ -158,7 +158,7 @@ DROP TABLE sales_range;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -169,15 +169,15 @@ CREATE TABLE sales_jan2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1)
 CREATE TABLE sales_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -187,8 +187,8 @@ SELECT * FROM sales_other;
 
 ALTER TABLE sales_date MERGE PARTITIONS (sales_jan2022, sales_feb2022) INTO sales_jan_feb2022;
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -200,14 +200,14 @@ DROP TABLE sales_date;
 --
 -- Test: merge partitions of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_20 PARTITION OF salesmans FOR VALUES FROM (10) TO (20);
-CREATE TABLE salesmans20_30 PARTITION OF salesmans FOR VALUES FROM (20) TO (30);
-CREATE TABLE salesmans30_40 PARTITION OF salesmans FOR VALUES FROM (30) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_20 PARTITION OF salespeople FOR VALUES FROM (10) TO (20);
+CREATE TABLE salespeople20_30 PARTITION OF salespeople FOR VALUES FROM (20) TO (30);
+CREATE TABLE salespeople30_40 PARTITION OF salespeople FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -216,80 +216,80 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salespeople VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_20 VALUES (19, 'Ivanov');
+INSERT INTO salespeople10_20 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (30, 'Ford');
+INSERT INTO salespeople10_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: merge partitions with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create partitions with some deleted columns:
-CREATE TABLE salesmans10_20(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-CREATE TABLE salesmans20_30(salesman_id INT PRIMARY KEY, d2 INT,  salesman_name VARCHAR(30));
-CREATE TABLE salesmans30_40(salesman_id INT PRIMARY KEY, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salespeople10_20(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+CREATE TABLE salespeople20_30(salesperson_id INT PRIMARY KEY, d2 INT,  salesperson_name VARCHAR(30));
+CREATE TABLE salespeople30_40(salesperson_id INT PRIMARY KEY, d3 DATE, salesperson_name VARCHAR(30));
 
-INSERT INTO salesmans10_20 VALUES ('dummy value 1', 19, 'Ivanov');
-INSERT INTO salesmans20_30 VALUES (20, 101, 'Smirnoff');
-INSERT INTO salesmans30_40 VALUES (31, now(), 'Popov');
+INSERT INTO salespeople10_20 VALUES ('dummy value 1', 19, 'Ivanov');
+INSERT INTO salespeople20_30 VALUES (20, 101, 'Smirnoff');
+INSERT INTO salespeople30_40 VALUES (31, now(), 'Popov');
 
-ALTER TABLE salesmans10_20 DROP COLUMN d1;
-ALTER TABLE salesmans20_30 DROP COLUMN d2;
-ALTER TABLE salesmans30_40 DROP COLUMN d3;
+ALTER TABLE salespeople10_20 DROP COLUMN d1;
+ALTER TABLE salespeople20_30 DROP COLUMN d2;
+ALTER TABLE salespeople30_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20);
-ALTER TABLE salesmans ATTACH PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30);
-ALTER TABLE salesmans ATTACH PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40);
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20);
+ALTER TABLE salespeople ATTACH PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30);
+ALTER TABLE salespeople ATTACH PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
-ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40;
+ALTER TABLE salespeople MERGE PARTITIONS (salespeople10_20, salespeople20_30, salespeople30_40) INTO salespeople10_40;
 
-select * from salesmans;
-select * from salesmans01_10;
-select * from salesmans10_40;
+select * from salespeople;
+select * from salespeople01_10;
+select * from salespeople10_40;
 
-DROP TABLE salesmans;
+DROP TABLE salespeople;
 
 --
 -- Test: merge sub-partitions
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr2022_01_10 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-04-10');
 CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');
 CREATE TABLE sales_apr2022_20_30 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-20') TO ('2022-05-01');
@@ -336,8 +336,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -373,14 +373,14 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, MERGE PARTITIONS with data
 --
 CREATE TABLE sales_list
-(salesman_id INT GENERATED ALWAYS AS IDENTITY,
- salesman_name VARCHAR(30),
+(salesperson_id INT GENERATED ALWAYS AS IDENTITY,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
 
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki');
@@ -389,20 +389,20 @@ CREATE TABLE sales_east PARTITION OF sales_list FOR VALUES IN ('Bejing', 'Delhi'
 CREATE TABLE sales_central PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Helsinki',       1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Oslo',            800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 
 -- show partitions with conditions:
 SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
@@ -427,7 +427,7 @@ SET enable_seqscan = OFF;
 
 SELECT * FROM sales_all WHERE sales_state = 'Warsaw';
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
 
 RESET enable_seqscan;
 
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index b4430133522..3a7f2f9c294 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -14,7 +14,7 @@ SET search_path = partition_split_schema, public;
 --
 -- Test for error codes
 --
-CREATE TABLE sales_range (salesman_id int, salesman_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id int, salesperson_name varchar(30), sales_amount int, sales_date date) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -109,7 +109,7 @@ DROP TABLE sales_others;
 --
 -- Add rows into partitioned table then split partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -146,7 +146,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Add split partition, then add rows into partitioned table
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
@@ -188,7 +188,7 @@ DROP TABLE sales_range CASCADE;
 --   * GENERATED column;
 --   * column with DEFAULT value.
 --
-CREATE TABLE sales_date (salesman_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
+CREATE TABLE sales_date (salesperson_name VARCHAR(30), sales_year INT, sales_month INT, sales_day INT,
   sales_date VARCHAR(10) GENERATED ALWAYS AS
     (LPAD(sales_year::text, 4, '0') || '.' || LPAD(sales_month::text, 2, '0') || '.' || LPAD(sales_day::text, 2, '0')) STORED,
   sales_department VARCHAR(30) DEFAULT 'Sales department')
@@ -198,15 +198,15 @@ CREATE TABLE sales_dec2022 PARTITION OF sales_date FOR VALUES FROM (2021, 12, 1)
 CREATE TABLE sales_jan_feb2022 PARTITION OF sales_date FOR VALUES FROM (2022, 1, 1) TO (2022, 3, 1);
 CREATE TABLE sales_other PARTITION OF sales_date FOR VALUES FROM (2022, 3, 1) TO (MAXVALUE, MAXVALUE, MAXVALUE);
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2021, 12, 7);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2021, 12, 8);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 1, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 2, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 1, 2);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 2, 1);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 3, 3);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 3, 4);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager3', 2022, 5, 1);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -217,8 +217,8 @@ ALTER TABLE sales_date SPLIT PARTITION sales_jan_feb2022 INTO
   (PARTITION sales_jan2022 FOR VALUES FROM (2022, 1, 1) TO (2022, 2, 1),
    PARTITION sales_feb2022 FOR VALUES FROM (2022, 2, 1) TO (2022, 3, 1));
 
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
-INSERT INTO sales_date(salesman_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager1', 2022, 1, 10);
+INSERT INTO sales_date(salesperson_name, sales_year, sales_month, sales_day) VALUES ('Manager2', 2022, 2, 10);
 
 SELECT * FROM sales_date;
 SELECT * FROM sales_dec2022;
@@ -234,7 +234,7 @@ DROP TABLE sales_date CASCADE;
 --
 -- Test: split DEFAULT partition; use an index on partition key; check index after split
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date);
@@ -285,7 +285,7 @@ DROP TABLE sales_range CASCADE;
 --
 -- Test: some cases for splitting DEFAULT partition (different bounds)
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- sales_error intersects with sales_dec2022 (lower bound)
@@ -335,7 +335,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
 
 DROP TABLE sales_range;
 
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 -- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022
@@ -350,11 +350,11 @@ DROP TABLE sales_range;
 --
 -- Test: split partition with CHECK and FOREIGN KEY CONSTRAINTs on partitioned table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30));
-INSERT INTO salesmans VALUES (1,  'Poirot');
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30));
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE TABLE sales_range (
-salesman_id INT REFERENCES salesmans(salesman_id),
+salesperson_id INT REFERENCES salespeople(salesperson_id),
 sales_amount INT CHECK (sales_amount > 1),
 sales_date DATE) PARTITION BY RANGE (sales_date);
 
@@ -376,28 +376,28 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre
 
 -- ERROR:  new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check"
 INSERT INTO sales_range VALUES (1, 0, '2022-03-11');
--- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey"
 INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
 -- ok
 INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
 
 DROP TABLE sales_range CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
-CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
+CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (19, 'Ivanov');
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (19, 'Ivanov');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
 INSERT INTO sales VALUES (1,  100, '2022-03-01');
 INSERT INTO sales VALUES (1,  110, '2022-03-02');
@@ -408,36 +408,36 @@ INSERT INTO sales VALUES (20, 50,  '2022-03-12');
 INSERT INTO sales VALUES (20, 170, '2022-03-02');
 INSERT INTO sales VALUES (30, 30,  '2022-03-04');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_40;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_20;
+SELECT * FROM salespeople20_30;
+SELECT * FROM salespeople30_40;
 
--- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesman_id_fkey"
+-- ERROR:  insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey"
 INSERT INTO sales VALUES (40, 50,  '2022-03-04');
 -- ok
 INSERT INTO sales VALUES (30, 50,  '2022-03-04');
 
 DROP TABLE sales CASCADE;
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition of partitioned table with triggers
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
-CREATE TABLE salesmans10_40 PARTITION OF salesmans FOR VALUES FROM (10) TO (40);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople10_40 PARTITION OF salespeople FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1,  'Poirot');
+INSERT INTO salespeople VALUES (1,  'Poirot');
 
 CREATE OR REPLACE FUNCTION after_insert_row_trigger() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$
 BEGIN
@@ -446,125 +446,125 @@ BEGIN
 END;
 $BODY$;
 
-CREATE TRIGGER salesmans_after_insert_statement_trigger
+CREATE TRIGGER salespeople_after_insert_statement_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH STATEMENT
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
-CREATE TRIGGER salesmans_after_insert_row_trigger
+CREATE TRIGGER salespeople_after_insert_row_trigger
     AFTER INSERT
-    ON salesmans
+    ON salespeople
     FOR EACH ROW
-    EXECUTE PROCEDURE after_insert_row_trigger('salesmans');
+    EXECUTE PROCEDURE after_insert_row_trigger('salespeople');
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (10, 'May');
+INSERT INTO salespeople VALUES (10, 'May');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans10_40 VALUES (19, 'Ivanov');
+INSERT INTO salespeople10_40 VALUES (19, 'Ivanov');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
 -- 2 triggers should fire here (row + statement):
-INSERT INTO salesmans VALUES (20, 'Smirnoff');
+INSERT INTO salespeople VALUES (20, 'Smirnoff');
 -- 1 trigger should fire here (row):
-INSERT INTO salesmans30_40 VALUES (30, 'Ford');
+INSERT INTO salespeople30_40 VALUES (30, 'Ford');
 
-SELECT * FROM salesmans01_10;
-SELECT * FROM salesmans10_20;
-SELECT * FROM salesmans20_30;
-SELECT * FROM salesmans30_40;
+SELECT * FROM salespeople01_10;
+SELECT * FROM salespeople10_20;
+SELECT * FROM salespeople20_30;
+SELECT * FROM salespeople30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 DROP FUNCTION after_insert_row_trigger();
 
 --
 -- Test: split partition witch identity column
 -- If split partition column is identity column, columns of new partitions are identity columns too.
 --
-CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2);
+CREATE TABLE salespeople1_2 PARTITION OF salespeople FOR VALUES FROM (1) TO (2);
 -- Create new partition with identity column:
-CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30));
-ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5);
+CREATE TABLE salespeople2_5(salesperson_id INT NOT NULL, salesperson_name VARCHAR(30));
+ALTER TABLE salespeople ATTACH PARTITION salespeople2_5 FOR VALUES FROM (2) TO (5);
 
-INSERT INTO salesmans (salesman_name) VALUES ('Poirot');
-INSERT INTO salesmans (salesman_name) VALUES ('Ivanov');
+INSERT INTO salespeople (salesperson_name) VALUES ('Poirot');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ivanov');
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
 -- Split partition has identity column:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_5'::regclass::oid;
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO
-  (PARTITION salesmans2_3 FOR VALUES FROM (2) TO (3),
-   PARTITION salesmans3_4 FOR VALUES FROM (3) TO (4),
-   PARTITION salesmans4_5 FOR VALUES FROM (4) TO (5));
+ALTER TABLE salespeople SPLIT PARTITION salespeople2_5 INTO
+  (PARTITION salespeople2_3 FOR VALUES FROM (2) TO (3),
+   PARTITION salespeople3_4 FOR VALUES FROM (3) TO (4),
+   PARTITION salespeople4_5 FOR VALUES FROM (4) TO (5));
 
-INSERT INTO salesmans (salesman_name) VALUES ('May');
-INSERT INTO salesmans (salesman_name) VALUES ('Ford');
+INSERT INTO salespeople (salesperson_name) VALUES ('May');
+INSERT INTO salespeople (salesperson_name) VALUES ('Ford');
 
-SELECT * FROM salesmans1_2;
-SELECT * FROM salesmans2_3;
-SELECT * FROM salesmans3_4;
-SELECT * FROM salesmans4_5;
+SELECT * FROM salespeople1_2;
+SELECT * FROM salespeople2_3;
+SELECT * FROM salespeople3_4;
+SELECT * FROM salespeople4_5;
 
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople1_2'::regclass::oid;
 -- New partitions have identity-columns:
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_3'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans3_4'::regclass::oid;
-SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans4_5'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople2_3'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople3_4'::regclass::oid;
+SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salespeople4_5'::regclass::oid;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split partition with deleted columns
 --
-CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id);
+CREATE TABLE salespeople(salesperson_id INT PRIMARY KEY, salesperson_name VARCHAR(30)) PARTITION BY RANGE (salesperson_id);
 
-CREATE TABLE salesmans01_10 PARTITION OF salesmans FOR VALUES FROM (1) TO (10);
+CREATE TABLE salespeople01_10 PARTITION OF salespeople FOR VALUES FROM (1) TO (10);
 -- Create new partition with some deleted columns:
-CREATE TABLE salesmans10_40(d1 VARCHAR(30), salesman_id INT PRIMARY KEY, d2 INT, d3 DATE, salesman_name VARCHAR(30));
+CREATE TABLE salespeople10_40(d1 VARCHAR(30), salesperson_id INT PRIMARY KEY, d2 INT, d3 DATE, salesperson_name VARCHAR(30));
 
-INSERT INTO salesmans10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
-INSERT INTO salesmans10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
+INSERT INTO salespeople10_40 VALUES ('dummy value 1', 19, 100, now(), 'Ivanov');
+INSERT INTO salespeople10_40 VALUES ('dummy value 2', 20, 101, now(), 'Smirnoff');
 
-ALTER TABLE salesmans10_40 DROP COLUMN d1;
-ALTER TABLE salesmans10_40 DROP COLUMN d2;
-ALTER TABLE salesmans10_40 DROP COLUMN d3;
+ALTER TABLE salespeople10_40 DROP COLUMN d1;
+ALTER TABLE salespeople10_40 DROP COLUMN d2;
+ALTER TABLE salespeople10_40 DROP COLUMN d3;
 
-ALTER TABLE salesmans ATTACH PARTITION salesmans10_40 FOR VALUES FROM (10) TO (40);
+ALTER TABLE salespeople ATTACH PARTITION salespeople10_40 FOR VALUES FROM (10) TO (40);
 
-INSERT INTO salesmans VALUES (1, 'Poirot');
-INSERT INTO salesmans VALUES (10, 'May');
-INSERT INTO salesmans VALUES (30, 'Ford');
+INSERT INTO salespeople VALUES (1, 'Poirot');
+INSERT INTO salespeople VALUES (10, 'May');
+INSERT INTO salespeople VALUES (30, 'Ford');
 
-ALTER TABLE salesmans SPLIT PARTITION salesmans10_40 INTO
-  (PARTITION salesmans10_20 FOR VALUES FROM (10) TO (20),
-   PARTITION salesmans20_30 FOR VALUES FROM (20) TO (30),
-   PARTITION salesmans30_40 FOR VALUES FROM (30) TO (40));
+ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO
+  (PARTITION salespeople10_20 FOR VALUES FROM (10) TO (20),
+   PARTITION salespeople20_30 FOR VALUES FROM (20) TO (30),
+   PARTITION salespeople30_40 FOR VALUES FROM (30) TO (40));
 
-select * from salesmans01_10;
-select * from salesmans10_20;
-select * from salesmans20_30;
-select * from salesmans30_40;
+select * from salespeople01_10;
+select * from salespeople10_20;
+select * from salespeople20_30;
+select * from salespeople30_40;
 
-DROP TABLE salesmans CASCADE;
+DROP TABLE salespeople CASCADE;
 
 --
 -- Test: split sub-partition
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');
 CREATE TABLE sales_mar2022 PARTITION OF sales_range FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
 
-CREATE TABLE sales_apr2022 (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_apr2022 (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_apr_all PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
 
@@ -611,8 +611,8 @@ DROP TABLE sales_range;
 -- Test: specific errors for BY LIST partitioning
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -648,8 +648,8 @@ DROP TABLE sales_list;
 --   * new partitions do not have a value that split partition has.
 --
 CREATE TABLE sales_list
-(salesman_id INT,
- salesman_name VARCHAR(30),
+(salesperson_id INT,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
@@ -676,34 +676,34 @@ DROP TABLE sales_list;
 -- Test: BY LIST partitioning, SPLIT PARTITION with data
 --
 CREATE TABLE sales_list
-(salesman_id SERIAL,
- salesman_name VARCHAR(30),
+(salesperson_id SERIAL,
+ salesperson_name VARCHAR(30),
  sales_state VARCHAR(20),
  sales_amount INT,
  sales_date DATE)
 PARTITION BY LIST (sales_state);
 
-CREATE INDEX sales_list_salesman_name_idx ON sales_list USING btree (salesman_name);
+CREATE INDEX sales_list_salesperson_name_idx ON sales_list USING btree (salesperson_name);
 CREATE INDEX sales_list_sales_state_idx ON sales_list USING btree (sales_state);
 
 CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo');
 CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok');
 CREATE TABLE sales_others PARTITION OF sales_list DEFAULT;
 
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
-INSERT INTO sales_list (salesman_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Trump',    'Bejing',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smirnoff', 'New York',        500, '2022-03-03');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ford',     'St. Petersburg', 2000, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Ivanov',   'Warsaw',          750, '2022-03-04');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Deev',     'Lisbon',          250, '2022-03-07');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Poirot',   'Berlin',         1000, '2022-03-01');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-06');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Li',       'Vladivostok',    1150, '2022-03-09');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('May',      'Oslo',           1200, '2022-03-11');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Halder',   'Helsinki',        800, '2022-03-02');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Muller',   'Madrid',          650, '2022-03-05');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Smith',    'Kyiv',            350, '2022-03-10');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Gandi',    'Warsaw',          150, '2022-03-08');
+INSERT INTO sales_list (salesperson_name, sales_state, sales_amount, sales_date) VALUES ('Plato',    'Lisbon',          950, '2022-03-05');
 
 ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
   (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
@@ -722,7 +722,7 @@ SET enable_seqscan = OFF;
 
 SELECT * FROM sales_central WHERE sales_state = 'Warsaw';
 SELECT * FROM sales_list WHERE sales_state = 'Warsaw';
-SELECT * FROM sales_list WHERE salesman_name = 'Ivanov';
+SELECT * FROM sales_list WHERE salesperson_name = 'Ivanov';
 
 SET enable_indexscan = ON;
 SET enable_seqscan = ON;
@@ -734,7 +734,7 @@ DROP TABLE sales_list;
 --   * split DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
 INSERT INTO sales_range VALUES (1,  'May',      1000, '2022-01-31');
@@ -772,7 +772,7 @@ DROP TABLE sales_range;
 --   * split non-DEFAULT partition to partitions with spaces between bounds;
 --   * random order of partitions in SPLIT PARTITION command.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-05-01');
 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT;
 
@@ -809,7 +809,7 @@ DROP TABLE sales_range;
 -- Test for split non-DEFAULT partition to DEFAULT partition + partitions
 -- with spaces between bounds.
 --
-CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
+CREATE TABLE sales_range (salesperson_id INT, salesperson_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date);
 CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01');
 CREATE TABLE sales_all PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01');
 
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v9-0007-Inherit-parent-s-AM-for-partition-MERGE-SPLIT-ope.patch (9.2K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/7-v9-0007-Inherit-parent-s-AM-for-partition-MERGE-SPLIT-ope.patch)
  download | inline diff:
From 72a122beae65917906a32767d715a9325aa12d97 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 13:21:14 +0300
Subject: [PATCH v9 7/7] Inherit parent's AM for partition MERGE/SPLIT
 operations

This commit makes new partitions created by ALTER TABLE ... SPLIT PARTITION
and ALTER TABLE ... MERGE PARTITIONS commands inherit the paret table access
method.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/84ada05b-be5c-473e-6d1c-ebe5dd21b190%40gmail.com
Reviewed-by: Pavel Borisov
---
 doc/src/sgml/ref/alter_table.sgml             |  2 ++
 src/backend/commands/tablecmds.c              |  6 +++++
 src/test/regress/expected/partition_merge.out | 18 +++++++++++++++
 src/test/regress/expected/partition_split.out | 23 +++++++++++++++++--
 src/test/regress/sql/partition_merge.sql      | 13 +++++++++++
 src/test/regress/sql/partition_split.sql      | 14 +++++++++++
 6 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 0f546357863..35c34a3fc90 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1158,6 +1158,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name1</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
       The indexes and identity are created later after moving the data
       while attaching new partitions.
+      New partitions will have the same table access method as the parent.
       If the parent table is persistent then new partitions are created
       persistent.  If the parent table is temporary then new partitions
       are also created temporary.
@@ -1227,6 +1228,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
       The indexes and identity are created later after moving the data
       while attaching the new partition.
+      The new partition will have the same table access method as the parent.
       If the parent table is persistent then the new partition is created
       persistent.  If the parent table is temporary then the new partition
       is also created temporary.
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 1b89e18eb7e..fd0812cd649 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21187,6 +21187,11 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  *
  * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
  * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ *
+ * Also, this function sets the new partition access method same as parent
+ * table access methods (similarly to CREATE TABLE ... PARTITION OF).  It
+ * checks that parent and child tables have compatible persistence.
+ *
  * Function returns the created relation (locked in AccessExclusiveLock mode).
  */
 static Relation
@@ -21217,6 +21222,7 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
 	createStmt->oncommit = ONCOMMIT_NOOP;
 	createStmt->tablespacename = NULL;
 	createStmt->if_not_exists = false;
+	createStmt->accessMethod = get_am_name(modelRel->rd_rel->relam);
 
 	tlc = makeNode(TableLikeClause);
 	tlc->relation = makeRangeVar(get_namespace_name(RelationGetNamespace(modelRel)),
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index a92a270c591..92999703217 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -862,6 +862,24 @@ SET search_path = partitions_merge_schema, pg_temp, public;
 -- Can't merge temporary partitions into a persistent partition
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ROLLBACK;
+-- Check the new partition inherits parent's table access method
+SET search_path = partitions_merge_schema, public;
+CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partitions_merge_heap;
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_2'::regclass);
+ relname |        amname         
+---------+-----------------------
+ tp_0_2  | partitions_merge_heap
+ t       | partitions_merge_heap
+(2 rows)
+
+DROP TABLE t;
+DROP ACCESS METHOD partitions_merge_heap;
 RESET search_path;
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 55ae37ad370..326fa1bd400 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -85,8 +85,8 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01'));
 ERROR:  upper bound of partition "sales_apr2022" is greater than upper bound of split partition
-LINE 4:    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO...
-                                                    ^
+LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0...
+                                                             ^
 -- ERROR:  lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022"
 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
@@ -1494,6 +1494,25 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
 (2 rows)
 
 DROP TABLE t;
+-- Check new partitions inherits parent's table access method
+CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partition_split_heap;
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_1'::regclass, 'tp_1_2'::regclass);
+ relname |        amname        
+---------+----------------------
+ t       | partition_split_heap
+ tp_0_1  | partition_split_heap
+ tp_1_2  | partition_split_heap
+(3 rows)
+
+DROP TABLE t;
+DROP ACCESS METHOD partition_split_heap;
 --
 DROP SCHEMA partition_split_schema;
 DROP SCHEMA partition_split_schema2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 085c422d540..23795cf9d94 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -535,6 +535,19 @@ SET search_path = partitions_merge_schema, pg_temp, public;
 ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
 ROLLBACK;
 
+-- Check the new partition inherits parent's table access method
+SET search_path = partitions_merge_schema, public;
+CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partitions_merge_heap;
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_2'::regclass);
+DROP TABLE t;
+DROP ACCESS METHOD partitions_merge_heap;
+
 RESET search_path;
 
 --
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index 3a7f2f9c294..73e8c2fbeb9 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -880,6 +880,20 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
 
 DROP TABLE t;
 
+-- Check new partitions inherits parent's table access method
+CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partition_split_heap;
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+SELECT c.relname, a.amname
+FROM pg_class c JOIN pg_am a ON c.relam = a.oid
+WHERE c.oid IN ('t'::regclass, 'tp_0_1'::regclass, 'tp_1_2'::regclass);
+DROP TABLE t;
+DROP ACCESS METHOD partition_split_heap;
+
+
 --
 DROP SCHEMA partition_split_schema;
 DROP SCHEMA partition_split_schema2;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v9-0006-Add-tab-completion-for-partition-MERGE-SPLIT-oper.patch (2.7K, ../../CAPpHfduYuYECrqpHMgcOsNr+4j3uJK+JPUJ_zDBn-tqjjh3p1Q@mail.gmail.com/8-v9-0006-Add-tab-completion-for-partition-MERGE-SPLIT-oper.patch)
  download | inline diff:
From 0a49f45bf3dbb2a5940b62ec405118c92f4e42aa Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Mon, 22 Apr 2024 13:20:11 +0300
Subject: [PATCH v9 6/7] Add tab completion for partition MERGE/SPLIT
 operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This commit implements psql tab completion for ALTER TABLE ... SPLIT PARTITION
and ALTER TABLE ... MERGE PARTITIONS commands.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/5dee3937-8e9f-cca4-11fb-737709a92b37%40gmail.com
Author: Dagfinn Ilmari Mannsåker, Pavel Borisov
---
 src/bin/psql/tab-complete.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 6fee3160f02..97cd5d9f628 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2353,6 +2353,7 @@ psql_completion(const char *text, int start, int end)
 					  "OWNER TO", "SET", "VALIDATE CONSTRAINT",
 					  "REPLICA IDENTITY", "ATTACH PARTITION",
 					  "DETACH PARTITION", "FORCE ROW LEVEL SECURITY",
+					  "SPLIT PARTITION", "MERGE PARTITIONS (",
 					  "OF", "NOT OF");
 	/* ALTER TABLE xxx ADD */
 	else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
@@ -2609,10 +2610,10 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH("FROM (", "IN (", "WITH (");
 
 	/*
-	 * If we have ALTER TABLE <foo> DETACH PARTITION, provide a list of
+	 * If we have ALTER TABLE <foo> DETACH|SPLIT PARTITION, provide a list of
 	 * partitions of <foo>.
 	 */
-	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION"))
+	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH|SPLIT", "PARTITION"))
 	{
 		set_completion_reference(prev3_wd);
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
@@ -2620,6 +2621,19 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches("ALTER", "TABLE", MatchAny, "DETACH", "PARTITION", MatchAny))
 		COMPLETE_WITH("CONCURRENTLY", "FINALIZE");
 
+	/* ALTER TABLE <name> SPLIT PARTITION <name> */
+	else if (Matches("ALTER", "TABLE", MatchAny, "SPLIT", "PARTITION", MatchAny))
+		COMPLETE_WITH("INTO ( PARTITION");
+
+	/* ALTER TABLE <name> MERGE PARTITIONS ( */
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "("))
+	{
+		set_completion_reference(prev4_wd);
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_partition_of_table);
+	}
+	else if (Matches("ALTER", "TABLE", MatchAny, "MERGE", "PARTITIONS", "(*)"))
+		COMPLETE_WITH("INTO");
+
 	/* ALTER TABLE <name> OF */
 	else if (Matches("ALTER", "TABLE", MatchAny, "OF"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_composite_datatypes);
-- 
2.39.3 (Apple Git-145)



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-04-26 13:33                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Pavel Borisov <[email protected]>
  2024-04-28 00:59                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-28 11:00                                               ` Alexander Lakhin <[email protected]>
  2024-04-28 11:36                                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-28 14:09                                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands David G. Johnston <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-28 11:00 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; +Cc: Justin Pryzby <[email protected]>; Robert Haas <[email protected]>; Pavel Borisov <[email protected]>; [email protected]

Hello,

28.04.2024 03:59, Alexander Korotkov wrote:
> The revised patchset is attached.  I'm going to push it if there are
> no objections.

I have one additional question regarding security, if you don't mind:
What permissions should a user have to perform split/merge?

When we deal with mixed ownership, say, bob is an owner of a
partitioned table, but not an owner of a partition, should we
allow him to perform merge with that partition?
Consider the following script:
CREATE ROLE alice;
GRANT CREATE ON SCHEMA public TO alice;

SET SESSION AUTHORIZATION alice;
CREATE TABLE t (i int PRIMARY KEY, t text, u text) PARTITION BY RANGE (i);
CREATE TABLE tp_00 PARTITION OF t FOR VALUES FROM (0) TO (10);
CREATE TABLE tp_10 PARTITION OF t FOR VALUES FROM (10) TO (20);

CREATE POLICY p1 ON tp_00 USING (u = current_user);
ALTER TABLE tp_00 ENABLE ROW LEVEL SECURITY;

INSERT INTO t(i, t, u)  VALUES (0, 'info for bob', 'bob');
INSERT INTO t(i, t, u)  VALUES (1, 'info for alice', 'alice');
RESET SESSION AUTHORIZATION;

CREATE ROLE bob;
GRANT CREATE ON SCHEMA public TO bob;
ALTER TABLE t OWNER TO bob;
GRANT SELECT ON TABLE tp_00 TO bob;

SET SESSION AUTHORIZATION bob;
SELECT * FROM tp_00;
--- here bob can see his info only
\d
  Schema | Name  |       Type        | Owner
--------+-------+-------------------+-------
  public | t     | partitioned table | bob
  public | tp_00 | table             | alice
  public | tp_10 | table             | alice

-- but then bob can do:
ALTER TABLE t MERGE PARTITIONS (tp_00, tp_10) INTO tp_00;
-- (yes, he also can detach the partition tp_00, but then he couldn't
-- re-attach nor read it)

\d
  Schema | Name  |       Type        | Owner
--------+-------+-------------------+-------
  public | t     | partitioned table | bob
  public | tp_00 | table             | bob

Thus bob effectively have captured the partition with the data.

What do you think, does this create a new security risk?

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-04-26 13:33                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Pavel Borisov <[email protected]>
  2024-04-28 00:59                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-28 11:00                                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-28 11:36                                                 ` Alexander Korotkov <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-28 11:36 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Justin Pryzby <[email protected]>; Robert Haas <[email protected]>; Pavel Borisov <[email protected]>; [email protected]

On Sun, Apr 28, 2024 at 2:00 PM Alexander Lakhin <[email protected]> wrote:
> 28.04.2024 03:59, Alexander Korotkov wrote:
> > The revised patchset is attached.  I'm going to push it if there are
> > no objections.
>
> I have one additional question regarding security, if you don't mind:
> What permissions should a user have to perform split/merge?
>
> When we deal with mixed ownership, say, bob is an owner of a
> partitioned table, but not an owner of a partition, should we
> allow him to perform merge with that partition?
> Consider the following script:
> CREATE ROLE alice;
> GRANT CREATE ON SCHEMA public TO alice;
>
> SET SESSION AUTHORIZATION alice;
> CREATE TABLE t (i int PRIMARY KEY, t text, u text) PARTITION BY RANGE (i);
> CREATE TABLE tp_00 PARTITION OF t FOR VALUES FROM (0) TO (10);
> CREATE TABLE tp_10 PARTITION OF t FOR VALUES FROM (10) TO (20);
>
> CREATE POLICY p1 ON tp_00 USING (u = current_user);
> ALTER TABLE tp_00 ENABLE ROW LEVEL SECURITY;
>
> INSERT INTO t(i, t, u)  VALUES (0, 'info for bob', 'bob');
> INSERT INTO t(i, t, u)  VALUES (1, 'info for alice', 'alice');
> RESET SESSION AUTHORIZATION;
>
> CREATE ROLE bob;
> GRANT CREATE ON SCHEMA public TO bob;
> ALTER TABLE t OWNER TO bob;
> GRANT SELECT ON TABLE tp_00 TO bob;
>
> SET SESSION AUTHORIZATION bob;
> SELECT * FROM tp_00;
> --- here bob can see his info only
> \d
>   Schema | Name  |       Type        | Owner
> --------+-------+-------------------+-------
>   public | t     | partitioned table | bob
>   public | tp_00 | table             | alice
>   public | tp_10 | table             | alice
>
> -- but then bob can do:
> ALTER TABLE t MERGE PARTITIONS (tp_00, tp_10) INTO tp_00;
> -- (yes, he also can detach the partition tp_00, but then he couldn't
> -- re-attach nor read it)
>
> \d
>   Schema | Name  |       Type        | Owner
> --------+-------+-------------------+-------
>   public | t     | partitioned table | bob
>   public | tp_00 | table             | bob
>
> Thus bob effectively have captured the partition with the data.
>
> What do you think, does this create a new security risk?

Alexander, thank you for discovering this.  I believe that the one who
merges partitions should have permissions for all the partitions
merged.  I'll recheck this and provide the patch.

------
Regards,
Alexander Korotkov






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-04-26 13:33                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Pavel Borisov <[email protected]>
  2024-04-28 00:59                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-28 11:00                                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-28 14:09                                                 ` David G. Johnston <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: David G. Johnston @ 2024-04-28 14:09 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; Dmitry Koval <[email protected]>; Justin Pryzby <[email protected]>; Robert Haas <[email protected]>; Pavel Borisov <[email protected]>; [email protected] <[email protected]>

On Sunday, April 28, 2024, Alexander Lakhin <[email protected]> wrote:

>
> When we deal with mixed ownership, say, bob is an owner of a
> partitioned table, but not an owner of a partition, should we
> allow him to perform merge with that partition?
>
>
Attaching via alter table requires the user to own both the partitioned
table and the table being acted upon.  Merge needs to behave similarly.

The fact that we let the superuser break the requirement of common
ownership is unfortunate but I guess understandable.  But given the
existing behavior of attach merge should likewise fail if it find the user
doesn’t own the partitions being merged.  The fact that the user can select
from those tables can be acted upon manually if desired; these
administrative commands should all ensure common ownership and fail if that
precondition is not met.

David J.


^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
@ 2024-04-28 01:04                                           ` Alexander Korotkov <[email protected]>
  2024-04-28 13:18                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Alexander Korotkov @ 2024-04-28 01:04 UTC (permalink / raw)
  To: Justin Pryzby <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; [email protected]

Hi Justin,

Thank you for your review.  Please check v9 of the patchset [1].

On Wed, Apr 24, 2024 at 11:26 PM Justin Pryzby <[email protected]> wrote:
> This patch also/already fixes the schema issue I reported.  Thanks.
>
> If you wanted to include a test case for that:
>
> begin;
> CREATE SCHEMA s;
> CREATE SCHEMA t;
> CREATE TABLE p(i int) PARTITION BY RANGE(i);
> CREATE TABLE s.c1 PARTITION OF p FOR VALUES FROM (1)TO(2);
> CREATE TABLE s.c2 PARTITION OF p FOR VALUES FROM (2)TO(3);
> ALTER TABLE p MERGE PARTITIONS (s.c1, s.c2) INTO s.c1; -- misbehaves if merging into the same name as an existing partition
> \d+ p
> ...
> Partitions: c1 FOR VALUES FROM (1) TO (3)

There is already a test which checks merging into the same name as an
existing partition.  And there are tests with schema-qualified names.
I'm not yet convinced we need a test with both these properties
together.

> > 0002
> > The persistence of the new partition is copied as suggested in [1].
> > But the checks are in-place, because search_path could influence new
> > table persistence.  Per review [2], commit message typos are fixed,
> > documentation is revised, revised tests to cover schema-qualification,
> > usage of search_path.
>
> Subject: [PATCH v8 2/7] Make new partitions with parent's persistence during MERGE/SPLIT operations
>
> This patch adds documentation saying:
> +      Any indexes, constraints and user-defined row-level triggers that exist
> +      in the parent table are cloned on new partitions [...]
>
> Which is good to say, and addresses part of my message [0]
> [0] ZiJW1g2nbQs9ekwK@pryzbyj2023
>
> But it doesn't have anything to do with "creating new partitions with
> parent's persistence".  Maybe there was a merge conflict and the docs
> ended up in the wrong patch ?

Makes sense.  Extracted this into a separate patch in v10.

> Also, defaults, storage options, compression are also copied.  As will
> be anything else from LIKE.  And since anything added in the future will
> also be copied, maybe it's better to just say that the tables will be
> created the same way as "LIKE .. INCLUDING ALL EXCLUDING ..", or
> similar.  Otherwise, the next person who adds a new option for LIKE
> would have to remember to update this paragraph...

Reworded that way.  Thank you.

> Also, extended stats objects are currently cloned to new child tables.
> But I suggested in [0] that they probably shouldn't be.

I will explore this.  Do we copy extended stats when we do CREATE
TABLE ... PARTITION OF?  I think we need to do the same here.

> > 007 – doc review by Justin [3]
>
> I suggest to drop this patch for now.  I'll send some more minor fixes to
> docs and code comments once the other patches are settled.

Your edits are welcome.  Dropped this for now.  And waiting for the
next revision from you.

Links.
1. https://www.postgresql.org/message-id/CAPpHfduYuYECrqpHMgcOsNr%2B4j3uJK%2BJPUJ_zDBn-tqjjh3p1Q%40mail...

------
Regards,
Alexander Korotkov
Supabase






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-04-28 01:04                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-28 13:18                                             ` Justin Pryzby <[email protected]>
  2024-04-28 14:54                                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Justin Pryzby @ 2024-04-28 13:18 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; Tomas Vondra <[email protected]>; Alvaro Herrera <[email protected]>; [email protected]

On Sun, Apr 28, 2024 at 04:04:54AM +0300, Alexander Korotkov wrote:
> Hi Justin,
> 
> Thank you for your review.  Please check v9 of the patchset [1].
> 
> On Wed, Apr 24, 2024 at 11:26 PM Justin Pryzby <[email protected]> wrote:
> > This patch also/already fixes the schema issue I reported.  Thanks.
> >
> > If you wanted to include a test case for that:
> >
> > begin;
> > CREATE SCHEMA s;
> > CREATE SCHEMA t;
> > CREATE TABLE p(i int) PARTITION BY RANGE(i);
> > CREATE TABLE s.c1 PARTITION OF p FOR VALUES FROM (1)TO(2);
> > CREATE TABLE s.c2 PARTITION OF p FOR VALUES FROM (2)TO(3);
> > ALTER TABLE p MERGE PARTITIONS (s.c1, s.c2) INTO s.c1; -- misbehaves if merging into the same name as an existing partition
> > \d+ p
> > ...
> > Partitions: c1 FOR VALUES FROM (1) TO (3)
> 
> There is already a test which checks merging into the same name as an
> existing partition.  And there are tests with schema-qualified names.
> I'm not yet convinced we need a test with both these properties
> together.

I mentioned that the combination of schemas and merge-into-same-name is
what currently doesn't work right.

> > Also, extended stats objects are currently cloned to new child tables.
> > But I suggested in [0] that they probably shouldn't be.
> 
> I will explore this.  Do we copy extended stats when we do CREATE
> TABLE ... PARTITION OF?  I think we need to do the same here.

Right, they're not copied because an extended stats objs on the parent
does something different than putting stats objects on each child.
I've convinced myself that it's wrong to copy the parent's stats obj.
If someone wants stats objects on each child, they'll have to handle
them specially after MERGE/SPLIT, just as they would for per-child
defaults/constraints/etc.

On Sun, Apr 28, 2024 at 04:04:54AM +0300, Alexander Korotkov wrote:
> On Wed, Apr 24, 2024 at 11:26 PM Justin Pryzby <[email protected]> wrote:
> > This patch adds documentation saying:
> > +      Any indexes, constraints and user-defined row-level triggers that exist
> > +      in the parent table are cloned on new partitions [...]
> >
> > Which is good to say, and addresses part of my message [0]
> > [0] ZiJW1g2nbQs9ekwK@pryzbyj2023
> 
> Makes sense.  Extracted this into a separate patch in v10.

I adjusted the language some and fixed a typo in the commit message.

s/parition/partition/

-- 
Justin


Attachments:

  [text/x-diff] 0001-Document-the-way-partition-MERGE-SPLIT-operations-cr.patch (2.1K, ../../Zi5Msg74C61DjJKW@pryzbyj2023/2-0001-Document-the-way-partition-MERGE-SPLIT-operations-cr.patch)
  download | inline diff:
From e00033fc4b8254c70bf8a3d41d513edd9540e2d7 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Sun, 28 Apr 2024 03:39:30 +0300
Subject: [PATCH] Document the way partition MERGE/SPLIT operations create new
 partitions

Reported-by: Justin Pryzby
Discussion: https://postgr.es/m/ZilrByTp-pbz6Mvf%40pryzbyj2023
---
 doc/src/sgml/ref/alter_table.sgml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index fe36ff82e52..fc2dfffe49f 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1153,6 +1153,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       splitting we have a partition with the same name).
       Only simple, non-partitioned partition can be split.
      </para>
+     <para>
+      The new partitions will be created the same as tables created with the
+      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_nameN</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
+      The indexes and identity are created later, after moving the data
+      into the new partitions.
+     </para>
      <note>
       <para>
        This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
@@ -1213,6 +1219,12 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
       can have the same name as one of the merged partitions.  Only simple,
       non-partitioned partitions can be merged.
      </para>
+     <para>
+      The new partition will be created the same as a table created with the
+      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
+      The indexes and identity are created later, after moving the data
+      into the new partition.
+     </para>
      <note>
       <para>
        This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
-- 
2.42.0



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-04-28 01:04                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-28 13:18                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
@ 2024-04-28 14:54                                               ` Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Justin Pryzby @ 2024-04-28 14:54 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; Robert Haas <[email protected]>; Tomas Vondra <[email protected]>; Alvaro Herrera <[email protected]>; [email protected]

On Sun, Apr 28, 2024 at 08:18:42AM -0500, Justin Pryzby wrote:
> > I will explore this.  Do we copy extended stats when we do CREATE
> > TABLE ... PARTITION OF?  I think we need to do the same here.
> 
> Right, they're not copied because an extended stats objs on the parent
> does something different than putting stats objects on each child.
> I've convinced myself that it's wrong to copy the parent's stats obj.
> If someone wants stats objects on each child, they'll have to handle
> them specially after MERGE/SPLIT, just as they would for per-child
> defaults/constraints/etc.

I dug up this thread, in which the idea of copying extended stats from
parent to child was considered some 6 years ago, but never implemented;
for consistency, MERGE/SPLIT shouldn't copy extended stats, either.

https://www.postgresql.org/message-id/20180305195750.aecbpihhcvuskzba%40alvherre.pgsql

-- 
Justin






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-29 18:00                                     ` Alexander Lakhin <[email protected]>
  2024-04-30 00:10                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-29 18:00 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi Dmitry,

19.04.2024 02:26, Dmitry Koval wrote:
>
> 18.04.2024 19:00, Alexander Lakhin wrote:
>> leaves a strange constraint:
>> \d+ t*
>>                                            Table "public.tp_0"
>> ...
>> Not-null constraints:
>>      "merge-16385-26BCB0-tmp_i_not_null" NOT NULL "i"
>
> Thanks!
> Attached fix (with test) for this case.
> The patch should be applied after patches
> v6-0001- ... .patch ... v6-0004- ... .patch

I still wonder, why that constraint (now with a less questionable name) is
created during MERGE?

That is, before MERGE, two partitions have only PRIMARY KEY indexes,
with no not-null constraint, and you can manually remove the constraint
after MERGE, so maybe it's not necessary...

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-29 18:00                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-30 00:10                                       ` Dmitry Koval <[email protected]>
  2024-04-30 03:00                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-04-30 00:10 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

Hi!

1.
29.04.2024 21:00, Alexander Lakhin wrote:
> I still wonder, why that constraint (now with a less questionable name) is
> created during MERGE?

The SPLIT/MERGE PARTITION(S) commands for creating partitions reuse the 
existing code of CREATE TABLE .. LIKE ... command. A new partition was 
created with the name "merge-16385-26BCB0-tmp" (since there was an old 
partition with the same name). The constraint 
"merge-16385-26BCB0-tmp_i_not_null" was created too together with the 
partition. Subsequently, the table was renamed, but the constraint was not.
Now a new partition is immediately created with the correct name (the 
old partition is renamed).

2.
Just in case, I am attaching a small fix v9_fix.diff for situation [1].

[1] 
https://www.postgresql.org/message-id/0520c72e-8d97-245e-53f9-173beca2ab2e%40gmail.com

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index fef084f5d5..e918a623c5 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3446,6 +3446,11 @@ checkPartition(Relation rel, Oid partRelOid)
 						RelationGetRelationName(partRel),
 						RelationGetRelationName(rel))));
 
+	/* Permissions checks */
+	if (!object_ownercheck(RelationRelationId, RelationGetRelid(partRel), GetUserId()))
+		aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(partRel->rd_rel->relkind),
+					   RelationGetRelationName(partRel));
+
 	relation_close(partRel, AccessShareLock);
 }
 


Attachments:

  [text/plain] v9_fix.diff (647B, ../../[email protected]/2-v9_fix.diff)
  download | inline diff:
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index fef084f5d5..e918a623c5 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3446,6 +3446,11 @@ checkPartition(Relation rel, Oid partRelOid)
 						RelationGetRelationName(partRel),
 						RelationGetRelationName(rel))));
 
+	/* Permissions checks */
+	if (!object_ownercheck(RelationRelationId, RelationGetRelid(partRel), GetUserId()))
+		aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(partRel->rd_rel->relkind),
+					   RelationGetRelationName(partRel));
+
 	relation_close(partRel, AccessShareLock);
 }
 


^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-29 18:00                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 00:10                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-04-30 03:00                                         ` Alexander Lakhin <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Alexander Lakhin @ 2024-04-30 03:00 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; Alexander Korotkov <[email protected]>; +Cc: Robert Haas <[email protected]>; PostgreSQL Hackers <[email protected]>

30.04.2024 03:10, Dmitry Koval wrote:
> Hi!
>
> 1.
> 29.04.2024 21:00, Alexander Lakhin wrote:
>> I still wonder, why that constraint (now with a less questionable name) is
>> created during MERGE?
>
> The SPLIT/MERGE PARTITION(S) commands for creating partitions reuse the existing code of CREATE TABLE .. LIKE ... 
> command. A new partition was created with the name "merge-16385-26BCB0-tmp" (since there was an old partition with the 
> same name). The constraint "merge-16385-26BCB0-tmp_i_not_null" was created too together with the partition. 
> Subsequently, the table was renamed, but the constraint was not.
> Now a new partition is immediately created with the correct name (the old partition is renamed).

Maybe I'm doing something wrong, but the following script:
CREATE TABLE t (i int, PRIMARY KEY(i)) PARTITION BY RANGE (i);
CREATE TABLE tp_0 PARTITION OF t FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1 PARTITION OF t FOR VALUES FROM (1) TO (2);

CREATE TABLE t2 (LIKE t INCLUDING ALL);
CREATE TABLE tp2 (LIKE tp_0 INCLUDING ALL);
creates tables t2, tp2 without not-null constraints.

But after
ALTER TABLE t MERGE PARTITIONS (tp_0, tp_1) INTO tp_0;
I see:
\d+ tp_0
...
Indexes:
     "tp_0_pkey" PRIMARY KEY, btree (i)
Not-null constraints:
     "tp_0_i_not_null" NOT NULL "i"

Best regards,
Alexander






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
  2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-04-18 19:59                                 ` Robert Haas <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: Robert Haas @ 2024-04-18 19:59 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; PostgreSQL Hackers <[email protected]>

On Thu, Apr 18, 2024 at 6:35 AM Alexander Korotkov <[email protected]> wrote:
> The revised patchset is attached.
> 1) I've split the fix for the CommandCounterIncrement() issue and the
> fix for relation persistence issue into a separate patch.
> 2) I've validated that the lock on the new partition is held in
> createPartitionTable() after ProcessUtility() as pointed out by
> Robert.  So, no need to place the lock again.
> 3) Added fix for problematic error message as a separate patch [1].
> 4) Added rename "salemans" => "salesmen" for tests as a separate patch.
>
> I think these fixes are reaching committable shape, but I'd like
> someone to check it before I push.

Reviewing 0001:

- Seems mostly fine. I think the comment /* Unlock and drop merged
partitions. */ is wrong. I think it should say something like /* Drop
the current partitions before adding the new one. */ because (a) it
doesn't unlock anything, and there's another comment saying that and
(b) we now know that the drop vs. add order matters.

Reviewing 0002:

- Commit message typos: behavious, corresponsing

- Given the change to the header comment of createPartitionTable, it's
rather surprising to me that this patch doesn't touch the
documentation. Isn't that a big change in semantics?

- My previous review comment was really about the code comment, I
believe, rather than the use of AccessExclusiveLock. NoLock is
probably fine, but if it were me I'd be tempted to write
AccessExclusiveLock and just make the comment say something like /* We
should already have the lock, but do it this way just to be certain
*/. But what you have is probably fine, too. Mostly, I want to clarify
the intent of my previous comment.

- Do we, or can we, have a test that if you split a partition that's
not in the search path, the resulting partitions end up in your
creation namespace? And similarly for merge? And maybe also that
schema-qualification works properly?

I haven't exhaustively verified the patch, but these are some things I
noticed when scrolling through it.

Reviewing 0003:

- Are you sure this can't dereference datum when datum is NULL, in
either the upper or lower half? It sure looks strange to have code
that looks like it can make datum a null pointer, and then an
unconditional deference just after.

- In general I think the wording changes are improvements. I'm
slightly suspicious that there might be an even better way to word it,
but I can't think of it right at this very moment.

- I'm kind of unhappy (but not totally unhappy) with the semantics.
Suppose I have a partition that allows values from 0 to 1000, but
actually only contains values that are either between 0 and 99 or
between 901 and 1000. If I try to to split the partition into one that
allows 0..100 and a second that allows 900..1000, it will fail. Maybe
that's good, because that means that if a failure is going to happen,
it will happen right at the beginning, rather than maybe after doing a
lot of work. But on the other hand, it also kind of stinks, because it
feels like I'm being told I can't do something that I know is
perfectly fine.

Reviewing 0004:

- Obviously this is quite trivial and there's no real problem with it,
but if we're changing it anyway, how about a gender-neutral term
(salesperson/salespeople)?

-- 
Robert Haas
EDB: http://www.enterprisedb.com






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
@ 2024-04-19 11:34                     ` Justin Pryzby <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: Justin Pryzby @ 2024-04-19 11:34 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; Alexander Lakhin <[email protected]>; Dmitry Koval <[email protected]>; Tomas Vondra <[email protected]>; Alvaro Herrera <[email protected]>; [email protected]

On Thu, Apr 11, 2024 at 10:20:53PM -0400, Robert Haas wrote:
> On Thu, Apr 11, 2024 at 9:54 PM Alexander Korotkov <[email protected]> wrote:
> > I think we shouldn't unconditionally copy schema name and
> > relpersistence from the parent table.  Instead we should throw the
> > error on a mismatch like CREATE TABLE ... PARTITION OF ... does.  I'm
> > working on revising this fix.
> 
> We definitely shouldn't copy the schema name from the parent table. It
> should be possible to schema-qualify the new partition names, and if
> you don't, then the search_path should determine where they get
> placed.

+1.  Alexander Lakhin reported an issue with schemas and SPLIT, and I
noticed an issue with schemas with MERGE.  The issue I hit is occurs
when MERGE'ing into a partition with the same name, and it's fixed like
so:

--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21526,8 +21526,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	{
 		/* Create partition table with generated temporary name. */
 		sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid);
-		mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),
-									 tmpRelName, -1);
+		mergePartName = makeRangeVar(mergePartName->schemaname, tmpRelName, -1);
 	}
 	createPartitionTable(mergePartName,
 						 makeRangeVar(get_namespace_name(RelationGetNamespace(rel)),

> One of the things I dislike about this type of feature -- not this
> implementation specifically, but just this kind of idea in general --
> is that the syntax mentions a whole bunch of tables but in a way where
> you can't set their properties. Persistence, reloptions, whatever.
> There's just no place to mention any of that stuff - and if you wanted
> to create a place, you'd have to invent special syntax for each
> separate thing. That's why I think it's good that the normal way of
> creating a partition is CREATE TABLE .. PARTITION OF. Because that
> way, we know that the full power of the CREATE TABLE statement is
> always available, and you can set anything that you could set for a
> table that is not a partition.

Right.  The current feature is useful and will probably work for 90% of
people's partitioned tables.

Currently, CREATE TABLE .. PARTITION OF does not create stats objects on
the child table, but MERGE PARTITIONS does, which seems strange.
Maybe stats should not be included on the new child ?

Note that stats on parent table are not analagous to indexes -
partitioned indexes do nothing other than cause indexes to be created on
any new/attached partitions.  But stats objects on the parent 1) cause
extended stats to be collected and computed across the whole partition
heirarchy, and 2) do not cause stats to be computed for the individual
partitions.

Partitions can have different column definitions, for example null
constraints, FKs, defaults.  And currently, if you MERGE partitions,
those will all be lost (or rather, replaced by whatever LIKE parent
gives).  I think that's totally fine - anyone using different defaults
on child tables could either not use MERGE PARTITIONS, or fix up the
defaults afterwards.  There's not much confusion that the details of the
differences between individual partitions will be lost when the
individual partitions are merged and no longer exist.
But I think it'd be useful to document how the new partitions will be
constructed.

-- 
Justin






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
@ 2024-04-30 20:15                 ` Justin Pryzby <[email protected]>
  2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Justin Pryzby @ 2024-04-30 20:15 UTC (permalink / raw)
  To: Alexander Lakhin <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Korotkov <[email protected]>; [email protected]

On Thu, Apr 11, 2024 at 08:00:00PM +0300, Alexander Lakhin wrote:
> 11.04.2024 16:27, Dmitry Koval wrote:
> > 
> > Added correction (and test), see v3-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch.
> 
> Thank you for the correction, but may be an attempt to merge into implicit
> pg_temp should fail just like CREATE TABLE ... PARTITION OF ... does?
> 
> Please look also at another anomaly with schemas:
> CREATE SCHEMA s1;
> CREATE TABLE t (i int) PARTITION BY RANGE (i);
> CREATE TABLE tp_0_2 PARTITION OF t
>   FOR VALUES FROM (0) TO (2);
> ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
>   (PARTITION s1.tp0 FOR VALUES FROM (0) TO (1), PARTITION s1.tp1 FOR VALUES FROM (1) TO (2));
> results in:
> \d+ s1.*
> Did not find any relation named "s1.*"
> \d+ tp*
>                                           Table "public.tp0"

Hi,

Is this issue already fixed ?

I wasn't able to reproduce it.  Maybe it only happened with earlier
patch versions applied ?

Thanks,
-- 
Justin






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
@ 2024-05-01 19:51                   ` Dmitry Koval <[email protected]>
  2024-05-03 13:23                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Dmitry Koval @ 2024-05-01 19:51 UTC (permalink / raw)
  To: Justin Pryzby <[email protected]>; Alexander Lakhin <[email protected]>; +Cc: Alexander Korotkov <[email protected]>; [email protected]

Hi!

30.04.2024 23:15, Justin Pryzby пишет:
> Is this issue already fixed ?
> I wasn't able to reproduce it.  Maybe it only happened with earlier
> patch versions applied ?

I think this was fixed in commit [1].

[1] 
https://github.com/postgres/postgres/commit/fcf80c5d5f0f3787e70fca8fd029d2e08a923f91

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
@ 2024-05-03 13:23                     ` Justin Pryzby <[email protected]>
  2024-05-03 13:32                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  0 siblings, 1 reply; 58+ messages in thread

From: Justin Pryzby @ 2024-05-03 13:23 UTC (permalink / raw)
  To: Dmitry Koval <[email protected]>; +Cc: Alexander Lakhin <[email protected]>; Alexander Korotkov <[email protected]>; [email protected]

On Wed, May 01, 2024 at 10:51:24PM +0300, Dmitry Koval wrote:
> Hi!
> 
> 30.04.2024 23:15, Justin Pryzby пишет:
> > Is this issue already fixed ?
> > I wasn't able to reproduce it.  Maybe it only happened with earlier
> > patch versions applied ?
> 
> I think this was fixed in commit [1].
> 
> [1] https://github.com/postgres/postgres/commit/fcf80c5d5f0f3787e70fca8fd029d2e08a923f91

I tried to reproduce it at fcf80c5d5f~, but couldn't.  
I don't see how that patch would fix it anyway.
I'm hoping Alexander can confirm what happened.

The other remaining issues I'm aware of are for EXCLUDING STATISTICS and
refusing to ALTER if the owners don't match.

Note that the error that led to "EXCLUDING IDENTITY" is being discused
over here:
https://www.postgresql.org/message-id/[email protected]

It's possible that once that's addressed, the exclusion should be
removed here, too.

-- 
Justin






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-05-03 13:23                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
@ 2024-05-03 13:32                       ` Alexander Korotkov <[email protected]>
  2024-05-08 18:00                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-05-25 17:53                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  0 siblings, 2 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-05-03 13:32 UTC (permalink / raw)
  To: Justin Pryzby <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; [email protected]

On Fri, May 3, 2024 at 4:23 PM Justin Pryzby <[email protected]> wrote:
> On Wed, May 01, 2024 at 10:51:24PM +0300, Dmitry Koval wrote:
> > 30.04.2024 23:15, Justin Pryzby пишет:
> > > Is this issue already fixed ?
> > > I wasn't able to reproduce it.  Maybe it only happened with earlier
> > > patch versions applied ?
> >
> > I think this was fixed in commit [1].
> >
> > [1] https://github.com/postgres/postgres/commit/fcf80c5d5f0f3787e70fca8fd029d2e08a923f91
>
> I tried to reproduce it at fcf80c5d5f~, but couldn't.
> I don't see how that patch would fix it anyway.
> I'm hoping Alexander can confirm what happened.

This problem is only relevant for an old version of fix [1], which
overrides schemas for new partitions.  That version was never
committed.

> The other remaining issues I'm aware of are for EXCLUDING STATISTICS and
> refusing to ALTER if the owners don't match.

These two are in my list.  I'm planning to work on them in the next few days.

> Note that the error that led to "EXCLUDING IDENTITY" is being discused
> over here:
> https://www.postgresql.org/message-id/[email protected]
>
> It's possible that once that's addressed, the exclusion should be
> removed here, too.

+1

Links.
1. https://www.postgresql.org/message-id/edfbd846-dcc1-42d1-ac26-715691b687d3%40postgrespro.ru

------
Regards,
Alexander Korotkov
Supabase






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-05-03 13:23                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-03 13:32                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-05-08 18:00                         ` Alexander Korotkov <[email protected]>
  1 sibling, 0 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-05-08 18:00 UTC (permalink / raw)
  To: Justin Pryzby <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; [email protected]

On Fri, May 3, 2024 at 4:32 PM Alexander Korotkov <[email protected]> wrote:
> On Fri, May 3, 2024 at 4:23 PM Justin Pryzby <[email protected]> wrote:
> > On Wed, May 01, 2024 at 10:51:24PM +0300, Dmitry Koval wrote:
> > > 30.04.2024 23:15, Justin Pryzby пишет:
> > > > Is this issue already fixed ?
> > > > I wasn't able to reproduce it.  Maybe it only happened with earlier
> > > > patch versions applied ?
> > >
> > > I think this was fixed in commit [1].
> > >
> > > [1] https://github.com/postgres/postgres/commit/fcf80c5d5f0f3787e70fca8fd029d2e08a923f91
> >
> > I tried to reproduce it at fcf80c5d5f~, but couldn't.
> > I don't see how that patch would fix it anyway.
> > I'm hoping Alexander can confirm what happened.
>
> This problem is only relevant for an old version of fix [1], which
> overrides schemas for new partitions.  That version was never
> committed.

Here are the patches.
0001 Adds permission checks on the partitions before doing MERGE/SPLIT
0002 Skips copying extended statistics while creating new partitions
in MERGE/SPLIT

0001 looks quite simple and trivial for me.  I'm going to push it if
no objections.
For 0002 I'd like to hear some feedback on wordings used in docs and comments.

------
Regards,
Alexander Korotkov
Supabase


Attachments:

  [application/octet-stream] v1-0002-Don-t-copy-extended-statistics-during-MERGE-SPLIT.patch (9.8K, ../../CAPpHfdtgLiT2d++-qLircLB8ATUfzgR=aTmRDdF7w=2E9yDHbQ@mail.gmail.com/2-v1-0002-Don-t-copy-extended-statistics-during-MERGE-SPLIT.patch)
  download | inline diff:
From 1a0dcde924ce020d8e3ff7242a8874bc3da70bfa Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Wed, 8 May 2024 20:32:20 +0300
Subject: [PATCH v1 2/2] Don't copy extended statistics during MERGE/SPLIT
 partition operations

Currenlty MERGE/SPLIT partition operations create new partiions copying the
extended statistics from the parent table.  However, parent's table extended
statistics already covers all its children.  Also, "CREATE TABLE ... PARTITION
OF" command doesn't copy extended statistics.  This commit makes
createPartitionTable() skip copying extended statistics from the parent.

Reported-by: Justin Pryzby
Discussion: https://postgr.es/m/ZiJW1g2nbQs9ekwK%40pryzbyj2023
---
 doc/src/sgml/ref/alter_table.sgml             |  8 ++++--
 src/backend/commands/tablecmds.c              |  8 +++---
 src/test/regress/expected/partition_merge.out | 17 ++++++++++++
 src/test/regress/expected/partition_split.out | 27 +++++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 10 +++++++
 src/test/regress/sql/partition_split.sql      | 12 +++++++++
 6 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 0bf11f6cb6d..a11a407b7a6 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1155,9 +1155,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
      </para>
      <para>
       The new partitions will be created the same as tables created with the
-      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_nameN</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
+      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_nameN</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY EXCLUDING STATISTICS)</literal>.
       The indexes and identity are created later, after moving the data
       into the new partitions.
+      The extended statistics aren't copied from the parent table, since
+      the parent's statistics cover all children and it's typically enough.
       New partitions will have the same table access method as the parent.
       If the parent table is persistent then new partitions are created
       persistent.  If the parent table is temporary then new partitions
@@ -1225,9 +1227,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
      </para>
      <para>
       The new partition will be created the same as a table created with the
-      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)</literal>.
+      SQL command <literal>CREATE TABLE <replaceable class="parameter">partition_name</replaceable> (LIKE <replaceable class="parameter">name</replaceable> INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY EXCLUDING STATISTICS)</literal>.
       The indexes and identity are created later, after moving the data
       into the new partition.
+      The extended statistics aren't copied from the parent table, since
+      the parent's statistics cover all children and it's typically enough.
       The new partition will have the same table access method as the parent.
       If the parent table is persistent then the new partition is created
       persistent.  If the parent table is temporary then the new partition
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 5bf5e69c5b8..dddf694b787 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -21245,7 +21245,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
  * (newPartName) like table (modelRel)
  *
  * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRel's name>
- * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY)
+ * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY EXCLUDING STATISTICS)
  *
  * Also, this function sets the new partition access method same as parent
  * table access methods (similarly to CREATE TABLE ... PARTITION OF).  It
@@ -21289,9 +21289,11 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
 
 	/*
 	 * Indexes will be inherited on "attach new partitions" stage, after data
-	 * moving.
+	 * moving.  We also don't copy the extended statistics since the parent's
+	 * statistics cover all children and it's typically enough.
 	 */
-	tlc->options = CREATE_TABLE_LIKE_ALL & ~(CREATE_TABLE_LIKE_INDEXES | CREATE_TABLE_LIKE_IDENTITY);
+	tlc->options = CREATE_TABLE_LIKE_ALL &
+		~(CREATE_TABLE_LIKE_INDEXES | CREATE_TABLE_LIKE_IDENTITY | CREATE_TABLE_LIKE_STATISTICS);
 	tlc->relationOid = InvalidOid;
 	createStmt->tableElts = lappend(createStmt->tableElts, tlc);
 
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 076264c88eb..36a60d7472c 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -910,6 +910,23 @@ RESET SESSION AUTHORIZATION;
 DROP TABLE t;
 DROP ROLE regress_partition_merge_alice;
 DROP ROLE regress_partition_merge_bob;
+-- Check extended statistics aren't copied from the parent table to the new
+-- partition.
+CREATE TABLE t (i int, j int) PARTITION BY RANGE (i);
+CREATE STATISTICS t_i_j (mcv) ON i, j FROM t;
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+\d+ tp_0_2
+                          Table "partitions_merge_schema.tp_0_2"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           |          |         | plain   |              | 
+ j      | integer |           |          |         | plain   |              | 
+Partition of: t FOR VALUES FROM (0) TO (2)
+Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 2))
+
+DROP TABLE t;
 RESET search_path;
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 74e19d250e9..461318db867 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1543,6 +1543,33 @@ RESET SESSION AUTHORIZATION;
 DROP TABLE t;
 DROP ROLE regress_partition_merge_alice;
 DROP ROLE regress_partition_merge_bob;
+-- Check extended statistics aren't copied from the parent table to new
+-- partitions.
+CREATE TABLE t (i int, j int) PARTITION BY RANGE (i);
+CREATE STATISTICS t_i_j (mcv) ON i, j FROM t;
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+\d+ tp_0_1
+                          Table "partition_split_schema.tp_0_1"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           |          |         | plain   |              | 
+ j      | integer |           |          |         | plain   |              | 
+Partition of: t FOR VALUES FROM (0) TO (1)
+Partition constraint: ((i IS NOT NULL) AND (i >= 0) AND (i < 1))
+
+\d+ tp_1_2
+                          Table "partition_split_schema.tp_1_2"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ i      | integer |           |          |         | plain   |              | 
+ j      | integer |           |          |         | plain   |              | 
+Partition of: t FOR VALUES FROM (1) TO (2)
+Partition constraint: ((i IS NOT NULL) AND (i >= 1) AND (i < 2))
+
+DROP TABLE t;
 --
 DROP SCHEMA partition_split_schema;
 DROP SCHEMA partition_split_schema2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 9bfeb0d7ef3..203811b6e39 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -582,6 +582,16 @@ DROP TABLE t;
 DROP ROLE regress_partition_merge_alice;
 DROP ROLE regress_partition_merge_bob;
 
+-- Check extended statistics aren't copied from the parent table to the new
+-- partition.
+CREATE TABLE t (i int, j int) PARTITION BY RANGE (i);
+CREATE STATISTICS t_i_j (mcv) ON i, j FROM t;
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+\d+ tp_0_2
+DROP TABLE t;
+
 RESET search_path;
 
 --
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index bb52514b7ed..dc7424256e8 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -927,6 +927,18 @@ DROP TABLE t;
 DROP ROLE regress_partition_merge_alice;
 DROP ROLE regress_partition_merge_bob;
 
+-- Check extended statistics aren't copied from the parent table to new
+-- partitions.
+CREATE TABLE t (i int, j int) PARTITION BY RANGE (i);
+CREATE STATISTICS t_i_j (mcv) ON i, j FROM t;
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+\d+ tp_0_1
+\d+ tp_1_2
+DROP TABLE t;
+
 
 --
 DROP SCHEMA partition_split_schema;
-- 
2.39.3 (Apple Git-145)



  [application/octet-stream] v1-0001-Add-permission-check-for-MERGE-SPLIT-partition-op.patch (8.5K, ../../CAPpHfdtgLiT2d++-qLircLB8ATUfzgR=aTmRDdF7w=2E9yDHbQ@mail.gmail.com/3-v1-0001-Add-permission-check-for-MERGE-SPLIT-partition-op.patch)
  download | inline diff:
From 02e3ca736fdc7425ccec294a9bc5fae8b82bc673 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Wed, 8 May 2024 17:30:09 +0300
Subject: [PATCH v1 1/2] Add permission check for MERGE/SPLIT partition
 operations

Currently, we check only owner permission for the parent table before
MERGE/SPLIT partition operations.  This leads to a security hole when users
can get access to the data of partitions without permission.  This commit
fixes this problem by requiring owner permission on all the partitions
involved.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/0520c72e-8d97-245e-53f9-173beca2ab2e%40gmail.com
Author: Dmitry Koval, Alexander Korotkov
---
 src/backend/parser/parse_utilcmd.c            |  5 +++
 src/test/regress/expected/partition_merge.out | 29 ++++++++++++++++
 src/test/regress/expected/partition_split.out | 29 ++++++++++++++++
 src/test/regress/sql/partition_merge.sql      | 33 +++++++++++++++++++
 src/test/regress/sql/partition_split.sql      | 33 +++++++++++++++++++
 5 files changed, 129 insertions(+)

diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 6520bf9baa5..0598e897d90 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3456,6 +3456,11 @@ checkPartition(Relation rel, Oid partRelOid)
 						RelationGetRelationName(partRel),
 						RelationGetRelationName(rel))));
 
+	/* Permissions checks */
+	if (!object_ownercheck(RelationRelationId, RelationGetRelid(partRel), GetUserId()))
+		aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(partRel->rd_rel->relkind),
+					   RelationGetRelationName(partRel));
+
 	relation_close(partRel, AccessShareLock);
 }
 
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index 52e5c3ce0da..076264c88eb 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -881,6 +881,35 @@ ORDER BY c.relname;
 
 DROP TABLE t;
 DROP ACCESS METHOD partitions_merge_heap;
+-- Test permission checks.  The user needs to own the parent table and all
+-- the merging partitions to do the merge.
+CREATE ROLE regress_partition_merge_alice;
+CREATE ROLE regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_alice;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  must be owner of table t
+RESET SESSION AUTHORIZATION;
+ALTER TABLE t OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  must be owner of table tp_0_1
+RESET SESSION AUTHORIZATION;
+ALTER TABLE tp_0_1 OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+ERROR:  must be owner of table tp_1_2
+RESET SESSION AUTHORIZATION;
+ALTER TABLE tp_1_2 OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+RESET SESSION AUTHORIZATION;
+DROP TABLE t;
+DROP ROLE regress_partition_merge_alice;
+DROP ROLE regress_partition_merge_bob;
 RESET search_path;
 --
 DROP SCHEMA partitions_merge_schema;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 641e1acc3d7..74e19d250e9 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -1514,6 +1514,35 @@ ORDER BY c.relname;
 
 DROP TABLE t;
 DROP ACCESS METHOD partition_split_heap;
+-- Test permission checks.  The user needs to own the parent table and the
+-- the partition to split to do the split.
+CREATE ROLE regress_partition_merge_alice;
+CREATE ROLE regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_alice;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+ERROR:  must be owner of table t
+RESET SESSION AUTHORIZATION;
+ALTER TABLE t OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+ERROR:  must be owner of table tp_0_2
+RESET SESSION AUTHORIZATION;
+ALTER TABLE tp_0_2 OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+RESET SESSION AUTHORIZATION;
+DROP TABLE t;
+DROP ROLE regress_partition_merge_alice;
+DROP ROLE regress_partition_merge_bob;
 --
 DROP SCHEMA partition_split_schema;
 DROP SCHEMA partition_split_schema2;
diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql
index 84a3462205a..9bfeb0d7ef3 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -549,6 +549,39 @@ ORDER BY c.relname;
 DROP TABLE t;
 DROP ACCESS METHOD partitions_merge_heap;
 
+-- Test permission checks.  The user needs to own the parent table and all
+-- the merging partitions to do the merge.
+CREATE ROLE regress_partition_merge_alice;
+CREATE ROLE regress_partition_merge_bob;
+
+SET SESSION AUTHORIZATION regress_partition_merge_alice;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
+CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
+
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+RESET SESSION AUTHORIZATION;
+
+ALTER TABLE t OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+RESET SESSION AUTHORIZATION;
+
+ALTER TABLE tp_0_1 OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+RESET SESSION AUTHORIZATION;
+
+ALTER TABLE tp_1_2 OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
+RESET SESSION AUTHORIZATION;
+
+DROP TABLE t;
+DROP ROLE regress_partition_merge_alice;
+DROP ROLE regress_partition_merge_bob;
+
 RESET search_path;
 
 --
diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql
index d2c687c41ba..bb52514b7ed 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -894,6 +894,39 @@ ORDER BY c.relname;
 DROP TABLE t;
 DROP ACCESS METHOD partition_split_heap;
 
+-- Test permission checks.  The user needs to own the parent table and the
+-- the partition to split to do the split.
+CREATE ROLE regress_partition_merge_alice;
+CREATE ROLE regress_partition_merge_bob;
+
+SET SESSION AUTHORIZATION regress_partition_merge_alice;
+CREATE TABLE t (i int) PARTITION BY RANGE (i);
+CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
+
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+RESET SESSION AUTHORIZATION;
+
+ALTER TABLE t OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+RESET SESSION AUTHORIZATION;
+
+ALTER TABLE tp_0_2 OWNER TO regress_partition_merge_bob;
+SET SESSION AUTHORIZATION regress_partition_merge_bob;
+ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
+  (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
+   PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
+RESET SESSION AUTHORIZATION;
+
+DROP TABLE t;
+DROP ROLE regress_partition_merge_alice;
+DROP ROLE regress_partition_merge_bob;
+
 
 --
 DROP SCHEMA partition_split_schema;
-- 
2.39.3 (Apple Git-145)



^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-05-03 13:23                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-03 13:32                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
@ 2024-05-25 17:53                         ` Justin Pryzby <[email protected]>
  2024-05-26 03:56                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  1 sibling, 1 reply; 58+ messages in thread

From: Justin Pryzby @ 2024-05-25 17:53 UTC (permalink / raw)
  To: Alexander Korotkov <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; [email protected]

On Fri, May 03, 2024 at 04:32:25PM +0300, Alexander Korotkov wrote:
> On Fri, May 3, 2024 at 4:23 PM Justin Pryzby <[email protected]> wrote:
> > Note that the error that led to "EXCLUDING IDENTITY" is being discused
> > over here:
> > https://www.postgresql.org/message-id/[email protected]
> >
> > It's possible that once that's addressed, the exclusion should be
> > removed here, too.
> 
> +1

Can EXCLUDING IDENTITY be removed now ?

I wasn't able to find why it was needed - at one point, I think there
was a test case that threw an error, but now when I remove the EXCLUDE,
nothing goes wrong.

-- 
Justin






^ permalink  raw  reply  [nested|flat] 58+ messages in thread

* Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
  2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
  2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
  2024-05-03 13:23                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
  2024-05-03 13:32                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
  2024-05-25 17:53                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
@ 2024-05-26 03:56                           ` Alexander Korotkov <[email protected]>
  0 siblings, 0 replies; 58+ messages in thread

From: Alexander Korotkov @ 2024-05-26 03:56 UTC (permalink / raw)
  To: Justin Pryzby <[email protected]>; +Cc: Dmitry Koval <[email protected]>; Alexander Lakhin <[email protected]>; [email protected]

On Sat, May 25, 2024 at 8:53 PM Justin Pryzby <[email protected]> wrote:
> On Fri, May 03, 2024 at 04:32:25PM +0300, Alexander Korotkov wrote:
> > On Fri, May 3, 2024 at 4:23 PM Justin Pryzby <[email protected]> wrote:
> > > Note that the error that led to "EXCLUDING IDENTITY" is being discused
> > > over here:
> > > https://www.postgresql.org/message-id/[email protected]
> > >
> > > It's possible that once that's addressed, the exclusion should be
> > > removed here, too.
> >
> > +1
>
> Can EXCLUDING IDENTITY be removed now ?
>
> I wasn't able to find why it was needed - at one point, I think there
> was a test case that threw an error, but now when I remove the EXCLUDE,
> nothing goes wrong.

Yes, it was broken before [1][2], but now it seems to work.  At the
same time, I'm not sure if we need to remove the EXCLUDE now.
IDENTITY is anyway successfully created when the new partition gets
attached.

Links.
1. https://www.postgresql.org/message-id/[email protected]...
2. https://www.postgresql.org/message-id/flat/ZiGH0xc1lxJ71ZfB%40pryzbyj2023#297b6aef85cb089abb38e9b1a9...

------
Regards,
Alexander Korotkov
Supabase






^ permalink  raw  reply  [nested|flat] 58+ messages in thread


end of thread, other threads:[~2024-05-26 03:56 UTC | newest]

Thread overview: 58+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 21:09 [PATCH v10 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v10 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v11 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v8 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v12 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v8 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v11 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v9 10/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-03-22 21:09 [PATCH v8 11/17] table_scan_bitmap_next_block counts lossy and exact pages Melanie Plageman <[email protected]>
2024-04-09 23:03 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-10 09:00 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-10 12:00   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-10 17:22     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-11 07:57       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Richard Guo <[email protected]>
2024-04-11 08:59         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-11 12:00           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-11 13:27             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-11 14:21               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-11 17:00               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-12 01:53                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-12 02:20                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
2024-04-12 13:04                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-12 17:00                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-12 19:59                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-13 10:04                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-15 14:30                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
2024-04-15 15:00                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-15 15:38                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
2024-04-15 15:26                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-18 10:35                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-18 16:00                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-18 17:03                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dagfinn Ilmari Mannsåker <[email protected]>
2024-04-18 23:26                                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-19 13:29                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-22 10:31                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-24 20:26                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-04-26 13:33                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Pavel Borisov <[email protected]>
2024-04-28 00:59                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-28 11:00                                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-28 11:36                                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-28 14:09                                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands David G. Johnston <[email protected]>
2024-04-28 01:04                                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-04-28 13:18                                             ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-04-28 14:54                                               ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-04-29 18:00                                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-30 00:10                                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-04-30 03:00                                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Lakhin <[email protected]>
2024-04-18 19:59                                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Robert Haas <[email protected]>
2024-04-19 11:34                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-04-30 20:15                 ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-05-01 19:51                   ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Dmitry Koval <[email protected]>
2024-05-03 13:23                     ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-05-03 13:32                       ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-05-08 18:00                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>
2024-05-25 17:53                         ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Justin Pryzby <[email protected]>
2024-05-26 03:56                           ` Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Alexander Korotkov <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox