]> granicus.if.org Git - postgresql/blobdiff - src/include/access/htup.h
Remove cvs keywords from all files.
[postgresql] / src / include / access / htup.h
index 84b6080c720c82832470d8fd543fe3fed228efa9..adf1321052cf1013ec647906facfe57a97688c06 100644 (file)
@@ -4,16 +4,18 @@
  *       POSTGRES heap tuple definitions.
  *
  *
- * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.96 2007/11/15 21:14:42 momjian Exp $
+ * src/include/access/htup.h
  *
  *-------------------------------------------------------------------------
  */
 #ifndef HTUP_H
 #define HTUP_H
 
+#include "access/tupdesc.h"
+#include "access/tupmacs.h"
 #include "storage/itemptr.h"
 #include "storage/relfilenode.h"
 
  * transaction respectively.  If a tuple is inserted and deleted in the same
  * transaction, we store a "combo" command id that can be mapped to the real
  * cmin and cmax, but only by use of local state within the originating
- * backend.  See combocid.c for more details.  Meanwhile, Xvac is only set
- * by VACUUM FULL, which does not have any command sub-structure and so does
- * not need either Cmin or Cmax.  (This requires that VACUUM FULL never try
- * to move a tuple whose Cmin or Cmax is still interesting, ie, an insert-
- * in-progress or delete-in-progress tuple.)
+ * backend.  See combocid.c for more details.  Meanwhile, Xvac is only set by
+ * old-style VACUUM FULL, which does not have any command sub-structure and so
+ * does not need either Cmin or Cmax.  (This requires that old-style VACUUM
+ * FULL never try to move a tuple whose Cmin or Cmax is still interesting,
+ * ie, an insert-in-progress or delete-in-progress tuple.)
  *
  * A word about t_ctid: whenever a new tuple is stored on disk, its t_ctid
  * is initialized with its own TID (location). If the tuple is ever updated,
@@ -109,7 +111,7 @@ typedef struct HeapTupleFields
        union
        {
                CommandId       t_cid;          /* inserting or deleting command ID, or both */
-               TransactionId t_xvac;   /* VACUUM FULL xact ID */
+               TransactionId t_xvac;   /* old-style VACUUM FULL xact ID */
        }                       t_field3;
 } HeapTupleFields;
 
@@ -173,10 +175,12 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
 #define HEAP_XMAX_INVALID              0x0800  /* t_xmax invalid/aborted */
 #define HEAP_XMAX_IS_MULTI             0x1000  /* t_xmax is a MultiXactId */
 #define HEAP_UPDATED                   0x2000  /* this is UPDATEd version of row */
-#define HEAP_MOVED_OFF                 0x4000  /* moved to another place by VACUUM
-                                                                                * FULL */
-#define HEAP_MOVED_IN                  0x8000  /* moved from another place by VACUUM
-                                                                                * FULL */
+#define HEAP_MOVED_OFF                 0x4000  /* moved to another place by pre-9.0
+                                                                                * VACUUM FULL; kept for binary
+                                                                                * upgrade support */
+#define HEAP_MOVED_IN                  0x8000  /* moved from another place by pre-9.0
+                                                                                * VACUUM FULL; kept for binary
+                                                                                * upgrade support */
 #define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN)
 
 #define HEAP_XACT_MASK                 0xFFE0  /* visibility-related bits */
@@ -360,12 +364,12 @@ do { \
  * other stuff that has to be on a disk page.  Since heap pages use no
  * "special space", there's no deduction for that.
  *
- * NOTE: we do not need to count an ItemId for the tuple because
- * sizeof(PageHeaderData) includes the first ItemId on the page.  But beware
- * of assuming that, say, you can fit 2 tuples of size MaxHeapTupleSize/2
- * on the same page.
+ * NOTE: we allow for the ItemId that must point to the tuple, ensuring that
+ * an otherwise-empty page can indeed hold a tuple of this size.  Because
+ * ItemIds and tuples have different alignment requirements, don't assume that
+ * you can, say, fit 2 tuples of size MaxHeapTupleSize/2 on the same page.
  */
-#define MaxHeapTupleSize  (BLCKSZ - MAXALIGN(sizeof(PageHeaderData)))
+#define MaxHeapTupleSize  (BLCKSZ - MAXALIGN(SizeOfPageHeaderData + sizeof(ItemIdData)))
 
 /*
  * MaxHeapTuplesPerPage is an upper bound on the number of tuples that can
@@ -379,7 +383,7 @@ do { \
  * require increases in the size of work arrays.
  */
 #define MaxHeapTuplesPerPage   \
-       ((int) ((BLCKSZ - offsetof(PageHeaderData, pd_linp)) / \
+       ((int) ((BLCKSZ - SizeOfPageHeaderData) / \
                        (MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData))))
 
 /*
@@ -392,19 +396,6 @@ do { \
 #define MaxAttrSize            (10 * 1024 * 1024)
 
 
-/*
- * Attribute numbers for the system-defined attributes
- */
-#define SelfItemPointerAttributeNumber                 (-1)
-#define ObjectIdAttributeNumber                                        (-2)
-#define MinTransactionIdAttributeNumber                        (-3)
-#define MinCommandIdAttributeNumber                            (-4)
-#define MaxTransactionIdAttributeNumber                        (-5)
-#define MaxCommandIdAttributeNumber                            (-6)
-#define TableOidAttributeNumber                                        (-7)
-#define FirstLowInvalidHeapAttributeNumber             (-8)
-
-
 /*
  * MinimalTuple is an alternative representation that is used for transient
  * tuples inside the executor, in places where transaction status information
@@ -431,11 +422,17 @@ do { \
  *
  * Note that t_hoff is computed the same as in a full tuple, hence it includes
  * the MINIMAL_TUPLE_OFFSET distance.  t_len does not include that, however.
+ *
+ * MINIMAL_TUPLE_DATA_OFFSET is the offset to the first useful (non-pad) data
+ * other than the length word. tuplesort.c and tuplestore.c use this to avoid
+ * writing the padding to disk.
  */
 #define MINIMAL_TUPLE_OFFSET \
        ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
 #define MINIMAL_TUPLE_PADDING \
        ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
+#define MINIMAL_TUPLE_DATA_OFFSET \
+       offsetof(MinimalTupleData, t_infomask2)
 
 typedef struct MinimalTupleData
 {
@@ -564,7 +561,7 @@ typedef HeapTupleData *HeapTuple;
 #define XLOG_HEAP_INSERT               0x00
 #define XLOG_HEAP_DELETE               0x10
 #define XLOG_HEAP_UPDATE               0x20
-#define XLOG_HEAP_MOVE                 0x30
+/* 0x030 is free, was XLOG_HEAP_MOVE */
 #define XLOG_HEAP_HOT_UPDATE   0x40
 #define XLOG_HEAP_NEWPAGE              0x50
 #define XLOG_HEAP_LOCK                 0x60
@@ -584,7 +581,8 @@ typedef HeapTupleData *HeapTuple;
  */
 #define XLOG_HEAP2_FREEZE              0x00
 #define XLOG_HEAP2_CLEAN               0x10
-#define XLOG_HEAP2_CLEAN_MOVE  0x20
+/* 0x20 is free, was XLOG_HEAP2_CLEAN_MOVE */
+#define XLOG_HEAP2_CLEANUP_INFO 0x30
 
 /*
  * All what we need to find changed tuple
@@ -606,9 +604,10 @@ typedef struct xl_heaptid
 typedef struct xl_heap_delete
 {
        xl_heaptid      target;                 /* deleted tuple id */
+       bool            all_visible_cleared;    /* PD_ALL_VISIBLE was cleared */
 } xl_heap_delete;
 
-#define SizeOfHeapDelete       (offsetof(xl_heap_delete, target) + SizeOfHeapTid)
+#define SizeOfHeapDelete       (offsetof(xl_heap_delete, all_visible_cleared) + sizeof(bool))
 
 /*
  * We don't store the whole fixed part (HeapTupleHeaderData) of an inserted
@@ -631,21 +630,23 @@ typedef struct xl_heap_header
 typedef struct xl_heap_insert
 {
        xl_heaptid      target;                 /* inserted tuple id */
+       bool            all_visible_cleared;    /* PD_ALL_VISIBLE was cleared */
        /* xl_heap_header & TUPLE DATA FOLLOWS AT END OF STRUCT */
 } xl_heap_insert;
 
-#define SizeOfHeapInsert       (offsetof(xl_heap_insert, target) + SizeOfHeapTid)
+#define SizeOfHeapInsert       (offsetof(xl_heap_insert, all_visible_cleared) + sizeof(bool))
 
-/* This is what we need to know about update|move|hot_update */
+/* This is what we need to know about update|hot_update */
 typedef struct xl_heap_update
 {
        xl_heaptid      target;                 /* deleted tuple id */
        ItemPointerData newtid;         /* new inserted tuple id */
-       /* NEW TUPLE xl_heap_header (PLUS xmax & xmin IF MOVE OP) */
-       /* and TUPLE DATA FOLLOWS AT END OF STRUCT */
+       bool            all_visible_cleared;    /* PD_ALL_VISIBLE was cleared */
+       bool            new_all_visible_cleared;                /* same for the page of newtid */
+       /* NEW TUPLE xl_heap_header AND TUPLE DATA FOLLOWS AT END OF STRUCT */
 } xl_heap_update;
 
-#define SizeOfHeapUpdate       (offsetof(xl_heap_update, newtid) + SizeOfIptrData)
+#define SizeOfHeapUpdate       (offsetof(xl_heap_update, new_all_visible_cleared) + sizeof(bool))
 
 /*
  * This is what we need to know about vacuum page cleanup/redirect
@@ -657,18 +658,12 @@ typedef struct xl_heap_update
  * The total number of OffsetNumbers is therefore 2*nredirected+ndead+nunused.
  * Note that nunused is not explicitly stored, but may be found by reference
  * to the total record length.
- *
- * If the opcode is CLEAN_MOVE instead of CLEAN, then each redirection pair
- * should be interpreted as physically moving the "to" item pointer to the
- * "from" slot, rather than placing a redirection item in the "from" slot.
- * The moved pointers should be replaced by LP_UNUSED items (there will not
- * be explicit entries in the "now-unused" list for this).     Also, the
- * HEAP_ONLY bit in the moved tuples must be turned off.
  */
 typedef struct xl_heap_clean
 {
        RelFileNode node;
        BlockNumber block;
+       TransactionId latestRemovedXid;
        uint16          nredirected;
        uint16          ndead;
        /* OFFSET NUMBERS FOLLOW */
@@ -676,11 +671,25 @@ typedef struct xl_heap_clean
 
 #define SizeOfHeapClean (offsetof(xl_heap_clean, ndead) + sizeof(uint16))
 
+/*
+ * Cleanup_info is required in some cases during a lazy VACUUM.
+ * Used for reporting the results of HeapTupleHeaderAdvanceLatestRemovedXid()
+ * see vacuumlazy.c for full explanation
+ */
+typedef struct xl_heap_cleanup_info
+{
+       RelFileNode node;
+       TransactionId latestRemovedXid;
+} xl_heap_cleanup_info;
+
+#define SizeOfHeapCleanupInfo (sizeof(xl_heap_cleanup_info))
+
 /* This is for replacing a page's contents in toto */
 /* NB: this is used for indexes as well as heaps */
 typedef struct xl_heap_newpage
 {
        RelFileNode node;
+       ForkNumber      forknum;
        BlockNumber blkno;                      /* location of new page */
        /* entire page contents follow at end of record */
 } xl_heap_newpage;
@@ -714,10 +723,13 @@ typedef struct xl_heap_freeze
        BlockNumber block;
        TransactionId cutoff_xid;
        /* TUPLE OFFSET NUMBERS FOLLOW AT THE END */
-}      xl_heap_freeze;
+} xl_heap_freeze;
 
 #define SizeOfHeapFreeze (offsetof(xl_heap_freeze, cutoff_xid) + sizeof(TransactionId))
 
+extern void HeapTupleHeaderAdvanceLatestRemovedXid(HeapTupleHeader tuple,
+                                                                          TransactionId *latestRemovedXid);
+
 /* HeapTupleHeader functions implemented in utils/time/combocid.c */
 extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup);
 extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup);
@@ -725,4 +737,132 @@ extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
                                                  CommandId *cmax,
                                                  bool *iscombo);
 
+/* ----------------
+ *             fastgetattr
+ *
+ *             Fetch a user attribute's value as a Datum (might be either a
+ *             value, or a pointer into the data area of the tuple).
+ *
+ *             This must not be used when a system attribute might be requested.
+ *             Furthermore, the passed attnum MUST be valid.  Use heap_getattr()
+ *             instead, if in doubt.
+ *
+ *             This gets called many times, so we macro the cacheable and NULL
+ *             lookups, and call nocachegetattr() for the rest.
+ * ----------------
+ */
+
+#if !defined(DISABLE_COMPLEX_MACRO)
+
+#define fastgetattr(tup, attnum, tupleDesc, isnull)                                    \
+(                                                                                                                                      \
+       AssertMacro((attnum) > 0),                                                                              \
+       (*(isnull) = false),                                                                                    \
+       HeapTupleNoNulls(tup) ?                                                                                 \
+       (                                                                                                                               \
+               (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ?                      \
+               (                                                                                                                       \
+                       fetchatt((tupleDesc)->attrs[(attnum)-1],                                \
+                               (char *) (tup)->t_data + (tup)->t_data->t_hoff +        \
+                                       (tupleDesc)->attrs[(attnum)-1]->attcacheoff)    \
+               )                                                                                                                       \
+               :                                                                                                                       \
+                       nocachegetattr((tup), (attnum), (tupleDesc))                    \
+       )                                                                                                                               \
+       :                                                                                                                               \
+       (                                                                                                                               \
+               att_isnull((attnum)-1, (tup)->t_data->t_bits) ?                         \
+               (                                                                                                                       \
+                       (*(isnull) = true),                                                                             \
+                       (Datum)NULL                                                                                             \
+               )                                                                                                                       \
+               :                                                                                                                       \
+               (                                                                                                                       \
+                       nocachegetattr((tup), (attnum), (tupleDesc))                    \
+               )                                                                                                                       \
+       )                                                                                                                               \
+)
+#else                                                  /* defined(DISABLE_COMPLEX_MACRO) */
+
+extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
+                       bool *isnull);
+#endif   /* defined(DISABLE_COMPLEX_MACRO) */
+
+
+/* ----------------
+ *             heap_getattr
+ *
+ *             Extract an attribute of a heap tuple and return it as a Datum.
+ *             This works for either system or user attributes.  The given attnum
+ *             is properly range-checked.
+ *
+ *             If the field in question has a NULL value, we return a zero Datum
+ *             and set *isnull == true.  Otherwise, we set *isnull == false.
+ *
+ *             <tup> is the pointer to the heap tuple.  <attnum> is the attribute
+ *             number of the column (field) caller wants.      <tupleDesc> is a
+ *             pointer to the structure describing the row and all its fields.
+ * ----------------
+ */
+#define heap_getattr(tup, attnum, tupleDesc, isnull) \
+( \
+       AssertMacro((tup) != NULL), \
+       ( \
+               ((attnum) > 0) ? \
+               ( \
+                       ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
+                       ( \
+                               (*(isnull) = true), \
+                               (Datum)NULL \
+                       ) \
+                       : \
+                               fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
+               ) \
+               : \
+                       heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
+       ) \
+)
+
+/* prototypes for functions in common/heaptuple.c */
+extern Size heap_compute_data_size(TupleDesc tupleDesc,
+                                          Datum *values, bool *isnull);
+extern void heap_fill_tuple(TupleDesc tupleDesc,
+                               Datum *values, bool *isnull,
+                               char *data, Size data_size,
+                               uint16 *infomask, bits8 *bit);
+extern bool heap_attisnull(HeapTuple tup, int attnum);
+extern Datum nocachegetattr(HeapTuple tup, int attnum,
+                          TupleDesc att);
+extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
+                               bool *isnull);
+extern HeapTuple heap_copytuple(HeapTuple tuple);
+extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
+extern HeapTuple heap_form_tuple(TupleDesc tupleDescriptor,
+                               Datum *values, bool *isnull);
+extern HeapTuple heap_modify_tuple(HeapTuple tuple,
+                                 TupleDesc tupleDesc,
+                                 Datum *replValues,
+                                 bool *replIsnull,
+                                 bool *doReplace);
+extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
+                                 Datum *values, bool *isnull);
+
+/* these three are deprecated versions of the three above: */
+extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
+                          Datum *values, char *nulls);
+extern HeapTuple heap_modifytuple(HeapTuple tuple,
+                                TupleDesc tupleDesc,
+                                Datum *replValues,
+                                char *replNulls,
+                                char *replActions);
+extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc,
+                                Datum *values, char *nulls);
+extern void heap_freetuple(HeapTuple htup);
+extern MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor,
+                                               Datum *values, bool *isnull);
+extern void heap_free_minimal_tuple(MinimalTuple mtup);
+extern MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup);
+extern HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup);
+extern MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup);
+
 #endif   /* HTUP_H */