aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAgg.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-03-16 21:38:10 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-03-16 21:38:10 +0000
commitf97aebd162987d00bd9b9f592ff54e9e90f11843 (patch)
tree78c6ff493070f92e7fda262a2c25e2545f0d2b21 /src/backend/executor/nodeAgg.c
parent712f053587b552769d1d3f6fe0ec03ab79c05d26 (diff)
downloadpostgresql-f97aebd162987d00bd9b9f592ff54e9e90f11843.tar.gz
postgresql-f97aebd162987d00bd9b9f592ff54e9e90f11843.zip
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.
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r--src/backend/executor/nodeAgg.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 8f641cc843b..1e211803df1 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -61,7 +61,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.129 2005/03/12 20:25:06 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.130 2005/03/16 21:38:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -748,7 +748,7 @@ agg_retrieve_direct(AggState *aggstate)
* Make a copy of the first input tuple; we will use this
* for comparisons (in group mode) and for projection.
*/
- aggstate->grp_firstTuple = heap_copytuple(outerslot->val);
+ aggstate->grp_firstTuple = ExecCopySlotTuple(outerslot);
}
else
{
@@ -813,9 +813,8 @@ agg_retrieve_direct(AggState *aggstate)
*/
if (node->aggstrategy == AGG_SORTED)
{
- if (!execTuplesMatch(firstSlot->val,
- outerslot->val,
- firstSlot->ttc_tupleDescriptor,
+ if (!execTuplesMatch(firstSlot,
+ outerslot,
node->numCols, node->grpColIdx,
aggstate->eqfunctions,
tmpcontext->ecxt_per_tuple_memory))
@@ -823,7 +822,7 @@ agg_retrieve_direct(AggState *aggstate)
/*
* Save the first input tuple of the next group.
*/
- aggstate->grp_firstTuple = heap_copytuple(outerslot->val);
+ aggstate->grp_firstTuple = ExecCopySlotTuple(outerslot);
break;
}
}
@@ -863,31 +862,11 @@ agg_retrieve_direct(AggState *aggstate)
*/
if (TupIsNull(firstSlot))
{
- TupleDesc tupType;
-
/* Should only happen in non-grouped mode */
Assert(node->aggstrategy == AGG_PLAIN);
Assert(aggstate->agg_done);
- tupType = firstSlot->ttc_tupleDescriptor;
- /* watch out for zero-column input tuples, though... */
- if (tupType && tupType->natts > 0)
- {
- HeapTuple nullsTuple;
- Datum *dvalues;
- char *dnulls;
-
- dvalues = (Datum *) palloc0(sizeof(Datum) * tupType->natts);
- dnulls = (char *) palloc(sizeof(char) * tupType->natts);
- MemSet(dnulls, 'n', sizeof(char) * tupType->natts);
- nullsTuple = heap_formtuple(tupType, dvalues, dnulls);
- ExecStoreTuple(nullsTuple,
- firstSlot,
- InvalidBuffer,
- true);
- pfree(dvalues);
- pfree(dnulls);
- }
+ ExecStoreAllNullTuple(firstSlot);
}
/*