From 2435c7d501b0a3129f6fc597a9c85863541cd596 Mon Sep 17 00:00:00 2001 From: "Vadim B. Mikheev" Date: Fri, 27 Nov 1998 19:33:35 +0000 Subject: [PATCH] New HeapTuple structure/interface. --- src/include/access/heapam.h | 27 +++++++++--------- src/include/access/htup.h | 41 +++++++++++++++++++-------- src/include/access/relscan.h | 50 ++++++++++++++++----------------- src/include/access/valid.h | 50 ++++++++++++++------------------- src/include/executor/executor.h | 4 +-- src/include/executor/tuptable.h | 16 +++++------ src/include/nodes/execnodes.h | 21 +++++++------- src/include/utils/tqual.h | 12 ++++---- 8 files changed, 117 insertions(+), 104 deletions(-) diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 35aad2fb14..0c756e0beb 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -6,7 +6,7 @@ * * 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) #define fastgetattr(tup, attnum, tupleDesc, isnull) \ @@ -101,7 +105,7 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics; (attnum) == 1) ? \ ( \ (Datum)fetchatt(&((tupleDesc)->attrs[(attnum)-1]), \ - (char *) (tup) + (tup)->t_hoff + \ + (char *) (tup)->t_data + (tup)->t_data->t_hoff + \ ( \ ((attnum) != 1) ? \ (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), \ (Datum)NULL \ @@ -129,9 +133,6 @@ typedef HeapAccessStatisticsData *HeapAccessStatistics; #else /* !defined(DISABLE_COMPLEX_MACRO) */ -extern Datum nocachegetattr(HeapTuple tup, int attnum, - TupleDesc att, bool *isnull); - static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) @@ -146,7 +147,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, (attnum) == 1) ? ( (Datum) fetchatt(&((tupleDesc)->attrs[(attnum) - 1]), - (char *) (tup) + (tup)->t_hoff + + (char *) (tup)->t_data + (tup)->t_data->t_hoff + ( ((attnum) != 1) ? (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), (Datum) NULL @@ -205,7 +206,7 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, AssertMacro((tup) != NULL && \ (attnum) > FirstLowInvalidHeapAttributeNumber && \ (attnum) != 0), \ - ((attnum) > (int) (tup)->t_natts) ? \ + ((attnum) > (int) (tup)->t_data->t_natts) ? \ ( \ ((isnull) ? (*(isnull) = true) : (dummyret)NULL), \ (Datum)NULL \ @@ -221,13 +222,12 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, ((isnull) ? (*(isnull) = false) : (dummyret)NULL), \ ((attnum) == SelfItemPointerAttributeNumber) ? \ ( \ - (Datum)((char *)(tup) + \ - heap_sysoffset[-SelfItemPointerAttributeNumber-1]) \ + (Datum)((char *)&((tup)->t_self)) \ ) \ : \ ( \ (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_endscan(HeapScanDesc scan); 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 int heap_delete(Relation relation, ItemPointer tid); 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, TupleDesc att, bool *isnull); extern HeapTuple heap_copytuple(HeapTuple tuple); +extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest); extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor, Datum *value, char *nulls); extern HeapTuple heap_modifytuple(HeapTuple tuple, diff --git a/src/include/access/htup.h b/src/include/access/htup.h index 703b032cdd..56197048ba 100644 --- a/src/include/access/htup.h +++ b/src/include/access/htup.h @@ -6,7 +6,7 @@ * * 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 * 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 */ 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_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 */ @@ -50,10 +48,9 @@ typedef struct HeapTupleData /* bit map of domains */ /* MORE DATA FOLLOWS AT END OF STRUCT */ -} HeapTupleData; - -typedef HeapTupleData *HeapTuple; +} HeapTupleHeaderData; +typedef HeapTupleHeaderData *HeapTupleHeader; #define SelfItemPointerAttributeNumber (-1) #define ObjectIdAttributeNumber (-2) @@ -66,11 +63,33 @@ typedef HeapTupleData *HeapTuple; /* If you make any changes above, the order off offsets in this must change */ 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 * ---------------- */ -#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 HeapTupleNoNulls(tuple) \ - (!(((HeapTuple) (tuple))->t_infomask & HEAP_HASNULL)) + (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL)) #define HeapTupleAllFixed(tuple) \ - (!(((HeapTuple) (tuple))->t_infomask & HEAP_HASVARLENA)) + (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA)) #endif /* HTUP_H */ diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h index c16b022bf2..a6553a5861 100644 --- a/src/include/access/relscan.h +++ b/src/include/access/relscan.h @@ -6,7 +6,7 @@ * * 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 $ * *------------------------------------------------------------------------- */ @@ -22,40 +22,40 @@ typedef ItemPointerData MarkData; typedef struct HeapScanDescData { - Relation rs_rd; /* pointer to relation descriptor */ - HeapTuple rs_ptup; /* previous tuple in scan */ - HeapTuple rs_ctup; /* current tuple in scan */ - HeapTuple rs_ntup; /* next tuple in scan */ - Buffer rs_pbuf; /* previous buffer in scan */ - Buffer rs_cbuf; /* current buffer in scan */ - Buffer rs_nbuf; /* next buffer in scan */ - ItemPointerData rs_mptid; /* marked previous tid */ - ItemPointerData rs_mctid; /* marked current tid */ - ItemPointerData rs_mntid; /* marked next tid */ - ItemPointerData rs_mcd; /* marked current delta XXX ??? */ - Snapshot rs_snapshot; /* snapshot to see */ - bool rs_atend; /* restart scan at end? */ - uint16 rs_cdelta; /* current delta in chain */ - uint16 rs_nkeys; /* number of attributes in keys */ - ScanKey rs_key; /* key descriptors */ + Relation rs_rd; /* pointer to relation descriptor */ + HeapTupleData rs_ptup; /* previous tuple in scan */ + HeapTupleData rs_ctup; /* current tuple in scan */ + HeapTupleData rs_ntup; /* next tuple in scan */ + Buffer rs_pbuf; /* previous buffer in scan */ + Buffer rs_cbuf; /* current buffer in scan */ + Buffer rs_nbuf; /* next buffer in scan */ + ItemPointerData rs_mptid; /* marked previous tid */ + ItemPointerData rs_mctid; /* marked current tid */ + ItemPointerData rs_mntid; /* marked next tid */ + ItemPointerData rs_mcd; /* marked current delta XXX ??? */ + Snapshot rs_snapshot; /* snapshot to see */ + bool rs_atend; /* restart scan at end? */ + uint16 rs_cdelta; /* current delta in chain */ + uint16 rs_nkeys; /* number of attributes in keys */ + ScanKey rs_key; /* key descriptors */ } HeapScanDescData; typedef HeapScanDescData *HeapScanDesc; typedef struct IndexScanDescData { - Relation relation; /* relation descriptor */ - void *opaque; /* am-specific slot */ + Relation relation; /* relation descriptor */ + void *opaque; /* am-specific slot */ ItemPointerData previousItemData; /* previous index pointer */ ItemPointerData currentItemData; /* current index pointer */ ItemPointerData nextItemData; /* next index pointer */ MarkData previousMarkData; /* marked previous pointer */ - MarkData currentMarkData;/* marked current pointer */ - MarkData nextMarkData; /* marked next pointer */ - uint8 flags; /* scan position flags */ - bool scanFromEnd; /* restart scan at end? */ - uint16 numberOfKeys; /* number of key attributes */ - ScanKey keyData; /* key descriptor */ + MarkData currentMarkData; /* marked current pointer */ + MarkData nextMarkData; /* marked next pointer */ + uint8 flags; /* scan position flags */ + bool scanFromEnd; /* restart scan at end? */ + uint16 numberOfKeys; /* number of key attributes */ + ScanKey keyData; /* key descriptor */ } IndexScanDescData; typedef IndexScanDescData *IndexScanDesc; diff --git a/src/include/access/valid.h b/src/include/access/valid.h index aadaf827c4..caa22261f1 100644 --- a/src/include/access/valid.h +++ b/src/include/access/valid.h @@ -6,7 +6,7 @@ * * 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,49 +109,41 @@ do \ * with joey's expensive function work. * ---------------- */ -#define HeapTupleSatisfies(itemId, \ +#define HeapTupleSatisfies(tuple, \ relation, \ buffer, \ disk_page, \ seeself, \ nKeys, \ - key, \ - result) \ + key) \ do \ { \ /* We use underscores to protect the variable passed in as parameters */ \ - HeapTuple _tuple; \ bool _res; \ \ - if (!ItemIdIsUsed(itemId)) \ - (result) = (HeapTuple) NULL; \ + if ((key) != NULL) \ + HeapKeyTest(tuple, RelationGetDescr(relation), \ + (nKeys), (key), _res); \ else \ - { \ - _tuple = (HeapTuple) PageGetItem((Page) (disk_page), (itemId)); \ - \ - if ((key) != NULL) \ - HeapKeyTest(_tuple, RelationGetDescr(relation), \ - (nKeys), (key), _res); \ - 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; \ - else \ - { \ - uint16 _infomask = _tuple->t_infomask; \ - \ - _res = HeapTupleSatisfiesVisibility(_tuple, (seeself)); \ - if (_tuple->t_infomask != _infomask) \ - SetBufferCommitInfoNeedsSave(buffer); \ - if (_res) \ - (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 \ + { \ + (tuple)->t_data = NULL; \ + } \ } while (0) extern bool TupleUpdatedByCurXactAndCmd(HeapTuple t); diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index d87e57ebb2..33774d21f4 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -6,7 +6,7 @@ * * 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 TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count); 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 extern int ExecutorLimit(int limit); extern int ExecutorGetLimit(void); diff --git a/src/include/executor/tuptable.h b/src/include/executor/tuptable.h index e0ab50b5f3..82a5651a29 100644 --- a/src/include/executor/tuptable.h +++ b/src/include/executor/tuptable.h @@ -6,7 +6,7 @@ * * 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 * The tuple table interface is getting pretty ugly. @@ -46,13 +46,13 @@ */ typedef struct TupleTableSlot { - NodeTag type; - HeapTuple val; - bool ttc_shouldFree; - bool ttc_descIsNew; - TupleDesc ttc_tupleDescriptor; - Buffer ttc_buffer; - int ttc_whichplan; + NodeTag type; + HeapTuple val; + bool ttc_shouldFree; + bool ttc_descIsNew; + TupleDesc ttc_tupleDescriptor; + Buffer ttc_buffer; + int ttc_whichplan; } TupleTableSlot; /* ---------------- diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index a062456c68..288051f1e9 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -6,7 +6,7 @@ * * 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 $ * *------------------------------------------------------------------------- */ @@ -396,15 +396,16 @@ typedef struct CommonScanState */ typedef struct IndexScanState { - CommonState cstate; /* its first field is NodeTag */ - int iss_NumIndices; - int iss_IndexPtr; - int iss_MarkIndexPtr; - ScanKey *iss_ScanKeys; - int *iss_NumScanKeys; - Pointer iss_RuntimeKeyInfo; - RelationPtr iss_RelationDescs; - IndexScanDescPtr iss_ScanDescs; + CommonState cstate; /* its first field is NodeTag */ + int iss_NumIndices; + int iss_IndexPtr; + int iss_MarkIndexPtr; + ScanKey *iss_ScanKeys; + int *iss_NumScanKeys; + Pointer iss_RuntimeKeyInfo; + RelationPtr iss_RelationDescs; + IndexScanDescPtr iss_ScanDescs; + HeapTupleData iss_htup; } IndexScanState; diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index 39bc9e8655..3d2f8531f4 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -7,7 +7,7 @@ * * 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) \ ( \ - TransactionIdEquals((tuple)->t_xmax, AmiTransactionId) ? \ + TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \ false \ : \ ( \ (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 HeapTupleSatisfiesNow(HeapTuple tuple); +extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple); +extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple); extern void setheapoverride(bool on); -- 2.40.0