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 "mb/pg_wchar.h"
9 #include "utils/fmgrprotos.h"
10 
11 /*
12 ** Text ops
13 */
22 
23 
24 /* define for comparison */
25 
26 static bool
27 gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
28 {
30  collation,
32  PointerGetDatum(b)));
33 }
34 
35 static bool
36 gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
37 {
39  collation,
41  PointerGetDatum(b)));
42 }
43 
44 static bool
45 gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
46 {
48  collation,
50  PointerGetDatum(b)));
51 }
52 
53 static bool
54 gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
55 {
57  collation,
59  PointerGetDatum(b)));
60 }
61 
62 static bool
63 gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
64 {
66  collation,
68  PointerGetDatum(b)));
69 }
70 
71 static int32
72 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
73 {
75  collation,
77  PointerGetDatum(b)));
78 }
79 
81 {
82  gbt_t_text,
83  0,
84  false,
85  gbt_textgt,
86  gbt_textge,
87  gbt_texteq,
88  gbt_textle,
89  gbt_textlt,
91  NULL
92 };
93 
94 /* bpchar needs its own comparison rules */
95 
96 static bool
97 gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
98 {
100  collation,
102  PointerGetDatum(b)));
103 }
104 
105 static bool
106 gbt_bpcharge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
107 {
109  collation,
111  PointerGetDatum(b)));
112 }
113 
114 static bool
115 gbt_bpchareq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
116 {
118  collation,
120  PointerGetDatum(b)));
121 }
122 
123 static bool
124 gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
125 {
127  collation,
129  PointerGetDatum(b)));
130 }
131 
132 static bool
133 gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
134 {
136  collation,
138  PointerGetDatum(b)));
139 }
140 
141 static int32
142 gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
143 {
145  collation,
147  PointerGetDatum(b)));
148 }
149 
151 {
152  gbt_t_bpchar,
153  0,
154  false,
155  gbt_bpchargt,
156  gbt_bpcharge,
157  gbt_bpchareq,
158  gbt_bpcharle,
159  gbt_bpcharlt,
161  NULL
162 };
163 
164 
165 /**************************************************
166  * Text ops
167  **************************************************/
168 
169 
170 Datum
172 {
173  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
174 
175  if (tinfo.eml == 0)
176  {
178  }
179 
181 }
182 
183 Datum
185 {
186  /* This should never have been distinct from gbt_text_compress */
187  return gbt_text_compress(fcinfo);
188 }
189 
190 
191 
192 Datum
194 {
195  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
196  void *query = DatumGetTextP(PG_GETARG_DATUM(1));
198 
199  /* Oid subtype = PG_GETARG_OID(3); */
200  bool *recheck = (bool *) PG_GETARG_POINTER(4);
201  bool retval;
204 
205  /* All cases served by this function are exact */
206  *recheck = false;
207 
208  if (tinfo.eml == 0)
209  {
211  }
212 
213  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
214  GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
215 
216  PG_RETURN_BOOL(retval);
217 }
218 
219 
220 Datum
222 {
223  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
224  void *query = DatumGetTextP(PG_GETARG_DATUM(1));
226 
227  /* Oid subtype = PG_GETARG_OID(3); */
228  bool *recheck = (bool *) PG_GETARG_POINTER(4);
229  bool retval;
232 
233  /* All cases served by this function are exact */
234  *recheck = false;
235 
236  if (bptinfo.eml == 0)
237  {
239  }
240 
241  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
242  GIST_LEAF(entry), &bptinfo, fcinfo->flinfo);
243  PG_RETURN_BOOL(retval);
244 }
245 
246 
247 Datum
249 {
251  int32 *size = (int *) PG_GETARG_POINTER(1);
252 
254  &tinfo, fcinfo->flinfo));
255 }
256 
257 
258 Datum
260 {
263 
264  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
265  &tinfo, fcinfo->flinfo);
267 }
268 
269 Datum
271 {
272  Datum d1 = PG_GETARG_DATUM(0);
273  Datum d2 = PG_GETARG_DATUM(1);
274  bool *result = (bool *) PG_GETARG_POINTER(2);
275 
276  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
277  PG_RETURN_POINTER(result);
278 }
279 
280 
281 Datum
283 {
286  float *result = (float *) PG_GETARG_POINTER(2);
287 
289  &tinfo, fcinfo->flinfo));
290 }
@ 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:270
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:106
Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:221
static int32 gbt_bpcharcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:142
static bool gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:63
static bool gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:36
Datum gbt_text_picksplit(PG_FUNCTION_ARGS)
Definition: btree_text.c:259
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:115
static gbtree_vinfo tinfo
Definition: btree_text.c:80
static int32 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:72
static bool gbt_bpcharle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:124
Datum gbt_text_penalty(PG_FUNCTION_ARGS)
Definition: btree_text.c:282
static bool gbt_bpcharlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:133
Datum gbt_text_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:193
Datum gbt_bpchar_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:184
static gbtree_vinfo bptinfo
Definition: btree_text.c:150
static bool gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:45
static bool gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:54
static bool gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:27
Datum gbt_text_union(PG_FUNCTION_ARGS)
Definition: btree_text.c:248
static bool gbt_bpchargt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:97
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:482
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:812
#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:170
int b
Definition: isn.c:69
int a
Definition: isn.c:68
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1546
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
unsigned int Oid
Definition: postgres_ext.h:31
static pg_noinline void Size size
Definition: slab.c:607
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:160
Definition: c.h:666
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:1760
Datum text_le(PG_FUNCTION_ARGS)
Definition: varlena.c:1730
Datum text_gt(PG_FUNCTION_ARGS)
Definition: varlena.c:1745
Datum texteq(PG_FUNCTION_ARGS)
Definition: varlena.c:1611
Datum bttextcmp(PG_FUNCTION_ARGS)
Definition: varlena.c:1814
Datum text_lt(PG_FUNCTION_ARGS)
Definition: varlena.c:1715