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);
138 /* Oid subtype = PG_GETARG_OID(3); */
139 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
141 GBT_VARKEY
*key
= (GBT_VARKEY
*) DatumGetPointer(entry
->key
);
142 GBT_VARKEY_R r
= gbt_var_key_readable(key
);
144 /* All cases served by this function are exact */
149 tinfo
.eml
= pg_database_encoding_max_length();
152 retval
= gbt_var_consistent(&r
, query
, &strategy
, GIST_LEAF(entry
), &tinfo
);
154 PG_RETURN_BOOL(retval
);
159 gbt_bpchar_consistent(PG_FUNCTION_ARGS
)
161 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
162 void *query
= (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
163 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
164 /* Oid subtype = PG_GETARG_OID(3); */
165 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
167 GBT_VARKEY
*key
= (GBT_VARKEY
*) DatumGetPointer(entry
->key
);
168 GBT_VARKEY_R r
= gbt_var_key_readable(key
);
169 void *trim
= (void *) DatumGetPointer(DirectFunctionCall1(rtrim1
, PointerGetDatum(query
)));
171 /* All cases served by this function are exact */
176 tinfo
.eml
= pg_database_encoding_max_length();
179 retval
= gbt_var_consistent(&r
, trim
, &strategy
, GIST_LEAF(entry
), &tinfo
);
180 PG_RETURN_BOOL(retval
);
185 gbt_text_union(PG_FUNCTION_ARGS
)
187 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
188 int32
*size
= (int *) PG_GETARG_POINTER(1);
190 PG_RETURN_POINTER(gbt_var_union(entryvec
, size
, &tinfo
));
195 gbt_text_picksplit(PG_FUNCTION_ARGS
)
197 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
198 GIST_SPLITVEC
*v
= (GIST_SPLITVEC
*) PG_GETARG_POINTER(1);
200 gbt_var_picksplit(entryvec
, v
, &tinfo
);
201 PG_RETURN_POINTER(v
);
205 gbt_text_same(PG_FUNCTION_ARGS
)
207 Datum d1
= PG_GETARG_DATUM(0);
208 Datum d2
= PG_GETARG_DATUM(1);
209 bool *result
= (bool *) PG_GETARG_POINTER(2);
211 PG_RETURN_POINTER(gbt_var_same(result
, d1
, d2
, &tinfo
));
216 gbt_text_penalty(PG_FUNCTION_ARGS
)
218 GISTENTRY
*o
= (GISTENTRY
*) PG_GETARG_POINTER(0);
219 GISTENTRY
*n
= (GISTENTRY
*) PG_GETARG_POINTER(1);
220 float *result
= (float *) PG_GETARG_POINTER(2);
222 PG_RETURN_POINTER(gbt_var_penalty(result
, o
, n
, &tinfo
));