summaryrefslogtreecommitdiff
path: root/src/backend/access/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/common')
-rw-r--r--src/backend/access/common/heaptuple.c159
-rw-r--r--src/backend/access/common/heapvalid.c6
-rw-r--r--src/backend/access/common/printtup.c14
-rw-r--r--src/backend/access/common/tupdesc.c4
4 files changed, 108 insertions, 75 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 1659484434..3d0b684306 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.45 1998/10/08 18:29:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.46 1998/11/27 19:51:27 vadim Exp $
*
* NOTES
* The old interface functions have been converted to macros
@@ -36,12 +36,12 @@
/* Used by heap_getattr() macro, for speed */
long heap_sysoffset[] = {
/* Only the first one is pass-by-ref, and is handled specially in the macro */
- offsetof(HeapTupleData, t_ctid),
- offsetof(HeapTupleData, t_oid),
- offsetof(HeapTupleData, t_xmin),
- offsetof(HeapTupleData, t_cmin),
- offsetof(HeapTupleData, t_xmax),
- offsetof(HeapTupleData, t_cmax)
+ offsetof(HeapTupleHeaderData, t_ctid),
+ offsetof(HeapTupleHeaderData, t_oid),
+ offsetof(HeapTupleHeaderData, t_xmin),
+ offsetof(HeapTupleHeaderData, t_cmin),
+ offsetof(HeapTupleHeaderData, t_xmax),
+ offsetof(HeapTupleHeaderData, t_cmax)
};
/* ----------------------------------------------------------------
@@ -167,14 +167,14 @@ DataFill(char *data,
int
heap_attisnull(HeapTuple tup, int attnum)
{
- if (attnum > (int) tup->t_natts)
+ if (attnum > (int) tup->t_data->t_natts)
return 1;
if (HeapTupleNoNulls(tup))
return 0;
if (attnum > 0)
- return att_isnull(attnum - 1, tup->t_bits);
+ return att_isnull(attnum - 1, tup->t_data->t_bits);
else
switch (attnum)
{
@@ -210,7 +210,7 @@ heap_attisnull(HeapTuple tup, int attnum)
int
heap_sysattrlen(AttrNumber attno)
{
- HeapTupleData *f = NULL;
+ HeapTupleHeader f = NULL;
switch (attno)
{
@@ -323,15 +323,16 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
* ----------------
*/
Datum
-nocachegetattr(HeapTuple tup,
+nocachegetattr(HeapTuple tuple,
int attnum,
TupleDesc tupleDesc,
bool *isnull)
{
- char *tp; /* ptr to att in tuple */
- bits8 *bp = tup->t_bits; /* ptr to att in tuple */
- int slow; /* do we have to walk nulls? */
- Form_pg_attribute *att = tupleDesc->attrs;
+ char *tp; /* ptr to att in tuple */
+ HeapTupleHeader tup = tuple->t_data;
+ bits8 *bp = tup->t_bits; /* ptr to att in tuple */
+ int slow; /* do we have to walk nulls? */
+ Form_pg_attribute *att = tupleDesc->attrs;
#if IN_MACRO
@@ -351,7 +352,7 @@ nocachegetattr(HeapTuple tup,
* ----------------
*/
- if (HeapTupleNoNulls(tup))
+ if (HeapTupleNoNulls(tuple))
{
attnum--;
@@ -449,7 +450,7 @@ nocachegetattr(HeapTuple tup,
}
else if (attnum == 0)
return (Datum) fetchatt(&(att[0]), (char *) tp);
- else if (!HeapTupleAllFixed(tup))
+ else if (!HeapTupleAllFixed(tuple))
{
int j = 0;
@@ -491,8 +492,8 @@ nocachegetattr(HeapTuple tup,
/* Can we compute more? We will probably need them */
(j < tup->t_natts &&
att[j]->attcacheoff == -1 &&
- (HeapTupleNoNulls(tup) || !att_isnull(j, bp)) &&
- (HeapTupleAllFixed(tup) ||
+ (HeapTupleNoNulls(tuple) || !att_isnull(j, bp)) &&
+ (HeapTupleAllFixed(tuple) ||
att[j]->attlen > 0 || VARLENA_FIXED_SIZE(att[j]))); j++)
{
@@ -527,7 +528,7 @@ nocachegetattr(HeapTuple tup,
for (i = 0; i < attnum; i++)
{
- if (!HeapTupleNoNulls(tup))
+ if (!HeapTupleNoNulls(tuple))
{
if (att_isnull(i, bp))
{
@@ -570,14 +571,41 @@ heap_copytuple(HeapTuple tuple)
{
HeapTuple newTuple;
- if (!HeapTupleIsValid(tuple))
+ if (!HeapTupleIsValid(tuple) || tuple->t_data == NULL)
return NULL;
- newTuple = (HeapTuple) palloc(tuple->t_len);
- memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len);
+ newTuple = (HeapTuple) palloc(HEAPTUPLESIZE + tuple->t_len);
+ newTuple->t_len = tuple->t_len;
+ newTuple->t_self = tuple->t_self;
+ newTuple->t_data = (HeapTupleHeader) ((char *) newTuple + HEAPTUPLESIZE);
+ memmove((char *) newTuple->t_data,
+ (char *) tuple->t_data, (int) tuple->t_len);
return newTuple;
}
+/* ----------------
+ * heap_copytuple_with_tuple
+ *
+ * returns a copy of an tuple->t_data
+ * ----------------
+ */
+void
+heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest)
+{
+ if (!HeapTupleIsValid(src) || src->t_data == NULL)
+ {
+ dest->t_data = NULL;
+ return;
+ }
+
+ dest->t_len = src->t_len;
+ dest->t_self = src->t_self;
+ dest->t_data = (HeapTupleHeader) palloc(src->t_len);
+ memmove((char *) dest->t_data,
+ (char *) src->t_data, (int) src->t_len);
+ return;
+}
+
#ifdef NOT_USED
/* ----------------
* heap_deformtuple
@@ -637,16 +665,16 @@ heap_formtuple(TupleDesc tupleDescriptor,
Datum *value,
char *nulls)
{
- char *tp; /* tuple pointer */
- HeapTuple tuple; /* return tuple */
- int bitmaplen;
- long len;
- int hoff;
- bool hasnull = false;
- int i;
- int numberOfAttributes = tupleDescriptor->natts;
+ HeapTuple tuple; /* return tuple */
+ HeapTupleHeader td; /* tuple data */
+ int bitmaplen;
+ long len;
+ int hoff;
+ bool hasnull = false;
+ int i;
+ int numberOfAttributes = tupleDescriptor->natts;
- len = offsetof(HeapTupleData, t_bits);
+ len = offsetof(HeapTupleHeaderData, t_bits);
for (i = 0; i < numberOfAttributes && !hasnull; i++)
{
@@ -668,23 +696,24 @@ heap_formtuple(TupleDesc tupleDescriptor,
len += ComputeDataSize(tupleDescriptor, value, nulls);
- tp = (char *) palloc(len);
- tuple = (HeapTuple) tp;
+ tuple = (HeapTuple) palloc(HEAPTUPLESIZE + len);
+ td = tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);;
- MemSet(tp, 0, (int) len);
+ MemSet((char *) td, 0, (int) len);
tuple->t_len = len;
- tuple->t_natts = numberOfAttributes;
- tuple->t_hoff = hoff;
+ ItemPointerSetInvalid(&(tuple->t_self));
+ td->t_natts = numberOfAttributes;
+ td->t_hoff = hoff;
- DataFill((char *) tuple + tuple->t_hoff,
+ DataFill((char *) td + td->t_hoff,
tupleDescriptor,
value,
nulls,
- &tuple->t_infomask,
- (hasnull ? tuple->t_bits : NULL));
+ &td->t_infomask,
+ (hasnull ? td->t_bits : NULL));
- tuple->t_infomask |= HEAP_XMAX_INVALID;
+ td->t_infomask |= HEAP_XMAX_INVALID;
return tuple;
}
@@ -767,13 +796,15 @@ heap_modifytuple(HeapTuple tuple,
* copy the header except for t_len, t_natts, t_hoff, t_bits, t_infomask
* ----------------
*/
- infomask = newTuple->t_infomask;
- memmove((char *) &newTuple->t_oid, /* XXX */
- (char *) &tuple->t_oid,
- ((char *) &tuple->t_hoff - (char *) &tuple->t_oid)); /* XXX */
- newTuple->t_infomask = infomask;
- newTuple->t_natts = numberOfAttributes; /* fix t_natts just in
- * case */
+ infomask = newTuple->t_data->t_infomask;
+ memmove((char *) &newTuple->t_data->t_oid, /* XXX */
+ (char *) &tuple->t_data->t_oid,
+ ((char *) &tuple->t_data->t_hoff -
+ (char *) &tuple->t_data->t_oid)); /* XXX */
+ newTuple->t_data->t_infomask = infomask;
+ newTuple->t_data->t_natts = numberOfAttributes;
+ newTuple->t_self = tuple->t_self;
+
return newTuple;
}
@@ -787,28 +818,30 @@ heap_addheader(uint32 natts, /* max domain index */
int structlen, /* its length */
char *structure) /* pointer to the struct */
{
- char *tp; /* tuple data pointer */
- HeapTuple tup;
- long len;
- int hoff;
+ HeapTuple tuple;
+ HeapTupleHeader td; /* tuple data */
+ long len;
+ int hoff;
AssertArg(natts > 0);
- len = offsetof(HeapTupleData, t_bits);
+ len = offsetof(HeapTupleHeaderData, t_bits);
hoff = len = DOUBLEALIGN(len); /* be conservative */
len += structlen;
- tp = (char *) palloc(len);
- tup = (HeapTuple) tp;
- MemSet((char *) tup, 0, len);
+ tuple = (HeapTuple) palloc(HEAPTUPLESIZE + len);
+ td = tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
+
+ MemSet((char *) td, 0, (int) len);
- tup->t_len = len;
- tp += tup->t_hoff = hoff;
- tup->t_natts = natts;
- tup->t_infomask = 0;
- tup->t_infomask |= HEAP_XMAX_INVALID;
+ tuple->t_len = len;
+ ItemPointerSetInvalid(&(tuple->t_self));
+ td->t_hoff = hoff;
+ td->t_natts = natts;
+ td->t_infomask = 0;
+ td->t_infomask |= HEAP_XMAX_INVALID;
- memmove(tp, structure, structlen);
+ memmove((char *) td + hoff, structure, structlen);
- return tup;
+ return tuple;
}
diff --git a/src/backend/access/common/heapvalid.c b/src/backend/access/common/heapvalid.c
index cbdd473478..79208bb3a5 100644
--- a/src/backend/access/common/heapvalid.c
+++ b/src/backend/access/common/heapvalid.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.21 1997/09/22 03:58:32 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.22 1998/11/27 19:51:28 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -25,9 +25,9 @@
bool
TupleUpdatedByCurXactAndCmd(HeapTuple t)
{
- if (TransactionIdEquals(t->t_xmax,
+ if (TransactionIdEquals(t->t_data->t_xmax,
GetCurrentTransactionId()) &&
- CommandIdGEScanCommandId(t->t_cmax))
+ CommandIdGEScanCommandId(t->t_data->t_cmax))
return true;
return false;
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c
index 68459beb01..4e8592ef56 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.35 1998/09/01 04:26:40 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.36 1998/11/27 19:51:28 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -100,7 +100,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
*/
j = 0;
k = 1 << 7;
- for (i = 0; i < tuple->t_natts;)
+ for (i = 0; i < tuple->t_data->t_natts;)
{
i++; /* heap_getattr is a macro, so no
* increment */
@@ -122,7 +122,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
* send the attributes of this tuple
* ----------------
*/
- for (i = 0; i < tuple->t_natts; ++i)
+ for (i = 0; i < tuple->t_data->t_natts; ++i)
{
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
if (isnull)
@@ -204,7 +204,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo)
bool isnull;
Oid typoutput;
- for (i = 0; i < tuple->t_natts; ++i)
+ for (i = 0; i < tuple->t_data->t_natts; ++i)
{
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
@@ -251,7 +251,7 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
*/
j = 0;
k = 1 << 7;
- for (i = 0; i < tuple->t_natts;)
+ for (i = 0; i < tuple->t_data->t_natts;)
{
i++; /* heap_getattr is a macro, so no
* increment */
@@ -274,9 +274,9 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
* ----------------
*/
#ifdef IPORTAL_DEBUG
- fprintf(stderr, "sending tuple with %d atts\n", tuple->t_natts);
+ fprintf(stderr, "sending tuple with %d atts\n", tuple->t_data->t_natts);
#endif
- for (i = 0; i < tuple->t_natts; ++i)
+ for (i = 0; i < tuple->t_data->t_natts; ++i)
{
int32 len = typeinfo->attrs[i]->attlen;
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 4e33e362a1..5b6181fe57 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.44 1998/09/01 04:26:41 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.45 1998/11/27 19:51:28 vadim Exp $
*
* NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -351,7 +351,7 @@ TupleDescInitEntry(TupleDesc desc,
*/
typeForm = (Form_pg_type) GETSTRUCT(tuple);
- att->atttypid = tuple->t_oid;
+ att->atttypid = tuple->t_data->t_oid;
att->attalign = typeForm->typalign;
/* ------------------------