Skip to content

Commit 2435c7d

Browse files
committed
New HeapTuple structure/interface.
1 parent 4d71880 commit 2435c7d

File tree

8 files changed

+117
-104
lines changed

8 files changed

+117
-104
lines changed

src/include/access/heapam.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: heapam.h,v 1.38 1998/10/08 18:30:22 momjian Exp $
9+
* $Id: heapam.h,v 1.39 1998/11/27 19:33:31 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -89,6 +89,10 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
8989
*
9090
* ----------------
9191
*/
92+
93+
extern Datum nocachegetattr(HeapTuple tup, int attnum,
94+
TupleDesc att, bool *isnull);
95+
9296
#if !defined(DISABLE_COMPLEX_MACRO)
9397

9498
#define fastgetattr(tup, attnum, tupleDesc, isnull) \
@@ -101,7 +105,7 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
101105
(attnum) == 1) ? \
102106
( \
103107
(Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
104-
(char *) (tup) + (tup)->t_hoff + \
108+
(char *) (tup)->t_data + (tup)->t_data->t_hoff + \
105109
( \
106110
((attnum) != 1) ? \
107111
(tupleDesc)->attrs[(attnum)-1]->attcacheoff \
@@ -115,7 +119,7 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
115119
) \
116120
: \
117121
( \
118-
att_isnull((attnum)-1, (tup)->t_bits) ? \
122+
att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
119123
( \
120124
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
121125
(Datum)NULL \
@@ -129,9 +133,6 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
129133

130134
#else /* !defined(DISABLE_COMPLEX_MACRO) */
131135

132-
extern Datum nocachegetattr(HeapTuple tup, int attnum,
133-
TupleDesc att, bool *isnull);
134-
135136
static Datum
136137
fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
137138
bool *isnull)
@@ -146,7 +147,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
146147
(attnum) == 1) ?
147148
(
148149
(Datum) fetchatt(&((tupleDesc)->attrs[(attnum) - 1]),
149-
(char *) (tup) + (tup)->t_hoff +
150+
(char *) (tup)->t_data + (tup)->t_data->t_hoff +
150151
(
151152
((attnum) != 1) ?
152153
(tupleDesc)->attrs[(attnum) - 1]->attcacheoff
@@ -160,7 +161,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
160161
)
161162
:
162163
(
163-
att_isnull((attnum) - 1, (tup)->t_bits) ?
164+
att_isnull((attnum) - 1, (tup)->t_data->t_bits) ?
164165
(
165166
((isnull) ? (*(isnull) = true) : (dummyret) NULL),
166167
(Datum) NULL
@@ -205,7 +206,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
205206
AssertMacro((tup) != NULL && \
206207
(attnum) > FirstLowInvalidHeapAttributeNumber && \
207208
(attnum) != 0), \
208-
((attnum) > (int) (tup)->t_natts) ? \
209+
((attnum) > (int) (tup)->t_data->t_natts) ? \
209210
( \
210211
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
211212
(Datum)NULL \
@@ -221,13 +222,12 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
221222
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
222223
((attnum) == SelfItemPointerAttributeNumber) ? \
223224
( \
224-
(Datum)((char *)(tup) + \
225-
heap_sysoffset[-SelfItemPointerAttributeNumber-1]) \
225+
(Datum)((char *)&((tup)->t_self)) \
226226
) \
227227
: \
228228
( \
229229
(Datum)*(unsigned int *) \
230-
((char *)(tup) + heap_sysoffset[-(attnum)-1]) \
230+
((char *)(tup)->t_data + heap_sysoffset[-(attnum)-1]) \
231231
) \
232232
) \
233233
) \
@@ -251,7 +251,7 @@ extern HeapScanDesc heap_beginscan(Relation relation, int atend,
251251
extern void heap_rescan(HeapScanDesc scan, bool scanFromEnd, ScanKey key);
252252
extern void heap_endscan(HeapScanDesc scan);
253253
extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw);
254-
extern HeapTuple heap_fetch(Relation relation, Snapshot snapshot, ItemPointer tid, Buffer *userbuf);
254+
extern void heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tup, Buffer *userbuf);
255255
extern Oid heap_insert(Relation relation, HeapTuple tup);
256256
extern int heap_delete(Relation relation, ItemPointer tid);
257257
extern int heap_replace(Relation relation, ItemPointer otid,
@@ -270,6 +270,7 @@ extern bool heap_sysattrbyval(AttrNumber attno);
270270
extern Datum nocachegetattr(HeapTuple tup, int attnum,
271271
TupleDesc att, bool *isnull);
272272
extern HeapTuple heap_copytuple(HeapTuple tuple);
273+
extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
273274
extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
274275
Datum *value, char *nulls);
275276
extern HeapTuple heap_modifytuple(HeapTuple tuple,

src/include/access/htup.h

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: htup.h,v 1.10 1998/09/01 04:34:14 momjian Exp $
9+
* $Id: htup.h,v 1.11 1998/11/27 19:33:31 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -26,10 +26,8 @@
2626
* to avoid wasting space, the attributes should be layed out in such a
2727
* way to reduce structure padding.
2828
*/
29-
typedef struct HeapTupleData
29+
typedef struct HeapTupleHeaderData
3030
{
31-
unsigned int t_len; /* length of entire tuple */
32-
3331
Oid t_oid; /* OID of this tuple -- 4 bytes */
3432

3533
CommandId t_cmin; /* insert CID stamp -- 4 bytes each */
@@ -38,7 +36,7 @@ typedef struct HeapTupleData
3836
TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */
3937
TransactionId t_xmax; /* delete XID stamp */
4038

41-
ItemPointerData t_ctid; /* current TID of this tuple */
39+
ItemPointerData t_ctid; /* current TID of this or newer tuple */
4240

4341
int16 t_natts; /* number of attributes */
4442

@@ -50,10 +48,9 @@ typedef struct HeapTupleData
5048
/* bit map of domains */
5149

5250
/* MORE DATA FOLLOWS AT END OF STRUCT */
53-
} HeapTupleData;
54-
55-
typedef HeapTupleData *HeapTuple;
51+
} HeapTupleHeaderData;
5652

53+
typedef HeapTupleHeaderData *HeapTupleHeader;
5754

5855
#define SelfItemPointerAttributeNumber (-1)
5956
#define ObjectIdAttributeNumber (-2)
@@ -66,11 +63,33 @@ typedef HeapTupleData *HeapTuple;
6663
/* If you make any changes above, the order off offsets in this must change */
6764
extern long heap_sysoffset[];
6865

66+
/*
67+
* This new HeapTuple for version >= 6.5 and this is why it was changed:
68+
*
69+
* 1. t_len moved off on-disk tuple data - ItemIdData is used to get len;
70+
* 2. t_ctid above is not self tuple TID now - it may point to
71+
* updated version of tuple (required by MVCC);
72+
* 3. someday someone let tuple to cross block boundaries -
73+
* he have to add something below...
74+
*/
75+
typedef struct HeapTupleData
76+
{
77+
uint32 t_len; /* length of *t_data */
78+
ItemPointerData t_self; /* SelfItemPointer */
79+
HeapTupleHeader t_data; /* */
80+
} HeapTupleData;
81+
82+
typedef HeapTupleData *HeapTuple;
83+
84+
#define HEAPTUPLESIZE DOUBLEALIGN(sizeof(HeapTupleData))
85+
86+
6987
/* ----------------
7088
* support macros
7189
* ----------------
7290
*/
73-
#define GETSTRUCT(TUP) (((char *)(TUP)) + ((HeapTuple)(TUP))->t_hoff)
91+
#define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
92+
((HeapTuple)(TUP))->t_data->t_hoff)
7493

7594

7695
/*
@@ -101,9 +120,9 @@ extern long heap_sysoffset[];
101120
#define HEAP_XACT_MASK 0x0F00 /* */
102121

103122
#define HeapTupleNoNulls(tuple) \
104-
(!(((HeapTuple) (tuple))->t_infomask & HEAP_HASNULL))
123+
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
105124

106125
#define HeapTupleAllFixed(tuple) \
107-
(!(((HeapTuple) (tuple))->t_infomask & HEAP_HASVARLENA))
126+
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
108127

109128
#endif /* HTUP_H */

src/include/access/relscan.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: relscan.h,v 1.12 1998/09/01 04:34:23 momjian Exp $
9+
* $Id: relscan.h,v 1.13 1998/11/27 19:33:31 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -22,40 +22,40 @@ typedef ItemPointerData MarkData;
2222

2323
typedef struct HeapScanDescData
2424
{
25-
Relation rs_rd; /* pointer to relation descriptor */
26-
HeapTuple rs_ptup; /* previous tuple in scan */
27-
HeapTuple rs_ctup; /* current tuple in scan */
28-
HeapTuple rs_ntup; /* next tuple in scan */
29-
Buffer rs_pbuf; /* previous buffer in scan */
30-
Buffer rs_cbuf; /* current buffer in scan */
31-
Buffer rs_nbuf; /* next buffer in scan */
32-
ItemPointerData rs_mptid; /* marked previous tid */
33-
ItemPointerData rs_mctid; /* marked current tid */
34-
ItemPointerData rs_mntid; /* marked next tid */
35-
ItemPointerData rs_mcd; /* marked current delta XXX ??? */
36-
Snapshot rs_snapshot; /* snapshot to see */
37-
bool rs_atend; /* restart scan at end? */
38-
uint16 rs_cdelta; /* current delta in chain */
39-
uint16 rs_nkeys; /* number of attributes in keys */
40-
ScanKey rs_key; /* key descriptors */
25+
Relation rs_rd; /* pointer to relation descriptor */
26+
HeapTupleData rs_ptup; /* previous tuple in scan */
27+
HeapTupleData rs_ctup; /* current tuple in scan */
28+
HeapTupleData rs_ntup; /* next tuple in scan */
29+
Buffer rs_pbuf; /* previous buffer in scan */
30+
Buffer rs_cbuf; /* current buffer in scan */
31+
Buffer rs_nbuf; /* next buffer in scan */
32+
ItemPointerData rs_mptid; /* marked previous tid */
33+
ItemPointerData rs_mctid; /* marked current tid */
34+
ItemPointerData rs_mntid; /* marked next tid */
35+
ItemPointerData rs_mcd; /* marked current delta XXX ??? */
36+
Snapshot rs_snapshot; /* snapshot to see */
37+
bool rs_atend; /* restart scan at end? */
38+
uint16 rs_cdelta; /* current delta in chain */
39+
uint16 rs_nkeys; /* number of attributes in keys */
40+
ScanKey rs_key; /* key descriptors */
4141
} HeapScanDescData;
4242

4343
typedef HeapScanDescData *HeapScanDesc;
4444

4545
typedef struct IndexScanDescData
4646
{
47-
Relation relation; /* relation descriptor */
48-
void *opaque; /* am-specific slot */
47+
Relation relation; /* relation descriptor */
48+
void *opaque; /* am-specific slot */
4949
ItemPointerData previousItemData; /* previous index pointer */
5050
ItemPointerData currentItemData; /* current index pointer */
5151
ItemPointerData nextItemData; /* next index pointer */
5252
MarkData previousMarkData; /* marked previous pointer */
53-
MarkData currentMarkData;/* marked current pointer */
54-
MarkData nextMarkData; /* marked next pointer */
55-
uint8 flags; /* scan position flags */
56-
bool scanFromEnd; /* restart scan at end? */
57-
uint16 numberOfKeys; /* number of key attributes */
58-
ScanKey keyData; /* key descriptor */
53+
MarkData currentMarkData; /* marked current pointer */
54+
MarkData nextMarkData; /* marked next pointer */
55+
uint8 flags; /* scan position flags */
56+
bool scanFromEnd; /* restart scan at end? */
57+
uint16 numberOfKeys; /* number of key attributes */
58+
ScanKey keyData; /* key descriptor */
5959
} IndexScanDescData;
6060

6161
typedef IndexScanDescData *IndexScanDesc;

src/include/access/valid.h

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: valid.h,v 1.15 1998/09/01 04:34:33 momjian Exp $
9+
* $Id: valid.h,v 1.16 1998/11/27 19:33:32 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -109,49 +109,41 @@ do \
109109
* with joey's expensive function work.
110110
* ----------------
111111
*/
112-
#define HeapTupleSatisfies(itemId, \
112+
#define HeapTupleSatisfies(tuple, \
113113
relation, \
114114
buffer, \
115115
disk_page, \
116116
seeself, \
117117
nKeys, \
118-
key, \
119-
result) \
118+
key) \
120119
do \
121120
{ \
122121
/* We use underscores to protect the variable passed in as parameters */ \
123-
HeapTuple _tuple; \
124122
bool _res; \
125123
\
126-
if (!ItemIdIsUsed(itemId)) \
127-
(result) = (HeapTuple) NULL; \
124+
if ((key) != NULL) \
125+
HeapKeyTest(tuple, RelationGetDescr(relation), \
126+
(nKeys), (key), _res); \
128127
else \
129-
{ \
130-
_tuple = (HeapTuple) PageGetItem((Page) (disk_page), (itemId)); \
131-
\
132-
if ((key) != NULL) \
133-
HeapKeyTest(_tuple, RelationGetDescr(relation), \
134-
(nKeys), (key), _res); \
135-
else \
136-
_res = TRUE; \
128+
_res = TRUE; \
137129
\
138-
(result) = (HeapTuple) NULL; \
139-
if (_res) \
130+
if (_res) \
131+
{ \
132+
if ((relation)->rd_rel->relkind != RELKIND_UNCATALOGED) \
140133
{ \
141-
if ((relation)->rd_rel->relkind == RELKIND_UNCATALOGED) \
142-
(result) = _tuple; \
143-
else \
144-
{ \
145-
uint16 _infomask = _tuple->t_infomask; \
146-
\
147-
_res = HeapTupleSatisfiesVisibility(_tuple, (seeself)); \
148-
if (_tuple->t_infomask != _infomask) \
149-
SetBufferCommitInfoNeedsSave(buffer); \
150-
if (_res) \
151-
(result) = _tuple; \
152-
} \
134+
uint16 _infomask = (tuple)->t_data->t_infomask; \
135+
\
136+
_res = HeapTupleSatisfiesVisibility((tuple), (seeself)); \
137+
if ((tuple)->t_data->t_infomask != _infomask) \
138+
SetBufferCommitInfoNeedsSave(buffer); \
139+
if (!_res) \
140+
(tuple)->t_data = NULL; \
153141
} \
154142
} \
143+
else \
144+
{ \
145+
(tuple)->t_data = NULL; \
146+
} \
155147
} while (0)
156148

157149
extern bool TupleUpdatedByCurXactAndCmd(HeapTuple t);

src/include/executor/executor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: executor.h,v 1.27 1998/10/14 05:10:05 momjian Exp $
9+
* $Id: executor.h,v 1.28 1998/11/27 19:33:32 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -85,7 +85,7 @@ extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
8585
extern TupleDesc ExecutorStart(QueryDesc *queryDesc, EState *estate);
8686
extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count);
8787
extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate);
88-
extern HeapTuple ExecConstraints(char *caller, Relation rel, HeapTuple tuple);
88+
extern void ExecConstraints(char *caller, Relation rel, HeapTuple tuple);
8989
#ifdef QUERY_LIMIT
9090
extern int ExecutorLimit(int limit);
9191
extern int ExecutorGetLimit(void);

src/include/executor/tuptable.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: tuptable.h,v 1.8 1998/09/01 04:36:13 momjian Exp $
9+
* $Id: tuptable.h,v 1.9 1998/11/27 19:33:33 vadim Exp $
1010
*
1111
* NOTES
1212
* The tuple table interface is getting pretty ugly.
@@ -46,13 +46,13 @@
4646
*/
4747
typedef struct TupleTableSlot
4848
{
49-
NodeTag type;
50-
HeapTuple val;
51-
bool ttc_shouldFree;
52-
bool ttc_descIsNew;
53-
TupleDesc ttc_tupleDescriptor;
54-
Buffer ttc_buffer;
55-
int ttc_whichplan;
49+
NodeTag type;
50+
HeapTuple val;
51+
bool ttc_shouldFree;
52+
bool ttc_descIsNew;
53+
TupleDesc ttc_tupleDescriptor;
54+
Buffer ttc_buffer;
55+
int ttc_whichplan;
5656
} TupleTableSlot;
5757

5858
/* ----------------

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