PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree_text.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_text.c
3 */
4#include "postgres.h"
5
6#include "btree_gist.h"
7#include "btree_utils_var.h"
8#include "mb/pg_wchar.h"
9#include "utils/fmgrprotos.h"
10#include "utils/sortsupport.h"
11
12/* GiST support functions */
23
24
25/* define for comparison */
26
27static bool
28gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
29{
31 collation,
34}
35
36static bool
37gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
38{
40 collation,
43}
44
45static bool
46gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
47{
49 collation,
52}
53
54static bool
55gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
56{
58 collation,
61}
62
63static bool
64gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
65{
67 collation,
70}
71
72static int32
73gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
74{
76 collation,
79}
80
82{
84 0,
85 false,
92 NULL
93};
94
95/* bpchar needs its own comparison rules */
96
97static bool
98gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
99{
101 collation,
104}
105
106static bool
107gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
108{
110 collation,
113}
114
115static bool
116gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
117{
119 collation,
122}
123
124static bool
125gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
126{
128 collation,
131}
132
133static bool
134gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
135{
137 collation,
140}
141
142static int32
143gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
144{
146 collation,
149}
150
152{
154 0,
155 false,
162 NULL
163};
164
165
166/**************************************************
167 * GiST support functions
168 **************************************************/
169
170Datum
172{
173 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
174
175 if (tinfo.eml == 0)
176 {
178 }
179
181}
182
183Datum
185{
186 /* This should never have been distinct from gbt_text_compress */
187 return gbt_text_compress(fcinfo);
188}
189
190Datum
192{
193 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
194 void *query = DatumGetTextP(PG_GETARG_DATUM(1));
196
197 /* Oid subtype = PG_GETARG_OID(3); */
198 bool *recheck = (bool *) PG_GETARG_POINTER(4);
199 bool retval;
202
203 /* All cases served by this function are exact */
204 *recheck = false;
205
206 if (tinfo.eml == 0)
207 {
209 }
210
211 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
212 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
213
214 PG_RETURN_BOOL(retval);
215}
216
217Datum
219{
220 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
221 void *query = DatumGetTextP(PG_GETARG_DATUM(1));
223
224 /* Oid subtype = PG_GETARG_OID(3); */
225 bool *recheck = (bool *) PG_GETARG_POINTER(4);
226 bool retval;
229
230 /* All cases served by this function are exact */
231 *recheck = false;
232
233 if (bptinfo.eml == 0)
234 {
236 }
237
238 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
239 GIST_LEAF(entry), &bptinfo, fcinfo->flinfo);
240 PG_RETURN_BOOL(retval);
241}
242
243Datum
245{
247 int32 *size = (int *) PG_GETARG_POINTER(1);
248
250 &tinfo, fcinfo->flinfo));
251}
252
253Datum
255{
258
259 gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
260 &tinfo, fcinfo->flinfo);
262}
263
264Datum
266{
267 Datum d1 = PG_GETARG_DATUM(0);
268 Datum d2 = PG_GETARG_DATUM(1);
269 bool *result = (bool *) PG_GETARG_POINTER(2);
270
271 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
272 PG_RETURN_POINTER(result);
273}
274
275Datum
277{
280 float *result = (float *) PG_GETARG_POINTER(2);
281
283 &tinfo, fcinfo->flinfo));
284}
285
286static int
288{
291
294 Datum result;
295
296 /* for leaf items we expect lower == upper, so only compare lower */
298 ssup->ssup_collation,
300 PointerGetDatum(arg2.lower));
301
302 GBT_FREE_IF_COPY(key1, x);
303 GBT_FREE_IF_COPY(key2, y);
304
305 return DatumGetInt32(result);
306}
307
308Datum
310{
312
314 ssup->ssup_extra = NULL;
315
317}
318
319static int
321{
324
327 Datum result;
328
329 /* for leaf items we expect lower == upper, so only compare lower */
331 ssup->ssup_collation,
333 PointerGetDatum(arg2.lower));
334
335 GBT_FREE_IF_COPY(key1, x);
336 GBT_FREE_IF_COPY(key2, y);
337
338 return DatumGetInt32(result);
339}
340
341Datum
343{
345
347 ssup->ssup_extra = NULL;
348
350}
@ gbt_t_text
Definition: btree_gist.h:31
@ gbt_t_bpchar
Definition: btree_gist.h:32
Datum gbt_text_same(PG_FUNCTION_ARGS)
Definition: btree_text.c:265
PG_FUNCTION_INFO_V1(gbt_text_compress)
Datum gbt_bpchar_sortsupport(PG_FUNCTION_ARGS)
Definition: btree_text.c:342
static bool gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:107
Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:218
static int32 gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:143
static bool gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:64
static int gbt_bpchar_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_text.c:320
static bool gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:37
Datum gbt_text_picksplit(PG_FUNCTION_ARGS)
Definition: btree_text.c:254
Datum gbt_text_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:171
static bool gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:116
static gbtree_vinfo tinfo
Definition: btree_text.c:81
static int32 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:73
static bool gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:125
Datum gbt_text_penalty(PG_FUNCTION_ARGS)
Definition: btree_text.c:276
static bool gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:134
Datum gbt_text_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:191
Datum gbt_bpchar_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:184
Datum gbt_text_sortsupport(PG_FUNCTION_ARGS)
Definition: btree_text.c:309
static int gbt_text_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_text.c:287
static gbtree_vinfo bptinfo
Definition: btree_text.c:151
static bool gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:46
static bool gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:55
static bool gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:28
Datum gbt_text_union(PG_FUNCTION_ARGS)
Definition: btree_text.c:244
static bool gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:98
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define GBT_FREE_IF_COPY(ptr1, ptr2)
int32_t int32
Definition: c.h:498
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:812
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_GET_COLLATION()
Definition: fmgr.h:198
#define DatumGetTextP(X)
Definition: fmgr.h:332
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:171
int y
Definition: isn.c:76
int b
Definition: isn.c:74
int x
Definition: isn.c:75
int a
Definition: isn.c:73
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1546
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
uintptr_t Datum
Definition: postgres.h:69
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
unsigned int Oid
Definition: postgres_ext.h:30
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:161
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87
Definition: c.h:658
Datum bpchargt(PG_FUNCTION_ARGS)
Definition: varchar.c:867
Datum bpcharge(PG_FUNCTION_ARGS)
Definition: varchar.c:888
Datum bpcharlt(PG_FUNCTION_ARGS)
Definition: varchar.c:825
Datum bpcharcmp(PG_FUNCTION_ARGS)
Definition: varchar.c:909
Datum bpchareq(PG_FUNCTION_ARGS)
Definition: varchar.c:743
Datum bpcharle(PG_FUNCTION_ARGS)
Definition: varchar.c:846
Datum text_ge(PG_FUNCTION_ARGS)
Definition: varlena.c:1832
Datum text_le(PG_FUNCTION_ARGS)
Definition: varlena.c:1802
Datum text_gt(PG_FUNCTION_ARGS)
Definition: varlena.c:1817
Datum texteq(PG_FUNCTION_ARGS)
Definition: varlena.c:1683
Datum bttextcmp(PG_FUNCTION_ARGS)
Definition: varlena.c:1886
Datum text_lt(PG_FUNCTION_ARGS)
Definition: varlena.c:1787