Skip to content

Commit adfa042

Browse files
committed
Save a few cycles in EXPLAIN and related commands by not bothering to form
a physical tuple in do_tup_output(). A virtual tuple is easier to set up and also easier for most tuple receivers to process. Per my comment on Robert Haas' recent patch in this code.
1 parent 6a0865e commit adfa042

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/backend/executor/execTuples.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.108 2009/07/22 17:00:20 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.109 2009/07/23 21:27:10 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1215,27 +1215,28 @@ begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc)
12151215

12161216
/*
12171217
* write a single tuple
1218-
*
1219-
* XXX This could be made more efficient, since in reality we probably only
1220-
* need a virtual tuple.
12211218
*/
12221219
void
12231220
do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
12241221
{
1225-
TupleDesc tupdesc = tstate->slot->tts_tupleDescriptor;
1226-
HeapTuple tuple;
1222+
TupleTableSlot *slot = tstate->slot;
1223+
int natts = slot->tts_tupleDescriptor->natts;
12271224

1228-
/* form a tuple */
1229-
tuple = heap_form_tuple(tupdesc, values, isnull);
1225+
/* make sure the slot is clear */
1226+
ExecClearTuple(slot);
12301227

1231-
/* put it in a slot */
1232-
ExecStoreTuple(tuple, tstate->slot, InvalidBuffer, true);
1228+
/* insert data */
1229+
memcpy(slot->tts_values, values, natts * sizeof(Datum));
1230+
memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
1231+
1232+
/* mark slot as containing a virtual tuple */
1233+
ExecStoreVirtualTuple(slot);
12331234

12341235
/* send the tuple to the receiver */
1235-
(*tstate->dest->receiveSlot) (tstate->slot, tstate->dest);
1236+
(*tstate->dest->receiveSlot) (slot, tstate->dest);
12361237

12371238
/* clean up */
1238-
ExecClearTuple(tstate->slot);
1239+
ExecClearTuple(slot);
12391240
}
12401241

12411242
/*

0 commit comments

Comments
 (0)