4 #include "btree_gist.h"
5 #include "btree_utils_var.h"
6 #include "utils/builtins.h"
11 PG_FUNCTION_INFO_V1(gbt_text_compress
);
12 PG_FUNCTION_INFO_V1(gbt_bpchar_compress
);
13 PG_FUNCTION_INFO_V1(gbt_text_union
);
14 PG_FUNCTION_INFO_V1(gbt_text_picksplit
);
15 PG_FUNCTION_INFO_V1(gbt_text_consistent
);
16 PG_FUNCTION_INFO_V1(gbt_bpchar_consistent
);
17 PG_FUNCTION_INFO_V1(gbt_text_penalty
);
18 PG_FUNCTION_INFO_V1(gbt_text_same
);
20 Datum
gbt_text_compress(PG_FUNCTION_ARGS
);
21 Datum
gbt_bpchar_compress(PG_FUNCTION_ARGS
);
22 Datum
gbt_text_union(PG_FUNCTION_ARGS
);
23 Datum
gbt_text_picksplit(PG_FUNCTION_ARGS
);
24 Datum
gbt_text_consistent(PG_FUNCTION_ARGS
);
25 Datum
gbt_bpchar_consistent(PG_FUNCTION_ARGS
);
26 Datum
gbt_text_penalty(PG_FUNCTION_ARGS
);
27 Datum
gbt_text_same(PG_FUNCTION_ARGS
);
30 /* define for comparison */
33 gbt_textgt(const void *a
, const void *b
)
35 return (DatumGetBool(DirectFunctionCall2(text_gt
, PointerGetDatum(a
), PointerGetDatum(b
))));
39 gbt_textge(const void *a
, const void *b
)
41 return (DatumGetBool(DirectFunctionCall2(text_ge
, PointerGetDatum(a
), PointerGetDatum(b
))));
45 gbt_texteq(const void *a
, const void *b
)
47 return (DatumGetBool(DirectFunctionCall2(texteq
, PointerGetDatum(a
), PointerGetDatum(b
))));
51 gbt_textle(const void *a
, const void *b
)
53 return (DatumGetBool(DirectFunctionCall2(text_le
, PointerGetDatum(a
), PointerGetDatum(b
))));
57 gbt_textlt(const void *a
, const void *b
)
59 return (DatumGetBool(DirectFunctionCall2(text_lt
, PointerGetDatum(a
), PointerGetDatum(b
))));
63 gbt_textcmp(const bytea
*a
, const bytea
*b
)
65 return DatumGetInt32(DirectFunctionCall2(bttextcmp
, PointerGetDatum(a
), PointerGetDatum(b
)));
68 static gbtree_vinfo tinfo
=
83 /**************************************************
85 **************************************************/
89 gbt_text_compress(PG_FUNCTION_ARGS
)
91 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
95 tinfo
.eml
= pg_database_encoding_max_length();
98 PG_RETURN_POINTER(gbt_var_compress(entry
, &tinfo
));
102 gbt_bpchar_compress(PG_FUNCTION_ARGS
)
105 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
110 tinfo
.eml
= pg_database_encoding_max_length();
116 Datum d
= DirectFunctionCall1(rtrim1
, entry
->key
);
119 gistentryinit(trim
, d
,
120 entry
->rel
, entry
->page
,
121 entry
->offset
, TRUE
);
122 retval
= gbt_var_compress(&trim
, &tinfo
);
127 PG_RETURN_POINTER(retval
);
133 gbt_text_consistent(PG_FUNCTION_ARGS
)
135 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
136 void *query
= (void *) DatumGetTextP(PG_GETARG_DATUM(1));
137 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
139 /* Oid subtype = PG_GETARG_OID(3); */
140 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
142 GBT_VARKEY
*key
= (GBT_VARKEY
*) DatumGetPointer(entry
->key
);
143 GBT_VARKEY_R r
= gbt_var_key_readable(key
);
145 /* All cases served by this function are exact */
150 tinfo
.eml
= pg_database_encoding_max_length();
153 retval
= gbt_var_consistent(&r
, query
, &strategy
, GIST_LEAF(entry
), &tinfo
);
155 PG_RETURN_BOOL(retval
);
160 gbt_bpchar_consistent(PG_FUNCTION_ARGS
)
162 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
163 void *query
= (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
164 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
166 /* Oid subtype = PG_GETARG_OID(3); */
167 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
169 GBT_VARKEY
*key
= (GBT_VARKEY
*) DatumGetPointer(entry
->key
);
170 GBT_VARKEY_R r
= gbt_var_key_readable(key
);
171 void *trim
= (void *) DatumGetPointer(DirectFunctionCall1(rtrim1
, PointerGetDatum(query
)));
173 /* All cases served by this function are exact */
178 tinfo
.eml
= pg_database_encoding_max_length();
181 retval
= gbt_var_consistent(&r
, trim
, &strategy
, GIST_LEAF(entry
), &tinfo
);
182 PG_RETURN_BOOL(retval
);
187 gbt_text_union(PG_FUNCTION_ARGS
)
189 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
190 int32
*size
= (int *) PG_GETARG_POINTER(1);
192 PG_RETURN_POINTER(gbt_var_union(entryvec
, size
, &tinfo
));
197 gbt_text_picksplit(PG_FUNCTION_ARGS
)
199 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
200 GIST_SPLITVEC
*v
= (GIST_SPLITVEC
*) PG_GETARG_POINTER(1);
202 gbt_var_picksplit(entryvec
, v
, &tinfo
);
203 PG_RETURN_POINTER(v
);
207 gbt_text_same(PG_FUNCTION_ARGS
)
209 Datum d1
= PG_GETARG_DATUM(0);
210 Datum d2
= PG_GETARG_DATUM(1);
211 bool *result
= (bool *) PG_GETARG_POINTER(2);
213 PG_RETURN_POINTER(gbt_var_same(result
, d1
, d2
, &tinfo
));
218 gbt_text_penalty(PG_FUNCTION_ARGS
)
220 GISTENTRY
*o
= (GISTENTRY
*) PG_GETARG_POINTER(0);
221 GISTENTRY
*n
= (GISTENTRY
*) PG_GETARG_POINTER(1);
222 float *result
= (float *) PG_GETARG_POINTER(2);
224 PG_RETURN_POINTER(gbt_var_penalty(result
, o
, n
, &tinfo
));