Only skip pages marked as clean in the visibility map, if the last 32
[PostgreSQL.git] / contrib / btree_gist / btree_text.c
blob4966dd35f391a63ba17780fbcc9d97a74413a7d2
1 /*
2 * $PostgreSQL:$
3 */
4 #include "btree_gist.h"
5 #include "btree_utils_var.h"
6 #include "utils/builtins.h"
8 /*
9 ** Text ops
11 PG_FUNCTION_INFO_V1(gbt_text_compress);
12 PG_FUNCTION_INFO_V1(gbt_bpchar_compress);
13 PG_FUNCTION_INFO_V1(gbt_text_union);
14 PG_FUNCTION_INFO_V1(gbt_text_picksplit);
15 PG_FUNCTION_INFO_V1(gbt_text_consistent);
16 PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
17 PG_FUNCTION_INFO_V1(gbt_text_penalty);
18 PG_FUNCTION_INFO_V1(gbt_text_same);
20 Datum gbt_text_compress(PG_FUNCTION_ARGS);
21 Datum gbt_bpchar_compress(PG_FUNCTION_ARGS);
22 Datum gbt_text_union(PG_FUNCTION_ARGS);
23 Datum gbt_text_picksplit(PG_FUNCTION_ARGS);
24 Datum gbt_text_consistent(PG_FUNCTION_ARGS);
25 Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS);
26 Datum gbt_text_penalty(PG_FUNCTION_ARGS);
27 Datum gbt_text_same(PG_FUNCTION_ARGS);
30 /* define for comparison */
32 static bool
33 gbt_textgt(const void *a, const void *b)
35 return (DatumGetBool(DirectFunctionCall2(text_gt, PointerGetDatum(a), PointerGetDatum(b))));
38 static bool
39 gbt_textge(const void *a, const void *b)
41 return (DatumGetBool(DirectFunctionCall2(text_ge, PointerGetDatum(a), PointerGetDatum(b))));
44 static bool
45 gbt_texteq(const void *a, const void *b)
47 return (DatumGetBool(DirectFunctionCall2(texteq, PointerGetDatum(a), PointerGetDatum(b))));
50 static bool
51 gbt_textle(const void *a, const void *b)
53 return (DatumGetBool(DirectFunctionCall2(text_le, PointerGetDatum(a), PointerGetDatum(b))));
56 static bool
57 gbt_textlt(const void *a, const void *b)
59 return (DatumGetBool(DirectFunctionCall2(text_lt, PointerGetDatum(a), PointerGetDatum(b))));
62 static int32
63 gbt_textcmp(const bytea *a, const bytea *b)
65 return DatumGetInt32(DirectFunctionCall2(bttextcmp, PointerGetDatum(a), PointerGetDatum(b)));
68 static gbtree_vinfo tinfo =
70 gbt_t_text,
72 FALSE,
73 gbt_textgt,
74 gbt_textge,
75 gbt_texteq,
76 gbt_textle,
77 gbt_textlt,
78 gbt_textcmp,
79 NULL
83 /**************************************************
84 * Text ops
85 **************************************************/
88 Datum
89 gbt_text_compress(PG_FUNCTION_ARGS)
91 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
93 if (tinfo.eml == 0)
95 tinfo.eml = pg_database_encoding_max_length();
98 PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
101 Datum
102 gbt_bpchar_compress(PG_FUNCTION_ARGS)
105 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
106 GISTENTRY *retval;
108 if (tinfo.eml == 0)
110 tinfo.eml = pg_database_encoding_max_length();
113 if (entry->leafkey)
116 Datum d = DirectFunctionCall1(rtrim1, entry->key);
117 GISTENTRY trim;
119 gistentryinit(trim, d,
120 entry->rel, entry->page,
121 entry->offset, TRUE);
122 retval = gbt_var_compress(&trim, &tinfo);
124 else
125 retval = entry;
127 PG_RETURN_POINTER(retval);
132 Datum
133 gbt_text_consistent(PG_FUNCTION_ARGS)
135 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
136 void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
137 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
138 /* Oid subtype = PG_GETARG_OID(3); */
139 bool *recheck = (bool *) PG_GETARG_POINTER(4);
140 bool retval;
141 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
142 GBT_VARKEY_R r = gbt_var_key_readable(key);
144 /* All cases served by this function are exact */
145 *recheck = false;
147 if (tinfo.eml == 0)
149 tinfo.eml = pg_database_encoding_max_length();
152 retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
154 PG_RETURN_BOOL(retval);
158 Datum
159 gbt_bpchar_consistent(PG_FUNCTION_ARGS)
161 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
162 void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
163 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
164 /* Oid subtype = PG_GETARG_OID(3); */
165 bool *recheck = (bool *) PG_GETARG_POINTER(4);
166 bool retval;
167 GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
168 GBT_VARKEY_R r = gbt_var_key_readable(key);
169 void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
171 /* All cases served by this function are exact */
172 *recheck = false;
174 if (tinfo.eml == 0)
176 tinfo.eml = pg_database_encoding_max_length();
179 retval = gbt_var_consistent(&r, trim, &strategy, GIST_LEAF(entry), &tinfo);
180 PG_RETURN_BOOL(retval);
184 Datum
185 gbt_text_union(PG_FUNCTION_ARGS)
187 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
188 int32 *size = (int *) PG_GETARG_POINTER(1);
190 PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
194 Datum
195 gbt_text_picksplit(PG_FUNCTION_ARGS)
197 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
198 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
200 gbt_var_picksplit(entryvec, v, &tinfo);
201 PG_RETURN_POINTER(v);
204 Datum
205 gbt_text_same(PG_FUNCTION_ARGS)
207 Datum d1 = PG_GETARG_DATUM(0);
208 Datum d2 = PG_GETARG_DATUM(1);
209 bool *result = (bool *) PG_GETARG_POINTER(2);
211 PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
215 Datum
216 gbt_text_penalty(PG_FUNCTION_ARGS)
218 GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
219 GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
220 float *result = (float *) PG_GETARG_POINTER(2);
222 PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));