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

  1. /*========================================================================
  2.  *
  3.  * FILE:
  4.  *    prs2stub.h
  5.  *
  6.  * IDENTIFICATION:
  7.  *    $Header: /private/postgres/src/lib/H/rules/RCS/prs2stub.h,v 1.14 1991/11/06 01:59:28 mer Exp $
  8.  *
  9.  * DESCRIPTION:
  10.  *
  11.  * This file contains the definitions of the rule 'stub' records.
  12.  * These come in 2 formats: 
  13.  *    Prs2Stub: this is the 'normal' format, and it is a pointer to
  14.  *            a structure which contains pointers to other structures
  15.  *        and so forth.
  16.  *    Prs2RawStub: this is similar to a pointer to a 'varlena' struct,
  17.  *        and it is a "flat" representation of 'Prs2Stub'.
  18.  *        It can be considered as a stream of raw bytes
  19.  *        (starting with a long int containing size information)
  20.  *        suitable for disk storage.
  21.  *
  22.  * The reason for using 2 formats instead of one, is that we have to
  23.  * have a "flat" representation (like Prs2RawStub) for reading/writing
  24.  * stub records to disk, but on the other hand, as these records
  25.  * contain a lot of variable length information, main memory
  26.  * operations (like adding/deleting stub record entries) would
  27.  * reequire a complex interface (probably inefficient & difficult to
  28.  * write & maintain)
  29.  *
  30.  * So, in order to manipulate stub records, first we use amgetattr to
  31.  * retrieve them in 'Prs2RawStub' format, and then we translate them into
  32.  * 'Prs2Stub' using the routine 'Prs2RawStubToStub()'.
  33.  * In order to write them back to disk, we use 'Prs2StubToRawStub()'
  34.  * to change them back into the 'Prs2RawStub' form and store them back
  35.  * into the tuple. Finally, we free the space occupied by the 'Prs2Stub'
  36.  * form using 'Prs2StubFree()'.
  37.  *
  38.  *========================================================================
  39.  */
  40.  
  41. #ifndef Prs2StubIncluded
  42. #define Prs2StubIncluded
  43.  
  44. /*--------------
  45.  * turn on/off debugging....
  46.  */
  47. /* #define STUB_DEBUG    10 */
  48.  
  49. #include "tmp/postgres.h"
  50. #include "access/attnum.h"
  51. #include "rules/prs2locks.h"
  52. #include "rules/prs2.h"
  53.  
  54. /*------------------------------------------------------------------------
  55.  *        Prs2Stub
  56.  *------------------------------------------------------------------------
  57.  *
  58.  * Prs2StubId: a stub record identifier, used to distinguish between
  59.  *     the many stub records a rule might use.
  60.  *
  61.  * Prs2Stub: a pointer to a 'PrsStubData' struct.
  62.  *
  63.  * Prs2StubData: this struct contains all the stub records information
  64.  *    of a tuple (a tuple can have 0 or more stub records).
  65.  *    It has the following fields:
  66.  *    numOfStubs: the number of stub records for this tuple.
  67.  *    stubRecors: an array of pointers to 'Prs2OneStubData' structures,
  68.  *    holding information about each individual stub record.
  69.  *
  70.  * Prs2OneStubData: a structure holding information about one
  71.  *    stub record. It has the following fields:
  72.  *    ruleId:    the oid of the rule where this stub belongs.
  73.  *    stubId: used to distinguish between the many stub records
  74.  *        a rule can put.
  75.  *    counter: It is possible for a rule to put many copies of
  76.  *        the same stub record to the same tuple. Instead of
  77.  *        duplicating information, we use a counter of these
  78.  *        copies.
  79.  *    lock: the RuleLock associated with this stub.
  80.  *    qualification: The qualification associated with the stub.
  81.  *        If the qualification is NULL then the qualification
  82.  *        of the stub is always true.
  83.  *
  84.  *    NOTE: XXX!!!!!!!!!!!!!  THIS IS A HACK !!!!!!!!!!
  85.  *    'lock' and 'qualification' are pointers to variable length
  86.  *    fields. In order to make transformation between the 'Prs2Stub'
  87.  *    format to 'Prs2RawStub' and vice versa easier, 
  88.  *    these fields MUST BE THE LAST FIELDS IN THE STRUCTURE
  89.  */
  90.  
  91. typedef uint16 Prs2StubId;
  92.  
  93. typedef struct Prs2OneStubData {
  94.     ObjectId ruleId;
  95.     Prs2StubId stubId;
  96.     int counter;
  97.     RuleLock lock;
  98.     LispValue qualification;
  99. } Prs2OneStubData;
  100.  
  101. typedef Prs2OneStubData *Prs2OneStub;
  102.  
  103. typedef struct Prs2StubData {
  104.     int numOfStubs;    /* number of Stub Records */
  105.     Prs2OneStub *stubRecords;    /* an array of pointers to the stub records */
  106. } Prs2StubData;
  107.  
  108. typedef Prs2StubData *Prs2Stub;
  109.  
  110. /*------------------------------------------------------------------------
  111.  *        Prs2RawStub
  112.  *
  113.  * This is exactly the same as a varlena struct.
  114.  *------------------------------------------------------------------------
  115.  */
  116.  
  117. typedef struct varlena Prs2RawStubData;
  118. typedef Prs2RawStubData *Prs2RawStub;
  119.  
  120. /*------------------------------------------------------------------------
  121.  *        Prs2StubStats
  122.  * used to keep some statistics (about rule stubs & rule locks
  123.  * added/deleted.
  124.  *------------------------------------------------------------------------
  125.  */
  126.  
  127. #define PRS2_ADDSTUB        1
  128. #define PRS2_DELETESTUB        2
  129. #define PRS2_ADDLOCK        3
  130. #define PRS2_DELETELOCK        4
  131.  
  132. typedef struct Prs2StubStatsData {
  133.     int stubsAdded;
  134.     int stubsDeleted;
  135.     int locksAdded;
  136.     int locksDeleted;
  137. } Prs2StubStatsData;
  138.  
  139. typedef Prs2StubStatsData *Prs2StubStats;
  140.  
  141. /*========================================================================
  142.  *        VARIOUS ROUTINES
  143.  *========================================================================
  144.  */
  145.  
  146. #define prs2StubIsEmpty(x) ((x)==NULL || (x)->numOfStubs == 0)
  147.  
  148. /*================= ROUTINES IN FILE 'stubraw.c' =======================*/
  149.  
  150. /*-------------------------
  151.  * Prs2StubToRawStub:
  152.  * given a 'Prs2Stub' create the equivalent 'Prs2RawStub'
  153.  */
  154. extern
  155. Prs2RawStub
  156. prs2StubToRawStub ARGS((
  157.     Prs2Stub    relstub
  158. ));
  159.  
  160. /*-------------------------
  161.  * Prs2StubToSmallRawStubs:
  162.  * given a 'Prs2Stub' create the equivalent 'Prs2RawStub', but
  163.  * break it into pieces, so that no piece is greater than 'maxsize'
  164.  * bytes
  165.  */
  166. extern
  167. Prs2RawStub *
  168. prs2StubToSmallRawStubs ARGS((
  169.     Prs2Stub    relstub,
  170.     int        maxsize,
  171.     int        *npieces
  172. ));
  173.  
  174. /*-------------------------
  175.  * Prs2RawStubToStub:
  176.  * given a 'Prs2RawStub' create the equivalent 'Prs2Stub'
  177.  */
  178. extern
  179. Prs2Stub
  180. prs2RawStubToStub ARGS((
  181.     Prs2RawStub    rawStub
  182. ));
  183.  
  184. /*-------------------------
  185.  * Prs2RawStubUnion
  186.  * create the union of two raw stubs
  187.  */
  188. extern
  189. Prs2RawStub
  190. prs2RawStubUnion ARGS((
  191.     Prs2RawStub    rawStub1,
  192.     Prs2RawStub    rawStub2
  193. ));
  194.  
  195.  
  196. /*================ ROUTINES IN FILE 'stubutil.c' ==================*/
  197.  
  198. /*-------------------------
  199.  * prs2StubQualIsEqual
  200.  *
  201.  * returns true if the given 'Prs2StubQual' point to the same stub
  202.  * qualifications.
  203.  */
  204. extern
  205. bool
  206. prs2StubQualIsEqual ARGS((
  207.     LispValue        q1,
  208.     LispValue        q2
  209. ));
  210.  
  211. /*-------------------------
  212.  * prs2OneStubIsEqual
  213.  *
  214.  * Return true iff the two given 'Prs2OneStub' pointers point to
  215.  * equal structures.
  216.  */
  217. extern
  218. bool
  219. prs2OneStubIsEqual ARGS((
  220.     Prs2OneStub    stub1,
  221.     Prs2OneStub    stub2
  222. ));
  223.  
  224. /*-------------------------
  225.  * prs2SearchStub:
  226.  * given a `Prs2Stub', return the index of the
  227.  * stub record (Prs2OneStub) that is equal to the given
  228.  * `Prs2OneStub'
  229.  * If no such record exist, return -1
  230.  */
  231. extern
  232. int
  233. prs2SearchStub ARGS((
  234.     Prs2Stub    stubs,
  235.     Prs2OneStub    oneStub
  236. ));
  237.  
  238. /*-------------------------
  239.  * prs2AddOneStub:
  240.  * add a new stub record (Prs2OneStub) to the given stub records.
  241.  * NOTE 1: We do NOT make a copy of the 'newStub'. So DO NOT pfree it
  242.  */
  243. extern
  244. void
  245. prs2AddOneStub();/* BAD PROTOTYPE DELETED -- glass */ 
  246.  /*ARGS((
  247.     Prs2Stubs    oldStubs,
  248.     Prs2OneStub    newStub
  249. ));*/
  250.  
  251. /*-------------------------
  252.  * prs2DeleteOneStub
  253.  * delete the given 'Prs2OneStub'
  254.  */
  255. extern
  256. void
  257. prs2DeleteOneStub ARGS((
  258.     Prs2Stub    oldStubs,
  259.     Prs2OneStub    deletedStub
  260. ));
  261.  
  262. /*-------------------------
  263.  * prs2RemoveStubsOfRule
  264.  * remove (in place) all the stubs of the given rule.
  265.  * Return true if some stubs have been removed, or false if no stubs
  266.  * for this rule were found.
  267.  */
  268. extern
  269. bool
  270. prs2RemoveStubsOfRule ARGS((
  271.     Prs2Stub    stubs,
  272.     ObjectId    ruleId
  273. ));
  274.  
  275. /*-------------------------
  276.  * prs2MakeStub
  277.  * create an empty 'Prs2Stub'
  278.  */
  279. extern
  280. Prs2Stub
  281. prs2MakeStub ARGS((
  282. ));
  283.  
  284. /*-------------------------
  285.  * prs2MakeOneStub
  286.  * create an empty 'Prs2OneStub' record
  287.  */
  288. extern
  289. Prs2OneStub
  290. prs2MakeOneStub ARGS((
  291. ));
  292.  
  293. /*================= ROUTINES IN FILE 'stubinout.c' =======================*/
  294.  
  295. /*-------------------------
  296.  * prs2StubToString:
  297.  * given a Prs2Stub transform it to a humanly readable string
  298.  */
  299. extern
  300. char *
  301. prs2StubToString ARGS((
  302.     Prs2Stub    relstub
  303. ));
  304.  
  305. /*-------------------------
  306.  * prs2StringToStub:
  307.  * given a string (as generated by prs2StubToString)
  308.  * recreate the Prs2Stub
  309.  */
  310. extern
  311. Prs2Stub
  312. prs2StringToStub ARGS((
  313.     char    *string
  314. ));
  315.  
  316. /*-------------------------
  317.  * stubout:
  318.  * given a Prs2RawStub transform it to a humanly readable string
  319.  */
  320. extern
  321. char *
  322. stubout ARGS((
  323.     Prs2RawStub    relstub
  324. ));
  325.  
  326. /*-------------------------
  327.  * stubin:
  328.  * given a string (as generated by stubout)
  329.  * recreate the Prs2RawStub
  330.  */
  331. extern
  332. Prs2RawStub
  333. stubin ARGS((
  334.     char    *string
  335. ));
  336.  
  337. /*================= ROUTINES IN FILE 'stubrel.c' =======================*/
  338.  
  339. /*-------------------------
  340.  * prs2AddRelationStub:
  341.  * add a new relation level stub record to the given relation.
  342.  */
  343. extern
  344. void
  345. prs2AddRelationStub ARGS((
  346.     Relation    relation,
  347.     Prs2OneStub    relstub
  348. ));
  349.  
  350. /*-------------------------
  351.  * prs2DeleteRelationStub:
  352.  * delete the given relation level stub record from the given relation.
  353.  */
  354. extern
  355. void
  356. prs2DeleteRelationStub ARGS((
  357.     Relation    relation,
  358.     Prs2OneStub    relstub
  359. ));
  360.  
  361. /*-------------------------
  362.  * prs2ReplaceRelationStub:
  363.  * Replace the relation stubs of a relation with the given ones
  364.  * (the old ones are completely ignored)
  365.  */
  366. extern
  367. void
  368. prs2ReplaceRelationStub ARGS((
  369.     ObjectId    relationOid,
  370.     Prs2Stub    stubs
  371. ));
  372.  
  373. /*-------------------------
  374.  * prs2GetRelationStubs
  375.  * given a relation OID, find all the associated rule stubs.
  376.  */
  377. extern
  378. Prs2Stub
  379. prs2GetRelationStubs ARGS((
  380.     ObjectId    relOid
  381. ));
  382.  
  383. #ifdef OBSOLETE
  384. /*-------------------------
  385.  * prs2PutStubsInPrs2StubTuple:
  386.  * put the given stubs to the appropriate attribute of a 
  387.  * pg_prs2stub relation tuple.
  388.  * Returns the new tuple
  389.  */
  390. extern
  391. HeapTuple
  392. prs2PutStubsInPrs2StubTuple ARGS((
  393.         HeapTuple        tuple,
  394.     Buffer            buffer,
  395.     TupleDesccriptor    tupleDesc,
  396.     Prs2Stub        stubs
  397. ));
  398. #endif OBSOLETE
  399.  
  400. /*================= ROUTINES IN FILE 'stubtuple.c' =======================*/
  401.  
  402. /*-------------------------
  403.  * prs2StubGetLocksForTuple
  404.  * given a collection of stub records and a tuple, find all the locks
  405.  * that the tuple must inherit.
  406.  *-------------------------
  407.  */
  408. extern
  409. RuleLock
  410. prs2StubGetLocksForTuple ARGS((
  411.     HeapTuple    tuple,
  412.     Buffer        buffer,
  413.     TupleDescriptor    tupDesc,
  414.     Prs2Stub    stubs
  415. ));
  416.  
  417. /*-------------------------
  418.  * prs2StubQualTestTuple
  419.  * test if a tuple satisfies the qualification of a
  420.  * stub record.
  421.  *-------------------------
  422.  */
  423. extern
  424. bool
  425. prs2StubQualTestTuple ARGS((
  426.     HeapTuple        tuple,
  427.     Buffer        buffer,
  428.     TupleDescriptor    tupDesc,
  429.     LispValue        qual
  430. ));
  431.  
  432. /*================= ROUTINES IN FILE 'stubjoin.c' =======================*/
  433.  
  434. /*--------------------------
  435.  * prs2MakeStubForInnerRelation:
  436.  * Create the 'prs2OneStub' corresponding to the inner relation
  437.  * when proccessing a Join.
  438.  */
  439. extern
  440. Prs2OneStub
  441. prs2MakeStubForInnerRelation(); /* BAD PROTOTYPE DELETED -- glass */ /*
  442. ARGS((
  443.     JoinRuleInfo    ruleInfo,
  444.     HeapTuple        tuple,
  445.     Buffer        buffer,
  446.     TupleDescriptor    outerTupleDesc
  447. ));
  448. */
  449. /*--------------------------
  450.  * prs2AddLocksAndReplaceTuple:
  451.  * test the given tuple to see if it satisfies the stub qualification,
  452.  * and if yes add to it the corresponding rule lock.
  453.  */
  454. extern
  455. bool
  456. prs2AddLocksAndReplaceTuple ARGS((
  457.     HeapTuple    tuple,
  458.     Buffer    buffer,
  459.     Relation    relation,
  460.     Prs2OneStub oneStub,
  461.     bool    *newExportLocksFlag
  462. ));
  463.  
  464. /*--------------------------
  465.  * prs2UpdateStats:
  466.  * used for benchmarks... Keep some statistics about rule stub records
  467.  * and stuff...
  468.  */
  469. extern
  470. void
  471. prs2UpdateStats(); /* BAD PROTOTYPE DELETED -- glass */
  472. /*
  473.     ARGS((
  474.     JoinRuleInfo    ruleInfo,
  475.     int            operation
  476. ));*/
  477.  
  478. #endif Prs2StubIncluded
  479.