Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 40f797b

Browse files
committed
Enable another five tuple status bits by using the high bits of the
nattr field, and rename the field. Heikki Linnakangas
1 parent ca9213e commit 40f797b

File tree

6 files changed

+44
-34
lines changed

6 files changed

+44
-34
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.113 2007/01/05 22:19:21 momjian Exp $
19+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.114 2007/01/09 22:00:59 momjian Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -295,7 +295,7 @@ DataFill(char *data,
295295
bool
296296
heap_attisnull(HeapTuple tup, int attnum)
297297
{
298-
if (attnum > (int) tup->t_data->t_natts)
298+
if (attnum > (int) HeapTupleHeaderGetNatts(tup->t_data))
299299
return true;
300300

301301
if (attnum > 0)
@@ -474,6 +474,7 @@ nocachegetattr(HeapTuple tuple,
474474
{
475475
int j = 1;
476476
long off;
477+
int natts = HeapTupleHeaderGetNatts(tup);
477478

478479
/*
479480
* need to set cache for some atts
@@ -488,7 +489,7 @@ nocachegetattr(HeapTuple tuple,
488489

489490
for (; j <= attnum ||
490491
/* Can we compute more? We will probably need them */
491-
(j < tup->t_natts &&
492+
(j < natts &&
492493
att[j]->attcacheoff == -1 &&
493494
(HeapTupleNoNulls(tuple) || !att_isnull(j, bp)) &&
494495
(HeapTupleAllFixed(tuple) || att[j]->attlen > 0)); j++)
@@ -739,7 +740,7 @@ heap_form_tuple(TupleDesc tupleDescriptor,
739740
HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
740741
HeapTupleHeaderSetTypMod(td, tupleDescriptor->tdtypmod);
741742

742-
td->t_natts = numberOfAttributes;
743+
HeapTupleHeaderSetNatts(td, numberOfAttributes);
743744
td->t_hoff = hoff;
744745

745746
if (tupleDescriptor->tdhasoid) /* else leave infomask = 0 */
@@ -846,7 +847,7 @@ heap_formtuple(TupleDesc tupleDescriptor,
846847
HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
847848
HeapTupleHeaderSetTypMod(td, tupleDescriptor->tdtypmod);
848849

849-
td->t_natts = numberOfAttributes;
850+
HeapTupleHeaderSetNatts(td, numberOfAttributes);
850851
td->t_hoff = hoff;
851852

852853
if (tupleDescriptor->tdhasoid) /* else leave infomask = 0 */
@@ -1035,7 +1036,7 @@ heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
10351036
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
10361037
bool slow = false; /* can we use/set attcacheoff? */
10371038

1038-
natts = tup->t_natts;
1039+
natts = HeapTupleHeaderGetNatts(tup);
10391040

10401041
/*
10411042
* In inheritance situations, it is possible that the given tuple actually
@@ -1128,7 +1129,7 @@ heap_deformtuple(HeapTuple tuple,
11281129
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
11291130
bool slow = false; /* can we use/set attcacheoff? */
11301131

1131-
natts = tup->t_natts;
1132+
natts = HeapTupleHeaderGetNatts(tup);
11321133

11331134
/*
11341135
* In inheritance situations, it is possible that the given tuple actually
@@ -1335,7 +1336,7 @@ slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
13351336
* than the tupdesc.)
13361337
*/
13371338
tup = tuple->t_data;
1338-
if (attnum > tup->t_natts)
1339+
if (attnum > HeapTupleHeaderGetNatts(tup))
13391340
{
13401341
*isnull = true;
13411342
return (Datum) 0;
@@ -1401,7 +1402,7 @@ slot_getallattrs(TupleTableSlot *slot)
14011402
/*
14021403
* load up any slots available from physical tuple
14031404
*/
1404-
attnum = tuple->t_data->t_natts;
1405+
attnum = HeapTupleHeaderGetNatts(tuple->t_data);
14051406
attnum = Min(attnum, tdesc_natts);
14061407

14071408
slot_deform_tuple(slot, attnum);
@@ -1448,7 +1449,7 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
14481449
/*
14491450
* load up any slots available from physical tuple
14501451
*/
1451-
attno = tuple->t_data->t_natts;
1452+
attno = HeapTupleHeaderGetNatts(tuple->t_data);
14521453
attno = Min(attno, attnum);
14531454

14541455
slot_deform_tuple(slot, attno);
@@ -1601,7 +1602,7 @@ heap_form_minimal_tuple(TupleDesc tupleDescriptor,
16011602
* And fill in the information.
16021603
*/
16031604
tuple->t_len = len;
1604-
tuple->t_natts = numberOfAttributes;
1605+
HeapTupleHeaderSetNatts(tuple, numberOfAttributes);
16051606
tuple->t_hoff = hoff + MINIMAL_TUPLE_OFFSET;
16061607

16071608
if (tupleDescriptor->tdhasoid) /* else leave infomask = 0 */
@@ -1663,7 +1664,7 @@ heap_tuple_from_minimal_tuple(MinimalTuple mtup)
16631664
result->t_tableOid = InvalidOid;
16641665
result->t_data = (HeapTupleHeader) ((char *) result + HEAPTUPLESIZE);
16651666
memcpy((char *) result->t_data + MINIMAL_TUPLE_OFFSET, mtup, mtup->t_len);
1666-
memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_natts));
1667+
memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_infomask2));
16671668
return result;
16681669
}
16691670

@@ -1729,7 +1730,7 @@ heap_addheader(int natts, /* max domain index */
17291730

17301731
/* we don't bother to fill the Datum fields */
17311732

1732-
td->t_natts = natts;
1733+
HeapTupleHeaderSetNatts(td, natts);
17331734
td->t_hoff = hoff;
17341735

17351736
if (withoid) /* else leave infomask = 0 */

src/backend/access/heap/heapam.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.223 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.224 2007/01/09 22:00:59 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1455,7 +1455,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
14551455
rdata[0].buffer = InvalidBuffer;
14561456
rdata[0].next = &(rdata[1]);
14571457

1458-
xlhdr.t_natts = heaptup->t_data->t_natts;
1458+
xlhdr.t_infomask2 = heaptup->t_data->t_infomask2;
14591459
xlhdr.t_infomask = heaptup->t_data->t_infomask;
14601460
xlhdr.t_hoff = heaptup->t_data->t_hoff;
14611461

@@ -3204,7 +3204,7 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
32043204
rdata[1].buffer_std = true;
32053205
rdata[1].next = &(rdata[2]);
32063206

3207-
xlhdr.hdr.t_natts = newtup->t_data->t_natts;
3207+
xlhdr.hdr.t_infomask2 = newtup->t_data->t_infomask2;
32083208
xlhdr.hdr.t_infomask = newtup->t_data->t_infomask;
32093209
xlhdr.hdr.t_hoff = newtup->t_data->t_hoff;
32103210
if (move) /* remember xmax & xmin */
@@ -3503,7 +3503,7 @@ heap_xlog_insert(XLogRecPtr lsn, XLogRecord *record)
35033503
(char *) xlrec + SizeOfHeapInsert + SizeOfHeapHeader,
35043504
newlen);
35053505
newlen += offsetof(HeapTupleHeaderData, t_bits);
3506-
htup->t_natts = xlhdr.t_natts;
3506+
htup->t_infomask2 = xlhdr.t_infomask2;
35073507
htup->t_infomask = xlhdr.t_infomask;
35083508
htup->t_hoff = xlhdr.t_hoff;
35093509
HeapTupleHeaderSetXmin(htup, record->xl_xid);
@@ -3666,7 +3666,7 @@ newsame:;
36663666
(char *) xlrec + hsize,
36673667
newlen);
36683668
newlen += offsetof(HeapTupleHeaderData, t_bits);
3669-
htup->t_natts = xlhdr.t_natts;
3669+
htup->t_infomask2 = xlhdr.t_infomask2;
36703670
htup->t_infomask = xlhdr.t_infomask;
36713671
htup->t_hoff = xlhdr.t_hoff;
36723672

src/backend/executor/spi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.168 2007/01/05 22:19:29 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.169 2007/01/09 22:00:59 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -651,7 +651,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
651651

652652
SPI_result = 0;
653653

654-
if (fnumber > tuple->t_data->t_natts || fnumber == 0 ||
654+
if (fnumber > HeapTupleHeaderGetNatts(tuple->t_data) || fnumber == 0 ||
655655
fnumber <= FirstLowInvalidHeapAttributeNumber)
656656
{
657657
SPI_result = SPI_ERROR_NOATTRIBUTE;
@@ -692,7 +692,7 @@ SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
692692
{
693693
SPI_result = 0;
694694

695-
if (fnumber > tuple->t_data->t_natts || fnumber == 0 ||
695+
if (fnumber > HeapTupleHeaderGetNatts(tuple->t_data) || fnumber == 0 ||
696696
fnumber <= FirstLowInvalidHeapAttributeNumber)
697697
{
698698
SPI_result = SPI_ERROR_NOATTRIBUTE;

src/include/access/heapam.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.118 2007/01/05 22:19:51 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.119 2007/01/09 22:01:00 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -98,7 +98,7 @@ extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
9898
( \
9999
((attnum) > 0) ? \
100100
( \
101-
((attnum) > (int) (tup)->t_data->t_natts) ? \
101+
((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
102102
( \
103103
(((isnull) != NULL) ? (*(isnull) = true) : (dummyret)NULL), \
104104
(Datum)NULL \

src/include/access/htup.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.88 2007/01/05 22:19:51 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.89 2007/01/09 22:01:00 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -139,7 +139,7 @@ typedef struct HeapTupleHeaderData
139139

140140
/* Fields below here must match MinimalTupleData! */
141141

142-
int16 t_natts; /* number of attributes */
142+
uint16 t_infomask2; /* number of attributes + various flags */
143143

144144
uint16 t_infomask; /* various flag bits, see below */
145145

@@ -182,6 +182,15 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
182182

183183
#define HEAP_XACT_MASK 0xFFC0 /* visibility-related bits */
184184

185+
/* information stored in t_infomask2, and accessor macros */
186+
#define HEAP_NATTS_MASK 0x7FF /* 11 bits for number of attributes */
187+
/* bits 0xF800 are unused */
188+
189+
#define HeapTupleHeaderGetNatts(tup) ((tup)->t_infomask2 & HEAP_NATTS_MASK)
190+
#define HeapTupleHeaderSetNatts(tup, natts) \
191+
( \
192+
(tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts) \
193+
)
185194

186195
/*
187196
* HeapTupleHeader accessor macros
@@ -367,8 +376,8 @@ do { \
367376
* and thereby prevent accidental use of the nonexistent fields.
368377
*
369378
* MinimalTupleData contains a length word, some padding, and fields matching
370-
* HeapTupleHeaderData beginning with t_natts. The padding is chosen so that
371-
* offsetof(t_natts) is the same modulo MAXIMUM_ALIGNOF in both structs.
379+
* HeapTupleHeaderData beginning with t_infomask2. The padding is chosen so that
380+
* offsetof(t_infomask2) is the same modulo MAXIMUM_ALIGNOF in both structs.
372381
* This makes data alignment rules equivalent in both cases.
373382
*
374383
* When a minimal tuple is accessed via a HeapTupleData pointer, t_data is
@@ -380,9 +389,9 @@ do { \
380389
* the MINIMAL_TUPLE_OFFSET distance. t_len does not include that, however.
381390
*/
382391
#define MINIMAL_TUPLE_OFFSET \
383-
((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
392+
((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
384393
#define MINIMAL_TUPLE_PADDING \
385-
((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
394+
((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
386395

387396
typedef struct MinimalTupleData
388397
{
@@ -392,7 +401,7 @@ typedef struct MinimalTupleData
392401

393402
/* Fields below here must match HeapTupleHeaderData! */
394403

395-
int16 t_natts; /* number of attributes */
404+
uint16 t_infomask2; /* number of attributes + various flags */
396405

397406
uint16 t_infomask; /* various flag bits, see below */
398407

@@ -552,7 +561,7 @@ typedef struct xl_heap_delete
552561
*/
553562
typedef struct xl_heap_header
554563
{
555-
int16 t_natts;
564+
uint16 t_infomask2;
556565
uint16 t_infomask;
557566
uint8 t_hoff;
558567
} xl_heap_header;

src/pl/plpgsql/src/pl_exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.182 2007/01/05 22:20:02 momjian Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.183 2007/01/09 22:01:00 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4092,7 +4092,7 @@ exec_move_row(PLpgSQL_execstate *estate,
40924092
* Row is a bit more complicated in that we assign the individual
40934093
* attributes of the tuple to the variables the row points to.
40944094
*
4095-
* NOTE: this code used to demand row->nfields == tup->t_data->t_natts,
4095+
* NOTE: this code used to demand row->nfields == HeapTupleHeaderGetNatts(tup->t_data,
40964096
* but that's wrong. The tuple might have more fields than we expected if
40974097
* it's from an inheritance-child table of the current table, or it might
40984098
* have fewer if the table has had columns added by ALTER TABLE. Ignore
@@ -4110,7 +4110,7 @@ exec_move_row(PLpgSQL_execstate *estate,
41104110
int anum;
41114111

41124112
if (HeapTupleIsValid(tup))
4113-
t_natts = tup->t_data->t_natts;
4113+
t_natts = HeapTupleHeaderGetNatts(tup->t_data);
41144114
else
41154115
t_natts = 0;
41164116

0 commit comments

Comments
 (0)