PostgreSQL Source Code  git master
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 "utils/builtins.h"
9 
10 /*
11 ** Text ops
12 */
21 
22 
23 /* define for comparison */
24 
25 static bool
26 gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
27 {
29  collation,
31  PointerGetDatum(b)));
32 }
33 
34 static bool
35 gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
36 {
38  collation,
40  PointerGetDatum(b)));
41 }
42 
43 static bool
44 gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
45 {
47  collation,
49  PointerGetDatum(b)));
50 }
51 
52 static bool
53 gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
54 {
56  collation,
58  PointerGetDatum(b)));
59 }
60 
61 static bool
62 gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
63 {
65  collation,
67  PointerGetDatum(b)));
68 }
69 
70 static int32
71 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
72 {
74  collation,
76  PointerGetDatum(b)));
77 }
78 
80 {
81  gbt_t_text,
82  0,
83  false,
84  gbt_textgt,
85  gbt_textge,
86  gbt_texteq,
87  gbt_textle,
88  gbt_textlt,
90  NULL
91 };
92 
93 /* bpchar needs its own comparison rules */
94 
95 static bool
96 gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
97 {
99  collation,
101  PointerGetDatum(b)));
102 }
103 
104 static bool
105 gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
106 {
108  collation,
110  PointerGetDatum(b)));
111 }
112 
113 static bool
114 gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
115 {
117  collation,
119  PointerGetDatum(b)));
120 }
121 
122 static bool
123 gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
124 {
126  collation,
128  PointerGetDatum(b)));
129 }
130 
131 static bool
132 gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
133 {
135  collation,
137  PointerGetDatum(b)));
138 }
139 
140 static int32
141 gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
142 {
144  collation,
146  PointerGetDatum(b)));
147 }
148 
150 {
151  gbt_t_bpchar,
152  0,
153  false,
154  gbt_bpchargt,
155  gbt_bpcharge,
156  gbt_bpchareq,
157  gbt_bpcharle,
158  gbt_bpcharlt,
160  NULL
161 };
162 
163 
164 /**************************************************
165  * Text ops
166  **************************************************/
167 
168 
169 Datum
171 {
172  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
173 
174  if (tinfo.eml == 0)
175  {
177  }
178 
180 }
181 
182 Datum
184 {
185  /* This should never have been distinct from gbt_text_compress */
186  return gbt_text_compress(fcinfo);
187 }
188 
189 
190 
191 Datum
193 {
194  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
195  void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
197 
198  /* Oid subtype = PG_GETARG_OID(3); */
199  bool *recheck = (bool *) PG_GETARG_POINTER(4);
200  bool retval;
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 
218 
219 Datum
221 {
222  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
223  void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
225 
226  /* Oid subtype = PG_GETARG_OID(3); */
227  bool *recheck = (bool *) PG_GETARG_POINTER(4);
228  bool retval;
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 
245 
246 Datum
248 {
250  int32 *size = (int *) PG_GETARG_POINTER(1);
251 
253  &tinfo, fcinfo->flinfo));
254 }
255 
256 
257 Datum
259 {
262 
263  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
264  &tinfo, fcinfo->flinfo);
266 }
267 
268 Datum
270 {
271  Datum d1 = PG_GETARG_DATUM(0);
272  Datum d2 = PG_GETARG_DATUM(1);
273  bool *result = (bool *) PG_GETARG_POINTER(2);
274 
275  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
276  PG_RETURN_POINTER(result);
277 }
278 
279 
280 Datum
282 {
285  float *result = (float *) PG_GETARG_POINTER(2);
286 
288  &tinfo, fcinfo->flinfo));
289 }
@ 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:269
PG_FUNCTION_INFO_V1(gbt_text_compress)
static bool gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:105
Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:220
static int32 gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:141
static bool gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:62
static bool gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:35
Datum gbt_text_picksplit(PG_FUNCTION_ARGS)
Definition: btree_text.c:258
Datum gbt_text_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:170
static bool gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:114
static gbtree_vinfo tinfo
Definition: btree_text.c:79
static int32 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:71
static bool gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:123
Datum gbt_text_penalty(PG_FUNCTION_ARGS)
Definition: btree_text.c:281
static bool gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:132
Datum gbt_text_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:192
Datum gbt_bpchar_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:183
static gbtree_vinfo bptinfo
Definition: btree_text.c:149
static bool gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:44
static bool gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:53
static bool gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:26
Datum gbt_text_union(PG_FUNCTION_ARGS)
Definition: btree_text.c:247
static bool gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:96
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)
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
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)
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
signed int int32
Definition: c.h:429
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:797
#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_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:168
int b
Definition: isn.c:70
int a
Definition: isn.c:69
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1495
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetBool(X)
Definition: postgres.h:437
#define DatumGetPointer(X)
Definition: postgres.h:593
#define DatumGetInt32(X)
Definition: postgres.h:516
#define PointerGetDatum(X)
Definition: postgres.h:600
unsigned int Oid
Definition: postgres_ext.h:31
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:158
Definition: c.h:622
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:738
Datum bpcharle(PG_FUNCTION_ARGS)
Definition: varchar.c:849
Datum text_ge(PG_FUNCTION_ARGS)
Definition: varlena.c:1914
Datum text_le(PG_FUNCTION_ARGS)
Definition: varlena.c:1884
Datum text_gt(PG_FUNCTION_ARGS)
Definition: varlena.c:1899
Datum texteq(PG_FUNCTION_ARGS)
Definition: varlena.c:1757
Datum bttextcmp(PG_FUNCTION_ARGS)
Definition: varlena.c:1969
Datum text_lt(PG_FUNCTION_ARGS)
Definition: varlena.c:1869