~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to contrib/btree_gist/btree_bytea.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * contrib/btree_gist/btree_bytea.c
 
3
 */
 
4
#include "btree_gist.h"
 
5
#include "btree_utils_var.h"
 
6
#include "utils/bytea.h"
 
7
 
 
8
 
 
9
/*
 
10
** Bytea ops
 
11
*/
 
12
PG_FUNCTION_INFO_V1(gbt_bytea_compress);
 
13
PG_FUNCTION_INFO_V1(gbt_bytea_union);
 
14
PG_FUNCTION_INFO_V1(gbt_bytea_picksplit);
 
15
PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
 
16
PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
 
17
PG_FUNCTION_INFO_V1(gbt_bytea_same);
 
18
 
 
19
Datum           gbt_bytea_compress(PG_FUNCTION_ARGS);
 
20
Datum           gbt_bytea_union(PG_FUNCTION_ARGS);
 
21
Datum           gbt_bytea_picksplit(PG_FUNCTION_ARGS);
 
22
Datum           gbt_bytea_consistent(PG_FUNCTION_ARGS);
 
23
Datum           gbt_bytea_penalty(PG_FUNCTION_ARGS);
 
24
Datum           gbt_bytea_same(PG_FUNCTION_ARGS);
 
25
 
 
26
 
 
27
/* define for comparison */
 
28
 
 
29
static bool
 
30
gbt_byteagt(const void *a, const void *b, Oid collation)
 
31
{
 
32
        return DatumGetBool(DirectFunctionCall2(byteagt,
 
33
                                                                                        PointerGetDatum(a),
 
34
                                                                                        PointerGetDatum(b)));
 
35
}
 
36
 
 
37
static bool
 
38
gbt_byteage(const void *a, const void *b, Oid collation)
 
39
{
 
40
        return DatumGetBool(DirectFunctionCall2(byteage,
 
41
                                                                                        PointerGetDatum(a),
 
42
                                                                                        PointerGetDatum(b)));
 
43
}
 
44
 
 
45
static bool
 
46
gbt_byteaeq(const void *a, const void *b, Oid collation)
 
47
{
 
48
        return DatumGetBool(DirectFunctionCall2(byteaeq,
 
49
                                                                                        PointerGetDatum(a),
 
50
                                                                                        PointerGetDatum(b)));
 
51
}
 
52
 
 
53
static bool
 
54
gbt_byteale(const void *a, const void *b, Oid collation)
 
55
{
 
56
        return DatumGetBool(DirectFunctionCall2(byteale,
 
57
                                                                                        PointerGetDatum(a),
 
58
                                                                                        PointerGetDatum(b)));
 
59
}
 
60
 
 
61
static bool
 
62
gbt_bytealt(const void *a, const void *b, Oid collation)
 
63
{
 
64
        return DatumGetBool(DirectFunctionCall2(bytealt,
 
65
                                                                                        PointerGetDatum(a),
 
66
                                                                                        PointerGetDatum(b)));
 
67
}
 
68
 
 
69
static int32
 
70
gbt_byteacmp(const void *a, const void *b, Oid collation)
 
71
{
 
72
        return DatumGetInt32(DirectFunctionCall2(byteacmp,
 
73
                                                                                         PointerGetDatum(a),
 
74
                                                                                         PointerGetDatum(b)));
 
75
}
 
76
 
 
77
 
 
78
static const gbtree_vinfo tinfo =
 
79
{
 
80
        gbt_t_bytea,
 
81
        0,
 
82
        TRUE,
 
83
        gbt_byteagt,
 
84
        gbt_byteage,
 
85
        gbt_byteaeq,
 
86
        gbt_byteale,
 
87
        gbt_bytealt,
 
88
        gbt_byteacmp,
 
89
        NULL
 
90
};
 
91
 
 
92
 
 
93
/**************************************************
 
94
 * Text ops
 
95
 **************************************************/
 
96
 
 
97
 
 
98
Datum
 
99
gbt_bytea_compress(PG_FUNCTION_ARGS)
 
100
{
 
101
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 
102
 
 
103
        PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
 
104
}
 
105
 
 
106
 
 
107
 
 
108
Datum
 
109
gbt_bytea_consistent(PG_FUNCTION_ARGS)
 
110
{
 
111
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 
112
        void       *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
 
113
        StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
 
114
 
 
115
        /* Oid          subtype = PG_GETARG_OID(3); */
 
116
        bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 
117
        bool            retval;
 
118
        GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
 
119
        GBT_VARKEY_R r = gbt_var_key_readable(key);
 
120
 
 
121
        /* All cases served by this function are exact */
 
122
        *recheck = false;
 
123
 
 
124
        retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
 
125
                                                                GIST_LEAF(entry), &tinfo);
 
126
        PG_RETURN_BOOL(retval);
 
127
}
 
128
 
 
129
 
 
130
 
 
131
Datum
 
132
gbt_bytea_union(PG_FUNCTION_ARGS)
 
133
{
 
134
        GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 
135
        int32      *size = (int *) PG_GETARG_POINTER(1);
 
136
 
 
137
        PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
 
138
                                                                        &tinfo));
 
139
}
 
140
 
 
141
 
 
142
Datum
 
143
gbt_bytea_picksplit(PG_FUNCTION_ARGS)
 
144
{
 
145
        GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 
146
        GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
 
147
 
 
148
        gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
 
149
                                          &tinfo);
 
150
        PG_RETURN_POINTER(v);
 
151
}
 
152
 
 
153
Datum
 
154
gbt_bytea_same(PG_FUNCTION_ARGS)
 
155
{
 
156
        Datum           d1 = PG_GETARG_DATUM(0);
 
157
        Datum           d2 = PG_GETARG_DATUM(1);
 
158
        bool       *result = (bool *) PG_GETARG_POINTER(2);
 
159
 
 
160
        *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
 
161
        PG_RETURN_POINTER(result);
 
162
}
 
163
 
 
164
 
 
165
Datum
 
166
gbt_bytea_penalty(PG_FUNCTION_ARGS)
 
167
{
 
168
        GISTENTRY  *o = (GISTENTRY *) PG_GETARG_POINTER(0);
 
169
        GISTENTRY  *n = (GISTENTRY *) PG_GETARG_POINTER(1);
 
170
        float      *result = (float *) PG_GETARG_POINTER(2);
 
171
 
 
172
        PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
 
173
                                                                          &tinfo));
 
174
}