PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_uuid.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "port/pg_bswap.h"
#include "utils/uuid.h"
Include dependency graph for btree_uuid.c:

Go to the source code of this file.

Data Structures

struct  uuidKEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_uuid_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_union)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_same)
 
static int uuid_internal_cmp (const pg_uuid_t *arg1, const pg_uuid_t *arg2)
 
static bool gbt_uuidgt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_uuidge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_uuideq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_uuidle (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_uuidlt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_uuidkey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
Datum gbt_uuid_compress (PG_FUNCTION_ARGS)
 
Datum gbt_uuid_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_uuid_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_uuid_union (PG_FUNCTION_ARGS)
 
static double uuid_2_double (const pg_uuid_t *u)
 
Datum gbt_uuid_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_uuid_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_uuid_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

Datum gbt_uuid_compress ( PG_FUNCTION_ARGS  )

Definition at line 101 of file btree_uuid.c.

References DatumGetUUIDP, FALSE, gistentryinit, GISTENTRY::key, GISTENTRY::leafkey, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, GISTENTRY::rel, and UUID_LEN.

102 {
103  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
104  GISTENTRY *retval;
105 
106  if (entry->leafkey)
107  {
108  char *r = (char *) palloc(2 * UUID_LEN);
109  pg_uuid_t *key = DatumGetUUIDP(entry->key);
110 
111  retval = palloc(sizeof(GISTENTRY));
112 
113  memcpy((void *) r, (void *) key, UUID_LEN);
114  memcpy((void *) (r + UUID_LEN), (void *) key, UUID_LEN);
115  gistentryinit(*retval, PointerGetDatum(r),
116  entry->rel, entry->page,
117  entry->offset, FALSE);
118  }
119  else
120  retval = entry;
121 
122  PG_RETURN_POINTER(retval);
123 }
Relation rel
Definition: gist.h:124
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetUUIDP(X)
Definition: uuid.h:28
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Page page
Definition: gist.h:125
#define FALSE
Definition: c.h:221
Datum key
Definition: gist.h:123
bool leafkey
Definition: gist.h:127
#define UUID_LEN
Definition: uuid.h:18
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
Definition: uuid.h:20
void * palloc(Size size)
Definition: mcxt.c:849
OffsetNumber offset
Definition: gist.h:126
Datum gbt_uuid_consistent ( PG_FUNCTION_ARGS  )

Definition at line 134 of file btree_uuid.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, uuidKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_GETARG_UUID_P, PG_RETURN_BOOL, uuidKEY::upper, and GBT_NUMKEY_R::upper.

135 {
136  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
137  pg_uuid_t *query = PG_GETARG_UUID_P(1);
139 
140  /* Oid subtype = PG_GETARG_OID(3); */
141  bool *recheck = (bool *) PG_GETARG_POINTER(4);
142  uuidKEY *kkk = (uuidKEY *) DatumGetPointer(entry->key);
143  GBT_NUMKEY_R key;
144 
145  /* All cases served by this function are exact */
146  *recheck = false;
147 
148  key.lower = (GBT_NUMKEY *) &kkk->lower;
149  key.upper = (GBT_NUMKEY *) &kkk->upper;
150 
152  gbt_num_consistent(&key, (void *) query, &strategy,
153  GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
154  );
155 }
#define GIST_LEAF(entry)
Definition: gist.h:133
#define PG_GETARG_UUID_P(X)
Definition: uuid.h:29
const GBT_NUMKEY * lower
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static const gbtree_ninfo tinfo
Definition: btree_uuid.c:80
pg_uuid_t lower
Definition: btree_uuid.c:13
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
Definition: uuid.h:20
pg_uuid_t upper
Definition: btree_uuid.c:13
Datum gbt_uuid_fetch ( PG_FUNCTION_ARGS  )

Definition at line 126 of file btree_uuid.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

127 {
128  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
129 
131 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_uuid.c:80
Datum gbt_uuid_penalty ( PG_FUNCTION_ARGS  )

Definition at line 199 of file btree_uuid.c.

References DatumGetPointer, uuidKEY::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, result, uuidKEY::upper, and uuid_2_double().

200 {
201  uuidKEY *origentry = (uuidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
202  uuidKEY *newentry = (uuidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
203  float *result = (float *) PG_GETARG_POINTER(2);
204  double olower,
205  oupper,
206  nlower,
207  nupper;
208 
209  olower = uuid_2_double(&origentry->lower);
210  oupper = uuid_2_double(&origentry->upper);
211  nlower = uuid_2_double(&newentry->lower);
212  nupper = uuid_2_double(&newentry->upper);
213 
214  penalty_num(result, olower, oupper, nlower, nupper);
215 
216  PG_RETURN_POINTER(result);
217 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
pg_uuid_t lower
Definition: btree_uuid.c:13
static double uuid_2_double(const pg_uuid_t *u)
Definition: btree_uuid.c:171
#define penalty_num(result, olower, oupper, nlower, nupper)
#define DatumGetPointer(X)
Definition: postgres.h:555
pg_uuid_t upper
Definition: btree_uuid.c:13
Datum gbt_uuid_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 220 of file btree_uuid.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

221 {
225  &tinfo, fcinfo->flinfo
226  ));
227 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_uuid.c:80
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum gbt_uuid_same ( PG_FUNCTION_ARGS  )

Definition at line 230 of file btree_uuid.c.

References gbt_num_same(), PG_GETARG_POINTER, PG_RETURN_POINTER, and result.

231 {
232  uuidKEY *b1 = (uuidKEY *) PG_GETARG_POINTER(0);
233  uuidKEY *b2 = (uuidKEY *) PG_GETARG_POINTER(1);
234  bool *result = (bool *) PG_GETARG_POINTER(2);
235 
236  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
237  PG_RETURN_POINTER(result);
238 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_uuid.c:80
Datum gbt_uuid_union ( PG_FUNCTION_ARGS  )

Definition at line 158 of file btree_uuid.c.

References gbt_num_union(), palloc(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

159 {
161  void *out = palloc(sizeof(uuidKEY));
162 
163  *(int *) PG_GETARG_POINTER(1) = sizeof(uuidKEY);
164  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
165 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_uuid.c:80
void * palloc(Size size)
Definition: mcxt.c:849
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static bool gbt_uuideq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 49 of file btree_uuid.c.

References uuid_internal_cmp().

50 {
51  return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) == 0;
52 }
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
Definition: uuid.h:20
static bool gbt_uuidge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 43 of file btree_uuid.c.

References uuid_internal_cmp().

44 {
45  return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) >= 0;
46 }
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
Definition: uuid.h:20
static bool gbt_uuidgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 37 of file btree_uuid.c.

References uuid_internal_cmp().

38 {
39  return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) > 0;
40 }
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
Definition: uuid.h:20
static int gbt_uuidkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 67 of file btree_uuid.c.

References uuidKEY::lower, uuidKEY::upper, and uuid_internal_cmp().

68 {
69  uuidKEY *ia = (uuidKEY *) (((const Nsrt *) a)->t);
70  uuidKEY *ib = (uuidKEY *) (((const Nsrt *) b)->t);
71  int res;
72 
73  res = uuid_internal_cmp(&ia->lower, &ib->lower);
74  if (res == 0)
75  res = uuid_internal_cmp(&ia->upper, &ib->upper);
76  return res;
77 }
pg_uuid_t lower
Definition: btree_uuid.c:13
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
pg_uuid_t upper
Definition: btree_uuid.c:13
static bool gbt_uuidle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 55 of file btree_uuid.c.

References uuid_internal_cmp().

56 {
57  return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) <= 0;
58 }
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
Definition: uuid.h:20
static bool gbt_uuidlt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 61 of file btree_uuid.c.

References uuid_internal_cmp().

62 {
63  return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) < 0;
64 }
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
Definition: uuid.h:20
PG_FUNCTION_INFO_V1 ( gbt_uuid_compress  )
PG_FUNCTION_INFO_V1 ( gbt_uuid_fetch  )
PG_FUNCTION_INFO_V1 ( gbt_uuid_union  )
PG_FUNCTION_INFO_V1 ( gbt_uuid_picksplit  )
PG_FUNCTION_INFO_V1 ( gbt_uuid_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_uuid_penalty  )
PG_FUNCTION_INFO_V1 ( gbt_uuid_same  )
static double uuid_2_double ( const pg_uuid_t u)
static

Definition at line 171 of file btree_uuid.c.

References BSWAP64, pg_uuid_t::data, and UUID_LEN.

Referenced by gbt_uuid_penalty().

172 {
173  uint64 uu[2];
174  const double two64 = 18446744073709551616.0; /* 2^64 */
175 
176  /* Source data may not be suitably aligned, so copy */
177  memcpy(uu, u->data, UUID_LEN);
178 
179  /*
180  * uuid values should be considered as big-endian numbers, since that
181  * corresponds to how memcmp will compare them. On a little-endian
182  * machine, byte-swap each half so we can use native uint64 arithmetic.
183  */
184 #ifndef WORDS_BIGENDIAN
185  uu[0] = BSWAP64(uu[0]);
186  uu[1] = BSWAP64(uu[1]);
187 #endif
188 
189  /*
190  * 2^128 is about 3.4e38, which in theory could exceed the range of
191  * "double" (POSIX only requires 1e37). To avoid any risk of overflow,
192  * put the decimal point between the two halves rather than treating the
193  * uuid value as a 128-bit integer.
194  */
195  return (double) uu[0] + (double) uu[1] / two64;
196 }
unsigned char data[UUID_LEN]
Definition: uuid.h:22
#define BSWAP64(x)
Definition: pg_bswap.h:37
#define UUID_LEN
Definition: uuid.h:18
static int uuid_internal_cmp ( const pg_uuid_t arg1,
const pg_uuid_t arg2 
)
static

Definition at line 31 of file btree_uuid.c.

References pg_uuid_t::data, and UUID_LEN.

Referenced by gbt_uuideq(), gbt_uuidge(), gbt_uuidgt(), gbt_uuidkey_cmp(), gbt_uuidle(), and gbt_uuidlt().

32 {
33  return memcmp(arg1->data, arg2->data, UUID_LEN);
34 }
unsigned char data[UUID_LEN]
Definition: uuid.h:22
#define UUID_LEN
Definition: uuid.h:18

Variable Documentation

const gbtree_ninfo tinfo
static
Initial value:
=
{
32,
}
static bool gbt_uuideq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:49
static bool gbt_uuidgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:37
static int gbt_uuidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:67
static bool gbt_uuidge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:43
static bool gbt_uuidle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:55
#define UUID_LEN
Definition: uuid.h:18
#define NULL
Definition: c.h:229
static bool gbt_uuidlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:61

Definition at line 80 of file btree_uuid.c.