home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / access / htup.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.6 KB  |  165 lines

  1. /*
  2.  * htup.h --
  3.  *    POSTGRES heap tuple definitions.
  4.  */
  5.  
  6. #ifndef    HTupIncluded        /* Include this file only once */
  7. #define HTupIncluded    1
  8.  
  9. /*
  10.  * Identification:
  11.  */
  12. #define HTUP_H    "$Header: /private/postgres/src/lib/H/access/RCS/htup.h,v 1.19 1992/05/28 20:24:15 mer Exp $"
  13.  
  14. #include "tmp/postgres.h"    /* XXX obsolete, for XID, etc. */
  15.  
  16. #include "access/attnum.h"
  17. #include "storage/form.h"
  18. #include "storage/page.h"          /* just to reduce levels of #include */
  19. #include "storage/part.h"          /* just to reduce levels of #include */
  20. #include "storage/itemptr.h"
  21. #include "rules/rlock.h"
  22.  
  23. #define MinHeapTupleBitmapSize    32        /* 8 * 4 */
  24.  
  25. /* check these, they are likely to be more severely limited by t_hoff */
  26.  
  27. #ifdef  vax
  28. #define MaxHeapAttributeNumber    1584        /* 8 * 198 */
  29. #else
  30. #define MaxHeapAttributeNumber    1600        /* 8 * 200 */
  31. #endif
  32.  
  33. /*-----------------------------------------------------------
  34.  * NOTE:
  35.  * A rule lock has 2 different representations:
  36.  *    The disk representation (t_lock.l_ltid) is an ItemPointer
  37.  * to the actual rule lock data (stored somewhere else in the disk page).
  38.  * In this case `t_locktype' has the value DISK_RULE_LOCK.
  39.  *    The main memory representation (t_lock.l_lock) is a pointer
  40.  * (RuleLock) to a (palloced) structure. In this case `t_locktype' has
  41.  * the value MEM_RULE_LOCK.
  42.  */
  43.  
  44. #define DISK_RULE_LOCK    'd'
  45. #define MEM_RULE_LOCK    'm'
  46.  
  47. /*
  48.  * to avoid wasting space, the attributes should be layed out in such a
  49.  * way to reduce structure padding.
  50.  */
  51.  
  52. typedef struct HeapTupleData {
  53.  
  54.     /* size is unsigned int */
  55.  
  56.     Size        t_len;        /* length of entire tuple */
  57.  
  58.                     /* anchor point TID -- 6 bytes, was
  59.                      * commented out, and I have removed
  60.                      * it from the file -mer 5/27/92 
  61.                      */
  62.  
  63.     ItemPointerData    t_ctid;        /* current TID of this tuple */
  64.  
  65.                     /* keep these here as padding */
  66.  
  67.  
  68.     ItemPointerData    t_chain;    /* replaced tuple TID */
  69.  
  70.                     /* keep these here as padding */
  71.  
  72.     union {
  73.         ItemPointerData    l_ltid;    /* TID of the lock */
  74.         RuleLock    l_lock;    /* internal lock format */
  75.     }        t_lock;
  76.  
  77.     ObjectId    t_oid;        /* OID of this tuple -- 4 bytes */
  78.  
  79.     CommandId    t_cmin;        /* insert CID stamp -- 2 bytes each */
  80.     CommandId    t_cmax;        /* delete CommandId stamp */
  81.  
  82.     TransactionId    t_xmin;        /* insert XID stamp -- 4 bytes each */
  83.     TransactionId    t_xmax;        /* delete XID stamp */
  84.  
  85.     ABSTIME        t_tmin, t_tmax;    /* time stamps -- 4 bytes each */
  86.  
  87.     AttributeNumber    t_natts;    /* number of attributes */
  88.  
  89.     char        t_vtype;    /* `d', `i', `r' */
  90.     char        t_infomask;    /* used for various stuff in getattr */
  91.     char        t_locktype;    /* type of rule lock representation*/
  92.     uint8        t_hoff;        /* sizeof tuple header */
  93.  
  94.  
  95.     char        t_bits[MinHeapTupleBitmapSize / 8];
  96.                     /* bit map of domains */
  97. } HeapTupleData;    /* MORE DATA FOLLOWS AT END OF STRUCT */
  98.  
  99. typedef HeapTupleData    *HeapTuple;
  100.  
  101. /* three files? */
  102.  
  103. #ifndef    RuleLockAttributeNumber
  104. #define SelfItemPointerAttributeNumber        (-1)
  105. #define RuleLockAttributeNumber            (-2)
  106. #define ObjectIdAttributeNumber            (-3)
  107. #define MinTransactionIdAttributeNumber        (-4)
  108. #define MinCommandIdAttributeNumber        (-5)
  109. #define MaxTransactionIdAttributeNumber        (-6)
  110. #define MaxCommandIdAttributeNumber        (-7)
  111. #define ChainItemPointerAttributeNumber        (-8)
  112. #define AnchorItemPointerAttributeNumber    (-9)
  113. #define MinAbsoluteTimeAttributeNumber        (-10)
  114. #define MaxAbsoluteTimeAttributeNumber        (-11)
  115. #define VersionTypeAttributeNumber        (-12)
  116. #define FirstLowInvalidHeapAttributeNumber    (-13)
  117. #endif    /* !defined(RuleLockAttributeNumber) */
  118.  
  119. /* ----------------
  120.  *    support macros
  121.  * ----------------
  122.  */
  123. #ifndef    GETSTRUCT
  124. #define GETSTRUCT(TUP)    (((char *)(TUP)) + ((HeapTuple)(TUP))->t_hoff)
  125.  
  126. /*
  127.  *    BITMAPLEN(NATTS)    - compute size of aligned bitmap
  128.  *    u_int2    NATTS;
  129.  *
  130.  *    Computes minimum size of bitmap given number of domains.
  131.  */
  132. #define BITMAPLEN(NATTS)\
  133.     ((((((int)NATTS - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) & ~03) + (MinHeapTupleBitmapSize >> 3))
  134.  
  135. /*
  136.  *    USEDBITMAPLEN(TUP)    - compute length of bitmap used
  137.  *    struct    tuple    *TUP;
  138.  */
  139. #define USEDBITMAPLEN(TUP)\
  140.     (1 + (((TUP)->t_natts - 1) >> 3))
  141. #endif
  142.  
  143. /*
  144.  * HeapTupleIsValid
  145.  *    True iff the heap tuple is valid.
  146.  */
  147. #define    HeapTupleIsValid(tuple)    PointerIsValid(tuple)
  148.  
  149. /*
  150.  * HeapTupleGetForm
  151.  *    Returns the formated user attribute values of a heap tuple.
  152.  */
  153. #define HeapTupleGetForm(tuple) \
  154.     ((Form) ((char *)(tuple) + (tuple)->t_hoff))
  155.  
  156. /* Various information about the tuple used by getattr() */
  157.  
  158. #define HeapTupleNoNulls(tuple) (!(((HeapTuple) (tuple))->t_infomask & 0x01))
  159. #define HeapTupleAllFixed(tuple) (!(((HeapTuple) (tuple))->t_infomask & 0x02))
  160.  
  161. #define HeapTupleSetNull(tuple) (((HeapTuple) (tuple))->t_infomask |= 0x01)
  162. #define HeapTupleSetVarlena(tuple) (((HeapTuple) (tuple))->t_infomask |= 0x02)
  163.  
  164. #endif    /* !defined(HTupIncluded) */
  165.