New HeapTuple structure/interface.

This commit is contained in:
Vadim B. Mikheev 1998-11-27 19:33:35 +00:00
parent 4d7188039a
commit 2435c7d501
8 changed files with 119 additions and 106 deletions

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: heapam.h,v 1.38 1998/10/08 18:30:22 momjian Exp $ * $Id: heapam.h,v 1.39 1998/11/27 19:33:31 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -89,6 +89,10 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
* *
* ---------------- * ----------------
*/ */
extern Datum nocachegetattr(HeapTuple tup, int attnum,
TupleDesc att, bool *isnull);
#if !defined(DISABLE_COMPLEX_MACRO) #if !defined(DISABLE_COMPLEX_MACRO)
#define fastgetattr(tup, attnum, tupleDesc, isnull) \ #define fastgetattr(tup, attnum, tupleDesc, isnull) \
@ -101,7 +105,7 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
(attnum) == 1) ? \ (attnum) == 1) ? \
( \ ( \
(Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \ (Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \
(char *) (tup) + (tup)->t_hoff + \ (char *) (tup)->t_data + (tup)->t_data->t_hoff + \
( \ ( \
((attnum) != 1) ? \ ((attnum) != 1) ? \
(tupleDesc)->attrs[(attnum)-1]->attcacheoff \ (tupleDesc)->attrs[(attnum)-1]->attcacheoff \
@ -115,7 +119,7 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
) \ ) \
: \ : \
( \ ( \
att_isnull((attnum)-1, (tup)->t_bits) ? \ att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
( \ ( \
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \ ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
(Datum)NULL \ (Datum)NULL \
@ -129,9 +133,6 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics;
#else /* !defined(DISABLE_COMPLEX_MACRO) */ #else /* !defined(DISABLE_COMPLEX_MACRO) */
extern Datum nocachegetattr(HeapTuple tup, int attnum,
TupleDesc att, bool *isnull);
static Datum static Datum
fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
bool *isnull) bool *isnull)
@ -146,7 +147,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
(attnum) == 1) ? (attnum) == 1) ?
( (
(Datum) fetchatt(&((tupleDesc)->attrs[(attnum) - 1]), (Datum) fetchatt(&((tupleDesc)->attrs[(attnum) - 1]),
(char *) (tup) + (tup)->t_hoff + (char *) (tup)->t_data + (tup)->t_data->t_hoff +
( (
((attnum) != 1) ? ((attnum) != 1) ?
(tupleDesc)->attrs[(attnum) - 1]->attcacheoff (tupleDesc)->attrs[(attnum) - 1]->attcacheoff
@ -160,7 +161,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
) )
: :
( (
att_isnull((attnum) - 1, (tup)->t_bits) ? att_isnull((attnum) - 1, (tup)->t_data->t_bits) ?
( (
((isnull) ? (*(isnull) = true) : (dummyret) NULL), ((isnull) ? (*(isnull) = true) : (dummyret) NULL),
(Datum) NULL (Datum) NULL
@ -205,7 +206,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
AssertMacro((tup) != NULL && \ AssertMacro((tup) != NULL && \
(attnum) > FirstLowInvalidHeapAttributeNumber && \ (attnum) > FirstLowInvalidHeapAttributeNumber && \
(attnum) != 0), \ (attnum) != 0), \
((attnum) > (int) (tup)->t_natts) ? \ ((attnum) > (int) (tup)->t_data->t_natts) ? \
( \ ( \
((isnull) ? (*(isnull) = true) : (dummyret)NULL), \ ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \
(Datum)NULL \ (Datum)NULL \
@ -221,13 +222,12 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
((isnull) ? (*(isnull) = false) : (dummyret)NULL), \ ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \
((attnum) == SelfItemPointerAttributeNumber) ? \ ((attnum) == SelfItemPointerAttributeNumber) ? \
( \ ( \
(Datum)((char *)(tup) + \ (Datum)((char *)&((tup)->t_self)) \
heap_sysoffset[-SelfItemPointerAttributeNumber-1]) \
) \ ) \
: \ : \
( \ ( \
(Datum)*(unsigned int *) \ (Datum)*(unsigned int *) \
((char *)(tup) + heap_sysoffset[-(attnum)-1]) \ ((char *)(tup)->t_data + heap_sysoffset[-(attnum)-1]) \
) \ ) \
) \ ) \
) \ ) \
@ -251,7 +251,7 @@ extern HeapScanDesc heap_beginscan(Relation relation, int atend,
extern void heap_rescan(HeapScanDesc scan, bool scanFromEnd, ScanKey key); extern void heap_rescan(HeapScanDesc scan, bool scanFromEnd, ScanKey key);
extern void heap_endscan(HeapScanDesc scan); extern void heap_endscan(HeapScanDesc scan);
extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw); extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw);
extern HeapTuple heap_fetch(Relation relation, Snapshot snapshot, ItemPointer tid, Buffer *userbuf); extern void heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tup, Buffer *userbuf);
extern Oid heap_insert(Relation relation, HeapTuple tup); extern Oid heap_insert(Relation relation, HeapTuple tup);
extern int heap_delete(Relation relation, ItemPointer tid); extern int heap_delete(Relation relation, ItemPointer tid);
extern int heap_replace(Relation relation, ItemPointer otid, extern int heap_replace(Relation relation, ItemPointer otid,
@ -270,6 +270,7 @@ extern bool heap_sysattrbyval(AttrNumber attno);
extern Datum nocachegetattr(HeapTuple tup, int attnum, extern Datum nocachegetattr(HeapTuple tup, int attnum,
TupleDesc att, bool *isnull); TupleDesc att, bool *isnull);
extern HeapTuple heap_copytuple(HeapTuple tuple); extern HeapTuple heap_copytuple(HeapTuple tuple);
extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor, extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
Datum *value, char *nulls); Datum *value, char *nulls);
extern HeapTuple heap_modifytuple(HeapTuple tuple, extern HeapTuple heap_modifytuple(HeapTuple tuple,

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: htup.h,v 1.10 1998/09/01 04:34:14 momjian Exp $ * $Id: htup.h,v 1.11 1998/11/27 19:33:31 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -26,10 +26,8 @@
* to avoid wasting space, the attributes should be layed out in such a * to avoid wasting space, the attributes should be layed out in such a
* way to reduce structure padding. * way to reduce structure padding.
*/ */
typedef struct HeapTupleData typedef struct HeapTupleHeaderData
{ {
unsigned int t_len; /* length of entire tuple */
Oid t_oid; /* OID of this tuple -- 4 bytes */ Oid t_oid; /* OID of this tuple -- 4 bytes */
CommandId t_cmin; /* insert CID stamp -- 4 bytes each */ CommandId t_cmin; /* insert CID stamp -- 4 bytes each */
@ -38,7 +36,7 @@ typedef struct HeapTupleData
TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */ TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */
TransactionId t_xmax; /* delete XID stamp */ TransactionId t_xmax; /* delete XID stamp */
ItemPointerData t_ctid; /* current TID of this tuple */ ItemPointerData t_ctid; /* current TID of this or newer tuple */
int16 t_natts; /* number of attributes */ int16 t_natts; /* number of attributes */
@ -50,10 +48,9 @@ typedef struct HeapTupleData
/* bit map of domains */ /* bit map of domains */
/* MORE DATA FOLLOWS AT END OF STRUCT */ /* MORE DATA FOLLOWS AT END OF STRUCT */
} HeapTupleData; } HeapTupleHeaderData;
typedef HeapTupleData *HeapTuple;
typedef HeapTupleHeaderData *HeapTupleHeader;
#define SelfItemPointerAttributeNumber (-1) #define SelfItemPointerAttributeNumber (-1)
#define ObjectIdAttributeNumber (-2) #define ObjectIdAttributeNumber (-2)
@ -66,11 +63,33 @@ typedef HeapTupleData *HeapTuple;
/* If you make any changes above, the order off offsets in this must change */ /* If you make any changes above, the order off offsets in this must change */
extern long heap_sysoffset[]; extern long heap_sysoffset[];
/*
* This new HeapTuple for version >= 6.5 and this is why it was changed:
*
* 1. t_len moved off on-disk tuple data - ItemIdData is used to get len;
* 2. t_ctid above is not self tuple TID now - it may point to
* updated version of tuple (required by MVCC);
* 3. someday someone let tuple to cross block boundaries -
* he have to add something below...
*/
typedef struct HeapTupleData
{
uint32 t_len; /* length of *t_data */
ItemPointerData t_self; /* SelfItemPointer */
HeapTupleHeader t_data; /* */
} HeapTupleData;
typedef HeapTupleData *HeapTuple;
#define HEAPTUPLESIZE DOUBLEALIGN(sizeof(HeapTupleData))
/* ---------------- /* ----------------
* support macros * support macros
* ---------------- * ----------------
*/ */
#define GETSTRUCT(TUP) (((char *)(TUP)) + ((HeapTuple)(TUP))->t_hoff) #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
((HeapTuple)(TUP))->t_data->t_hoff)
/* /*
@ -101,9 +120,9 @@ extern long heap_sysoffset[];
#define HEAP_XACT_MASK 0x0F00 /* */ #define HEAP_XACT_MASK 0x0F00 /* */
#define HeapTupleNoNulls(tuple) \ #define HeapTupleNoNulls(tuple) \
(!(((HeapTuple) (tuple))->t_infomask & HEAP_HASNULL)) (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
#define HeapTupleAllFixed(tuple) \ #define HeapTupleAllFixed(tuple) \
(!(((HeapTuple) (tuple))->t_infomask & HEAP_HASVARLENA)) (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
#endif /* HTUP_H */ #endif /* HTUP_H */

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: relscan.h,v 1.12 1998/09/01 04:34:23 momjian Exp $ * $Id: relscan.h,v 1.13 1998/11/27 19:33:31 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -23,9 +23,9 @@ typedef ItemPointerData MarkData;
typedef struct HeapScanDescData typedef struct HeapScanDescData
{ {
Relation rs_rd; /* pointer to relation descriptor */ Relation rs_rd; /* pointer to relation descriptor */
HeapTuple rs_ptup; /* previous tuple in scan */ HeapTupleData rs_ptup; /* previous tuple in scan */
HeapTuple rs_ctup; /* current tuple in scan */ HeapTupleData rs_ctup; /* current tuple in scan */
HeapTuple rs_ntup; /* next tuple in scan */ HeapTupleData rs_ntup; /* next tuple in scan */
Buffer rs_pbuf; /* previous buffer in scan */ Buffer rs_pbuf; /* previous buffer in scan */
Buffer rs_cbuf; /* current buffer in scan */ Buffer rs_cbuf; /* current buffer in scan */
Buffer rs_nbuf; /* next buffer in scan */ Buffer rs_nbuf; /* next buffer in scan */

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: valid.h,v 1.15 1998/09/01 04:34:33 momjian Exp $ * $Id: valid.h,v 1.16 1998/11/27 19:33:32 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -109,48 +109,40 @@ do \
* with joey's expensive function work. * with joey's expensive function work.
* ---------------- * ----------------
*/ */
#define HeapTupleSatisfies(itemId, \ #define HeapTupleSatisfies(tuple, \
relation, \ relation, \
buffer, \ buffer, \
disk_page, \ disk_page, \
seeself, \ seeself, \
nKeys, \ nKeys, \
key, \ key) \
result) \
do \ do \
{ \ { \
/* We use underscores to protect the variable passed in as parameters */ \ /* We use underscores to protect the variable passed in as parameters */ \
HeapTuple _tuple; \
bool _res; \ bool _res; \
\
if (!ItemIdIsUsed(itemId)) \
(result) = (HeapTuple) NULL; \
else \
{ \
_tuple = (HeapTuple) PageGetItem((Page) (disk_page), (itemId)); \
\ \
if ((key) != NULL) \ if ((key) != NULL) \
HeapKeyTest(_tuple, RelationGetDescr(relation), \ HeapKeyTest(tuple, RelationGetDescr(relation), \
(nKeys), (key), _res); \ (nKeys), (key), _res); \
else \ else \
_res = TRUE; \ _res = TRUE; \
\ \
(result) = (HeapTuple) NULL; \
if (_res) \ if (_res) \
{ \ { \
if ((relation)->rd_rel->relkind == RELKIND_UNCATALOGED) \ if ((relation)->rd_rel->relkind != RELKIND_UNCATALOGED) \
(result) = _tuple; \ { \
uint16 _infomask = (tuple)->t_data->t_infomask; \
\
_res = HeapTupleSatisfiesVisibility((tuple), (seeself)); \
if ((tuple)->t_data->t_infomask != _infomask) \
SetBufferCommitInfoNeedsSave(buffer); \
if (!_res) \
(tuple)->t_data = NULL; \
} \
} \
else \ else \
{ \ { \
uint16 _infomask = _tuple->t_infomask; \ (tuple)->t_data = NULL; \
\
_res = HeapTupleSatisfiesVisibility(_tuple, (seeself)); \
if (_tuple->t_infomask != _infomask) \
SetBufferCommitInfoNeedsSave(buffer); \
if (_res) \
(result) = _tuple; \
} \
} \
} \ } \
} while (0) } while (0)

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: executor.h,v 1.27 1998/10/14 05:10:05 momjian Exp $ * $Id: executor.h,v 1.28 1998/11/27 19:33:32 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -85,7 +85,7 @@ extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
extern TupleDesc ExecutorStart(QueryDesc *queryDesc, EState *estate); extern TupleDesc ExecutorStart(QueryDesc *queryDesc, EState *estate);
extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count); extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count);
extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate); extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate);
extern HeapTuple ExecConstraints(char *caller, Relation rel, HeapTuple tuple); extern void ExecConstraints(char *caller, Relation rel, HeapTuple tuple);
#ifdef QUERY_LIMIT #ifdef QUERY_LIMIT
extern int ExecutorLimit(int limit); extern int ExecutorLimit(int limit);
extern int ExecutorGetLimit(void); extern int ExecutorGetLimit(void);

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: tuptable.h,v 1.8 1998/09/01 04:36:13 momjian Exp $ * $Id: tuptable.h,v 1.9 1998/11/27 19:33:33 vadim Exp $
* *
* NOTES * NOTES
* The tuple table interface is getting pretty ugly. * The tuple table interface is getting pretty ugly.

View file

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: execnodes.h,v 1.18 1998/09/01 04:36:35 momjian Exp $ * $Id: execnodes.h,v 1.19 1998/11/27 19:33:33 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -405,6 +405,7 @@ typedef struct IndexScanState
Pointer iss_RuntimeKeyInfo; Pointer iss_RuntimeKeyInfo;
RelationPtr iss_RelationDescs; RelationPtr iss_RelationDescs;
IndexScanDescPtr iss_ScanDescs; IndexScanDescPtr iss_ScanDescs;
HeapTupleData iss_htup;
} IndexScanState; } IndexScanState;

View file

@ -7,7 +7,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: tqual.h,v 1.14 1998/09/01 04:39:35 momjian Exp $ * $Id: tqual.h,v 1.15 1998/11/27 19:33:35 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -42,14 +42,14 @@ extern CommandId HeapSpecialCommandId;
*/ */
#define HeapTupleSatisfiesVisibility(tuple, snapshot) \ #define HeapTupleSatisfiesVisibility(tuple, snapshot) \
( \ ( \
TransactionIdEquals((tuple)->t_xmax, AmiTransactionId) ? \ TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \
false \ false \
: \ : \
( \ ( \
(IsSnapshotSelf(snapshot) || heapisoverride()) ? \ (IsSnapshotSelf(snapshot) || heapisoverride()) ? \
HeapTupleSatisfiesItself(tuple) \ HeapTupleSatisfiesItself((tuple)->t_data) \
: \ : \
HeapTupleSatisfiesNow(tuple) \ HeapTupleSatisfiesNow((tuple)->t_data) \
) \ ) \
) )
@ -71,8 +71,8 @@ extern CommandId HeapSpecialCommandId;
) \ ) \
) )
extern bool HeapTupleSatisfiesItself(HeapTuple tuple); extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesNow(HeapTuple tuple); extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple);
extern void setheapoverride(bool on); extern void setheapoverride(bool on);