home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / access / common / indexvalid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.0 KB  |  128 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    indexvalid.c
  4.  *    
  5.  *   DESCRIPTION
  6.  *    index tuple qualification validity checking code
  7.  *
  8.  *   INTERFACE ROUTINES
  9.  *    index_keytest
  10.  *      index_satisifies
  11.  *
  12.  *   OLD INTERFACE FUNCTIONS
  13.  *    ikeytest_tupdesc, ikeytest
  14.  *    ItemIdSatisfiesScanKey
  15.  *
  16.  *   NOTES
  17.  *    
  18.  *   IDENTIFICATION
  19.  *    $Header: /private/postgres/src/access/common/RCS/indexvalid.c,v 1.4 1991/05/01 02:48:59 cimarron Exp $
  20.  * ----------------------------------------------------------------
  21.  */
  22.  
  23. #include "tmp/postgres.h"
  24.  
  25. RcsId("$Header: /private/postgres/src/access/common/RCS/indexvalid.c,v 1.4 1991/05/01 02:48:59 cimarron Exp $");
  26.  
  27. #include "executor/execdebug.h"
  28. #include "access/genam.h"
  29. #include "access/iqual.h"
  30. #include "access/itup.h"
  31. #include "access/skey.h"
  32.  
  33. #include "storage/buf.h"
  34. #include "storage/itemid.h"
  35. #include "storage/page.h"
  36. #include "utils/rel.h"
  37.  
  38. /* ----------------------------------------------------------------
  39.  *          index scan key qualification code
  40.  * ----------------------------------------------------------------
  41.  */
  42. int    NIndexTupleProcessed;
  43.  
  44. /* ----------------
  45.  *    index_keytest
  46.  *
  47.  * old comments
  48.  *    May eventually combine with other tests (like timeranges)?
  49.  *    Should have Buffer buffer; as an argument and pass it to amgetattr.
  50.  * ----------------
  51.  */
  52. bool
  53. index_keytest(tuple, tupdesc, scanKeySize, key)
  54.     IndexTuple        tuple;
  55.     TupleDescriptor tupdesc;
  56.     ScanKeySize        scanKeySize;
  57.     ScanKey        key;
  58. {
  59.     Boolean        isNull;
  60.     Datum        datum;
  61.     int            test;
  62.  
  63.     IncrIndexProcessed();
  64.     
  65.     while (scanKeySize > 0) {
  66.     datum = IndexTupleGetAttributeValue(tuple,
  67.                         1,
  68.                         tupdesc,
  69.                         &isNull);
  70.                         
  71.     if (isNull) {
  72.         /* XXX eventually should check if SK_ISNULL */
  73.         return (false);
  74.     }
  75.     
  76.     if (key->data[0].flags & CommuteArguments) {
  77.         test = (int) (*(key->data[0].func))
  78.                  (DatumGetPointer(key->data[0].argument),
  79.                   datum);
  80.     } else {
  81.         test = (int) (*(key->data[0].func))
  82.                  (datum,
  83.                   DatumGetPointer(key->data[0].argument));
  84.     }
  85.  
  86.     if (!test == !(key->data[0].flags & NegateResult)) {
  87.         return (false);
  88.     }
  89.  
  90.     scanKeySize -= 1;
  91.     key = (ScanKey)&key->data[1];
  92.     }
  93.  
  94.     return (true);
  95. }
  96.  
  97. /* ----------------
  98.  *      index_satisifies
  99.  * ----------------
  100.  */
  101. bool
  102. index_satisifies(itemId, page, relation, scanKeySize, key)
  103.     ItemId    itemId;
  104.     Page    page;
  105.     Relation    relation;
  106.     ScanKeySize    scanKeySize;
  107.     ScanKey    key;    
  108. {
  109.     IndexTuple    tuple;
  110.     TupleDescriptor tupdesc;
  111.  
  112.     Assert(ItemIdIsValid(itemId));
  113.     Assert(PageIsValid(page));    /* XXX needs better checking */
  114.     Assert(RelationIsValid(relation));
  115.     Assert(ScanKeyIsValid(scanKeySize, key));
  116.  
  117.     if (!ItemIdIsUsed(itemId) || ItemIdIsContinuation(itemId)) 
  118.     return (false);
  119.  
  120.     tuple = (IndexTuple) PageGetItem(page, itemId);
  121.     tupdesc = RelationGetTupleDescriptor(relation);
  122.     
  123.     if (! index_keytest(tuple, tupdesc, scanKeySize, key))
  124.     return (false);
  125.     
  126.     return (true);
  127. }
  128.