Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/backend/access/common/attmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/backend/access/common/tupconvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
96 changes: 22 additions & 74 deletions src/backend/executor/nodeModifyTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/include/access/attmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */