2 * contrib/btree_gist/btree_text.c
4 #include "btree_gist.h"
5 #include "btree_utils_var.h"
6 #include "catalog/pg_collation.h"
7 #include "utils/builtins.h"
12 PG_FUNCTION_INFO_V1(gbt_text_compress);
13 PG_FUNCTION_INFO_V1(gbt_bpchar_compress);
14 PG_FUNCTION_INFO_V1(gbt_text_union);
15 PG_FUNCTION_INFO_V1(gbt_text_picksplit);
16 PG_FUNCTION_INFO_V1(gbt_text_consistent);
17 PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
18 PG_FUNCTION_INFO_V1(gbt_text_penalty);
19 PG_FUNCTION_INFO_V1(gbt_text_same);
21 Datum gbt_text_compress(PG_FUNCTION_ARGS);
22 Datum gbt_bpchar_compress(PG_FUNCTION_ARGS);
23 Datum gbt_text_union(PG_FUNCTION_ARGS);
24 Datum gbt_text_picksplit(PG_FUNCTION_ARGS);
25 Datum gbt_text_consistent(PG_FUNCTION_ARGS);
26 Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS);
27 Datum gbt_text_penalty(PG_FUNCTION_ARGS);
28 Datum gbt_text_same(PG_FUNCTION_ARGS);
31 /* define for comparison */
34 gbt_textgt(const void *a, const void *b)
36 return (DatumGetBool(DirectFunctionCall2WithCollation(text_gt, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))));
40 gbt_textge(const void *a, const void *b)
42 return (DatumGetBool(DirectFunctionCall2WithCollation(text_ge, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))));
46 gbt_texteq(const void *a, const void *b)
48 return (DatumGetBool(DirectFunctionCall2WithCollation(texteq, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))));
52 gbt_textle(const void *a, const void *b)
54 return (DatumGetBool(DirectFunctionCall2WithCollation(text_le, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))));
58 gbt_textlt(const void *a, const void *b)
60 return (DatumGetBool(DirectFunctionCall2WithCollation(text_lt, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b))));
64 gbt_textcmp(const bytea *a, const bytea *b)
66 return DatumGetInt32(DirectFunctionCall2WithCollation(bttextcmp, DEFAULT_COLLATION_OID, PointerGetDatum(a), PointerGetDatum(b)));
69 static gbtree_vinfo tinfo =
84 /**************************************************
86 **************************************************/
90 gbt_text_compress(PG_FUNCTION_ARGS)
92 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
96 tinfo.eml = pg_database_encoding_max_length();
99 PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
103 gbt_bpchar_compress(PG_FUNCTION_ARGS)
106 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
111 tinfo.eml = pg_database_encoding_max_length();
117 Datum d = DirectFunctionCall1(rtrim1, entry->key);
120 gistentryinit(trim, d,
121 entry->rel, entry->page,
122 entry->offset, TRUE);
123 retval = gbt_var_compress(&trim, &tinfo);
128 PG_RETURN_POINTER(retval);
134 gbt_text_consistent(PG_FUNCTION_ARGS)
136 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
137 void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
138 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
140 /* Oid subtype = PG_GETARG_OID(3); */
141 bool *recheck = (bool *) PG_GETARG_POINTER(4);
143 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
144 GBT_VARKEY_R r = gbt_var_key_readable(key);
146 /* All cases served by this function are exact */
151 tinfo.eml = pg_database_encoding_max_length();
154 retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
156 PG_RETURN_BOOL(retval);
161 gbt_bpchar_consistent(PG_FUNCTION_ARGS)
163 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
164 void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
165 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
167 /* Oid subtype = PG_GETARG_OID(3); */
168 bool *recheck = (bool *) PG_GETARG_POINTER(4);
170 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
171 GBT_VARKEY_R r = gbt_var_key_readable(key);
172 void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
174 /* All cases served by this function are exact */
179 tinfo.eml = pg_database_encoding_max_length();
182 retval = gbt_var_consistent(&r, trim, &strategy, GIST_LEAF(entry), &tinfo);
183 PG_RETURN_BOOL(retval);
188 gbt_text_union(PG_FUNCTION_ARGS)
190 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
191 int32 *size = (int *) PG_GETARG_POINTER(1);
193 PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
198 gbt_text_picksplit(PG_FUNCTION_ARGS)
200 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
201 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
203 gbt_var_picksplit(entryvec, v, &tinfo);
204 PG_RETURN_POINTER(v);
208 gbt_text_same(PG_FUNCTION_ARGS)
210 Datum d1 = PG_GETARG_DATUM(0);
211 Datum d2 = PG_GETARG_DATUM(1);
212 bool *result = (bool *) PG_GETARG_POINTER(2);
214 PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
219 gbt_text_penalty(PG_FUNCTION_ARGS)
221 GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
222 GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
223 float *result = (float *) PG_GETARG_POINTER(2);
225 PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));