mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Revise TupleTableSlot code to avoid unnecessary construction and disassembly
of tuples when passing data up through multiple plan nodes. A slot can now hold either a normal "physical" HeapTuple, or a "virtual" tuple consisting of Datum/isnull arrays. Upper plan levels can usually just copy the Datum arrays, avoiding heap_formtuple() and possible subsequent nocachegetattr() calls to extract the data again. This work extends Atsushi Ogawa's earlier patch, which provided the key idea of adding Datum arrays to TupleTableSlots. (I believe however that something like this was foreseen way back in Berkeley days --- see the old comment on ExecProject.) A test case involving many levels of join of fairly wide tables (about 80 columns altogether) showed about 3x overall speedup, though simple queries will probably not be helped very much. I have also duplicated some code in heaptuple.c in order to provide versions of heap_formtuple and friends that use "bool" arrays to indicate null attributes, instead of the old convention of "char" arrays containing either 'n' or ' '. This provides a better match to the convention used by ExecEvalExpr. While I have not made a concerted effort to get rid of uses of the old routines, I think they should be deprecated and eventually removed.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.82 2005/02/11 00:41:12 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.83 2005/03/16 21:38:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -448,14 +448,11 @@ compute_index_stats(Relation onerel, double totalrows,
|
||||
{
|
||||
MemoryContext ind_context,
|
||||
old_context;
|
||||
TupleDesc heapDescriptor;
|
||||
Datum attdata[INDEX_MAX_KEYS];
|
||||
char nulls[INDEX_MAX_KEYS];
|
||||
int ind,
|
||||
i;
|
||||
|
||||
heapDescriptor = RelationGetDescr(onerel);
|
||||
|
||||
ind_context = AllocSetContextCreate(anl_context,
|
||||
"Analyze Index",
|
||||
ALLOCSET_DEFAULT_MINSIZE,
|
||||
@ -468,7 +465,6 @@ compute_index_stats(Relation onerel, double totalrows,
|
||||
AnlIndexData *thisdata = &indexdata[ind];
|
||||
IndexInfo *indexInfo = thisdata->indexInfo;
|
||||
int attr_cnt = thisdata->attr_cnt;
|
||||
TupleTable tupleTable;
|
||||
TupleTableSlot *slot;
|
||||
EState *estate;
|
||||
ExprContext *econtext;
|
||||
@ -492,9 +488,7 @@ compute_index_stats(Relation onerel, double totalrows,
|
||||
estate = CreateExecutorState();
|
||||
econtext = GetPerTupleExprContext(estate);
|
||||
/* Need a slot to hold the current heap tuple, too */
|
||||
tupleTable = ExecCreateTupleTable(1);
|
||||
slot = ExecAllocTableSlot(tupleTable);
|
||||
ExecSetSlotDescriptor(slot, heapDescriptor, false);
|
||||
slot = MakeSingleTupleTableSlot(RelationGetDescr(onerel));
|
||||
|
||||
/* Arrange for econtext's scan tuple to be the tuple under test */
|
||||
econtext->ecxt_scantuple = slot;
|
||||
@ -532,8 +526,7 @@ compute_index_stats(Relation onerel, double totalrows,
|
||||
* convenient.
|
||||
*/
|
||||
FormIndexDatum(indexInfo,
|
||||
heapTuple,
|
||||
heapDescriptor,
|
||||
slot,
|
||||
estate,
|
||||
attdata,
|
||||
nulls);
|
||||
@ -585,7 +578,7 @@ compute_index_stats(Relation onerel, double totalrows,
|
||||
/* And clean up */
|
||||
MemoryContextSwitchTo(ind_context);
|
||||
|
||||
ExecDropTupleTable(tupleTable, true);
|
||||
ExecDropSingleTupleTableSlot(slot);
|
||||
FreeExecutorState(estate);
|
||||
MemoryContextResetAndDeleteChildren(ind_context);
|
||||
}
|
||||
|
Reference in New Issue
Block a user