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#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
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#ifdef NOT_USED
197 Oid subtype = PG_GETARG_OID(3);
198#endif
199 bool *recheck = (bool *) PG_GETARG_POINTER(4);
200 bool retval;
201 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
203
204 /* All cases served by this function are exact */
205 *recheck = false;
206
207 if (tinfo.eml == 0)
208 {
210 }
211
212 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
213 GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
214
215 PG_RETURN_BOOL(retval);
216}
217
218Datum
220{
221 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
222 void *query = DatumGetTextP(PG_GETARG_DATUM(1));
224#ifdef NOT_USED
225 Oid subtype = PG_GETARG_OID(3);
226#endif
227 bool *recheck = (bool *) PG_GETARG_POINTER(4);
228 bool retval;
229 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
231
232 /* All cases served by this function are exact */
233 *recheck = false;
234
235 if (bptinfo.eml == 0)
236 {
238 }
239
240 retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
241 GIST_LEAF(entry), &bptinfo, fcinfo->flinfo);
242 PG_RETURN_BOOL(retval);
243}
244
245Datum
254
255Datum
265
266Datum
268{
269 Datum d1 = PG_GETARG_DATUM(0);
270 Datum d2 = PG_GETARG_DATUM(1);
271 bool *result = (bool *) PG_GETARG_POINTER(2);
272
273 *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
274 PG_RETURN_POINTER(result);
275}
276
277Datum
279{
282 float *result = (float *) PG_GETARG_POINTER(2);
283
285 &tinfo, fcinfo->flinfo));
286}
287
288static int
290{
293
296 Datum result;
297
298 /* for leaf items we expect lower == upper, so only compare lower */
300 ssup->ssup_collation,
301 PointerGetDatum(arg1.lower),
302 PointerGetDatum(arg2.lower));
303
306
307 return DatumGetInt32(result);
308}
309
310Datum
320
321static int
323{
326
329 Datum result;
330
331 /* for leaf items we expect lower == upper, so only compare lower */
333 ssup->ssup_collation,
334 PointerGetDatum(arg1.lower),
335 PointerGetDatum(arg2.lower));
336
339
340 return DatumGetInt32(result);
341}
342
343Datum
@ 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:267
Datum gbt_bpchar_sortsupport(PG_FUNCTION_ARGS)
Definition btree_text.c:344
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:219
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:322
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:256
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:278
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:311
static int gbt_text_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_text.c:289
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:246
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:542
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition fmgr.c:813
#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
int pg_database_encoding_max_length(void)
Definition mbutils.c:1549
static bool DatumGetBool(Datum X)
Definition postgres.h:100
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
static int32 DatumGetInt32(Datum X)
Definition postgres.h:212
unsigned int Oid
static int fb(int x)
struct SortSupportData * SortSupport
Definition sortsupport.h:58
uint16 StrategyNumber
Definition stratnum.h:22
Datum key
Definition gist.h:161
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition c.h:706
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:1530
Datum text_le(PG_FUNCTION_ARGS)
Definition varlena.c:1500
Datum text_gt(PG_FUNCTION_ARGS)
Definition varlena.c:1515
Datum texteq(PG_FUNCTION_ARGS)
Definition varlena.c:1381
Datum bttextcmp(PG_FUNCTION_ARGS)
Definition varlena.c:1584
Datum text_lt(PG_FUNCTION_ARGS)
Definition varlena.c:1485