~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/backend/access/common/scankey.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * scankey.c
 
4
 *        scan key support code
 
5
 *
 
6
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 
7
 * Portions Copyright (c) 1994, Regents of the University of California
 
8
 *
 
9
 *
 
10
 * IDENTIFICATION
 
11
 *        $PostgreSQL$
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
#include "postgres.h"
 
16
 
 
17
#include "access/skey.h"
 
18
 
 
19
 
 
20
/*
 
21
 * ScanKeyEntryInitialize
 
22
 *              Initializes a scan key entry given all the field values.
 
23
 *              The target procedure is specified by OID (but can be invalid
 
24
 *              if SK_SEARCHNULL is set).
 
25
 *
 
26
 * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
 
27
 * itself, because that's what will be used for any subsidiary info attached
 
28
 * to the ScanKey's FmgrInfo record.
 
29
 */
 
30
void
 
31
ScanKeyEntryInitialize(ScanKey entry,
 
32
                                           int flags,
 
33
                                           AttrNumber attributeNumber,
 
34
                                           StrategyNumber strategy,
 
35
                                           Oid subtype,
 
36
                                           RegProcedure procedure,
 
37
                                           Datum argument)
 
38
{
 
39
        entry->sk_flags = flags;
 
40
        entry->sk_attno = attributeNumber;
 
41
        entry->sk_strategy = strategy;
 
42
        entry->sk_subtype = subtype;
 
43
        entry->sk_argument = argument;
 
44
        if (RegProcedureIsValid(procedure))
 
45
                fmgr_info(procedure, &entry->sk_func);
 
46
        else
 
47
        {
 
48
                Assert(flags & SK_SEARCHNULL);
 
49
                MemSet(&entry->sk_func, 0, sizeof(entry->sk_func));
 
50
        }
 
51
}
 
52
 
 
53
/*
 
54
 * ScanKeyInit
 
55
 *              Shorthand version of ScanKeyEntryInitialize: flags and subtype
 
56
 *              are assumed to be zero (the usual value).
 
57
 *
 
58
 * This is the recommended version for hardwired lookups in system catalogs.
 
59
 * It cannot handle NULL arguments, unary operators, or nondefault operators,
 
60
 * but we need none of those features for most hardwired lookups.
 
61
 *
 
62
 * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
 
63
 * itself, because that's what will be used for any subsidiary info attached
 
64
 * to the ScanKey's FmgrInfo record.
 
65
 */
 
66
void
 
67
ScanKeyInit(ScanKey entry,
 
68
                        AttrNumber attributeNumber,
 
69
                        StrategyNumber strategy,
 
70
                        RegProcedure procedure,
 
71
                        Datum argument)
 
72
{
 
73
        entry->sk_flags = 0;
 
74
        entry->sk_attno = attributeNumber;
 
75
        entry->sk_strategy = strategy;
 
76
        entry->sk_subtype = InvalidOid;
 
77
        entry->sk_argument = argument;
 
78
        fmgr_info(procedure, &entry->sk_func);
 
79
}
 
80
 
 
81
/*
 
82
 * ScanKeyEntryInitializeWithInfo
 
83
 *              Initializes a scan key entry using an already-completed FmgrInfo
 
84
 *              function lookup record.
 
85
 *
 
86
 * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
 
87
 * itself, because that's what will be used for any subsidiary info attached
 
88
 * to the ScanKey's FmgrInfo record.
 
89
 */
 
90
void
 
91
ScanKeyEntryInitializeWithInfo(ScanKey entry,
 
92
                                                           int flags,
 
93
                                                           AttrNumber attributeNumber,
 
94
                                                           StrategyNumber strategy,
 
95
                                                           Oid subtype,
 
96
                                                           FmgrInfo *finfo,
 
97
                                                           Datum argument)
 
98
{
 
99
        entry->sk_flags = flags;
 
100
        entry->sk_attno = attributeNumber;
 
101
        entry->sk_strategy = strategy;
 
102
        entry->sk_subtype = subtype;
 
103
        entry->sk_argument = argument;
 
104
        fmgr_info_copy(&entry->sk_func, finfo, CurrentMemoryContext);
 
105
}