1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Improve ExecStoreTuple to be smarter about replacing the contents of

a TupleTableSlot: instead of calling ExecClearTuple, inline the needed
operations, so that we can avoid redundant steps.  In particular, when
the old and new tuples are both on the same disk page, avoid releasing
and re-acquiring the buffer pin --- this saves work in both the bufmgr
and ResourceOwner modules.  To make this improvement actually useful,
partially revert a change I made on 2004-04-21 that caused SeqNext
et al to call ExecClearTuple before ExecStoreTuple.  The motivation
for that, to avoid grabbing the BufMgrLock separately for releasing
the old buffer and grabbing the new one, no longer applies.  My
profiling says that this saves about 5% of the CPU time for an
all-in-memory seqscan.
This commit is contained in:
Tom Lane
2005-11-25 04:24:48 +00:00
parent c0a2f8cc4d
commit dab52ab13d
5 changed files with 33 additions and 55 deletions

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.89 2005/11/22 18:17:10 momjian Exp $
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.90 2005/11/25 04:24:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -402,28 +402,38 @@ ExecStoreTuple(HeapTuple tuple,
Assert(BufferIsValid(buffer) ? (!shouldFree) : true);
/*
* clear out any old contents of the slot
* Free any old physical tuple belonging to the slot.
*/
if (!slot->tts_isempty)
ExecClearTuple(slot);
if (slot->tts_shouldFree)
heap_freetuple(slot->tts_tuple);
/*
* store the new tuple into the specified slot.
* Store the new tuple into the specified slot.
*/
slot->tts_isempty = false;
slot->tts_shouldFree = shouldFree;
slot->tts_tuple = tuple;
/* Mark extracted state invalid */
slot->tts_nvalid = 0;
/*
* If tuple is on a disk page, keep the page pinned as long as we hold a
* pointer into it. We assume the caller already has such a pin.
*
* This is coded to optimize the case where the slot previously held a
* tuple on the same disk page: in that case releasing and re-acquiring
* the pin is a waste of cycles. This is a common situation during
* seqscans, so it's worth troubling over.
*/
slot->tts_buffer = buffer;
if (BufferIsValid(buffer))
IncrBufferRefCount(buffer);
/* Mark extracted state invalid */
slot->tts_nvalid = 0;
if (slot->tts_buffer != buffer)
{
if (BufferIsValid(slot->tts_buffer))
ReleaseBuffer(slot->tts_buffer);
slot->tts_buffer = buffer;
if (BufferIsValid(buffer))
IncrBufferRefCount(buffer);
}
return slot;
}