2 * contrib/btree_gist/btree_bytea.c
6 #include "btree_gist.h"
7 #include "btree_utils_var.h"
8 #include "utils/builtins.h"
9 #include "utils/bytea.h"
15 PG_FUNCTION_INFO_V1(gbt_bytea_compress);
16 PG_FUNCTION_INFO_V1(gbt_bytea_union);
17 PG_FUNCTION_INFO_V1(gbt_bytea_picksplit);
18 PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
19 PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
20 PG_FUNCTION_INFO_V1(gbt_bytea_same);
23 /* define for comparison */
26 gbt_byteagt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
28 return DatumGetBool(DirectFunctionCall2(byteagt,
34 gbt_byteage(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
36 return DatumGetBool(DirectFunctionCall2(byteage,
42 gbt_byteaeq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
44 return DatumGetBool(DirectFunctionCall2(byteaeq,
50 gbt_byteale(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
52 return DatumGetBool(DirectFunctionCall2(byteale,
58 gbt_bytealt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
60 return DatumGetBool(DirectFunctionCall2(bytealt,
66 gbt_byteacmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
68 return DatumGetInt32(DirectFunctionCall2(byteacmp,
74 static const gbtree_vinfo tinfo =
89 /**************************************************
91 **************************************************/
95 gbt_bytea_compress(PG_FUNCTION_ARGS)
97 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
99 PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
105 gbt_bytea_consistent(PG_FUNCTION_ARGS)
107 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
108 void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
109 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
111 /* Oid subtype = PG_GETARG_OID(3); */
112 bool *recheck = (bool *) PG_GETARG_POINTER(4);
114 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
115 GBT_VARKEY_R r = gbt_var_key_readable(key);
117 /* All cases served by this function are exact */
120 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
121 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
122 PG_RETURN_BOOL(retval);
128 gbt_bytea_union(PG_FUNCTION_ARGS)
130 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
131 int32 *size = (int *) PG_GETARG_POINTER(1);
133 PG_RETURN_POINTER(gbt_var_union(entryvec, size, PG_GET_COLLATION(),
134 &tinfo, fcinfo->flinfo));
139 gbt_bytea_picksplit(PG_FUNCTION_ARGS)
141 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
142 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
144 gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
145 &tinfo, fcinfo->flinfo);
146 PG_RETURN_POINTER(v);
150 gbt_bytea_same(PG_FUNCTION_ARGS)
152 Datum d1 = PG_GETARG_DATUM(0);
153 Datum d2 = PG_GETARG_DATUM(1);
154 bool *result = (bool *) PG_GETARG_POINTER(2);
156 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
157 PG_RETURN_POINTER(result);
162 gbt_bytea_penalty(PG_FUNCTION_ARGS)
164 GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
165 GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
166 float *result = (float *) PG_GETARG_POINTER(2);
168 PG_RETURN_POINTER(gbt_var_penalty(result, o, n, PG_GET_COLLATION(),
169 &tinfo, fcinfo->flinfo));