aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/common/scankey.c
blob: f79b2c71432d21f813a8b487b859793adc92c9fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*-------------------------------------------------------------------------
 *
 * scan.c
 *	  scan direction and key code
 *
 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.22 2003/08/04 02:39:56 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

#include "access/skey.h"

/*
 * ScanKeyEntryIsLegal
 *		True iff the scan key entry is legal.
 */
#define ScanKeyEntryIsLegal(entry) \
( \
	AssertMacro(PointerIsValid(entry)), \
	AttributeNumberIsValid((entry)->sk_attno) \
)

/*
 * ScanKeyEntrySetIllegal
 *		Marks a scan key entry as illegal.
 */
void
ScanKeyEntrySetIllegal(ScanKey entry)
{

	Assert(PointerIsValid(entry));

	entry->sk_flags = 0;		/* just in case... */
	entry->sk_attno = InvalidAttrNumber;
	entry->sk_procedure = 0;	/* should be InvalidRegProcedure */
	entry->sk_func.fn_oid = InvalidOid;
	entry->sk_argument = (Datum) 0;
}

/*
 * ScanKeyEntryInitialize
 *		Initializes a scan key entry.
 *
 * Note:
 *		Assumes the scan key entry is valid.
 *		Assumes the intialized scan key entry will be legal.
 */
void
ScanKeyEntryInitialize(ScanKey entry,
					   bits16 flags,
					   AttrNumber attributeNumber,
					   RegProcedure procedure,
					   Datum argument)
{
	Assert(PointerIsValid(entry));

	entry->sk_flags = flags;
	entry->sk_attno = attributeNumber;
	entry->sk_procedure = procedure;
	entry->sk_argument = argument;
	fmgr_info(procedure, &entry->sk_func);

	Assert(ScanKeyEntryIsLegal(entry));
}

/*
 * ScanKeyEntryInitializeWithInfo
 *		Initializes a scan key entry using an already-completed FmgrInfo
 *		function lookup record.
 *
 * mcxt is the memory context holding the scan key; it'll be used for
 * any subsidiary info attached to the scankey's FmgrInfo record.
 */
void
ScanKeyEntryInitializeWithInfo(ScanKey entry,
							   bits16 flags,
							   AttrNumber attributeNumber,
							   FmgrInfo *finfo,
							   MemoryContext mcxt,
							   Datum argument)
{
	Assert(PointerIsValid(entry));
	Assert(RegProcedureIsValid(finfo->fn_oid));

	entry->sk_flags = flags;
	entry->sk_attno = attributeNumber;
	entry->sk_procedure = finfo->fn_oid;
	entry->sk_argument = argument;
	fmgr_info_copy(&entry->sk_func, finfo, mcxt);

	Assert(ScanKeyEntryIsLegal(entry));
}