@@ -4241,11 +4241,6 @@ ExecModifyTable(PlanState *pstate)
42414241 HeapTupleData oldtupdata ;
42424242 HeapTuple oldtuple ;
42434243 ItemPointer tupleid ;
4244- /* for INSERT ... EXECUTE */
4245- bool tsql_insert_exec = node -> callStmt != NULL ;
4246- Tuplestorestate * tss = NULL ;
4247- TupleDesc tupdesc = NULL ;
4248- DestReceiver * dest = NULL ;
42494244 bool tuplock ;
42504245
42514246 CHECK_FOR_INTERRUPTS ();
@@ -4289,36 +4284,6 @@ ExecModifyTable(PlanState *pstate)
42894284 context .epqstate = & node -> mt_epqstate ;
42904285 context .estate = estate ;
42914286
4292- /*
4293- * If we are here for INSERT ... EXECUTE, create a TuplestoreDestReceiver
4294- * and pass it to the procedure execution. The procedure execution will send
4295- * its result sets to the tuplestore via the receiver function.
4296- */
4297- if (tsql_insert_exec )
4298- {
4299- tss = tuplestore_begin_heap (false, false, work_mem );
4300- tupdesc = RelationGetDescr (resultRelInfo -> ri_RelationDesc );
4301- dest = CreateTuplestoreDestReceiver ();
4302- SetTuplestoreDestReceiverParams (dest , tss , CurrentMemoryContext , false, NULL , NULL );
4303- dest -> rStartup (dest , -1 , tupdesc );
4304-
4305- switch (nodeTag (node -> callStmt ))
4306- {
4307- case T_CallStmt :
4308- ExecuteCallStmt ((CallStmt * )node -> callStmt ,
4309- pstate -> state -> es_param_list_info , false, dest );
4310- break ;
4311- case T_DoStmt :
4312- ExecuteDoStmtInsertExec ((DoStmt * )node -> callStmt , false, dest );
4313- break ;
4314- default :
4315- ereport (ERROR ,
4316- (errcode (ERRCODE_SYNTAX_ERROR ),
4317- errmsg ("Unrecognized stmt in INSERT EXEC" )));
4318- break ;
4319- }
4320- }
4321-
43224287 /*
43234288 * Fetch rows from subplan(s), and execute the required table modification
43244289 * for each row.
@@ -4348,43 +4313,35 @@ ExecModifyTable(PlanState *pstate)
43484313 break ;
43494314 }
43504315
4351- if (tsql_insert_exec )
4316+ /*
4317+ * If there is a pending MERGE ... WHEN NOT MATCHED [BY TARGET] action
4318+ * to execute, do so now --- see the comments in ExecMerge().
4319+ */
4320+ if (node -> mt_merge_pending_not_matched != NULL )
43524321 {
4353- context .planSlot = MakeSingleTupleTableSlot (tupdesc , & TTSOpsMinimalTuple );
4354- tuplestore_gettupleslot (tss , true, false, context .planSlot );
4355- }
4356- else
4357- {
4358- /*
4359- * If there is a pending MERGE ... WHEN NOT MATCHED [BY TARGET] action
4360- * to execute, do so now --- see the comments in ExecMerge().
4361- */
4362- if (node -> mt_merge_pending_not_matched != NULL )
4363- {
4364- context .planSlot = node -> mt_merge_pending_not_matched ;
4365- context .cpDeletedSlot = NULL ;
4366-
4367- slot = ExecMergeNotMatched (& context , node -> resultRelInfo ,
4368- node -> canSetTag );
4322+ context .planSlot = node -> mt_merge_pending_not_matched ;
4323+ context .cpDeletedSlot = NULL ;
43694324
4370- /* Clear the pending action */
4371- node -> mt_merge_pending_not_matched = NULL ;
4325+ slot = ExecMergeNotMatched ( & context , node -> resultRelInfo ,
4326+ node -> canSetTag ) ;
43724327
4373- /*
4374- * If we got a RETURNING result, return it to the caller. We'll
4375- * continue the work on next call.
4376- */
4377- if (slot )
4378- return slot ;
4328+ /* Clear the pending action */
4329+ node -> mt_merge_pending_not_matched = NULL ;
43794330
4380- continue ; /* continue with the next tuple */
4381- }
4331+ /*
4332+ * If we got a RETURNING result, return it to the caller. We'll
4333+ * continue the work on next call.
4334+ */
4335+ if (slot )
4336+ return slot ;
43824337
4383- /* Fetch the next row from subplan */
4384- context .planSlot = ExecProcNode (subplanstate );
4385- context .cpDeletedSlot = NULL ;
4338+ continue ; /* continue with the next tuple */
43864339 }
43874340
4341+ /* Fetch the next row from subplan */
4342+ context .planSlot = ExecProcNode (subplanstate );
4343+ context .cpDeletedSlot = NULL ;
4344+
43884345 /* No more tuples to process? */
43894346 if (TupIsNull (context .planSlot ))
43904347 break ;
@@ -4674,9 +4631,6 @@ ExecModifyTable(PlanState *pstate)
46744631 break ;
46754632 }
46764633
4677- if (tsql_insert_exec )
4678- ExecDropSingleTupleTableSlot (context .planSlot );
4679-
46804634 /*
46814635 * If we got a RETURNING result, return it to caller. We'll continue
46824636 * the work on next call.
@@ -4685,12 +4639,6 @@ ExecModifyTable(PlanState *pstate)
46854639 return slot ;
46864640 }
46874641
4688- if (tsql_insert_exec && dest )
4689- {
4690- dest -> rShutdown (dest );
4691- dest -> rDestroy (dest );
4692- }
4693-
46944642 /*
46954643 * Insert remaining tuples for batch insert.
46964644 */
0 commit comments