PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_text.c
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_text.c
3 *
4 * Support for text and bpchar types.
5 */
6#include "postgres.h"
7
8#include "btree_gist.h"
9#include "btree_utils_var.h"
10#include "mb/pg_wchar.h"
11#include "utils/fmgrprotos.h"
12#include "utils/sortsupport.h"
13
14/* GiST support functions */
25
26
27/* define for comparison */
28
29static bool
30gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
31{
33 collation,
36}
37
38static bool
39gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
40{
42 collation,
45}
46
47static bool
48gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
49{
51 collation,
54}
55
56static bool
57gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
58{
60 collation,
63}
64
65static bool
66gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
67{
69 collation,
72}
73
74static int32
75gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
76{
78 collation,
81}
82
83/*
84 * Originally this module permitted truncation of internal keys, but that
85 * tends to result in wrong comparison answers if the collation is any
86 * more complicated than C. The prefix-match hack used for simpler types
87 * can't fix it, either.
88 */
89static const gbtree_vinfo tinfo =
90{
92 false, /* no truncation permitted */
99 NULL
100};
101
102/* bpchar needs its own comparison rules */
103
104static bool
105gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
106{
108 collation,
111}
112
113static bool
114gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
115{
117 collation,
120}
121
122static bool
123gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
124{
126 collation,
129}
130
131static bool
132gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
133{
135 collation,
138}
139
140static bool
141gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
142{
144 collation,
147}
148
149static int32
150gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
151{
153 collation,
156}
157
158static const gbtree_vinfo bptinfo =
159{
161 false, /* as above, no truncation permitted */
168 NULL
169};
170
171
172/**************************************************
173 * GiST support functions
174 **************************************************/
175
176Datum
183
184Datum
186{
187 /* This should never have been distinct from gbt_text_compress */
188 return gbt_text_compress(fcinfo);
189}
190
191Datum
193{
194 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
195 void *query = DatumGetTextP(PG_GETARG_DATUM(1));
197#ifdef NOT_USED
198 Oid subtype = PG_GETARG_OID(3);
199#endif
200 bool *recheck = (bool *) PG_GETARG_POINTER(4);
201 bool retval;
202 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
204
205 /* All cases served by this function are exact */
206 *recheck = false;
207
208 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
209 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
210
211 PG_RETURN_BOOL(retval);
212}
213
214Datum
216{
217 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
218 void *query = DatumGetTextP(PG_GETARG_DATUM(1));
220#ifdef NOT_USED
221 Oid subtype = PG_GETARG_OID(3);
222#endif
223 bool *recheck = (bool *) PG_GETARG_POINTER(4);
224 bool retval;
225 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
227
228 /* All cases served by this function are exact */
229 *recheck = false;
230
231 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
232 GIST_LEAF(entry), &bptinfo, fcinfo->flinfo);
233 PG_RETURN_BOOL(retval);
234}
235
236Datum
245
246Datum
256
257Datum
259{
260 Datum d1 = PG_GETARG_DATUM(0);
261 Datum d2 = PG_GETARG_DATUM(1);
262 bool *result = (bool *) PG_GETARG_POINTER(2);
263
264 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
266}
267
268Datum
270{
273 float *result = (float *) PG_GETARG_POINTER(2);
274
276 &tinfo, fcinfo->flinfo));
277}
278
279static int
281{
284
288
289 /* for leaf items we expect lower == upper, so only compare lower */
291 ssup->ssup_collation,
292 PointerGetDatum(arg1.lower),
293 PointerGetDatum(arg2.lower));
294
297
298 return DatumGetInt32(result);
299}
300
301Datum
311
312static int
314{
317
321
322 /* for leaf items we expect lower == upper, so only compare lower */
324 ssup->ssup_collation,
325 PointerGetDatum(arg1.lower),
326 PointerGetDatum(arg2.lower));
327
330
331 return DatumGetInt32(result);
332}
333
334Datum
@ 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:258
Datum gbt_bpchar_sortsupport(PG_FUNCTION_ARGS)
Definition btree_text.c:335
static bool gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:114
Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS)
Definition btree_text.c:215
static int32 gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:150
static bool gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:66
static int gbt_bpchar_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_text.c:313
static bool gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:39
static const gbtree_vinfo bptinfo
Definition btree_text.c:158
Datum gbt_text_picksplit(PG_FUNCTION_ARGS)
Definition btree_text.c:247
Datum gbt_text_compress(PG_FUNCTION_ARGS)
Definition btree_text.c:177
static bool gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:123
static int32 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:75
static bool gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:132
static const gbtree_vinfo tinfo
Definition btree_text.c:89
Datum gbt_text_penalty(PG_FUNCTION_ARGS)
Definition btree_text.c:269
static bool gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:141
Datum gbt_text_consistent(PG_FUNCTION_ARGS)
Definition btree_text.c:192
Datum gbt_bpchar_compress(PG_FUNCTION_ARGS)
Definition btree_text.c:185
Datum gbt_text_sortsupport(PG_FUNCTION_ARGS)
Definition btree_text.c:302
static int gbt_text_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_text.c:280
static bool gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:48
static bool gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:57
static bool gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:30
Datum gbt_text_union(PG_FUNCTION_ARGS)
Definition btree_text.c:237
static bool gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition btree_text.c:105
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
bool gbt_var_consistent(const 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:679
uint32 result
struct SortSupportData * SortSupport
Definition execnodes.h:61
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition fmgr.c:814
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#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:363
#define PG_GET_COLLATION()
Definition fmgr.h:198
#define DatumGetTextP(X)
Definition fmgr.h:333
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
#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
static bool DatumGetBool(Datum X)
Definition postgres.h:100
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
#define PointerGetDatum(X)
Definition postgres.h:354
unsigned int Oid
static int fb(int x)
uint16 StrategyNumber
Definition stratnum.h:22
Datum key
Definition gist.h:161
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition c.h:835
Datum bpchargt(PG_FUNCTION_ARGS)
Definition varchar.c:870
Datum bpcharge(PG_FUNCTION_ARGS)
Definition varchar.c:891
Datum bpcharlt(PG_FUNCTION_ARGS)
Definition varchar.c:828
Datum bpcharcmp(PG_FUNCTION_ARGS)
Definition varchar.c:912
Datum bpchareq(PG_FUNCTION_ARGS)
Definition varchar.c:746
Datum bpcharle(PG_FUNCTION_ARGS)
Definition varchar.c:849
Datum text_ge(PG_FUNCTION_ARGS)
Definition varlena.c:1578
Datum text_le(PG_FUNCTION_ARGS)
Definition varlena.c:1548
Datum text_gt(PG_FUNCTION_ARGS)
Definition varlena.c:1563
Datum texteq(PG_FUNCTION_ARGS)
Definition varlena.c:1429
Datum bttextcmp(PG_FUNCTION_ARGS)
Definition varlena.c:1632
Datum text_lt(PG_FUNCTION_ARGS)
Definition varlena.c:1533