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,
30  PointerGetDatum(a),
31  PointerGetDatum(b)));
32 }
33 
34 static bool
35 gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
36 {
38  collation,
39  PointerGetDatum(a),
40  PointerGetDatum(b)));
41 }
42 
43 static bool
44 gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
45 {
47  collation,
48  PointerGetDatum(a),
49  PointerGetDatum(b)));
50 }
51 
52 static bool
53 gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
54 {
56  collation,
57  PointerGetDatum(a),
58  PointerGetDatum(b)));
59 }
60 
61 static bool
62 gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
63 {
65  collation,
66  PointerGetDatum(a),
67  PointerGetDatum(b)));
68 }
69 
70 static int32
71 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
72 {
74  collation,
75  PointerGetDatum(a),
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 
94 /**************************************************
95  * Text ops
96  **************************************************/
97 
98 
99 Datum
101 {
102  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
103 
104  if (tinfo.eml == 0)
105  {
107  }
108 
109  PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
110 }
111 
112 Datum
114 {
115  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
116  GISTENTRY *retval;
117 
118  if (tinfo.eml == 0)
119  {
121  }
122 
123  if (entry->leafkey)
124  {
125 
126  Datum d = DirectFunctionCall1(rtrim1, entry->key);
127  GISTENTRY trim;
128 
129  gistentryinit(trim, d,
130  entry->rel, entry->page,
131  entry->offset, true);
132  retval = gbt_var_compress(&trim, &tinfo);
133  }
134  else
135  retval = entry;
136 
137  PG_RETURN_POINTER(retval);
138 }
139 
140 
141 
142 Datum
144 {
145  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
146  void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
148 
149  /* Oid subtype = PG_GETARG_OID(3); */
150  bool *recheck = (bool *) PG_GETARG_POINTER(4);
151  bool retval;
152  GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
154 
155  /* All cases served by this function are exact */
156  *recheck = false;
157 
158  if (tinfo.eml == 0)
159  {
161  }
162 
163  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
164  GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
165 
166  PG_RETURN_BOOL(retval);
167 }
168 
169 
170 Datum
172 {
173  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
174  void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
176 
177  /* Oid subtype = PG_GETARG_OID(3); */
178  bool *recheck = (bool *) PG_GETARG_POINTER(4);
179  bool retval;
180  GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
182  void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
183 
184  /* All cases served by this function are exact */
185  *recheck = false;
186 
187  if (tinfo.eml == 0)
188  {
190  }
191 
192  retval = gbt_var_consistent(&r, trim, strategy, PG_GET_COLLATION(),
193  GIST_LEAF(entry), &tinfo, fcinfo->flinfo);
194  PG_RETURN_BOOL(retval);
195 }
196 
197 
198 Datum
200 {
202  int32 *size = (int *) PG_GETARG_POINTER(1);
203 
205  &tinfo, fcinfo->flinfo));
206 }
207 
208 
209 Datum
211 {
214 
215  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
216  &tinfo, fcinfo->flinfo);
218 }
219 
220 Datum
222 {
223  Datum d1 = PG_GETARG_DATUM(0);
224  Datum d2 = PG_GETARG_DATUM(1);
225  bool *result = (bool *) PG_GETARG_POINTER(2);
226 
227  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
228  PG_RETURN_POINTER(result);
229 }
230 
231 
232 Datum
234 {
237  float *result = (float *) PG_GETARG_POINTER(2);
238 
240  &tinfo, fcinfo->flinfo));
241 }
#define GIST_LEAF(entry)
Definition: gist.h:133
Relation rel
Definition: gist.h:124
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Definition: fmgr.h:56
Datum gbt_text_same(PG_FUNCTION_ARGS)
Definition: btree_text.c:221
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
PG_FUNCTION_INFO_V1(gbt_text_compress)
Datum text_lt(PG_FUNCTION_ARGS)
Definition: varlena.c:1706
#define DatumGetInt32(X)
Definition: postgres.h:478
#define PointerGetDatum(X)
Definition: postgres.h:562
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
static gbtree_vinfo tinfo
Definition: btree_text.c:79
Datum gbt_text_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:143
uint16 StrategyNumber
Definition: stratnum.h:22
bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
Datum gbt_text_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:100
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
unsigned int Oid
Definition: postgres_ext.h:31
static bool gbt_textlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:62
#define PG_GET_COLLATION()
Definition: fmgr.h:163
signed int int32
Definition: c.h:284
Page page
Definition: gist.h:125
static bool gbt_texteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:44
Datum rtrim1(PG_FUNCTION_ARGS)
Datum texteq(PG_FUNCTION_ARGS)
Definition: varlena.c:1642
Datum key
Definition: gist.h:123
int pg_database_encoding_max_length(void)
Definition: wchar.c:1833
#define DatumGetBool(X)
Definition: postgres.h:399
static bool gbt_textle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:53
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
Datum text_gt(PG_FUNCTION_ARGS)
Definition: varlena.c:1736
bool leafkey
Definition: gist.h:127
Datum text_le(PG_FUNCTION_ARGS)
Definition: varlena.c:1721
Datum gbt_text_picksplit(PG_FUNCTION_ARGS)
Definition: btree_text.c:210
Datum gbt_text_union(PG_FUNCTION_ARGS)
Definition: btree_text.c:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
uintptr_t Datum
Definition: postgres.h:372
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
Datum text_ge(PG_FUNCTION_ARGS)
Definition: varlena.c:1751
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS)
Definition: btree_text.c:171
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
Datum gbt_text_penalty(PG_FUNCTION_ARGS)
Definition: btree_text.c:233
#define DatumGetTextP(X)
Definition: fmgr.h:296
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
Datum bttextcmp(PG_FUNCTION_ARGS)
Definition: varlena.c:1766
static int32 gbt_textcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:71
Datum gbt_bpchar_compress(PG_FUNCTION_ARGS)
Definition: btree_text.c:113
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:722
Definition: c.h:487
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
static bool gbt_textge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:35
OffsetNumber offset
Definition: gist.h:126
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
static bool gbt_textgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_text.c:26