Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * nbtcompare.c
4 : : * Comparison functions for btree access method.
5 : : *
6 : : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 : : * Portions Copyright (c) 1994, Regents of the University of California
8 : : *
9 : : *
10 : : * IDENTIFICATION
11 : : * src/backend/access/nbtree/nbtcompare.c
12 : : *
13 : : * NOTES
14 : : *
15 : : * These functions are stored in pg_amproc. For each operator class
16 : : * defined on btrees, they compute
17 : : *
18 : : * compare(a, b):
19 : : * < 0 if a < b,
20 : : * = 0 if a == b,
21 : : * > 0 if a > b.
22 : : *
23 : : * The result is always an int32 regardless of the input datatype.
24 : : *
25 : : * Although any negative int32 is acceptable for reporting "<",
26 : : * and any positive int32 is acceptable for reporting ">", routines
27 : : * that work on 32-bit or wider datatypes can't just return "a - b".
28 : : * That could overflow and give the wrong answer.
29 : : *
30 : : * NOTE: it is critical that the comparison function impose a total order
31 : : * on all non-NULL values of the data type, and that the datatype's
32 : : * boolean comparison operators (= < >= etc) yield results consistent
33 : : * with the comparison routine. Otherwise bad behavior may ensue.
34 : : * (For example, the comparison operators must NOT punt when faced with
35 : : * NAN or other funny values; you must devise some collation sequence for
36 : : * all such values.) If the datatype is not trivial, this is most
37 : : * reliably done by having the boolean operators invoke the same
38 : : * three-way comparison code that the btree function does. Therefore,
39 : : * this file contains only btree support for "trivial" datatypes ---
40 : : * all others are in the /utils/adt/ files that implement their datatypes.
41 : : *
42 : : * NOTE: these routines must not leak memory, since memory allocated
43 : : * during an index access won't be recovered till end of query. This
44 : : * primarily affects comparison routines for toastable datatypes;
45 : : * they have to be careful to free any detoasted copy of an input datum.
46 : : *
47 : : * NOTE: we used to forbid comparison functions from returning INT_MIN,
48 : : * but that proves to be too error-prone because some platforms' versions
49 : : * of memcmp() etc can return INT_MIN. As a means of stress-testing
50 : : * callers, this file can be compiled with STRESS_SORT_INT_MIN defined
51 : : * to cause many of these functions to return INT_MIN or INT_MAX instead of
52 : : * their customary -1/+1. For production, though, that's not a good idea
53 : : * since users or third-party code might expect the traditional results.
54 : : *-------------------------------------------------------------------------
55 : : */
56 : : #include "postgres.h"
57 : :
58 : : #include <limits.h>
59 : :
60 : : #include "utils/fmgrprotos.h"
61 : : #include "utils/skipsupport.h"
62 : : #include "utils/sortsupport.h"
63 : :
64 : : #ifdef STRESS_SORT_INT_MIN
65 : : #define A_LESS_THAN_B INT_MIN
66 : : #define A_GREATER_THAN_B INT_MAX
67 : : #else
68 : : #define A_LESS_THAN_B (-1)
69 : : #define A_GREATER_THAN_B 1
70 : : #endif
71 : :
72 : :
73 : : Datum
9224 tgl@sss.pgh.pa.us 74 :CBC 29809390 : btboolcmp(PG_FUNCTION_ARGS)
75 : : {
76 : 29809390 : bool a = PG_GETARG_BOOL(0);
77 : 29809390 : bool b = PG_GETARG_BOOL(1);
78 : :
79 : 29809390 : PG_RETURN_INT32((int32) a - (int32) b);
80 : : }
81 : :
82 : : static Datum
155 pg@bowt.ie 83 :UBC 0 : bool_decrement(Relation rel, Datum existing, bool *underflow)
84 : : {
85 : 0 : bool bexisting = DatumGetBool(existing);
86 : :
87 [ # # ]: 0 : if (bexisting == false)
88 : : {
89 : : /* return value is undefined */
90 : 0 : *underflow = true;
91 : 0 : return (Datum) 0;
92 : : }
93 : :
94 : 0 : *underflow = false;
95 : 0 : return BoolGetDatum(bexisting - 1);
96 : : }
97 : :
98 : : static Datum
99 : 0 : bool_increment(Relation rel, Datum existing, bool *overflow)
100 : : {
101 : 0 : bool bexisting = DatumGetBool(existing);
102 : :
103 [ # # ]: 0 : if (bexisting == true)
104 : : {
105 : : /* return value is undefined */
106 : 0 : *overflow = true;
107 : 0 : return (Datum) 0;
108 : : }
109 : :
110 : 0 : *overflow = false;
111 : 0 : return BoolGetDatum(bexisting + 1);
112 : : }
113 : :
114 : : Datum
115 : 0 : btboolskipsupport(PG_FUNCTION_ARGS)
116 : : {
117 : 0 : SkipSupport sksup = (SkipSupport) PG_GETARG_POINTER(0);
118 : :
119 : 0 : sksup->decrement = bool_decrement;
120 : 0 : sksup->increment = bool_increment;
121 : 0 : sksup->low_elem = BoolGetDatum(false);
122 : 0 : sksup->high_elem = BoolGetDatum(true);
123 : :
124 : 0 : PG_RETURN_VOID();
125 : : }
126 : :
127 : : Datum
9224 tgl@sss.pgh.pa.us 128 :CBC 5607815 : btint2cmp(PG_FUNCTION_ARGS)
129 : : {
130 : 5607815 : int16 a = PG_GETARG_INT16(0);
131 : 5607815 : int16 b = PG_GETARG_INT16(1);
132 : :
133 : 5607815 : PG_RETURN_INT32((int32) a - (int32) b);
134 : : }
135 : :
136 : : static int
5022 137 : 21803305 : btint2fastcmp(Datum x, Datum y, SortSupport ssup)
138 : : {
139 : 21803305 : int16 a = DatumGetInt16(x);
140 : 21803305 : int16 b = DatumGetInt16(y);
141 : :
142 : 21803305 : return (int) a - (int) b;
143 : : }
144 : :
145 : : Datum
146 : 5984 : btint2sortsupport(PG_FUNCTION_ARGS)
147 : : {
4836 bruce@momjian.us 148 : 5984 : SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
149 : :
5022 tgl@sss.pgh.pa.us 150 : 5984 : ssup->comparator = btint2fastcmp;
151 : 5984 : PG_RETURN_VOID();
152 : : }
153 : :
154 : : static Datum
155 pg@bowt.ie 155 :UBC 0 : int2_decrement(Relation rel, Datum existing, bool *underflow)
156 : : {
157 : 0 : int16 iexisting = DatumGetInt16(existing);
158 : :
159 [ # # ]: 0 : if (iexisting == PG_INT16_MIN)
160 : : {
161 : : /* return value is undefined */
162 : 0 : *underflow = true;
163 : 0 : return (Datum) 0;
164 : : }
165 : :
166 : 0 : *underflow = false;
167 : 0 : return Int16GetDatum(iexisting - 1);
168 : : }
169 : :
170 : : static Datum
155 pg@bowt.ie 171 :CBC 2 : int2_increment(Relation rel, Datum existing, bool *overflow)
172 : : {
173 : 2 : int16 iexisting = DatumGetInt16(existing);
174 : :
175 [ - + ]: 2 : if (iexisting == PG_INT16_MAX)
176 : : {
177 : : /* return value is undefined */
155 pg@bowt.ie 178 :UBC 0 : *overflow = true;
179 : 0 : return (Datum) 0;
180 : : }
181 : :
155 pg@bowt.ie 182 :CBC 2 : *overflow = false;
183 : 2 : return Int16GetDatum(iexisting + 1);
184 : : }
185 : :
186 : : Datum
187 : 93 : btint2skipsupport(PG_FUNCTION_ARGS)
188 : : {
189 : 93 : SkipSupport sksup = (SkipSupport) PG_GETARG_POINTER(0);
190 : :
191 : 93 : sksup->decrement = int2_decrement;
192 : 93 : sksup->increment = int2_increment;
193 : 93 : sksup->low_elem = Int16GetDatum(PG_INT16_MIN);
194 : 93 : sksup->high_elem = Int16GetDatum(PG_INT16_MAX);
195 : :
196 : 93 : PG_RETURN_VOID();
197 : : }
198 : :
199 : : Datum
9224 tgl@sss.pgh.pa.us 200 : 48746716 : btint4cmp(PG_FUNCTION_ARGS)
201 : : {
202 : 48746716 : int32 a = PG_GETARG_INT32(0);
203 : 48746716 : int32 b = PG_GETARG_INT32(1);
204 : :
9278 bruce@momjian.us 205 [ + + ]: 48746716 : if (a > b)
2528 tgl@sss.pgh.pa.us 206 : 17911299 : PG_RETURN_INT32(A_GREATER_THAN_B);
9278 bruce@momjian.us 207 [ + + ]: 30835417 : else if (a == b)
9224 tgl@sss.pgh.pa.us 208 : 10319303 : PG_RETURN_INT32(0);
209 : : else
2528 210 : 20516114 : PG_RETURN_INT32(A_LESS_THAN_B);
211 : : }
212 : :
213 : : Datum
5022 214 : 85825 : btint4sortsupport(PG_FUNCTION_ARGS)
215 : : {
4836 bruce@momjian.us 216 : 85825 : SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
217 : :
1253 john.naylor@postgres 218 : 85825 : ssup->comparator = ssup_datum_int32_cmp;
5022 tgl@sss.pgh.pa.us 219 : 85825 : PG_RETURN_VOID();
220 : : }
221 : :
222 : : static Datum
155 pg@bowt.ie 223 : 1983 : int4_decrement(Relation rel, Datum existing, bool *underflow)
224 : : {
225 : 1983 : int32 iexisting = DatumGetInt32(existing);
226 : :
227 [ - + ]: 1983 : if (iexisting == PG_INT32_MIN)
228 : : {
229 : : /* return value is undefined */
155 pg@bowt.ie 230 :UBC 0 : *underflow = true;
231 : 0 : return (Datum) 0;
232 : : }
233 : :
155 pg@bowt.ie 234 :CBC 1983 : *underflow = false;
235 : 1983 : return Int32GetDatum(iexisting - 1);
236 : : }
237 : :
238 : : static Datum
239 : 1911 : int4_increment(Relation rel, Datum existing, bool *overflow)
240 : : {
241 : 1911 : int32 iexisting = DatumGetInt32(existing);
242 : :
243 [ + + ]: 1911 : if (iexisting == PG_INT32_MAX)
244 : : {
245 : : /* return value is undefined */
246 : 15 : *overflow = true;
247 : 15 : return (Datum) 0;
248 : : }
249 : :
250 : 1896 : *overflow = false;
251 : 1896 : return Int32GetDatum(iexisting + 1);
252 : : }
253 : :
254 : : Datum
255 : 123 : btint4skipsupport(PG_FUNCTION_ARGS)
256 : : {
257 : 123 : SkipSupport sksup = (SkipSupport) PG_GETARG_POINTER(0);
258 : :
259 : 123 : sksup->decrement = int4_decrement;
260 : 123 : sksup->increment = int4_increment;
261 : 123 : sksup->low_elem = Int32GetDatum(PG_INT32_MIN);
262 : 123 : sksup->high_elem = Int32GetDatum(PG_INT32_MAX);
263 : :
264 : 123 : PG_RETURN_VOID();
265 : : }
266 : :
267 : : Datum
9224 tgl@sss.pgh.pa.us 268 : 8321675 : btint8cmp(PG_FUNCTION_ARGS)
269 : : {
270 : 8321675 : int64 a = PG_GETARG_INT64(0);
271 : 8321675 : int64 b = PG_GETARG_INT64(1);
272 : :
273 [ + + ]: 8321675 : if (a > b)
2528 274 : 4863874 : PG_RETURN_INT32(A_GREATER_THAN_B);
9224 275 [ + + ]: 3457801 : else if (a == b)
276 : 422567 : PG_RETURN_INT32(0);
277 : : else
2528 278 : 3035234 : PG_RETURN_INT32(A_LESS_THAN_B);
279 : : }
280 : :
281 : : Datum
5022 282 : 1744 : btint8sortsupport(PG_FUNCTION_ARGS)
283 : : {
4836 bruce@momjian.us 284 : 1744 : SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
285 : :
1253 john.naylor@postgres 286 : 1744 : ssup->comparator = ssup_datum_signed_cmp;
5022 tgl@sss.pgh.pa.us 287 : 1744 : PG_RETURN_VOID();
288 : : }
289 : :
290 : : static Datum
155 pg@bowt.ie 291 :UBC 0 : int8_decrement(Relation rel, Datum existing, bool *underflow)
292 : : {
293 : 0 : int64 iexisting = DatumGetInt64(existing);
294 : :
295 [ # # ]: 0 : if (iexisting == PG_INT64_MIN)
296 : : {
297 : : /* return value is undefined */
298 : 0 : *underflow = true;
299 : 0 : return (Datum) 0;
300 : : }
301 : :
302 : 0 : *underflow = false;
303 : 0 : return Int64GetDatum(iexisting - 1);
304 : : }
305 : :
306 : : static Datum
307 : 0 : int8_increment(Relation rel, Datum existing, bool *overflow)
308 : : {
309 : 0 : int64 iexisting = DatumGetInt64(existing);
310 : :
311 [ # # ]: 0 : if (iexisting == PG_INT64_MAX)
312 : : {
313 : : /* return value is undefined */
314 : 0 : *overflow = true;
315 : 0 : return (Datum) 0;
316 : : }
317 : :
318 : 0 : *overflow = false;
319 : 0 : return Int64GetDatum(iexisting + 1);
320 : : }
321 : :
322 : : Datum
323 : 0 : btint8skipsupport(PG_FUNCTION_ARGS)
324 : : {
325 : 0 : SkipSupport sksup = (SkipSupport) PG_GETARG_POINTER(0);
326 : :
327 : 0 : sksup->decrement = int8_decrement;
328 : 0 : sksup->increment = int8_increment;
329 : 0 : sksup->low_elem = Int64GetDatum(PG_INT64_MIN);
330 : 0 : sksup->high_elem = Int64GetDatum(PG_INT64_MAX);
331 : :
332 : 0 : PG_RETURN_VOID();
333 : : }
334 : :
335 : : Datum
7969 tgl@sss.pgh.pa.us 336 :CBC 743 : btint48cmp(PG_FUNCTION_ARGS)
337 : : {
338 : 743 : int32 a = PG_GETARG_INT32(0);
339 : 743 : int64 b = PG_GETARG_INT64(1);
340 : :
341 [ + + ]: 743 : if (a > b)
2528 342 : 255 : PG_RETURN_INT32(A_GREATER_THAN_B);
7969 343 [ + + ]: 488 : else if (a == b)
344 : 38 : PG_RETURN_INT32(0);
345 : : else
2528 346 : 450 : PG_RETURN_INT32(A_LESS_THAN_B);
347 : : }
348 : :
349 : : Datum
7969 350 : 110 : btint84cmp(PG_FUNCTION_ARGS)
351 : : {
352 : 110 : int64 a = PG_GETARG_INT64(0);
353 : 110 : int32 b = PG_GETARG_INT32(1);
354 : :
355 [ + + ]: 110 : if (a > b)
2528 356 : 39 : PG_RETURN_INT32(A_GREATER_THAN_B);
7969 357 [ + + ]: 71 : else if (a == b)
358 : 29 : PG_RETURN_INT32(0);
359 : : else
2528 360 : 42 : PG_RETURN_INT32(A_LESS_THAN_B);
361 : : }
362 : :
363 : : Datum
7969 364 : 24951 : btint24cmp(PG_FUNCTION_ARGS)
365 : : {
366 : 24951 : int16 a = PG_GETARG_INT16(0);
367 : 24951 : int32 b = PG_GETARG_INT32(1);
368 : :
369 [ + + ]: 24951 : if (a > b)
2528 370 : 13455 : PG_RETURN_INT32(A_GREATER_THAN_B);
7969 371 [ + + ]: 11496 : else if (a == b)
372 : 3659 : PG_RETURN_INT32(0);
373 : : else
2528 374 : 7837 : PG_RETURN_INT32(A_LESS_THAN_B);
375 : : }
376 : :
377 : : Datum
7969 378 : 781 : btint42cmp(PG_FUNCTION_ARGS)
379 : : {
380 : 781 : int32 a = PG_GETARG_INT32(0);
381 : 781 : int16 b = PG_GETARG_INT16(1);
382 : :
383 [ + + ]: 781 : if (a > b)
2528 384 : 68 : PG_RETURN_INT32(A_GREATER_THAN_B);
7969 385 [ + + ]: 713 : else if (a == b)
386 : 162 : PG_RETURN_INT32(0);
387 : : else
2528 388 : 551 : PG_RETURN_INT32(A_LESS_THAN_B);
389 : : }
390 : :
391 : : Datum
7969 392 : 35 : btint28cmp(PG_FUNCTION_ARGS)
393 : : {
394 : 35 : int16 a = PG_GETARG_INT16(0);
395 : 35 : int64 b = PG_GETARG_INT64(1);
396 : :
397 [ + + ]: 35 : if (a > b)
2528 tgl@sss.pgh.pa.us 398 :GBC 6 : PG_RETURN_INT32(A_GREATER_THAN_B);
7969 tgl@sss.pgh.pa.us 399 [ + + ]:CBC 29 : else if (a == b)
7969 tgl@sss.pgh.pa.us 400 :GBC 5 : PG_RETURN_INT32(0);
401 : : else
2528 tgl@sss.pgh.pa.us 402 :CBC 24 : PG_RETURN_INT32(A_LESS_THAN_B);
403 : : }
404 : :
405 : : Datum
7969 tgl@sss.pgh.pa.us 406 :GBC 17 : btint82cmp(PG_FUNCTION_ARGS)
407 : : {
408 : 17 : int64 a = PG_GETARG_INT64(0);
409 : 17 : int16 b = PG_GETARG_INT16(1);
410 : :
411 [ + + ]: 17 : if (a > b)
2528 412 : 6 : PG_RETURN_INT32(A_GREATER_THAN_B);
7969 413 [ + + ]: 11 : else if (a == b)
414 : 5 : PG_RETURN_INT32(0);
415 : : else
2528 416 : 6 : PG_RETURN_INT32(A_LESS_THAN_B);
417 : : }
418 : :
419 : : Datum
9224 tgl@sss.pgh.pa.us 420 :CBC 103054834 : btoidcmp(PG_FUNCTION_ARGS)
421 : : {
422 : 103054834 : Oid a = PG_GETARG_OID(0);
423 : 103054834 : Oid b = PG_GETARG_OID(1);
424 : :
10226 bruce@momjian.us 425 [ + + ]: 103054834 : if (a > b)
2528 tgl@sss.pgh.pa.us 426 : 27063956 : PG_RETURN_INT32(A_GREATER_THAN_B);
10226 bruce@momjian.us 427 [ + + ]: 75990878 : else if (a == b)
9224 tgl@sss.pgh.pa.us 428 : 24879000 : PG_RETURN_INT32(0);
429 : : else
2528 430 : 51111878 : PG_RETURN_INT32(A_LESS_THAN_B);
431 : : }
432 : :
433 : : static int
5022 434 : 129178232 : btoidfastcmp(Datum x, Datum y, SortSupport ssup)
435 : : {
436 : 129178232 : Oid a = DatumGetObjectId(x);
437 : 129178232 : Oid b = DatumGetObjectId(y);
438 : :
439 [ + + ]: 129178232 : if (a > b)
2528 440 : 32045089 : return A_GREATER_THAN_B;
5022 441 [ + + ]: 97133143 : else if (a == b)
442 : 65233033 : return 0;
443 : : else
2528 444 : 31900110 : return A_LESS_THAN_B;
445 : : }
446 : :
447 : : Datum
5022 448 : 60444 : btoidsortsupport(PG_FUNCTION_ARGS)
449 : : {
4836 bruce@momjian.us 450 : 60444 : SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
451 : :
5022 tgl@sss.pgh.pa.us 452 : 60444 : ssup->comparator = btoidfastcmp;
453 : 60444 : PG_RETURN_VOID();
454 : : }
455 : :
456 : : static Datum
155 pg@bowt.ie 457 :UBC 0 : oid_decrement(Relation rel, Datum existing, bool *underflow)
458 : : {
459 : 0 : Oid oexisting = DatumGetObjectId(existing);
460 : :
461 [ # # ]: 0 : if (oexisting == InvalidOid)
462 : : {
463 : : /* return value is undefined */
464 : 0 : *underflow = true;
465 : 0 : return (Datum) 0;
466 : : }
467 : :
468 : 0 : *underflow = false;
469 : 0 : return ObjectIdGetDatum(oexisting - 1);
470 : : }
471 : :
472 : : static Datum
155 pg@bowt.ie 473 :CBC 180 : oid_increment(Relation rel, Datum existing, bool *overflow)
474 : : {
475 : 180 : Oid oexisting = DatumGetObjectId(existing);
476 : :
477 [ - + ]: 180 : if (oexisting == OID_MAX)
478 : : {
479 : : /* return value is undefined */
155 pg@bowt.ie 480 :UBC 0 : *overflow = true;
481 : 0 : return (Datum) 0;
482 : : }
483 : :
155 pg@bowt.ie 484 :CBC 180 : *overflow = false;
485 : 180 : return ObjectIdGetDatum(oexisting + 1);
486 : : }
487 : :
488 : : Datum
489 : 1431 : btoidskipsupport(PG_FUNCTION_ARGS)
490 : : {
491 : 1431 : SkipSupport sksup = (SkipSupport) PG_GETARG_POINTER(0);
492 : :
493 : 1431 : sksup->decrement = oid_decrement;
494 : 1431 : sksup->increment = oid_increment;
495 : 1431 : sksup->low_elem = ObjectIdGetDatum(InvalidOid);
496 : 1431 : sksup->high_elem = ObjectIdGetDatum(OID_MAX);
497 : :
498 : 1431 : PG_RETURN_VOID();
499 : : }
500 : :
501 : : Datum
9224 tgl@sss.pgh.pa.us 502 : 4028949 : btoidvectorcmp(PG_FUNCTION_ARGS)
503 : : {
7466 504 : 4028949 : oidvector *a = (oidvector *) PG_GETARG_POINTER(0);
505 : 4028949 : oidvector *b = (oidvector *) PG_GETARG_POINTER(1);
506 : : int i;
507 : :
508 : : /* We arbitrarily choose to sort first by vector length */
509 [ + + ]: 4028949 : if (a->dim1 != b->dim1)
510 : 724210 : PG_RETURN_INT32(a->dim1 - b->dim1);
511 : :
512 [ + + ]: 5808390 : for (i = 0; i < a->dim1; i++)
513 : : {
514 [ + + ]: 4431803 : if (a->values[i] != b->values[i])
515 : : {
516 [ + + ]: 1928152 : if (a->values[i] > b->values[i])
2528 517 : 996225 : PG_RETURN_INT32(A_GREATER_THAN_B);
518 : : else
519 : 931927 : PG_RETURN_INT32(A_LESS_THAN_B);
520 : : }
521 : : }
9224 522 : 1376587 : PG_RETURN_INT32(0);
523 : : }
524 : :
525 : : Datum
526 : 30773770 : btcharcmp(PG_FUNCTION_ARGS)
527 : : {
528 : 30773770 : char a = PG_GETARG_CHAR(0);
529 : 30773770 : char b = PG_GETARG_CHAR(1);
530 : :
531 : : /* Be careful to compare chars as unsigned */
532 : 30773770 : PG_RETURN_INT32((int32) ((uint8) a) - (int32) ((uint8) b));
533 : : }
534 : :
535 : : static Datum
155 pg@bowt.ie 536 :UBC 0 : char_decrement(Relation rel, Datum existing, bool *underflow)
537 : : {
32 peter@eisentraut.org 538 :UNC 0 : uint8 cexisting = DatumGetUInt8(existing);
539 : :
155 pg@bowt.ie 540 [ # # ]:UBC 0 : if (cexisting == 0)
541 : : {
542 : : /* return value is undefined */
543 : 0 : *underflow = true;
544 : 0 : return (Datum) 0;
545 : : }
546 : :
547 : 0 : *underflow = false;
548 : 0 : return CharGetDatum((uint8) cexisting - 1);
549 : : }
550 : :
551 : : static Datum
552 : 0 : char_increment(Relation rel, Datum existing, bool *overflow)
553 : : {
32 peter@eisentraut.org 554 :UNC 0 : uint8 cexisting = DatumGetUInt8(existing);
555 : :
155 pg@bowt.ie 556 [ # # ]:UBC 0 : if (cexisting == UCHAR_MAX)
557 : : {
558 : : /* return value is undefined */
559 : 0 : *overflow = true;
560 : 0 : return (Datum) 0;
561 : : }
562 : :
563 : 0 : *overflow = false;
564 : 0 : return CharGetDatum((uint8) cexisting + 1);
565 : : }
566 : :
567 : : Datum
568 : 0 : btcharskipsupport(PG_FUNCTION_ARGS)
569 : : {
570 : 0 : SkipSupport sksup = (SkipSupport) PG_GETARG_POINTER(0);
571 : :
572 : 0 : sksup->decrement = char_decrement;
573 : 0 : sksup->increment = char_increment;
574 : :
575 : : /* btcharcmp compares chars as unsigned */
576 : 0 : sksup->low_elem = UInt8GetDatum(0);
577 : 0 : sksup->high_elem = UInt8GetDatum(UCHAR_MAX);
578 : :
579 : 0 : PG_RETURN_VOID();
580 : : }
|