v1-0001-refactor-ExecForPortionOfLeftovers.patch
text/x-patch
Filename: v1-0001-refactor-ExecForPortionOfLeftovers.patch
Type: text/x-patch
Part: 1
Message:
Re: SQL:2011 application time
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: refactor ExecForPortionOfLeftovers.
| File | + | − |
|---|---|---|
| src/backend/executor/nodeModifyTable.c | 19 | 14 |
From 1dff6266fabca760681512fc69ec6b7ccce60896 Mon Sep 17 00:00:00 2001
From: pgaddict <jian.universality@gmail.com>
Date: Sun, 22 Oct 2023 12:48:05 +0800
Subject: [PATCH v1 1/1] refactor ExecForPortionOfLeftovers.
FOR PORTION OF UPDATE/DELETE, upper and lower leftover range tuple
will have same the partition key as pre-update/delete tuple.
So refactor some comments.
ExecForPortionOfLeftovers is excuted inside ExecUpdateEpilogue or
ExecDeleteEpilogue, it means at least one part of leftover range
is not empty. in leftoverRangeType1, leftoverRangeType2 at least one is
not empty. So instead of call ExecFetchSlotHeapTuple twice, call it
once.
based on other code, add bool shouldFree.
---
src/backend/executor/nodeModifyTable.c | 33 +++++++++++++++-----------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 92d6611f..063efa79 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1232,7 +1232,7 @@ static void set_leftover_tuple_bounds(TupleTableSlot *leftoverTuple,
/* ----------------------------------------------------------------
* ExecForPortionOfLeftovers
*
- * Insert tuples for the untouched timestamp of a row in a FOR
+ * Insert tuples for the untouched range of a row in a FOR
* PORTION OF UPDATE/DELETE
* ----------------------------------------------------------------
*/
@@ -1257,6 +1257,8 @@ ExecForPortionOfLeftovers(ModifyTableContext *context,
TupleTableSlot *oldtupleSlot = fpoState->fp_Existing;
TupleTableSlot *leftoverTuple1 = fpoState->fp_Leftover1;
TupleTableSlot *leftoverTuple2 = fpoState->fp_Leftover2;
+ HeapTuple oldtuple;
+ bool shouldFree;
/*
* Get the range of the old pre-UPDATE/DELETE tuple,
@@ -1303,18 +1305,19 @@ ExecForPortionOfLeftovers(ModifyTableContext *context,
range_leftover_internal(typcache, oldRangeType, targetRangeType, &leftoverRangeType1,
&leftoverRangeType2);
+ /* fetch the existing, old pre-UPDATE/DELETE tuple */
+ oldtuple = ExecFetchSlotHeapTuple(oldtupleSlot, false, &shouldFree);
+
/*
* Insert a copy of the tuple with the lower leftover range.
- * Even if the table is partitioned,
- * our insert won't extend past the current row, so we don't need to re-route.
- * TODO: Really? What if you update the partition key?
+ * Even if the table is partitioned and we did UPDATE/DELETE the partition key.
+ * the partition key of the lower leftover range tuple
+ * will be the same as the partition key of the original tuple.
+ *
*/
-
if (!RangeIsEmpty(leftoverRangeType1))
{
- // TODO: anything we need to clear here?
- // Are we in the row context?
- HeapTuple oldtuple = ExecFetchSlotHeapTuple(oldtupleSlot, false, NULL);
+ // TODO: Are we in the row context?
ExecForceStoreHeapTuple(oldtuple, leftoverTuple1, false);
set_leftover_tuple_bounds(leftoverTuple1, forPortionOf, typcache, leftoverRangeType1);
@@ -1325,15 +1328,14 @@ ExecForPortionOfLeftovers(ModifyTableContext *context,
}
/*
- * Insert a copy of the tuple with the upper leftover range
- * Even if the table is partitioned,
- * our insert won't extend past the current row, so we don't need to re-route.
- * TODO: Really? What if you update the partition key?
+ * Insert a copy of the tuple with the upper leftover range.
+ * Even if the table is partitioned and we did UPDATE/DELETE the partion key.
+ * the partition key of the (upper leftover range) tuple
+ * will be the same as the partition key of the original tuple.
+ *
*/
-
if (!RangeIsEmpty(leftoverRangeType2))
{
- HeapTuple oldtuple = ExecFetchSlotHeapTuple(oldtupleSlot, false, NULL);
ExecForceStoreHeapTuple(oldtuple, leftoverTuple2, false);
set_leftover_tuple_bounds(leftoverTuple2, forPortionOf, typcache, leftoverRangeType2);
@@ -1342,6 +1344,9 @@ ExecForPortionOfLeftovers(ModifyTableContext *context,
// TODO: Need to save context->mtstate->mt_transition_capture? (See comment on ExecInsert)
ExecInsert(context, resultRelInfo, leftoverTuple2, node->canSetTag, NULL, NULL);
}
+
+ if (shouldFree)
+ heap_freetuple(oldtuple);
}
/* ----------------------------------------------------------------
--
2.34.1