Skip to content

Commit 6beba21

Browse files
committed
New HeapTuple structure/interface.
1 parent 2435c7d commit 6beba21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+835
-851
lines changed

src/backend/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#
3535
#
3636
# IDENTIFICATION
37-
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.33 1998/04/27 04:04:05 momjian Exp $
37+
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.34 1998/11/27 19:51:27 vadim Exp $
3838
#
3939
#-------------------------------------------------------------------------
4040

@@ -86,6 +86,9 @@ catalog/global1.description catalog/local1_template1.description:
8686
postgres.o: $(OBJS)
8787
$(CC) -r -o postgres.o $(OBJS) $(LDFLAGS)
8888

89+
fast:
90+
$(CC) -r -o postgres.o $(OBJS) $(LDFLAGS)
91+
8992

9093
############################################################################
9194
# The following targets are specified in make commands that appear in the

src/backend/access/common/heaptuple.c

Lines changed: 96 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.45 1998/10/08 18:29:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.46 1998/11/27 19:51:27 vadim Exp $
1212
*
1313
* NOTES
1414
* The old interface functions have been converted to macros
@@ -36,12 +36,12 @@
3636
/* Used by heap_getattr() macro, for speed */
3737
long heap_sysoffset[] = {
3838
/* Only the first one is pass-by-ref, and is handled specially in the macro */
39-
offsetof(HeapTupleData, t_ctid),
40-
offsetof(HeapTupleData, t_oid),
41-
offsetof(HeapTupleData, t_xmin),
42-
offsetof(HeapTupleData, t_cmin),
43-
offsetof(HeapTupleData, t_xmax),
44-
offsetof(HeapTupleData, t_cmax)
39+
offsetof(HeapTupleHeaderData, t_ctid),
40+
offsetof(HeapTupleHeaderData, t_oid),
41+
offsetof(HeapTupleHeaderData, t_xmin),
42+
offsetof(HeapTupleHeaderData, t_cmin),
43+
offsetof(HeapTupleHeaderData, t_xmax),
44+
offsetof(HeapTupleHeaderData, t_cmax)
4545
};
4646

4747
/* ----------------------------------------------------------------
@@ -167,14 +167,14 @@ DataFill(char *data,
167167
int
168168
heap_attisnull(HeapTuple tup, int attnum)
169169
{
170-
if (attnum > (int) tup->t_natts)
170+
if (attnum > (int) tup->t_data->t_natts)
171171
return 1;
172172

173173
if (HeapTupleNoNulls(tup))
174174
return 0;
175175

176176
if (attnum > 0)
177-
return att_isnull(attnum - 1, tup->t_bits);
177+
return att_isnull(attnum - 1, tup->t_data->t_bits);
178178
else
179179
switch (attnum)
180180
{
@@ -210,7 +210,7 @@ heap_attisnull(HeapTuple tup, int attnum)
210210
int
211211
heap_sysattrlen(AttrNumber attno)
212212
{
213-
HeapTupleData *f = NULL;
213+
HeapTupleHeader f = NULL;
214214

215215
switch (attno)
216216
{
@@ -323,15 +323,16 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
323323
* ----------------
324324
*/
325325
Datum
326-
nocachegetattr(HeapTuple tup,
326+
nocachegetattr(HeapTuple tuple,
327327
int attnum,
328328
TupleDesc tupleDesc,
329329
bool *isnull)
330330
{
331-
char *tp; /* ptr to att in tuple */
332-
bits8 *bp = tup->t_bits; /* ptr to att in tuple */
333-
int slow; /* do we have to walk nulls? */
334-
Form_pg_attribute *att = tupleDesc->attrs;
331+
char *tp; /* ptr to att in tuple */
332+
HeapTupleHeader tup = tuple->t_data;
333+
bits8 *bp = tup->t_bits; /* ptr to att in tuple */
334+
int slow; /* do we have to walk nulls? */
335+
Form_pg_attribute *att = tupleDesc->attrs;
335336

336337

337338
#if IN_MACRO
@@ -351,7 +352,7 @@ nocachegetattr(HeapTuple tup,
351352
* ----------------
352353
*/
353354

354-
if (HeapTupleNoNulls(tup))
355+
if (HeapTupleNoNulls(tuple))
355356
{
356357
attnum--;
357358

@@ -449,7 +450,7 @@ nocachegetattr(HeapTuple tup,
449450
}
450451
else if (attnum == 0)
451452
return (Datum) fetchatt(&(att[0]), (char *) tp);
452-
else if (!HeapTupleAllFixed(tup))
453+
else if (!HeapTupleAllFixed(tuple))
453454
{
454455
int j = 0;
455456

@@ -491,8 +492,8 @@ nocachegetattr(HeapTuple tup,
491492
/* Can we compute more? We will probably need them */
492493
(j < tup->t_natts &&
493494
att[j]->attcacheoff == -1 &&
494-
(HeapTupleNoNulls(tup) || !att_isnull(j, bp)) &&
495-
(HeapTupleAllFixed(tup) ||
495+
(HeapTupleNoNulls(tuple) || !att_isnull(j, bp)) &&
496+
(HeapTupleAllFixed(tuple) ||
496497
att[j]->attlen > 0 || VARLENA_FIXED_SIZE(att[j]))); j++)
497498
{
498499

@@ -527,7 +528,7 @@ nocachegetattr(HeapTuple tup,
527528

528529
for (i = 0; i < attnum; i++)
529530
{
530-
if (!HeapTupleNoNulls(tup))
531+
if (!HeapTupleNoNulls(tuple))
531532
{
532533
if (att_isnull(i, bp))
533534
{
@@ -570,14 +571,41 @@ heap_copytuple(HeapTuple tuple)
570571
{
571572
HeapTuple newTuple;
572573

573-
if (!HeapTupleIsValid(tuple))
574+
if (!HeapTupleIsValid(tuple) || tuple->t_data == NULL)
574575
return NULL;
575576

576-
newTuple = (HeapTuple) palloc(tuple->t_len);
577-
memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len);
577+
newTuple = (HeapTuple) palloc(HEAPTUPLESIZE + tuple->t_len);
578+
newTuple->t_len = tuple->t_len;
579+
newTuple->t_self = tuple->t_self;
580+
newTuple->t_data = (HeapTupleHeader) ((char *) newTuple + HEAPTUPLESIZE);
581+
memmove((char *) newTuple->t_data,
582+
(char *) tuple->t_data, (int) tuple->t_len);
578583
return newTuple;
579584
}
580585

586+
/* ----------------
587+
* heap_copytuple_with_tuple
588+
*
589+
* returns a copy of an tuple->t_data
590+
* ----------------
591+
*/
592+
void
593+
heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest)
594+
{
595+
if (!HeapTupleIsValid(src) || src->t_data == NULL)
596+
{
597+
dest->t_data = NULL;
598+
return;
599+
}
600+
601+
dest->t_len = src->t_len;
602+
dest->t_self = src->t_self;
603+
dest->t_data = (HeapTupleHeader) palloc(src->t_len);
604+
memmove((char *) dest->t_data,
605+
(char *) src->t_data, (int) src->t_len);
606+
return;
607+
}
608+
581609
#ifdef NOT_USED
582610
/* ----------------
583611
* heap_deformtuple
@@ -637,16 +665,16 @@ heap_formtuple(TupleDesc tupleDescriptor,
637665
Datum *value,
638666
char *nulls)
639667
{
640-
char *tp; /* tuple pointer */
641-
HeapTuple tuple; /* return tuple */
642-
int bitmaplen;
643-
long len;
644-
int hoff;
645-
bool hasnull = false;
646-
int i;
647-
int numberOfAttributes = tupleDescriptor->natts;
668+
HeapTuple tuple; /* return tuple */
669+
HeapTupleHeader td; /* tuple data */
670+
int bitmaplen;
671+
long len;
672+
int hoff;
673+
bool hasnull = false;
674+
int i;
675+
int numberOfAttributes = tupleDescriptor->natts;
648676

649-
len = offsetof(HeapTupleData, t_bits);
677+
len = offsetof(HeapTupleHeaderData, t_bits);
650678

651679
for (i = 0; i < numberOfAttributes && !hasnull; i++)
652680
{
@@ -668,23 +696,24 @@ heap_formtuple(TupleDesc tupleDescriptor,
668696

669697
len += ComputeDataSize(tupleDescriptor, value, nulls);
670698

671-
tp = (char *) palloc(len);
672-
tuple = (HeapTuple) tp;
699+
tuple = (HeapTuple) palloc(HEAPTUPLESIZE + len);
700+
td = tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);;
673701

674-
MemSet(tp, 0, (int) len);
702+
MemSet((char *) td, 0, (int) len);
675703

676704
tuple->t_len = len;
677-
tuple->t_natts = numberOfAttributes;
678-
tuple->t_hoff = hoff;
705+
ItemPointerSetInvalid(&(tuple->t_self));
706+
td->t_natts = numberOfAttributes;
707+
td->t_hoff = hoff;
679708

680-
DataFill((char *) tuple + tuple->t_hoff,
709+
DataFill((char *) td + td->t_hoff,
681710
tupleDescriptor,
682711
value,
683712
nulls,
684-
&tuple->t_infomask,
685-
(hasnull ? tuple->t_bits : NULL));
713+
&td->t_infomask,
714+
(hasnull ? td->t_bits : NULL));
686715

687-
tuple->t_infomask |= HEAP_XMAX_INVALID;
716+
td->t_infomask |= HEAP_XMAX_INVALID;
688717

689718
return tuple;
690719
}
@@ -767,13 +796,15 @@ heap_modifytuple(HeapTuple tuple,
767796
* copy the header except for t_len, t_natts, t_hoff, t_bits, t_infomask
768797
* ----------------
769798
*/
770-
infomask = newTuple->t_infomask;
771-
memmove((char *) &newTuple->t_oid, /* XXX */
772-
(char *) &tuple->t_oid,
773-
((char *) &tuple->t_hoff - (char *) &tuple->t_oid)); /* XXX */
774-
newTuple->t_infomask = infomask;
775-
newTuple->t_natts = numberOfAttributes; /* fix t_natts just in
776-
* case */
799+
infomask = newTuple->t_data->t_infomask;
800+
memmove((char *) &newTuple->t_data->t_oid, /* XXX */
801+
(char *) &tuple->t_data->t_oid,
802+
((char *) &tuple->t_data->t_hoff -
803+
(char *) &tuple->t_data->t_oid)); /* XXX */
804+
newTuple->t_data->t_infomask = infomask;
805+
newTuple->t_data->t_natts = numberOfAttributes;
806+
newTuple->t_self = tuple->t_self;
807+
777808
return newTuple;
778809
}
779810

@@ -787,28 +818,30 @@ heap_addheader(uint32 natts, /* max domain index */
787818
int structlen, /* its length */
788819
char *structure) /* pointer to the struct */
789820
{
790-
char *tp; /* tuple data pointer */
791-
HeapTuple tup;
792-
long len;
793-
int hoff;
821+
HeapTuple tuple;
822+
HeapTupleHeader td; /* tuple data */
823+
long len;
824+
int hoff;
794825

795826
AssertArg(natts > 0);
796827

797-
len = offsetof(HeapTupleData, t_bits);
828+
len = offsetof(HeapTupleHeaderData, t_bits);
798829

799830
hoff = len = DOUBLEALIGN(len); /* be conservative */
800831
len += structlen;
801-
tp = (char *) palloc(len);
802-
tup = (HeapTuple) tp;
803-
MemSet((char *) tup, 0, len);
832+
tuple = (HeapTuple) palloc(HEAPTUPLESIZE + len);
833+
td = tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
834+
835+
MemSet((char *) td, 0, (int) len);
804836

805-
tup->t_len = len;
806-
tp += tup->t_hoff = hoff;
807-
tup->t_natts = natts;
808-
tup->t_infomask = 0;
809-
tup->t_infomask |= HEAP_XMAX_INVALID;
837+
tuple->t_len = len;
838+
ItemPointerSetInvalid(&(tuple->t_self));
839+
td->t_hoff = hoff;
840+
td->t_natts = natts;
841+
td->t_infomask = 0;
842+
td->t_infomask |= HEAP_XMAX_INVALID;
810843

811-
memmove(tp, structure, structlen);
844+
memmove((char *) td + hoff, structure, structlen);
812845

813-
return tup;
846+
return tuple;
814847
}

src/backend/access/common/heapvalid.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.21 1997/09/22 03:58:32 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.22 1998/11/27 19:51:28 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -25,9 +25,9 @@
2525
bool
2626
TupleUpdatedByCurXactAndCmd(HeapTuple t)
2727
{
28-
if (TransactionIdEquals(t->t_xmax,
28+
if (TransactionIdEquals(t->t_data->t_xmax,
2929
GetCurrentTransactionId()) &&
30-
CommandIdGEScanCommandId(t->t_cmax))
30+
CommandIdGEScanCommandId(t->t_data->t_cmax))
3131
return true;
3232

3333
return false;

src/backend/access/common/printtup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.35 1998/09/01 04:26:40 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.36 1998/11/27 19:51:28 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -100,7 +100,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
100100
*/
101101
j = 0;
102102
k = 1 << 7;
103-
for (i = 0; i < tuple->t_natts;)
103+
for (i = 0; i < tuple->t_data->t_natts;)
104104
{
105105
i++; /* heap_getattr is a macro, so no
106106
* increment */
@@ -122,7 +122,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
122122
* send the attributes of this tuple
123123
* ----------------
124124
*/
125-
for (i = 0; i < tuple->t_natts; ++i)
125+
for (i = 0; i < tuple->t_data->t_natts; ++i)
126126
{
127127
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
128128
if (isnull)
@@ -204,7 +204,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo)
204204
bool isnull;
205205
Oid typoutput;
206206

207-
for (i = 0; i < tuple->t_natts; ++i)
207+
for (i = 0; i < tuple->t_data->t_natts; ++i)
208208
{
209209
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
210210
typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
@@ -251,7 +251,7 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
251251
*/
252252
j = 0;
253253
k = 1 << 7;
254-
for (i = 0; i < tuple->t_natts;)
254+
for (i = 0; i < tuple->t_data->t_natts;)
255255
{
256256
i++; /* heap_getattr is a macro, so no
257257
* increment */
@@ -274,9 +274,9 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
274274
* ----------------
275275
*/
276276
#ifdef IPORTAL_DEBUG
277-
fprintf(stderr, "sending tuple with %d atts\n", tuple->t_natts);
277+
fprintf(stderr, "sending tuple with %d atts\n", tuple->t_data->t_natts);
278278
#endif
279-
for (i = 0; i < tuple->t_natts; ++i)
279+
for (i = 0; i < tuple->t_data->t_natts; ++i)
280280
{
281281
int32 len = typeinfo->attrs[i]->attlen;
282282

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy