PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree_uuid.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "port/pg_bswap.h"
#include "utils/sortsupport.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)
 
 PG_FUNCTION_INFO_V1 (gbt_uuid_sortsupport)
 
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)
 
static int gbt_uuid_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_uuid_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

◆ gbt_uuid_compress()

Datum gbt_uuid_compress ( PG_FUNCTION_ARGS  )

Definition at line 100 of file btree_uuid.c.

101{
102 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
103 GISTENTRY *retval;
104
105 if (entry->leafkey)
106 {
107 char *r = (char *) palloc(2 * UUID_LEN);
108 pg_uuid_t *key = DatumGetUUIDP(entry->key);
109
110 retval = palloc(sizeof(GISTENTRY));
111
112 memcpy(r, key, UUID_LEN);
113 memcpy(r + UUID_LEN, key, UUID_LEN);
114 gistentryinit(*retval, PointerGetDatum(r),
115 entry->rel, entry->page,
116 entry->offset, false);
117 }
118 else
119 retval = entry;
120
121 PG_RETURN_POINTER(retval);
122}
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:245
void * palloc(Size size)
Definition: mcxt.c:1321
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
OffsetNumber offset
Definition: gist.h:164
Datum key
Definition: gist.h:161
Page page
Definition: gist.h:163
Relation rel
Definition: gist.h:162
bool leafkey
Definition: gist.h:165
Definition: uuid.h:21
static pg_uuid_t * DatumGetUUIDP(Datum X)
Definition: uuid.h:35
#define UUID_LEN
Definition: uuid.h:18

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

◆ gbt_uuid_consistent()

Datum gbt_uuid_consistent ( PG_FUNCTION_ARGS  )

Definition at line 133 of file btree_uuid.c.

134{
135 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
136 pg_uuid_t *query = PG_GETARG_UUID_P(1);
138
139 /* Oid subtype = PG_GETARG_OID(3); */
140 bool *recheck = (bool *) PG_GETARG_POINTER(4);
141 uuidKEY *kkk = (uuidKEY *) DatumGetPointer(entry->key);
143
144 /* All cases served by this function are exact */
145 *recheck = false;
146
147 key.lower = (GBT_NUMKEY *) &kkk->lower;
148 key.upper = (GBT_NUMKEY *) &kkk->upper;
149
150 PG_RETURN_BOOL(gbt_num_consistent(&key, query, &strategy,
151 GIST_LEAF(entry), &tinfo,
152 fcinfo->flinfo));
153}
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
char GBT_NUMKEY
static const gbtree_ninfo tinfo
Definition: btree_uuid.c:80
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
uint16 StrategyNumber
Definition: stratnum.h:22
pg_uuid_t upper
Definition: btree_uuid.c:15
pg_uuid_t lower
Definition: btree_uuid.c:14
#define PG_GETARG_UUID_P(X)
Definition: uuid.h:40

References DatumGetPointer(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, sort-test::key, uuidKEY::lower, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_GETARG_UUID_P, PG_RETURN_BOOL, tinfo, and uuidKEY::upper.

◆ gbt_uuid_fetch()

Datum gbt_uuid_fetch ( PG_FUNCTION_ARGS  )

Definition at line 125 of file btree_uuid.c.

126{
127 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
128
130}
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

References gbt_num_fetch(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_uuid_penalty()

Datum gbt_uuid_penalty ( PG_FUNCTION_ARGS  )

Definition at line 197 of file btree_uuid.c.

198{
199 uuidKEY *origentry = (uuidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
201 float *result = (float *) PG_GETARG_POINTER(2);
202 double olower,
203 oupper,
204 nlower,
205 nupper;
206
207 olower = uuid_2_double(&origentry->lower);
208 oupper = uuid_2_double(&origentry->upper);
209 nlower = uuid_2_double(&newentry->lower);
210 nupper = uuid_2_double(&newentry->upper);
211
212 penalty_num(result, olower, oupper, nlower, nupper);
213
214 PG_RETURN_POINTER(result);
215}
#define penalty_num(result, olower, oupper, nlower, nupper)
static double uuid_2_double(const pg_uuid_t *u)
Definition: btree_uuid.c:169

References DatumGetPointer(), sort-test::key, uuidKEY::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, uuidKEY::upper, and uuid_2_double().

◆ gbt_uuid_picksplit()

Datum gbt_uuid_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 218 of file btree_uuid.c.

219{
222 &tinfo, fcinfo->flinfo));
223}
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

References gbt_num_picksplit(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_uuid_same()

Datum gbt_uuid_same ( PG_FUNCTION_ARGS  )

Definition at line 226 of file btree_uuid.c.

227{
228 uuidKEY *b1 = (uuidKEY *) PG_GETARG_POINTER(0);
229 uuidKEY *b2 = (uuidKEY *) PG_GETARG_POINTER(1);
230 bool *result = (bool *) PG_GETARG_POINTER(2);
231
232 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
233 PG_RETURN_POINTER(result);
234}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_uuid_sortsupport()

Datum gbt_uuid_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 247 of file btree_uuid.c.

248{
250
252 ssup->ssup_extra = NULL;
253
255}
static int gbt_uuid_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_uuid.c:237
#define PG_RETURN_VOID()
Definition: fmgr.h:349
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87

References SortSupportData::comparator, gbt_uuid_ssup_cmp(), PG_GETARG_POINTER, PG_RETURN_VOID, and SortSupportData::ssup_extra.

◆ gbt_uuid_ssup_cmp()

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

Definition at line 237 of file btree_uuid.c.

238{
239 uuidKEY *arg1 = (uuidKEY *) DatumGetPointer(x);
240 uuidKEY *arg2 = (uuidKEY *) DatumGetPointer(y);
241
242 /* for leaf items we expect lower == upper, so only compare lower */
243 return uuid_internal_cmp(&arg1->lower, &arg2->lower);
244}
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition: btree_uuid.c:31
int y
Definition: isn.c:76
int x
Definition: isn.c:75

References DatumGetPointer(), uuidKEY::lower, uuid_internal_cmp(), x, and y.

Referenced by gbt_uuid_sortsupport().

◆ gbt_uuid_union()

Datum gbt_uuid_union ( PG_FUNCTION_ARGS  )

Definition at line 156 of file btree_uuid.c.

157{
159 void *out = palloc(sizeof(uuidKEY));
160
161 *(int *) PG_GETARG_POINTER(1) = sizeof(uuidKEY);
162 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
163}
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_uuideq()

static bool gbt_uuideq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 49 of file btree_uuid.c.

50{
51 return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) == 0;
52}
int b
Definition: isn.c:74
int a
Definition: isn.c:73

References a, b, and uuid_internal_cmp().

◆ gbt_uuidge()

static bool gbt_uuidge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 43 of file btree_uuid.c.

44{
45 return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) >= 0;
46}

References a, b, and uuid_internal_cmp().

◆ gbt_uuidgt()

static bool gbt_uuidgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 37 of file btree_uuid.c.

38{
39 return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) > 0;
40}

References a, b, and uuid_internal_cmp().

◆ gbt_uuidkey_cmp()

static int gbt_uuidkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 67 of file btree_uuid.c.

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}

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

◆ gbt_uuidle()

static bool gbt_uuidle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 55 of file btree_uuid.c.

56{
57 return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) <= 0;
58}

References a, b, and uuid_internal_cmp().

◆ gbt_uuidlt()

static bool gbt_uuidlt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 61 of file btree_uuid.c.

62{
63 return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) < 0;
64}

References a, b, and uuid_internal_cmp().

◆ PG_FUNCTION_INFO_V1() [1/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_compress  )

◆ PG_FUNCTION_INFO_V1() [2/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_fetch  )

◆ PG_FUNCTION_INFO_V1() [4/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_penalty  )

◆ PG_FUNCTION_INFO_V1() [5/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_picksplit  )

◆ PG_FUNCTION_INFO_V1() [6/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_same  )

◆ PG_FUNCTION_INFO_V1() [7/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [8/8]

PG_FUNCTION_INFO_V1 ( gbt_uuid_union  )

◆ uuid_2_double()

static double uuid_2_double ( const pg_uuid_t u)
static

Definition at line 169 of file btree_uuid.c.

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

References pg_uuid_t::data, pg_bswap64(), and UUID_LEN.

Referenced by gbt_uuid_penalty().

◆ uuid_internal_cmp()

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.

32{
33 return memcmp(arg1->data, arg2->data, UUID_LEN);
34}

References pg_uuid_t::data, and UUID_LEN.

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

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
32,
NULL
}
@ gbt_t_uuid
Definition: btree_gist.h:37
static bool gbt_uuidle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:55
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 bool gbt_uuidge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:43
static bool gbt_uuidlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:61
static int gbt_uuidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_uuid.c:67

Definition at line 80 of file btree_uuid.c.

Referenced by gbt_uuid_consistent(), gbt_uuid_fetch(), gbt_uuid_picksplit(), gbt_uuid_same(), and gbt_uuid_union().