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