26
26
*
27
27
*
28
28
* IDENTIFICATION
29
- * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.256 2005/10/15 02:49:16 momjian Exp $
29
+ * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.257 2005/11/14 17:42:54 tgl Exp $
30
30
*
31
31
*-------------------------------------------------------------------------
32
32
*/
@@ -582,7 +582,8 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
582
582
* initialize the executor "tuple" table. We need slots for all the plan
583
583
* nodes, plus possibly output slots for the junkfilter(s). At this point
584
584
* we aren't sure if we need junkfilters, so just add slots for them
585
- * unconditionally.
585
+ * unconditionally. Also, if it's not a SELECT, set up a slot for use
586
+ * for trigger output tuples.
586
587
*/
587
588
{
588
589
int nSlots = ExecCountSlotsNode (plan );
@@ -591,7 +592,14 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
591
592
nSlots += list_length (parseTree -> resultRelations );
592
593
else
593
594
nSlots += 1 ;
595
+ if (operation != CMD_SELECT )
596
+ nSlots ++ ;
597
+
594
598
estate -> es_tupleTable = ExecCreateTupleTable (nSlots );
599
+
600
+ if (operation != CMD_SELECT )
601
+ estate -> es_trig_tuple_slot =
602
+ ExecAllocTableSlot (estate -> es_tupleTable );
595
603
}
596
604
597
605
/* mark EvalPlanQual not active */
@@ -1399,12 +1407,19 @@ ExecInsert(TupleTableSlot *slot,
1399
1407
if (newtuple != tuple ) /* modified by Trigger(s) */
1400
1408
{
1401
1409
/*
1402
- * Insert modified tuple into tuple table slot, replacing the
1403
- * original . We assume that it was allocated in per-tuple memory
1410
+ * Put the modified tuple into a slot for convenience of routines
1411
+ * below . We assume the tuple was allocated in per-tuple memory
1404
1412
* context, and therefore will go away by itself. The tuple table
1405
1413
* slot should not try to clear it.
1406
1414
*/
1407
- ExecStoreTuple (newtuple , slot , InvalidBuffer , false);
1415
+ TupleTableSlot * newslot = estate -> es_trig_tuple_slot ;
1416
+
1417
+ if (newslot -> tts_tupleDescriptor != slot -> tts_tupleDescriptor )
1418
+ ExecSetSlotDescriptor (newslot ,
1419
+ slot -> tts_tupleDescriptor ,
1420
+ false);
1421
+ ExecStoreTuple (newtuple , newslot , InvalidBuffer , false);
1422
+ slot = newslot ;
1408
1423
tuple = newtuple ;
1409
1424
}
1410
1425
}
@@ -1600,12 +1615,19 @@ ExecUpdate(TupleTableSlot *slot,
1600
1615
if (newtuple != tuple ) /* modified by Trigger(s) */
1601
1616
{
1602
1617
/*
1603
- * Insert modified tuple into tuple table slot, replacing the
1604
- * original . We assume that it was allocated in per-tuple memory
1618
+ * Put the modified tuple into a slot for convenience of routines
1619
+ * below . We assume the tuple was allocated in per-tuple memory
1605
1620
* context, and therefore will go away by itself. The tuple table
1606
1621
* slot should not try to clear it.
1607
1622
*/
1608
- ExecStoreTuple (newtuple , slot , InvalidBuffer , false);
1623
+ TupleTableSlot * newslot = estate -> es_trig_tuple_slot ;
1624
+
1625
+ if (newslot -> tts_tupleDescriptor != slot -> tts_tupleDescriptor )
1626
+ ExecSetSlotDescriptor (newslot ,
1627
+ slot -> tts_tupleDescriptor ,
1628
+ false);
1629
+ ExecStoreTuple (newtuple , newslot , InvalidBuffer , false);
1630
+ slot = newslot ;
1609
1631
tuple = newtuple ;
1610
1632
}
1611
1633
}
0 commit comments