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

New HeapTuple structure/interface.

This commit is contained in:
Vadim B. Mikheev
1998-11-27 19:52:36 +00:00
parent 2435c7d501
commit 6beba218d7
65 changed files with 834 additions and 850 deletions

View File

@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.58 1998/10/14 05:10:00 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.59 1998/11/27 19:51:59 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -963,16 +963,7 @@ ExecAppend(TupleTableSlot *slot,
if (resultRelationDesc->rd_att->constr)
{
HeapTuple newtuple;
newtuple = ExecConstraints("ExecAppend", resultRelationDesc, tuple);
if (newtuple != tuple) /* modified by DEFAULT */
{
Assert(slot->ttc_shouldFree);
pfree(tuple);
slot->val = tuple = newtuple;
}
ExecConstraints("ExecAppend", resultRelationDesc, tuple);
}
/******************
@ -993,7 +984,7 @@ ExecAppend(TupleTableSlot *slot,
*/
numIndices = resultRelationInfo->ri_NumIndices;
if (numIndices > 0)
ExecInsertIndexTuples(slot, &(tuple->t_ctid), estate, false);
ExecInsertIndexTuples(slot, &(tuple->t_self), estate, false);
(estate->es_processed)++;
estate->es_lastoid = newId;
@ -1146,16 +1137,7 @@ ExecReplace(TupleTableSlot *slot,
if (resultRelationDesc->rd_att->constr)
{
HeapTuple newtuple;
newtuple = ExecConstraints("ExecReplace", resultRelationDesc, tuple);
if (newtuple != tuple) /* modified by DEFAULT */
{
Assert(slot->ttc_shouldFree);
pfree(tuple);
slot->val = tuple = newtuple;
}
ExecConstraints("ExecReplace", resultRelationDesc, tuple);
}
/******************
@ -1200,7 +1182,7 @@ ExecReplace(TupleTableSlot *slot,
numIndices = resultRelationInfo->ri_NumIndices;
if (numIndices > 0)
ExecInsertIndexTuples(slot, &(tuple->t_ctid), estate, true);
ExecInsertIndexTuples(slot, &(tuple->t_self), estate, true);
/* AFTER ROW UPDATE Triggers */
if (resultRelationDesc->trigdesc &&
@ -1334,18 +1316,12 @@ ExecRelCheck(Relation rel, HeapTuple tuple)
}
HeapTuple
void
ExecConstraints(char *caller, Relation rel, HeapTuple tuple)
{
HeapTuple newtuple = tuple;
Assert(rel->rd_att->constr);
#if 0
if (rel->rd_att->constr->num_defval > 0)
newtuple = tuple = ExecAttrDefault(rel, tuple);
#endif
if (rel->rd_att->constr->has_not_null)
{
int attrChk;
@ -1366,5 +1342,5 @@ ExecConstraints(char *caller, Relation rel, HeapTuple tuple)
elog(ERROR, "%s: rejected due to CHECK constraint %s", caller, failed);
}
return newtuple;
return;
}

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.37 1998/09/25 13:38:31 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.38 1998/11/27 19:52:00 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -274,7 +274,7 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull)
* the entire tuple, we give back a whole slot so that callers know
* what the tuple looks like.
*/
if (attnum == InvalidAttrNumber)
if (attnum == InvalidAttrNumber)
{
TupleTableSlot *tempSlot;
TupleDesc td;
@ -287,7 +287,7 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull)
tempSlot->ttc_buffer = InvalidBuffer;
tempSlot->ttc_whichplan = -1;
tup = heap_copytuple(slot->val);
tup = heap_copytuple(heapTuple);
td = CreateTupleDescCopy(slot->ttc_tupleDescriptor);
ExecSetSlotDescriptor(tempSlot, td);
@ -549,7 +549,6 @@ GetAttributeByName(TupleTableSlot *slot, char *attname, bool *isNull)
{
AttrNumber attrno;
TupleDesc tupdesc;
HeapTuple tuple;
Datum retval;
int natts;
int i;
@ -567,9 +566,7 @@ GetAttributeByName(TupleTableSlot *slot, char *attname, bool *isNull)
}
tupdesc = slot->ttc_tupleDescriptor;
tuple = slot->val;
natts = tuple->t_natts;
natts = slot->val->t_data->t_natts;
attrno = InvalidAttrNumber;
for (i = 0; i < tupdesc->natts; i++)

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.39 1998/09/23 04:22:06 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.40 1998/11/27 19:52:01 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -1138,7 +1138,7 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
result = index_insert(relationDescs[i], /* index relation */
datum, /* array of heaptuple Datums */
nulls, /* info on nulls */
&(heapTuple->t_ctid), /* oid of heap tuple */
&(heapTuple->t_self), /* tid of heap tuple */
heapRelation);
/* ----------------

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.20 1998/09/01 04:28:23 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.21 1998/11/27 19:52:01 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -270,7 +270,7 @@ copy_function_result(FunctionCachePtr fcache,
int i = 0;
TupleDesc funcTd = funcSlot->ttc_tupleDescriptor;
while (i < oldTuple->t_natts)
while (i < oldTuple->t_data->t_natts)
{
funcTd->attrs[i] =
(Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
@ -341,13 +341,11 @@ postquel_execute(execution_state *es,
resSlot = copy_function_result(fcache, slot);
if (fTlist != NIL)
{
HeapTuple tup;
TargetEntry *tle = lfirst(fTlist);
tup = resSlot->val;
value = ProjectAttribute(resSlot->ttc_tupleDescriptor,
tle,
tup,
resSlot->val,
isNull);
}
else

View File

@ -248,16 +248,12 @@ ExecAgg(Agg *node)
*/
for (;;)
{
HeapTuple outerTuple = NULL;
TupleTableSlot *outerslot;
isNull = isNull1 = isNull2 = 0;
outerslot = ExecProcNode(outerPlan, (Plan *) node);
if (outerslot)
outerTuple = outerslot->val;
if (!HeapTupleIsValid(outerTuple))
if (TupIsNull(outerslot))
{
/*
* when the outerplan doesn't return a single tuple,
* create a dummy heaptuple anyway because we still need
@ -666,7 +662,7 @@ aggGetAttr(TupleTableSlot *slot,
tempSlot->ttc_buffer = InvalidBuffer;
tempSlot->ttc_whichplan = -1;
tup = heap_copytuple(slot->val);
tup = heap_copytuple(heapTuple);
td = CreateTupleDescCopy(slot->ttc_tupleDescriptor);
ExecSetSlotDescriptor(tempSlot, td);

View File

@ -13,7 +13,7 @@
* columns. (ie. tuples from the same group are consecutive)
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.22 1998/09/01 04:28:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.23 1998/11/27 19:52:01 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -102,13 +102,12 @@ ExecGroupEveryTuple(Group *node)
else
{
outerslot = ExecProcNode(outerPlan(node), (Plan *) node);
if (outerslot)
outerTuple = outerslot->val;
if (!HeapTupleIsValid(outerTuple))
if (TupIsNull(outerslot))
{
grpstate->grp_done = TRUE;
return NULL;
}
outerTuple = outerslot->val;
firsttuple = grpstate->grp_firstTuple;
/* this should occur on the first call only */
@ -121,7 +120,7 @@ ExecGroupEveryTuple(Group *node)
* Compare with first tuple and see if this tuple is of the
* same group.
*/
if (!sameGroup(firsttuple, outerslot->val,
if (!sameGroup(firsttuple, outerTuple,
node->numCols, node->grpColIdx,
ExecGetScanType(&grpstate->csstate)))
{
@ -189,14 +188,13 @@ ExecGroupOneTuple(Group *node)
if (firsttuple == NULL)
{
outerslot = ExecProcNode(outerPlan(node), (Plan *) node);
if (outerslot)
outerTuple = outerslot->val;
if (!HeapTupleIsValid(outerTuple))
if (TupIsNull(outerslot))
{
grpstate->grp_done = TRUE;
return NULL;
}
grpstate->grp_firstTuple = firsttuple = heap_copytuple(outerTuple);
grpstate->grp_firstTuple = firsttuple =
heap_copytuple(outerslot->val);
}
/*
@ -205,19 +203,20 @@ ExecGroupOneTuple(Group *node)
for (;;)
{
outerslot = ExecProcNode(outerPlan(node), (Plan *) node);
outerTuple = (outerslot) ? outerslot->val : NULL;
if (!HeapTupleIsValid(outerTuple))
if (TupIsNull(outerslot))
{
grpstate->grp_done = TRUE;
outerTuple = NULL;
break;
}
outerTuple = outerslot->val;
/* ----------------
* Compare with first tuple and see if this tuple is of
* the same group.
* ----------------
*/
if ((!sameGroup(firsttuple, outerslot->val,
if ((!sameGroup(firsttuple, outerTuple,
node->numCols, node->grpColIdx,
ExecGetScanType(&grpstate->csstate))))
break;

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.23 1998/09/01 04:28:29 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.24 1998/11/27 19:52:02 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -489,16 +489,19 @@ ExecHashTableInsert(HashJoinTable hashtable,
*/
bucket = (HashBucket)
(ABSADDR(hashtable->top) + bucketno * hashtable->bucketsize);
if ((char *) LONGALIGN(ABSADDR(bucket->bottom))
- (char *) bucket + heapTuple->t_len > hashtable->bucketsize)
if ((char *) LONGALIGN(ABSADDR(bucket->bottom)) - (char *) bucket
+ heapTuple->t_len + HEAPTUPLESIZE > hashtable->bucketsize)
ExecHashOverflowInsert(hashtable, bucket, heapTuple);
else
{
memmove((char *) LONGALIGN(ABSADDR(bucket->bottom)),
heapTuple,
HEAPTUPLESIZE);
memmove((char *) LONGALIGN(ABSADDR(bucket->bottom)) + HEAPTUPLESIZE,
heapTuple->t_data,
heapTuple->t_len);
bucket->bottom =
((RelativeAddr) LONGALIGN(bucket->bottom) + heapTuple->t_len);
bucket->bottom = ((RelativeAddr) LONGALIGN(bucket->bottom) +
heapTuple->t_len + HEAPTUPLESIZE);
}
}
else
@ -611,7 +614,7 @@ ExecHashOverflowInsert(HashJoinTable hashtable,
* ----------------
*/
newend = (RelativeAddr) LONGALIGN(hashtable->overflownext + sizeof(*otuple)
+ heapTuple->t_len);
+ heapTuple->t_len + HEAPTUPLESIZE);
if (newend > hashtable->bottom)
{
#if 0
@ -664,6 +667,9 @@ ExecHashOverflowInsert(HashJoinTable hashtable,
otuple->tuple = RELADDR(LONGALIGN(((char *) otuple + sizeof(*otuple))));
memmove(ABSADDR(otuple->tuple),
heapTuple,
HEAPTUPLESIZE);
memmove(ABSADDR(otuple->tuple) + HEAPTUPLESIZE,
heapTuple->t_data,
heapTuple->t_len);
}
@ -704,7 +710,10 @@ ExecScanHashBucket(HashJoinState *hjstate,
LONGALIGN(ABSADDR(bucket->top));
else
heapTuple = (HeapTuple)
LONGALIGN(((char *) curtuple + curtuple->t_len));
LONGALIGN(((char *) curtuple + curtuple->t_len + HEAPTUPLESIZE));
heapTuple->t_data = (HeapTupleHeader)
((char *) heapTuple + HEAPTUPLESIZE);
while (heapTuple < (HeapTuple) ABSADDR(bucket->bottom))
{
@ -721,7 +730,9 @@ ExecScanHashBucket(HashJoinState *hjstate,
return heapTuple;
heapTuple = (HeapTuple)
LONGALIGN(((char *) heapTuple + heapTuple->t_len));
LONGALIGN(((char *) heapTuple + heapTuple->t_len + HEAPTUPLESIZE));
heapTuple->t_data = (HeapTupleHeader)
((char *) heapTuple + HEAPTUPLESIZE);
}
if (firstotuple == NULL)
@ -742,6 +753,8 @@ ExecScanHashBucket(HashJoinState *hjstate,
while (otuple != NULL)
{
heapTuple = (HeapTuple) ABSADDR(otuple->tuple);
heapTuple->t_data = (HeapTupleHeader)
((char *) heapTuple + HEAPTUPLESIZE);
inntuple = ExecStoreTuple(heapTuple, /* tuple to store */
hjstate->hj_HashTupleSlot, /* slot */

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.13 1998/09/01 04:28:31 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.14 1998/11/27 19:52:02 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -646,7 +646,10 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
(*position) = bufstart;
}
heapTuple = (HeapTuple) (*position);
(*position) = (char *) LONGALIGN(*position + heapTuple->t_len);
heapTuple->t_data = (HeapTupleHeader)
((char *) heapTuple + HEAPTUPLESIZE);
(*position) = (char *) LONGALIGN(*position +
heapTuple->t_len + HEAPTUPLESIZE);
return ExecStoreTuple(heapTuple, tupleSlot, InvalidBuffer, false);
}
@ -824,7 +827,7 @@ ExecHashJoinSaveTuple(HeapTuple heapTuple,
if (position == NULL)
position = pagestart;
if (position + heapTuple->t_len >= pagebound)
if (position + heapTuple->t_len + HEAPTUPLESIZE >= pagebound)
{
cc = FileSeek(file, 0L, SEEK_END);
if (cc < 0)
@ -836,8 +839,9 @@ ExecHashJoinSaveTuple(HeapTuple heapTuple,
position = pagestart;
*pageend = 0;
}
memmove(position, heapTuple, heapTuple->t_len);
position = (char *) LONGALIGN(position + heapTuple->t_len);
memmove(position, heapTuple, HEAPTUPLESIZE);
memmove(position + HEAPTUPLESIZE, heapTuple->t_data, heapTuple->t_len);
position = (char *) LONGALIGN(position + heapTuple->t_len + HEAPTUPLESIZE);
*pageend = position - buffer;
return position;

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.28 1998/11/22 10:48:36 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.29 1998/11/27 19:52:03 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -91,7 +91,7 @@ IndexNext(IndexScan *node)
IndexScanDesc scandesc;
Relation heapRelation;
RetrieveIndexResult result;
HeapTuple tuple;
HeapTuple tuple;
TupleTableSlot *slot;
Buffer buffer = InvalidBuffer;
int numIndices;
@ -109,6 +109,7 @@ IndexNext(IndexScan *node)
heapRelation = scanstate->css_currentRelation;
numIndices = indexstate->iss_NumIndices;
slot = scanstate->css_ScanTupleSlot;
tuple = &(indexstate->iss_htup);
/* ----------------
* ok, now that we have what we need, fetch an index tuple.
@ -121,11 +122,11 @@ IndexNext(IndexScan *node)
scandesc = scanDescs[indexstate->iss_IndexPtr];
while ((result = index_getnext(scandesc, direction)) != NULL)
{
tuple = heap_fetch(heapRelation, snapshot,
&result->heap_iptr, &buffer);
tuple->t_self = result->heap_iptr;
heap_fetch(heapRelation, snapshot, tuple, &buffer);
pfree(result);
if (tuple != NULL)
if (tuple->t_data != NULL)
{
bool prev_matches = false;
int prev_index;

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.17 1998/09/01 04:28:34 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.18 1998/11/27 19:52:03 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -114,13 +114,22 @@ ExecMaterial(Material *node)
{
slot = ExecProcNode(outerNode, (Plan *) node);
heapTuple = slot->val;
if (heapTuple == NULL)
if (TupIsNull(slot))
break;
/*
* heap_insert changes something...
*/
if (slot->ttc_buffer != InvalidBuffer)
heapTuple = heap_copytuple(slot->val);
else
heapTuple = slot->val;
heap_insert(tempRelation, heapTuple);
heap_insert(tempRelation, /* relation desc */
heapTuple); /* heap tuple to insert */
if (slot->ttc_buffer != InvalidBuffer)
pfree(heapTuple);
ExecClearTuple(slot);
}
currentRelation = tempRelation;

View File

@ -15,7 +15,7 @@
* ExecEndTee
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/Attic/nodeTee.c,v 1.24 1998/10/08 18:29:27 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/Attic/nodeTee.c,v 1.25 1998/11/27 19:52:03 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -342,11 +342,20 @@ ExecTee(Tee *node, Plan *parent)
slot = ExecProcNode(childNode, (Plan *) node);
if (!TupIsNull(slot))
{
heapTuple = slot->val;
/*
* heap_insert changes something...
*/
if (slot->ttc_buffer != InvalidBuffer)
heapTuple = heap_copytuple(slot->val);
else
heapTuple = slot->val;
/* insert into temporary relation */
heap_insert(bufferRel, heapTuple);
if (slot->ttc_buffer != InvalidBuffer)
pfree(heapTuple);
/*
* once there is data in the temporary relation, ensure that
* the left and right scandescs are initialized

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeUnique.c,v 1.17 1998/02/26 04:31:34 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeUnique.c,v 1.18 1998/11/27 19:52:03 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@ -76,7 +76,7 @@ ExecIdenticalTuples(TupleTableSlot *t1, TupleTableSlot *t2)
* THE t_len FIELDS CAN BE THE SAME IN THIS CASE!!
* ----------------
*/
if (h1->t_hoff != h2->t_hoff)
if (h1->t_data->t_hoff != h2->t_data->t_hoff)
return false;
/* ----------------
@ -86,7 +86,7 @@ ExecIdenticalTuples(TupleTableSlot *t1, TupleTableSlot *t2)
*/
d1 = (char *) GETSTRUCT(h1);
d2 = (char *) GETSTRUCT(h2);
len = (int) h1->t_len - (int) h1->t_hoff;
len = (int) h1->t_len - (int) h1->t_data->t_hoff;
/* ----------------
* byte compare the data areas and return the result.

View File

@ -356,11 +356,12 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum,
if (i == natts) /* no errors in *attnum */
{
mtuple = heap_formtuple(rel->rd_att, v, n);
infomask = mtuple->t_infomask;
memmove(&(mtuple->t_ctid), &(tuple->t_ctid),
((char *) &(tuple->t_hoff) - (char *) &(tuple->t_ctid)));
mtuple->t_infomask = infomask;
mtuple->t_natts = numberOfAttributes;
infomask = mtuple->t_data->t_infomask;
memmove(&(mtuple->t_data->t_oid), &(tuple->t_data->t_oid),
((char *) &(tuple->t_data->t_hoff) -
(char *) &(tuple->t_data->t_oid)));
mtuple->t_data->t_infomask = infomask;
mtuple->t_data->t_natts = numberOfAttributes;
}
else
{
@ -413,7 +414,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Oid foutoid;
SPI_result = 0;
if (tuple->t_natts < fnumber || fnumber <= 0)
if (tuple->t_data->t_natts < fnumber || fnumber <= 0)
{
SPI_result = SPI_ERROR_NOATTRIBUTE;
return NULL;
@ -441,7 +442,7 @@ SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
*isnull = true;
SPI_result = 0;
if (tuple->t_natts < fnumber || fnumber <= 0)
if (tuple->t_data->t_natts < fnumber || fnumber <= 0)
{
SPI_result = SPI_ERROR_NOATTRIBUTE;
return (Datum) NULL;