8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.41 2001/03/22 03:59:14 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.42 2001/05/03 19:00:36 tgl Exp $
12
12
*
13
13
* NOTES
14
14
*
25
25
* NOTE: although any negative int32 is acceptable for reporting "<",
26
26
* and any positive int32 is acceptable for reporting ">", routines
27
27
* that work on 32-bit or wider datatypes can't just return "a - b".
28
- * That could overflow and give the wrong answer.
28
+ * That could overflow and give the wrong answer. Also, one should not
29
+ * return INT_MIN to report "<", since some callers will negate the result.
30
+ *
31
+ * NOTE: it is critical that the comparison function impose a total order
32
+ * on all non-NULL values of the data type, and that the datatype's
33
+ * boolean comparison operators (= < >= etc) yield results consistent
34
+ * with the comparison routine. Otherwise bad behavior may ensue.
35
+ * (For example, the comparison operators must NOT punt when faced with
36
+ * NAN or other funny values; you must devise some collation sequence for
37
+ * all such values.) If the datatype is not trivial, this is most
38
+ * reliably done by having the boolean operators invoke the same
39
+ * three-way comparison code that the btree function does. Therefore,
40
+ * this file contains only btree support for "trivial" datatypes ---
41
+ * all others are in the /utils/adt/ files that implement their datatypes.
29
42
*
30
43
* NOTE: these routines must not leak memory, since memory allocated
31
44
* during an index access won't be recovered till end of query. This
32
45
* primarily affects comparison routines for toastable datatypes;
33
46
* they have to be careful to free any detoasted copy of an input datum.
34
47
*-------------------------------------------------------------------------
35
48
*/
36
-
37
49
#include "postgres.h"
38
50
39
- #include "utils/nabstime.h"
40
51
#include "utils/builtins.h"
41
52
53
+
42
54
Datum
43
55
btboolcmp (PG_FUNCTION_ARGS )
44
56
{
@@ -85,34 +97,6 @@ btint8cmp(PG_FUNCTION_ARGS)
85
97
PG_RETURN_INT32 (-1 );
86
98
}
87
99
88
- Datum
89
- btfloat4cmp (PG_FUNCTION_ARGS )
90
- {
91
- float4 a = PG_GETARG_FLOAT4 (0 );
92
- float4 b = PG_GETARG_FLOAT4 (1 );
93
-
94
- if (a > b )
95
- PG_RETURN_INT32 (1 );
96
- else if (a == b )
97
- PG_RETURN_INT32 (0 );
98
- else
99
- PG_RETURN_INT32 (-1 );
100
- }
101
-
102
- Datum
103
- btfloat8cmp (PG_FUNCTION_ARGS )
104
- {
105
- float8 a = PG_GETARG_FLOAT8 (0 );
106
- float8 b = PG_GETARG_FLOAT8 (1 );
107
-
108
- if (a > b )
109
- PG_RETURN_INT32 (1 );
110
- else if (a == b )
111
- PG_RETURN_INT32 (0 );
112
- else
113
- PG_RETURN_INT32 (-1 );
114
- }
115
-
116
100
Datum
117
101
btoidcmp (PG_FUNCTION_ARGS )
118
102
{
@@ -147,20 +131,6 @@ btoidvectorcmp(PG_FUNCTION_ARGS)
147
131
PG_RETURN_INT32 (0 );
148
132
}
149
133
150
- Datum
151
- btabstimecmp (PG_FUNCTION_ARGS )
152
- {
153
- AbsoluteTime a = PG_GETARG_ABSOLUTETIME (0 );
154
- AbsoluteTime b = PG_GETARG_ABSOLUTETIME (1 );
155
-
156
- if (AbsoluteTimeIsBefore (a , b ))
157
- PG_RETURN_INT32 (-1 );
158
- else if (AbsoluteTimeIsBefore (b , a ))
159
- PG_RETURN_INT32 (1 );
160
- else
161
- PG_RETURN_INT32 (0 );
162
- }
163
-
164
134
Datum
165
135
btcharcmp (PG_FUNCTION_ARGS )
166
136
{
@@ -179,79 +149,3 @@ btnamecmp(PG_FUNCTION_ARGS)
179
149
180
150
PG_RETURN_INT32 (strncmp (NameStr (* a ), NameStr (* b ), NAMEDATALEN ));
181
151
}
182
-
183
- Datum
184
- bttextcmp (PG_FUNCTION_ARGS )
185
- {
186
- text * a = PG_GETARG_TEXT_P (0 );
187
- text * b = PG_GETARG_TEXT_P (1 );
188
- int res ;
189
- unsigned char * ap ,
190
- * bp ;
191
-
192
- #ifdef USE_LOCALE
193
- int la = VARSIZE (a ) - VARHDRSZ ;
194
- int lb = VARSIZE (b ) - VARHDRSZ ;
195
-
196
- ap = (unsigned char * ) palloc (la + 1 );
197
- bp = (unsigned char * ) palloc (lb + 1 );
198
-
199
- memcpy (ap , VARDATA (a ), la );
200
- * (ap + la ) = '\0' ;
201
- memcpy (bp , VARDATA (b ), lb );
202
- * (bp + lb ) = '\0' ;
203
-
204
- res = strcoll (ap , bp );
205
-
206
- pfree (ap );
207
- pfree (bp );
208
-
209
- #else
210
- int len = VARSIZE (a );
211
-
212
- /* len is the length of the shorter of the two strings */
213
- if (len > VARSIZE (b ))
214
- len = VARSIZE (b );
215
-
216
- len -= VARHDRSZ ;
217
-
218
- ap = (unsigned char * ) VARDATA (a );
219
- bp = (unsigned char * ) VARDATA (b );
220
-
221
- /*
222
- * If the two strings differ in the first len bytes, or if they're the
223
- * same in the first len bytes and they're both len bytes long, we're
224
- * done.
225
- */
226
-
227
- res = 0 ;
228
- if (len > 0 )
229
- {
230
- do
231
- {
232
- res = (int ) * ap ++ - (int ) * bp ++ ;
233
- len -- ;
234
- } while (res == 0 && len != 0 );
235
- }
236
-
237
- if (res == 0 && VARSIZE (a ) != VARSIZE (b ))
238
- {
239
-
240
- /*
241
- * The two strings are the same in the first len bytes, and they
242
- * are of different lengths.
243
- */
244
- if (VARSIZE (a ) < VARSIZE (b ))
245
- res = -1 ;
246
- else
247
- res = 1 ;
248
- }
249
-
250
- #endif
251
-
252
- /* Avoid leaking memory when handed toasted input. */
253
- PG_FREE_IF_COPY (a , 0 );
254
- PG_FREE_IF_COPY (b , 1 );
255
-
256
- PG_RETURN_INT32 (res );
257
- }
0 commit comments