indexvalid.c 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*-------------------------------------------------------------------------
 *
 * indexvalid.c--
 *    index tuple qualification validity checking code
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
Marc G. Fournier's avatar
Marc G. Fournier committed
10
 *    $Header: /cvsroot/pgsql/src/backend/access/common/Attic/indexvalid.c,v 1.8 1996/10/31 07:48:37 scrappy Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
Marc G. Fournier's avatar
Marc G. Fournier committed
14

15
#include <time.h>
16

17
#include "postgres.h"
18
#include "access/attnum.h"
19 20
#include "catalog/pg_attribute.h"
#include "executor/execdebug.h"
Marc G. Fournier's avatar
Marc G. Fournier committed
21
#include "nodes/nodes.h"
22
#include "nodes/pg_list.h"
23 24 25
#include "storage/off.h"
#include "storage/block.h"
#include "utils/nabstime.h"
26

27
#include "access/skey.h"
28 29
#include "access/tupdesc.h"
#include "storage/itemptr.h"
30

Marc G. Fournier's avatar
Marc G. Fournier committed
31
#include "access/htup.h"
32
#include "access/itup.h"
33

Marc G. Fournier's avatar
Marc G. Fournier committed
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* ----------------------------------------------------------------
 *		  index scan key qualification code
 * ----------------------------------------------------------------
 */
int	NIndexTupleProcessed;

/* ----------------
 *	index_keytest
 *
 * old comments
 *	May eventually combine with other tests (like timeranges)?
 *	Should have Buffer buffer; as an argument and pass it to amgetattr.
 * ----------------
 */
bool
index_keytest(IndexTuple tuple,
	      TupleDesc tupdesc,
	      int scanKeySize,
	      ScanKey key)
{
    bool	    isNull;
    Datum	    datum;
    int		    test;
    
    IncrIndexProcessed();
    
    while (scanKeySize > 0) {
	datum = index_getattr(tuple,
			      1,
			      tupdesc,
			      &isNull);
	
	if (isNull) {
	    /* XXX eventually should check if SK_ISNULL */
	    return (false);
	}
	
Marc G. Fournier's avatar
Marc G. Fournier committed
72 73 74 75
	if (key[0].sk_flags & SK_ISNULL) {
	    return (false);
	}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
	if (key[0].sk_flags & SK_COMMUTE) {
	    test = (int) (*(key[0].sk_func))
		(DatumGetPointer(key[0].sk_argument),
		 datum);
	} else {
	    test = (int) (*(key[0].sk_func))
		(datum,
		 DatumGetPointer(key[0].sk_argument));
	}
	
	if (!test == !(key[0].sk_flags & SK_NEGATE)) {
	    return (false);
	}
	
	scanKeySize -= 1;
	key++;
    }
    
    return (true);
}