diff --git a/src/backend/access/common/attmap.c b/src/backend/access/common/attmap.c index abccf60ec8b..f55f7b42602 100644 --- a/src/backend/access/common/attmap.c +++ b/src/backend/access/common/attmap.c @@ -25,7 +25,6 @@ #include "access/attmap.h" #include "utils/builtins.h" -called_from_tsql_insert_exec_hook_type called_from_tsql_insert_exec_hook = NULL; called_for_tsql_itvf_func_hook_type called_for_tsql_itvf_func_hook = NULL; static bool check_attrmap_match(TupleDesc indesc, @@ -112,10 +111,9 @@ build_attrmap_by_position(TupleDesc indesc, nincols++; /* Found matching column, now check type */ - /* skip check type if it's tsql insert exec or if it is for tsql inline table valued function */ + /* skip check type if it is for tsql inline table valued function */ if ((outatt->atttypid != inatt->atttypid || (outatt->atttypmod != inatt->atttypmod && outatt->atttypmod >= 0)) && - !(called_from_tsql_insert_exec_hook && called_from_tsql_insert_exec_hook()) && !(called_for_tsql_itvf_func_hook && called_for_tsql_itvf_func_hook())) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), @@ -318,10 +316,9 @@ check_attrmap_match(TupleDesc indesc, return false; /** - * in tsql insert exec or for tsql inline table valued function, we need a cast + * for tsql inline table valued function, we need a cast */ - if (((called_from_tsql_insert_exec_hook && called_from_tsql_insert_exec_hook()) - || (called_for_tsql_itvf_func_hook && called_for_tsql_itvf_func_hook())) + if ((called_for_tsql_itvf_func_hook && called_for_tsql_itvf_func_hook()) && (inatt_form_attributes->atttypid != outatt_form_attributes->atttypid || inatt_form_attributes->atttypmod != outatt_form_attributes->atttypmod)) return false; diff --git a/src/backend/access/common/tupconvert.c b/src/backend/access/common/tupconvert.c index 6060a555b76..8847b1062b4 100644 --- a/src/backend/access/common/tupconvert.c +++ b/src/backend/access/common/tupconvert.c @@ -177,10 +177,9 @@ execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map) int j = attrMap->attnums[i]; /** - * if it's tsql insert exec or if it is for tsql inline table valued function, we'll consider value cast + * if it is for tsql inline table valued function, we'll consider value cast */ - if ((called_from_tsql_insert_exec_hook && called_from_tsql_insert_exec_hook()) - || (called_for_tsql_itvf_func_hook && called_for_tsql_itvf_func_hook())) + if (called_for_tsql_itvf_func_hook && called_for_tsql_itvf_func_hook()) { Oid intypeid; Oid outtypeid; diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 404fd5d9de3..834ed7a6589 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -4241,11 +4241,6 @@ ExecModifyTable(PlanState *pstate) HeapTupleData oldtupdata; HeapTuple oldtuple; ItemPointer tupleid; - /* for INSERT ... EXECUTE */ - bool tsql_insert_exec = node->callStmt != NULL; - Tuplestorestate *tss = NULL; - TupleDesc tupdesc = NULL; - DestReceiver *dest = NULL; bool tuplock; CHECK_FOR_INTERRUPTS(); @@ -4289,36 +4284,6 @@ ExecModifyTable(PlanState *pstate) context.epqstate = &node->mt_epqstate; context.estate = estate; - /* - * If we are here for INSERT ... EXECUTE, create a TuplestoreDestReceiver - * and pass it to the procedure execution. The procedure execution will send - * its result sets to the tuplestore via the receiver function. - */ - if (tsql_insert_exec) - { - tss = tuplestore_begin_heap(false, false, work_mem); - tupdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc); - dest = CreateTuplestoreDestReceiver(); - SetTuplestoreDestReceiverParams(dest, tss, CurrentMemoryContext, false, NULL, NULL); - dest->rStartup(dest, -1, tupdesc); - - switch (nodeTag(node->callStmt)) - { - case T_CallStmt: - ExecuteCallStmt((CallStmt *)node->callStmt, - pstate->state->es_param_list_info, false, dest); - break; - case T_DoStmt: - ExecuteDoStmtInsertExec((DoStmt *)node->callStmt, false, dest); - break; - default: - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Unrecognized stmt in INSERT EXEC"))); - break; - } - } - /* * Fetch rows from subplan(s), and execute the required table modification * for each row. @@ -4348,43 +4313,35 @@ ExecModifyTable(PlanState *pstate) break; } - if (tsql_insert_exec) + /* + * If there is a pending MERGE ... WHEN NOT MATCHED [BY TARGET] action + * to execute, do so now --- see the comments in ExecMerge(). + */ + if (node->mt_merge_pending_not_matched != NULL) { - context.planSlot = MakeSingleTupleTableSlot(tupdesc, &TTSOpsMinimalTuple); - tuplestore_gettupleslot(tss, true, false, context.planSlot); - } - else - { - /* - * If there is a pending MERGE ... WHEN NOT MATCHED [BY TARGET] action - * to execute, do so now --- see the comments in ExecMerge(). - */ - if (node->mt_merge_pending_not_matched != NULL) - { - context.planSlot = node->mt_merge_pending_not_matched; - context.cpDeletedSlot = NULL; - - slot = ExecMergeNotMatched(&context, node->resultRelInfo, - node->canSetTag); + context.planSlot = node->mt_merge_pending_not_matched; + context.cpDeletedSlot = NULL; - /* Clear the pending action */ - node->mt_merge_pending_not_matched = NULL; + slot = ExecMergeNotMatched(&context, node->resultRelInfo, + node->canSetTag); - /* - * If we got a RETURNING result, return it to the caller. We'll - * continue the work on next call. - */ - if (slot) - return slot; + /* Clear the pending action */ + node->mt_merge_pending_not_matched = NULL; - continue; /* continue with the next tuple */ - } + /* + * If we got a RETURNING result, return it to the caller. We'll + * continue the work on next call. + */ + if (slot) + return slot; - /* Fetch the next row from subplan */ - context.planSlot = ExecProcNode(subplanstate); - context.cpDeletedSlot = NULL; + continue; /* continue with the next tuple */ } + /* Fetch the next row from subplan */ + context.planSlot = ExecProcNode(subplanstate); + context.cpDeletedSlot = NULL; + /* No more tuples to process? */ if (TupIsNull(context.planSlot)) break; @@ -4674,9 +4631,6 @@ ExecModifyTable(PlanState *pstate) break; } - if(tsql_insert_exec) - ExecDropSingleTupleTableSlot(context.planSlot); - /* * If we got a RETURNING result, return it to caller. We'll continue * the work on next call. @@ -4685,12 +4639,6 @@ ExecModifyTable(PlanState *pstate) return slot; } - if (tsql_insert_exec && dest) - { - dest->rShutdown(dest); - dest->rDestroy(dest); - } - /* * Insert remaining tuples for batch insert. */ diff --git a/src/include/access/attmap.h b/src/include/access/attmap.h index 618135fbb2e..391b9e64e6b 100644 --- a/src/include/access/attmap.h +++ b/src/include/access/attmap.h @@ -50,9 +50,7 @@ extern AttrMap *build_attrmap_by_name_if_req(TupleDesc indesc, extern AttrMap *build_attrmap_by_position(TupleDesc indesc, TupleDesc outdesc, const char *msg); -typedef bool (*called_from_tsql_insert_exec_hook_type)(); typedef bool (*called_for_tsql_itvf_func_hook_type)(); -extern PGDLLEXPORT called_from_tsql_insert_exec_hook_type called_from_tsql_insert_exec_hook; extern PGDLLIMPORT called_for_tsql_itvf_func_hook_type called_for_tsql_itvf_func_hook; #endif /* ATTMAP_H */