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

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    itup.h
  4.  *
  5.  *   DESCRIPTION
  6.  *    POSTGRES index tuple definitions.
  7.  *
  8.  *   IDENTIFICATION
  9.  *    $Header: /private/postgres/src/lib/H/access/RCS/itup.h,v 1.17 1991/11/08 15:43:24 kemnitz Exp $
  10.  * ----------------------------------------------------------------
  11.  */
  12. #ifndef ITUP_H
  13. #define ITUP_H
  14.  
  15. #include "tmp/c.h"
  16. #include "storage/form.h"
  17. #include "access/ibit.h"
  18. #include "storage/itemptr.h"
  19. #include "rules/rlock.h"
  20.  
  21. #define MaxIndexAttributeNumber    7
  22.  
  23. /* ----------------
  24.  * NOTE:
  25.  * A rule lock has 2 different representations:
  26.  *    The disk representation (t_lock.l_ltid) is an ItemPointer
  27.  * to the actual rule lock data (stored somewher else in the disk page).
  28.  * In this case `t_locktype' has the value DISK_INDX_RULE_LOCK.
  29.  *    The main memory representation (t_lock.l_lock) is a pointer
  30.  * (RuleLock) to a (palloced) structure. In this case `t_locktype'
  31.  * has the value MEM_INDX_RULE_LOCK.
  32.  * ----------------
  33.  */
  34.  
  35. #define DISK_INDX_RULE_LOCK    'd'
  36. #define MEM_INDX_RULE_LOCK    'm'
  37.  
  38. typedef union 
  39. {
  40.         ItemPointerData    l_ltid;    /* TID of the lock */
  41.         RuleLock    l_lock;        /* internal lock format */
  42. }
  43. IndexTupleRuleLock;
  44.  
  45. typedef struct IndexTupleData {
  46.     ItemPointerData            t_tid; /* reference TID to base tuple */
  47.  
  48.     /*
  49.      * t_info is layed out in the following fashion:
  50.      *
  51.      * first (leftmost) bit: "has nulls" bit
  52.      * second bit: "has varlenas" bit
  53.      * third bit: "has rules" bit
  54.      * fourth-16th bit: size of tuple.
  55.      */
  56.  
  57.     unsigned short            t_info; /* various info about tuple */
  58.  
  59. #ifdef NOTDEF
  60.         char            t_locktype;     /* type of rule lock representation*/
  61.     IndexAttributeBitMapData    bits;    /* bitmap of domains */
  62. #endif
  63. } IndexTupleData;    /* MORE DATA FOLLOWS AT END OF STRUCT */
  64.  
  65. /*
  66.  *  Warning: T_* defined also in tuple.h
  67.  */
  68.  
  69. /* ----------------
  70.  * "Special" attributes of index tuples...
  71.  * NOTE: I used these big values so that there is no overlapping
  72.  * with the HeapTuple system attributes.
  73.  * ----------------
  74.  */
  75. #define IndxBaseTupleIdAttributeNumber         (-101)
  76. #define IndxRuleLockAttributeNumber        (-102)
  77.  
  78. /* ----------------
  79.  *    {,general,general retrieve} index insert result crap
  80.  * ----------------
  81.  */
  82. typedef IndexTupleData    *IndexTuple;
  83.  
  84. typedef struct GeneralInsertIndexResultData {
  85.     ItemPointerData    pointerData;
  86.     RuleLock    lock;
  87. } GeneralInsertIndexResultData;
  88.  
  89. typedef GeneralInsertIndexResultData
  90.     *GeneralInsertIndexResult;    /* from AMinsert() */
  91.  
  92. typedef struct InsertIndexResultData {
  93.     ItemPointerData    pointerData;
  94.     RuleLock    lock;
  95.     double        offset;
  96. } InsertIndexResultData;
  97.  
  98. typedef InsertIndexResultData
  99.     *InsertIndexResult;    /* from newinsert() */
  100.  
  101. typedef struct GeneralRetrieveIndexResultData {
  102.     ItemPointerData    heapItemData;
  103. } GeneralRetrieveIndexResultData;
  104.  
  105. typedef GeneralRetrieveIndexResultData    *GeneralRetrieveIndexResult;
  106.                 /* from AMgettuple() */
  107.  
  108. typedef struct RetrieveIndexResultData {
  109.     ItemPointerData    indexItemData;
  110.     ItemPointerData    heapItemData;
  111. } RetrieveIndexResultData;
  112.  
  113. typedef RetrieveIndexResultData    *RetrieveIndexResult;
  114.                 /* from newgettuple() */
  115.  
  116. /* ----------------
  117.  *    support macros
  118.  * ----------------
  119.  */
  120. /*
  121.  * IndexTupleIsValid --
  122.  *    True iff index tuple is valid.
  123.  */
  124. #define    IndexTupleIsValid(tuple)            PointerIsValid(tuple)
  125.  
  126. /*
  127.  * IndexTupleGetRuleLockItemPointer --
  128.  *    Returns rule lock item pointer for an index tuple.
  129.  *
  130.  * Note:
  131.  *    Assumes index tuple is a valid internal index tuple.
  132.  */
  133. #define IndexTupleGetRuleLockItemPointer(tuple) \
  134.     (AssertMacro(IndexTupleIsValid(tuple)) ? \
  135.      ((ItemPointer) (&(tuple)->t_lock.l_ltid)) : (ItemPointer) 0)
  136.  
  137. /*
  138.  * IndexTupleGetRuleLock --
  139.  *    Returns rule lock for an index tuple.
  140.  *
  141.  * Note:
  142.  *    Assumes index tuple is a valid external index tuple.
  143.  */
  144. #define IndexTupleGetRuleLock(tuple) \
  145.     (AssertMacro(IndexTupleIsValid(tuple)) ? \
  146.      ((RuleLock) ((tuple)->t_lock.l_lock)) : (RuleLock) 0)
  147.  
  148. /*
  149.  * IndexTupleGetIndexAttributeBitMap --
  150.  *    Returns attribute bit map for an index tuple.
  151.  *
  152.  * Note:
  153.  *    Assumes index tuple is valid.
  154.  */
  155. #define IndexTupleGetIndexAttributeBitMap(tuple) \
  156.     (AssertMacro(IndexTupleIsValid(tuple)) ? \
  157.      ((IndexAttributeBitMap) (&(tuple)->bits)) : (IndexAttributeBitMap) 0)
  158.  
  159. /*
  160.  * IndexTupleGetForm --
  161.  *    Returns formated data for an index tuple.
  162.  *
  163.  * Note:
  164.  *    Assumes index tuple is valid.
  165.  */
  166. #define IndexTupleGetForm(tuple) \
  167.     (AssertMacro(IndexTupleIsValid(tuple)) ? \
  168.      ((Form) &(tuple)[1]) : (Form) 0)
  169.  
  170. /* ----------------
  171.  *    soon to be obsolete index result stuff
  172.  * ----------------
  173.  */
  174. /*
  175.  * GeneralInsertIndexResultIsValid --
  176.  *    True iff general index insertion result is valid.
  177.  */
  178. #define    GeneralInsertIndexResultIsValid(result)        PointerIsValid(result)
  179.  
  180. /*
  181.  * InsertIndexResultIsValid --
  182.  *    True iff (specific) index insertion result is valid.
  183.  */
  184. #define    InsertIndexResultIsValid(result)        PointerIsValid(result)
  185.  
  186. /*
  187.  * GeneralRetrieveIndexResultIsValid --
  188.  *    True iff general index retrieval result is valid.
  189.  */
  190. #define    GeneralRetrieveIndexResultIsValid(result)    PointerIsValid(result)
  191.  
  192. /*
  193.  * RetrieveIndexResultIsValid --
  194.  *    True iff (specific) index retrieval result is valid.
  195.  */
  196. #define    RetrieveIndexResultIsValid(result)        PointerIsValid(result)
  197.  
  198. /*
  199.  * GeneralInsertIndexResultGetItemPointer --
  200.  *    Returns heap tuple item pointer associated with a general index
  201.  *    insertion result.
  202.  *
  203.  * Note:
  204.  *    Assumes general index insertion result is valid.
  205.  */
  206. #define GeneralInsertIndexResultGetItemPointer(result) \
  207.     (AssertMacro(GeneralInsertIndexResultIsValid(result)) ? \
  208.      ((ItemPointer) (&(result)->pointerData)) : (ItemPointer) 0)
  209.  
  210. /*
  211.  * GeneralInsertIndexResultGetRuleLock --
  212.  *    Returns rule lock associated with a general index insertion result.
  213.  *
  214.  * Note:
  215.  *    Assumes general index insertion result is valid.
  216.  */
  217. #define GeneralInsertIndexResultGetRuleLock(result) \
  218.     (AssertMacro(GeneralInsertIndexResultIsValid(result)) ? \
  219.      ((RuleLock) ((result)->lock)) : (RuleLock) 0)
  220.  
  221. /*
  222.  * InsertIndexResultGetItemPointer --
  223.  *    Returns heap tuple item pointer associated with a (specific) index
  224.  *    insertion result.
  225.  *
  226.  * Note:
  227.  *    Assumes (specific) index insertion result is valid.
  228.  */
  229. #define InsertIndexResultGetItemPointer(result) \
  230.     (AssertMacro(InsertIndexResultIsValid(result)) ? \
  231.      ((ItemPointer) (&(result)->pointerData)) | (ItemPointer) 0)
  232.  
  233. /*
  234.  * InsertIndexResultGetRuleLock --
  235.  *    Returns rule lock associated with a (specific) index insertion result.
  236.  *
  237.  * Note:
  238.  *    Assumes (specific) index insertion result is valid.
  239.  */
  240. #define InsertIndexResultGetRuleLock(result) \
  241.     (AssertMacro(InsertIndexResultIsValid(result)) ? \
  242.      ((RuleLock) ((result)->lock)) : (RuleLock) 0)
  243.  
  244. /*
  245.  * InsertIndexResultGetInsertOffset --
  246.  *    Returns insertion offset for a (specific) index insertion result.
  247.  *
  248.  * Note:
  249.  *    Assumes (specific) index insertion result is valid.
  250.  */
  251. #define InsertIndexResultGetInsertOffset(result) \
  252.     (AssertMacro(InsertIndexResultIsValid(result)) ? \
  253.      ((double) ((result)->offset)) : (double) 0)
  254.  
  255. /*
  256.  * GeneralRetrieveIndexResultGetHeapItemPointer --
  257.  *    Returns heap item pointer associated with a general index retrieval.
  258.  *
  259.  * Note:
  260.  *    Assumes general index retrieval result is valid.
  261.  */
  262. #define GeneralRetrieveIndexResultGetHeapItemPointer(result) \
  263.     (AssertMacro(GeneralRetrieveIndexResultIsValid(result)) ? \
  264.      ((ItemPointer) (&(result)->heapItemData)) : (ItemPointer) 0)
  265.  
  266. /*
  267.  * RetrieveIndexResultGetIndexItemPointer --
  268.  *    Returns index item pointer associated with a (specific) index retrieval
  269.  *
  270.  * Note:
  271.  *    Assumes (specific) index retrieval result is valid.
  272.  */
  273. #define RetrieveIndexResultGetIndexItemPointer(result) \
  274.     (AssertMacro(RetrieveIndexResultIsValid(result)) ? \
  275.      ((ItemPointer) (&(result)->indexItemData)) : (ItemPointer) 0)
  276.  
  277. /*
  278.  * RetrieveIndexResultGetHeapItemPointer --
  279.  *    Returns heap item pointer associated with a (specific) index retrieval.
  280.  *
  281.  * Note:
  282.  *    Assumes (specific) index retrieval result is valid.
  283.  */
  284. #define RetrieveIndexResultGetHeapItemPointer(result) \
  285.     (AssertMacro(RetrieveIndexResultIsValid(result)) ? \
  286.      ((ItemPointer) (&(result)->heapItemData)) : (ItemPointer) 0)
  287.  
  288. /* ----------------
  289.  *    externs 
  290.  * ----------------
  291.  */
  292.  
  293. /*
  294.  * IndexTupleGetHeapTupleItemPointer --
  295.  *    Returns heap tuple item pointer for an index tuple.
  296.  *
  297.  * Note:
  298.  *    Assumes index tuple is valid.
  299.  */
  300. extern
  301. ItemPointer
  302. IndexTupleGetHeapTupleItemPointer ARGS((
  303.     IndexTuple    tuple
  304. ));
  305.  
  306. /*
  307.  * ItemPointerFormGeneralInsertIndexResult --
  308.  *    Returns a general index insertion result.
  309.  *
  310.  * Note:
  311.  *    Assumes item pointer is valid.
  312.  *    Assumes rule lock is valid.
  313.  */
  314. extern
  315. GeneralInsertIndexResult
  316. ItemPointerFormGeneralInsertIndexResult ARGS((
  317.     ItemPointer    itemPointer,
  318.     RuleLock    lock
  319. ));
  320.  
  321. /*
  322.  * ItemPointerFormInsertIndexResult --
  323.  *    Returns a (specific) index insertion result.
  324.  *
  325.  * Note:
  326.  *    Assumes item pointer is valid.
  327.  *    Assumes rule lock is valid.
  328.  *    Assumes insertion offset is valid.
  329.  */
  330. extern
  331. InsertIndexResult
  332. ItemPointerFormInsertIndexResult ARGS((
  333.     ItemPointer    itemPointer,
  334.     RuleLock    lock,
  335.     double        offset
  336. ));
  337.  
  338. /*
  339.  * ItemPointerFormGeneralRetrieveIndexResult --
  340.  *    Returns a (specific) index retrieval result.
  341.  *
  342.  * Note:
  343.  *    Assumes item pointer is valid.
  344.  */
  345. extern
  346. GeneralRetrieveIndexResult
  347. ItemPointerFormGeneralRetrieveIndexResult ARGS((
  348.     ItemPointer    heapItemPointer
  349. ));
  350.  
  351. /*
  352.  * ItemPointerFormRetrieveIndexResult --
  353.  *    Returns a general index retrieval result.
  354.  *
  355.  * Note:
  356.  *    Assumes item pointers are valid.
  357.  */
  358. extern
  359. RetrieveIndexResult
  360. ItemPointerFormRetrieveIndexResult ARGS((
  361.     ItemPointer    indexItemPointer,
  362.     ItemPointer    heapItemPointer
  363. ));
  364.  
  365.  
  366. #define INDEX_SIZE_MASK 0x1FFF
  367. #define INDEX_NULL_MASK 0x8000
  368. #define INDEX_VAR_MASK  0x4000
  369. #define INDEX_RULE_MASK 0x2000
  370.  
  371. #define IndexTupleSize(itup)       (((IndexTuple) (itup))->t_info & 0x1FFF)
  372. #define IndexTupleDSize(itup)                      ((itup).t_info & 0x1FFF)
  373. #define IndexTupleNoNulls(itup)  (!(((IndexTuple) (itup))->t_info & 0x8000))
  374. #define IndexTupleAllFixed(itup) (!(((IndexTuple) (itup))->t_info & 0x4000))
  375. #define IndexTupleNoRule(itup)   (!(((IndexTuple) (itup))->t_info & 0x2000))
  376. #define IndexTupleHasMinHeader(itup) (IndexTupleNoNulls(itup) \
  377.                                    && IndexTupleNoRule(itup))
  378.  
  379. extern Size IndexInfoFindDataOffset ARGS((
  380.      unsigned short t_info
  381. ));
  382.  
  383. #endif
  384.