]> granicus.if.org Git - postgresql/commitdiff
New HeapTuple structure/interface.
authorVadim B. Mikheev <vadim4o@yahoo.com>
Fri, 27 Nov 1998 19:33:35 +0000 (19:33 +0000)
committerVadim B. Mikheev <vadim4o@yahoo.com>
Fri, 27 Nov 1998 19:33:35 +0000 (19:33 +0000)
src/include/access/heapam.h
src/include/access/htup.h
src/include/access/relscan.h
src/include/access/valid.h
src/include/executor/executor.h
src/include/executor/tuptable.h
src/include/nodes/execnodes.h
src/include/utils/tqual.h

index 35aad2fb14a615572a9b756508d894f1a79881ed..0c756e0beba6ad0dfd14ae0d2983161e52be6bab 100644 (file)
@@ -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,
index 703b032cdd1696fb4939141d7f482391457651a0..56197048ba0cd5c4d25637573c49336cf86714e7 100644 (file)
@@ -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 $
  *
  *-------------------------------------------------------------------------
  */
  * 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 */
index c16b022bf284918a43098f8ea9898bc72dc62232..a6553a586114bc5c5c72255228f24901b55c6a7e 100644 (file)
@@ -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;
index aadaf827c4bda7902e4ad8a6f1a8c4701bd24b45..caa22261f16212e3b44ec37430ca3d4dd615035f 100644 (file)
@@ -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);
index d87e57ebb253362eed115289465c2369c58f23a7..33774d21f41db63a6d7e7a8f4c36e4c5d8f184f9 100644 (file)
@@ -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);
index e0ab50b5f385d2f961efcdc8096f354cc4398eb5..82a5651a2992783d8d16b77aadc2f929e1c58cea 100644 (file)
@@ -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.
  */
 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;
 
 /* ----------------
index a062456c68d296076711c10a8382a3f009c43c2f..288051f1e9a21c489b10b9544efcf078d699e4ff 100644 (file)
@@ -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;
 
 
index 39bc9e865514f8d96173c6c998e525527854f749..3d2f8531f47070b29c52223f0d59dbb244225cdf 100644 (file)
@@ -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);