aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.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/execMain.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/execMain.c')
-rw-r--r--src/backend/executor/execMain.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 1e7a1b5440f..0294063d3f5 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.241 2005/01/14 17:53:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.242 2005/03/16 21:38:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1082,7 +1082,6 @@ lnext: ;
if ((junkfilter = estate->es_junkFilter) != NULL)
{
Datum datum;
- HeapTuple newTuple;
bool isNull;
/*
@@ -1180,13 +1179,7 @@ lnext: ;
* Finally create a new "clean" tuple with all junk attributes
* removed
*/
- newTuple = ExecRemoveJunk(junkfilter, slot);
-
- slot = ExecStoreTuple(newTuple, /* tuple to store */
- junkfilter->jf_resultSlot, /* dest slot */
- InvalidBuffer, /* this tuple has no
- * buffer */
- true); /* tuple should be pfreed */
+ slot = ExecFilterJunk(junkfilter, slot);
}
/*
@@ -1276,15 +1269,6 @@ ExecSelect(TupleTableSlot *slot,
DestReceiver *dest,
EState *estate)
{
- HeapTuple tuple;
- TupleDesc attrtype;
-
- /*
- * get the heap tuple out of the tuple table slot
- */
- tuple = slot->val;
- attrtype = slot->ttc_tupleDescriptor;
-
/*
* insert the tuple into the "into relation"
*
@@ -1292,15 +1276,20 @@ ExecSelect(TupleTableSlot *slot,
*/
if (estate->es_into_relation_descriptor != NULL)
{
+ HeapTuple tuple;
+
+ tuple = ExecCopySlotTuple(slot);
heap_insert(estate->es_into_relation_descriptor, tuple,
estate->es_snapshot->curcid);
+ /* we know there are no indexes to update */
+ heap_freetuple(tuple);
IncrAppended();
}
/*
* send the tuple to the destination
*/
- (*dest->receiveTuple) (tuple, attrtype, dest);
+ (*dest->receiveSlot) (slot, dest);
IncrRetrieved();
(estate->es_processed)++;
}
@@ -1325,9 +1314,10 @@ ExecInsert(TupleTableSlot *slot,
Oid newId;
/*
- * get the heap tuple out of the tuple table slot
+ * get the heap tuple out of the tuple table slot, making sure
+ * we have a writable copy
*/
- tuple = slot->val;
+ tuple = ExecMaterializeSlot(slot);
/*
* get information on the (current) result relation
@@ -1520,9 +1510,10 @@ ExecUpdate(TupleTableSlot *slot,
elog(ERROR, "cannot UPDATE during bootstrap");
/*
- * get the heap tuple out of the tuple table slot
+ * get the heap tuple out of the tuple table slot, making sure
+ * we have a writable copy
*/
- tuple = slot->val;
+ tuple = ExecMaterializeSlot(slot);
/*
* get information on the (current) result relation
@@ -1604,10 +1595,8 @@ lreplace:;
if (!TupIsNull(epqslot))
{
*tupleid = ctid;
- tuple = ExecRemoveJunk(estate->es_junkFilter, epqslot);
- slot = ExecStoreTuple(tuple,
- estate->es_junkFilter->jf_resultSlot,
- InvalidBuffer, true);
+ slot = ExecFilterJunk(estate->es_junkFilter, epqslot);
+ tuple = ExecMaterializeSlot(slot);
goto lreplace;
}
}
@@ -1712,7 +1701,6 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate)
{
Relation rel = resultRelInfo->ri_RelationDesc;
- HeapTuple tuple = slot->val;
TupleConstr *constr = rel->rd_att->constr;
Assert(constr);
@@ -1725,7 +1713,7 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
for (attrChk = 1; attrChk <= natts; attrChk++)
{
if (rel->rd_att->attrs[attrChk - 1]->attnotnull &&
- heap_attisnull(tuple, attrChk))
+ slot_attisnull(slot, attrChk))
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("null value in column \"%s\" violates not-null constraint",