PostgreSQL Source Code  git master
nbtcompare.c File Reference
#include "postgres.h"
#include <limits.h>
#include "utils/fmgrprotos.h"
#include "utils/sortsupport.h"
Include dependency graph for nbtcompare.c:

Go to the source code of this file.

Macros

#define A_LESS_THAN_B   (-1)
 
#define A_GREATER_THAN_B   1
 

Functions

Datum btboolcmp (PG_FUNCTION_ARGS)
 
Datum btint2cmp (PG_FUNCTION_ARGS)
 
static int btint2fastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btint2sortsupport (PG_FUNCTION_ARGS)
 
Datum btint4cmp (PG_FUNCTION_ARGS)
 
Datum btint4sortsupport (PG_FUNCTION_ARGS)
 
Datum btint8cmp (PG_FUNCTION_ARGS)
 
static int btint8fastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btint8sortsupport (PG_FUNCTION_ARGS)
 
Datum btint48cmp (PG_FUNCTION_ARGS)
 
Datum btint84cmp (PG_FUNCTION_ARGS)
 
Datum btint24cmp (PG_FUNCTION_ARGS)
 
Datum btint42cmp (PG_FUNCTION_ARGS)
 
Datum btint28cmp (PG_FUNCTION_ARGS)
 
Datum btint82cmp (PG_FUNCTION_ARGS)
 
Datum btoidcmp (PG_FUNCTION_ARGS)
 
static int btoidfastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btoidsortsupport (PG_FUNCTION_ARGS)
 
Datum btoidvectorcmp (PG_FUNCTION_ARGS)
 
Datum btcharcmp (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ A_GREATER_THAN_B

#define A_GREATER_THAN_B   1

Definition at line 68 of file nbtcompare.c.

◆ A_LESS_THAN_B

#define A_LESS_THAN_B   (-1)

Definition at line 67 of file nbtcompare.c.

Function Documentation

◆ btboolcmp()

Datum btboolcmp ( PG_FUNCTION_ARGS  )

Definition at line 73 of file nbtcompare.c.

74 {
75  bool a = PG_GETARG_BOOL(0);
76  bool b = PG_GETARG_BOOL(1);
77 
78  PG_RETURN_INT32((int32) a - (int32) b);
79 }
int32_t int32
Definition: c.h:481
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
int b
Definition: isn.c:69
int a
Definition: isn.c:68

References a, b, PG_GETARG_BOOL, and PG_RETURN_INT32.

◆ btcharcmp()

Datum btcharcmp ( PG_FUNCTION_ARGS  )

Definition at line 320 of file nbtcompare.c.

321 {
322  char a = PG_GETARG_CHAR(0);
323  char b = PG_GETARG_CHAR(1);
324 
325  /* Be careful to compare chars as unsigned */
326  PG_RETURN_INT32((int32) ((uint8) a) - (int32) ((uint8) b));
327 }
uint8_t uint8
Definition: c.h:483
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:273

References a, b, PG_GETARG_CHAR, and PG_RETURN_INT32.

◆ btint24cmp()

Datum btint24cmp ( PG_FUNCTION_ARGS  )

Definition at line 203 of file nbtcompare.c.

204 {
205  int16 a = PG_GETARG_INT16(0);
206  int32 b = PG_GETARG_INT32(1);
207 
208  if (a > b)
210  else if (a == b)
211  PG_RETURN_INT32(0);
212  else
214 }
int16_t int16
Definition: c.h:480
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
#define A_LESS_THAN_B
Definition: nbtcompare.c:67

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT32.

◆ btint28cmp()

Datum btint28cmp ( PG_FUNCTION_ARGS  )

Definition at line 231 of file nbtcompare.c.

232 {
233  int16 a = PG_GETARG_INT16(0);
234  int64 b = PG_GETARG_INT64(1);
235 
236  if (a > b)
238  else if (a == b)
239  PG_RETURN_INT32(0);
240  else
242 }
int64_t int64
Definition: c.h:482
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_INT32.

◆ btint2cmp()

Datum btint2cmp ( PG_FUNCTION_ARGS  )

Definition at line 82 of file nbtcompare.c.

83 {
84  int16 a = PG_GETARG_INT16(0);
85  int16 b = PG_GETARG_INT16(1);
86 
87  PG_RETURN_INT32((int32) a - (int32) b);
88 }

References a, b, PG_GETARG_INT16, and PG_RETURN_INT32.

◆ btint2fastcmp()

static int btint2fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 91 of file nbtcompare.c.

92 {
95 
96  return (int) a - (int) b;
97 }
int y
Definition: isn.c:71
int x
Definition: isn.c:70
static int16 DatumGetInt16(Datum X)
Definition: postgres.h:162

References a, b, DatumGetInt16(), x, and y.

Referenced by btint2sortsupport().

◆ btint2sortsupport()

Datum btint2sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 100 of file nbtcompare.c.

101 {
103 
104  ssup->comparator = btint2fastcmp;
105  PG_RETURN_VOID();
106 }
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static int btint2fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:91
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106

References btint2fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

◆ btint42cmp()

Datum btint42cmp ( PG_FUNCTION_ARGS  )

Definition at line 217 of file nbtcompare.c.

218 {
219  int32 a = PG_GETARG_INT32(0);
220  int16 b = PG_GETARG_INT16(1);
221 
222  if (a > b)
224  else if (a == b)
225  PG_RETURN_INT32(0);
226  else
228 }

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT32.

◆ btint48cmp()

Datum btint48cmp ( PG_FUNCTION_ARGS  )

Definition at line 175 of file nbtcompare.c.

176 {
177  int32 a = PG_GETARG_INT32(0);
178  int64 b = PG_GETARG_INT64(1);
179 
180  if (a > b)
182  else if (a == b)
183  PG_RETURN_INT32(0);
184  else
186 }

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT32.

◆ btint4cmp()

Datum btint4cmp ( PG_FUNCTION_ARGS  )

Definition at line 109 of file nbtcompare.c.

110 {
111  int32 a = PG_GETARG_INT32(0);
112  int32 b = PG_GETARG_INT32(1);
113 
114  if (a > b)
116  else if (a == b)
117  PG_RETURN_INT32(0);
118  else
120 }

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT32, and PG_RETURN_INT32.

◆ btint4sortsupport()

Datum btint4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 123 of file nbtcompare.c.

124 {
126 
128  PG_RETURN_VOID();
129 }
int ssup_datum_int32_cmp(Datum x, Datum y, SortSupport ssup)
Definition: tuplesort.c:3166

References SortSupportData::comparator, PG_GETARG_POINTER, PG_RETURN_VOID, and ssup_datum_int32_cmp().

◆ btint82cmp()

Datum btint82cmp ( PG_FUNCTION_ARGS  )

Definition at line 245 of file nbtcompare.c.

246 {
247  int64 a = PG_GETARG_INT64(0);
248  int16 b = PG_GETARG_INT16(1);
249 
250  if (a > b)
252  else if (a == b)
253  PG_RETURN_INT32(0);
254  else
256 }

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_INT32.

◆ btint84cmp()

Datum btint84cmp ( PG_FUNCTION_ARGS  )

Definition at line 189 of file nbtcompare.c.

190 {
191  int64 a = PG_GETARG_INT64(0);
192  int32 b = PG_GETARG_INT32(1);
193 
194  if (a > b)
196  else if (a == b)
197  PG_RETURN_INT32(0);
198  else
200 }

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT32.

◆ btint8cmp()

Datum btint8cmp ( PG_FUNCTION_ARGS  )

Definition at line 132 of file nbtcompare.c.

133 {
134  int64 a = PG_GETARG_INT64(0);
135  int64 b = PG_GETARG_INT64(1);
136 
137  if (a > b)
139  else if (a == b)
140  PG_RETURN_INT32(0);
141  else
143 }

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_INT64, and PG_RETURN_INT32.

◆ btint8fastcmp()

static int btint8fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 147 of file nbtcompare.c.

148 {
149  int64 a = DatumGetInt64(x);
150  int64 b = DatumGetInt64(y);
151 
152  if (a > b)
153  return A_GREATER_THAN_B;
154  else if (a == b)
155  return 0;
156  else
157  return A_LESS_THAN_B;
158 }
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:385

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, DatumGetInt64(), x, and y.

Referenced by btint8sortsupport().

◆ btint8sortsupport()

Datum btint8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 162 of file nbtcompare.c.

163 {
165 
166 #if SIZEOF_DATUM >= 8
167  ssup->comparator = ssup_datum_signed_cmp;
168 #else
169  ssup->comparator = btint8fastcmp;
170 #endif
171  PG_RETURN_VOID();
172 }
static int btint8fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:147

References btint8fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

◆ btoidcmp()

Datum btoidcmp ( PG_FUNCTION_ARGS  )

Definition at line 259 of file nbtcompare.c.

260 {
261  Oid a = PG_GETARG_OID(0);
262  Oid b = PG_GETARG_OID(1);
263 
264  if (a > b)
266  else if (a == b)
267  PG_RETURN_INT32(0);
268  else
270 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
unsigned int Oid
Definition: postgres_ext.h:31

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, PG_GETARG_OID, and PG_RETURN_INT32.

◆ btoidfastcmp()

static int btoidfastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 273 of file nbtcompare.c.

274 {
275  Oid a = DatumGetObjectId(x);
276  Oid b = DatumGetObjectId(y);
277 
278  if (a > b)
279  return A_GREATER_THAN_B;
280  else if (a == b)
281  return 0;
282  else
283  return A_LESS_THAN_B;
284 }
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, DatumGetObjectId(), x, and y.

Referenced by btoidsortsupport().

◆ btoidsortsupport()

Datum btoidsortsupport ( PG_FUNCTION_ARGS  )

Definition at line 287 of file nbtcompare.c.

288 {
290 
291  ssup->comparator = btoidfastcmp;
292  PG_RETURN_VOID();
293 }
static int btoidfastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:273

References btoidfastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

◆ btoidvectorcmp()

Datum btoidvectorcmp ( PG_FUNCTION_ARGS  )

Definition at line 296 of file nbtcompare.c.

297 {
300  int i;
301 
302  /* We arbitrarily choose to sort first by vector length */
303  if (a->dim1 != b->dim1)
304  PG_RETURN_INT32(a->dim1 - b->dim1);
305 
306  for (i = 0; i < a->dim1; i++)
307  {
308  if (a->values[i] != b->values[i])
309  {
310  if (a->values[i] > b->values[i])
312  else
314  }
315  }
316  PG_RETURN_INT32(0);
317 }
int i
Definition: isn.c:72
Definition: c.h:680

References a, A_GREATER_THAN_B, A_LESS_THAN_B, b, i, PG_GETARG_POINTER, and PG_RETURN_INT32.

Referenced by oidvectoreq(), oidvectorge(), oidvectorgt(), oidvectorle(), oidvectorlt(), and oidvectorne().