From 198ade8acc28916a374462725612301b4531ca73 Mon Sep 17 00:00:00 2001 From: Herambh Shah Date: Mon, 15 Sep 2025 00:59:48 +0000 Subject: [PATCH 1/2] Testing return processing after EPQ Signed-off-by: Herambh Shah --- src/backend/executor/nodeModifyTable.c | 105 +++++++++++++------------ 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 80cef648ab3..97748e2144f 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -846,9 +846,9 @@ ExecInsert(ModifyTableContext *context, return NULL; /* "do nothing" */ } - /* Process RETURNING if present */ - if (resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) - result = ExecProcessReturning(resultRelInfo, slot, planSlot); + // /* Process RETURNING if present */ + // if (resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) + // result = ExecProcessReturning(resultRelInfo, slot, planSlot); /* INSTEAD OF ROW INSERT Triggers */ if (resultRelInfo->ri_TrigDesc && @@ -1241,7 +1241,7 @@ ExecInsert(ModifyTableContext *context, ExecWithCheckOptions(WCO_VIEW_CHECK, resultRelInfo, slot, estate); /* Process RETURNING if present */ - if (resultRelInfo->ri_projectReturning && sql_dialect != SQL_DIALECT_TSQL) + if (resultRelInfo->ri_projectReturning) result = ExecProcessReturning(resultRelInfo, slot, planSlot); if (inserted_tuple) @@ -1480,7 +1480,7 @@ ExecDelete(ModifyTableContext *context, Relation resultRelationDesc = resultRelInfo->ri_RelationDesc; TupleTableSlot *slot = NULL; TM_Result result; - TupleTableSlot *rslot_output = NULL; + // TupleTableSlot *rslot_output = NULL; if (tupleDeleted) *tupleDeleted = false; @@ -1494,41 +1494,41 @@ ExecDelete(ModifyTableContext *context, return NULL; /* Process RETURNING if present and if requested */ - if (processReturning && resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) - { - /* - * We have to put the target tuple into a slot, which means first we - * gotta fetch it. We can use the trigger tuple slot. - */ - if (resultRelInfo->ri_FdwRoutine) - { - /* FDW must have provided a slot containing the deleted row */ - Assert(!TupIsNull(slot)); - } - else - { - slot = ExecGetReturningSlot(estate, resultRelInfo); - if (oldtuple != NULL) - { - ExecForceStoreHeapTuple(oldtuple, slot, false); - } - else - { - if (!table_tuple_fetch_row_version(resultRelationDesc, tupleid, - SnapshotAny, slot)) - elog(ERROR, "failed to fetch deleted tuple for DELETE RETURNING"); - } - } - rslot_output = ExecProcessReturning(resultRelInfo, slot, context->planSlot); - - /* - * Before releasing the target tuple again, make sure rslot has a - * local copy of any pass-by-reference values. - */ - ExecMaterializeSlot(rslot_output); - - ExecClearTuple(slot); - } + // if (processReturning && resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) + // { + // /* + // * We have to put the target tuple into a slot, which means first we + // * gotta fetch it. We can use the trigger tuple slot. + // */ + // if (resultRelInfo->ri_FdwRoutine) + // { + // /* FDW must have provided a slot containing the deleted row */ + // Assert(!TupIsNull(slot)); + // } + // else + // { + // slot = ExecGetReturningSlot(estate, resultRelInfo); + // if (oldtuple != NULL) + // { + // ExecForceStoreHeapTuple(oldtuple, slot, false); + // } + // else + // { + // if (!table_tuple_fetch_row_version(resultRelationDesc, tupleid, + // SnapshotAny, slot)) + // elog(ERROR, "failed to fetch deleted tuple for DELETE RETURNING"); + // } + // } + // rslot_output = ExecProcessReturning(resultRelInfo, slot, context->planSlot); + + // /* + // * Before releasing the target tuple again, make sure rslot has a + // * local copy of any pass-by-reference values. + // */ + // ExecMaterializeSlot(rslot_output); + + // ExecClearTuple(slot); + // } if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->trig_delete_instead_statement && @@ -1765,7 +1765,7 @@ ExecDelete(ModifyTableContext *context, ExecDeleteEpilogue(context, resultRelInfo, tupleid, oldtuple, changingPart); /* Process RETURNING if present and if requested */ - if (processReturning && resultRelInfo->ri_projectReturning && sql_dialect != SQL_DIALECT_TSQL) + if (processReturning && resultRelInfo->ri_projectReturning) { /* * We have to put the target tuple into a slot, which means first we @@ -1806,8 +1806,8 @@ ExecDelete(ModifyTableContext *context, return rslot; } - if (processReturning && resultRelInfo->ri_projectReturning && rslot_output) - return rslot_output; + // if (processReturning && resultRelInfo->ri_projectReturning && rslot_output) + // return rslot_output; return NULL; } @@ -2371,7 +2371,7 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo, Relation resultRelationDesc = resultRelInfo->ri_RelationDesc; UpdateContext updateCxt = {0}; TM_Result result; - TupleTableSlot *rslot = NULL; + // TupleTableSlot *rslot = NULL; /* * abort the operation if not running transactions @@ -2386,9 +2386,9 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo, if (!ExecUpdatePrologue(context, resultRelInfo, tupleid, oldtuple, slot, NULL)) return NULL; - /* Process RETURNING if present */ - if (resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) - rslot = ExecProcessReturning(resultRelInfo, slot, context->planSlot); + // /* Process RETURNING if present */ + // if (resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) + // rslot = ExecProcessReturning(resultRelInfo, slot, context->planSlot); if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->trig_update_instead_statement && @@ -2612,12 +2612,15 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo, ExecUpdateEpilogue(context, &updateCxt, resultRelInfo, tupleid, oldtuple, slot); - /* Process RETURNING if present */ - if (resultRelInfo->ri_projectReturning && sql_dialect != SQL_DIALECT_TSQL) - return ExecProcessReturning(resultRelInfo, slot, context->planSlot); + // /* Process RETURNING if present */ + // if (resultRelInfo->ri_projectReturning && sql_dialect != SQL_DIALECT_TSQL) + // return ExecProcessReturning(resultRelInfo, slot, context->planSlot); if (resultRelInfo->ri_projectReturning) - return rslot; + return ExecProcessReturning(resultRelInfo, slot, context->planSlot); + + // if (resultRelInfo->ri_projectReturning) + // return rslot; return NULL; } From 8817c5e2908adf59233721b876849020036b7387 Mon Sep 17 00:00:00 2001 From: Herambh Shah Date: Mon, 15 Sep 2025 23:23:58 +0000 Subject: [PATCH 2/2] removed output/return processing before EPQ Signed-off-by: Herambh Shah --- src/backend/executor/nodeModifyTable.c | 58 +------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 97748e2144f..01b091d0598 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -846,10 +846,6 @@ ExecInsert(ModifyTableContext *context, return NULL; /* "do nothing" */ } - // /* Process RETURNING if present */ - // if (resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) - // result = ExecProcessReturning(resultRelInfo, slot, planSlot); - /* INSTEAD OF ROW INSERT Triggers */ if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->trig_insert_instead_row) @@ -1480,7 +1476,6 @@ ExecDelete(ModifyTableContext *context, Relation resultRelationDesc = resultRelInfo->ri_RelationDesc; TupleTableSlot *slot = NULL; TM_Result result; - // TupleTableSlot *rslot_output = NULL; if (tupleDeleted) *tupleDeleted = false; @@ -1493,43 +1488,6 @@ ExecDelete(ModifyTableContext *context, epqreturnslot, tmresult)) return NULL; - /* Process RETURNING if present and if requested */ - // if (processReturning && resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) - // { - // /* - // * We have to put the target tuple into a slot, which means first we - // * gotta fetch it. We can use the trigger tuple slot. - // */ - // if (resultRelInfo->ri_FdwRoutine) - // { - // /* FDW must have provided a slot containing the deleted row */ - // Assert(!TupIsNull(slot)); - // } - // else - // { - // slot = ExecGetReturningSlot(estate, resultRelInfo); - // if (oldtuple != NULL) - // { - // ExecForceStoreHeapTuple(oldtuple, slot, false); - // } - // else - // { - // if (!table_tuple_fetch_row_version(resultRelationDesc, tupleid, - // SnapshotAny, slot)) - // elog(ERROR, "failed to fetch deleted tuple for DELETE RETURNING"); - // } - // } - // rslot_output = ExecProcessReturning(resultRelInfo, slot, context->planSlot); - - // /* - // * Before releasing the target tuple again, make sure rslot has a - // * local copy of any pass-by-reference values. - // */ - // ExecMaterializeSlot(rslot_output); - - // ExecClearTuple(slot); - // } - if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->trig_delete_instead_statement && sql_dialect == SQL_DIALECT_TSQL && @@ -1806,9 +1764,6 @@ ExecDelete(ModifyTableContext *context, return rslot; } - // if (processReturning && resultRelInfo->ri_projectReturning && rslot_output) - // return rslot_output; - return NULL; } @@ -2371,7 +2326,6 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo, Relation resultRelationDesc = resultRelInfo->ri_RelationDesc; UpdateContext updateCxt = {0}; TM_Result result; - // TupleTableSlot *rslot = NULL; /* * abort the operation if not running transactions @@ -2386,10 +2340,6 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo, if (!ExecUpdatePrologue(context, resultRelInfo, tupleid, oldtuple, slot, NULL)) return NULL; - // /* Process RETURNING if present */ - // if (resultRelInfo->ri_projectReturning && sql_dialect == SQL_DIALECT_TSQL) - // rslot = ExecProcessReturning(resultRelInfo, slot, context->planSlot); - if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->trig_update_instead_statement && sql_dialect == SQL_DIALECT_TSQL && bbfViewHasInsteadofTrigger_hook && (bbfViewHasInsteadofTrigger_hook)(resultRelationDesc, CMD_UPDATE) && @@ -2612,16 +2562,10 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo, ExecUpdateEpilogue(context, &updateCxt, resultRelInfo, tupleid, oldtuple, slot); - // /* Process RETURNING if present */ - // if (resultRelInfo->ri_projectReturning && sql_dialect != SQL_DIALECT_TSQL) - // return ExecProcessReturning(resultRelInfo, slot, context->planSlot); - + /* Process RETURNING if present */ if (resultRelInfo->ri_projectReturning) return ExecProcessReturning(resultRelInfo, slot, context->planSlot); - // if (resultRelInfo->ri_projectReturning) - // return rslot; - return NULL; }