PostgreSQL Source Code  git master
nbtcompare.c File Reference
#include "postgres.h"
#include <limits.h>
#include "utils/builtins.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)
 
static int btint4fastcmp (Datum x, Datum y, SortSupport ssup)
 
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

◆ A_LESS_THAN_B

Function Documentation

◆ btboolcmp()

Datum btboolcmp ( PG_FUNCTION_ARGS  )

Definition at line 73 of file nbtcompare.c.

References PG_GETARG_BOOL, and PG_RETURN_INT32.

Referenced by leftmostvalue_bool().

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 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:346

◆ btcharcmp()

Datum btcharcmp ( PG_FUNCTION_ARGS  )

Definition at line 328 of file nbtcompare.c.

References PG_GETARG_CHAR, and PG_RETURN_INT32.

Referenced by leftmostvalue_char().

329 {
330  char a = PG_GETARG_CHAR(0);
331  char b = PG_GETARG_CHAR(1);
332 
333  /* Be careful to compare chars as unsigned */
334  PG_RETURN_INT32((int32) ((uint8) a) - (int32) ((uint8) b));
335 }
unsigned char uint8
Definition: c.h:356
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:346
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:268

◆ btint24cmp()

Datum btint24cmp ( PG_FUNCTION_ARGS  )

Definition at line 211 of file nbtcompare.c.

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

212 {
213  int16 a = PG_GETARG_INT16(0);
214  int32 b = PG_GETARG_INT32(1);
215 
216  if (a > b)
218  else if (a == b)
219  PG_RETURN_INT32(0);
220  else
222 }
signed short int16
Definition: c.h:345
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
signed int int32
Definition: c.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ btint28cmp()

Datum btint28cmp ( PG_FUNCTION_ARGS  )

Definition at line 239 of file nbtcompare.c.

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

240 {
241  int16 a = PG_GETARG_INT16(0);
242  int64 b = PG_GETARG_INT64(1);
243 
244  if (a > b)
246  else if (a == b)
247  PG_RETURN_INT32(0);
248  else
250 }
signed short int16
Definition: c.h:345
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ btint2cmp()

Datum btint2cmp ( PG_FUNCTION_ARGS  )

Definition at line 82 of file nbtcompare.c.

References PG_GETARG_INT16, and PG_RETURN_INT32.

Referenced by leftmostvalue_int2().

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 }
signed short int16
Definition: c.h:345
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ btint2fastcmp()

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

Definition at line 91 of file nbtcompare.c.

References DatumGetInt16.

Referenced by btint2sortsupport().

92 {
93  int16 a = DatumGetInt16(x);
94  int16 b = DatumGetInt16(y);
95 
96  return (int) a - (int) b;
97 }
signed short int16
Definition: c.h:345
#define DatumGetInt16(X)
Definition: postgres.h:444

◆ btint2sortsupport()

Datum btint2sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 100 of file nbtcompare.c.

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

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

◆ btint42cmp()

Datum btint42cmp ( PG_FUNCTION_ARGS  )

Definition at line 225 of file nbtcompare.c.

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

226 {
227  int32 a = PG_GETARG_INT32(0);
228  int16 b = PG_GETARG_INT16(1);
229 
230  if (a > b)
232  else if (a == b)
233  PG_RETURN_INT32(0);
234  else
236 }
signed short int16
Definition: c.h:345
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
signed int int32
Definition: c.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ btint48cmp()

Datum btint48cmp ( PG_FUNCTION_ARGS  )

Definition at line 183 of file nbtcompare.c.

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

184 {
185  int32 a = PG_GETARG_INT32(0);
186  int64 b = PG_GETARG_INT64(1);
187 
188  if (a > b)
190  else if (a == b)
191  PG_RETURN_INT32(0);
192  else
194 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
signed int int32
Definition: c.h:346
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ btint4cmp()

Datum btint4cmp ( PG_FUNCTION_ARGS  )

Definition at line 109 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, PG_GETARG_INT32, and PG_RETURN_INT32.

Referenced by leftmostvalue_int4().

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 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
signed int int32
Definition: c.h:346

◆ btint4fastcmp()

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

Definition at line 123 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, and DatumGetInt32.

Referenced by btint4sortsupport().

124 {
125  int32 a = DatumGetInt32(x);
126  int32 b = DatumGetInt32(y);
127 
128  if (a > b)
129  return A_GREATER_THAN_B;
130  else if (a == b)
131  return 0;
132  else
133  return A_LESS_THAN_B;
134 }
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define DatumGetInt32(X)
Definition: postgres.h:472
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
signed int int32
Definition: c.h:346

◆ btint4sortsupport()

Datum btint4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 137 of file nbtcompare.c.

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

138 {
140 
141  ssup->comparator = btint4fastcmp;
142  PG_RETURN_VOID();
143 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
static int btint4fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:123
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:339

◆ btint82cmp()

Datum btint82cmp ( PG_FUNCTION_ARGS  )

Definition at line 253 of file nbtcompare.c.

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

254 {
255  int64 a = PG_GETARG_INT64(0);
256  int16 b = PG_GETARG_INT16(1);
257 
258  if (a > b)
260  else if (a == b)
261  PG_RETURN_INT32(0);
262  else
264 }
signed short int16
Definition: c.h:345
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ btint84cmp()

Datum btint84cmp ( PG_FUNCTION_ARGS  )

Definition at line 197 of file nbtcompare.c.

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

198 {
199  int64 a = PG_GETARG_INT64(0);
200  int32 b = PG_GETARG_INT32(1);
201 
202  if (a > b)
204  else if (a == b)
205  PG_RETURN_INT32(0);
206  else
208 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
signed int int32
Definition: c.h:346
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ btint8cmp()

Datum btint8cmp ( PG_FUNCTION_ARGS  )

Definition at line 146 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, PG_GETARG_INT64, and PG_RETURN_INT32.

Referenced by leftmostvalue_int8().

147 {
148  int64 a = PG_GETARG_INT64(0);
149  int64 b = PG_GETARG_INT64(1);
150 
151  if (a > b)
153  else if (a == b)
154  PG_RETURN_INT32(0);
155  else
157 }
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ btint8fastcmp()

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

Definition at line 160 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, and DatumGetInt64.

Referenced by btint8sortsupport().

161 {
162  int64 a = DatumGetInt64(x);
163  int64 b = DatumGetInt64(y);
164 
165  if (a > b)
166  return A_GREATER_THAN_B;
167  else if (a == b)
168  return 0;
169  else
170  return A_LESS_THAN_B;
171 }
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
#define DatumGetInt64(X)
Definition: postgres.h:607

◆ btint8sortsupport()

Datum btint8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 174 of file nbtcompare.c.

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

175 {
177 
178  ssup->comparator = btint8fastcmp;
179  PG_RETURN_VOID();
180 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:339
static int btint8fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:160

◆ btoidcmp()

Datum btoidcmp ( PG_FUNCTION_ARGS  )

Definition at line 267 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, PG_GETARG_OID, and PG_RETURN_INT32.

Referenced by leftmostvalue_oid().

268 {
269  Oid a = PG_GETARG_OID(0);
270  Oid b = PG_GETARG_OID(1);
271 
272  if (a > b)
274  else if (a == b)
275  PG_RETURN_INT32(0);
276  else
278 }
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:270

◆ btoidfastcmp()

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

Definition at line 281 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, and DatumGetObjectId.

Referenced by btoidsortsupport().

282 {
283  Oid a = DatumGetObjectId(x);
284  Oid b = DatumGetObjectId(y);
285 
286  if (a > b)
287  return A_GREATER_THAN_B;
288  else if (a == b)
289  return 0;
290  else
291  return A_LESS_THAN_B;
292 }
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define DatumGetObjectId(X)
Definition: postgres.h:500
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
unsigned int Oid
Definition: postgres_ext.h:31

◆ btoidsortsupport()

Datum btoidsortsupport ( PG_FUNCTION_ARGS  )

Definition at line 295 of file nbtcompare.c.

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

296 {
298 
299  ssup->comparator = btoidfastcmp;
300  PG_RETURN_VOID();
301 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
static int btoidfastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:281
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:339

◆ btoidvectorcmp()

Datum btoidvectorcmp ( PG_FUNCTION_ARGS  )

Definition at line 304 of file nbtcompare.c.

References A_GREATER_THAN_B, A_LESS_THAN_B, oidvector::dim1, i, PG_GETARG_POINTER, PG_RETURN_INT32, and oidvector::values.

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

305 {
308  int i;
309 
310  /* We arbitrarily choose to sort first by vector length */
311  if (a->dim1 != b->dim1)
312  PG_RETURN_INT32(a->dim1 - b->dim1);
313 
314  for (i = 0; i < a->dim1; i++)
315  {
316  if (a->values[i] != b->values[i])
317  {
318  if (a->values[i] > b->values[i])
320  else
322  }
323  }
324  PG_RETURN_INT32(0);
325 }
Definition: c.h:588
#define A_LESS_THAN_B
Definition: nbtcompare.c:67
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define A_GREATER_THAN_B
Definition: nbtcompare.c:68
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:596
int dim1
Definition: c.h:594
int i