PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_uuid.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "port/pg_bswap.h"
#include "utils/rel.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 101 of file btree_uuid.c.

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_object(GISTENTRY);
112
113 memcpy(r, key, UUID_LEN);
114 memcpy(r + UUID_LEN, 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}
#define palloc_object(type)
Definition fe_memutils.h:74
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define gistentryinit(e, k, r, pg, o, l)
Definition gist.h:245
void * palloc(Size size)
Definition mcxt.c:1387
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static int fb(int x)
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
static pg_uuid_t * DatumGetUUIDP(Datum X)
Definition uuid.h:35
#define UUID_LEN
Definition uuid.h:18

References DatumGetUUIDP(), fb(), gistentryinit, GISTENTRY::key, GISTENTRY::leafkey, GISTENTRY::offset, GISTENTRY::page, palloc(), palloc_object, 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 134 of file btree_uuid.c.

135{
136 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
137 pg_uuid_t *query = PG_GETARG_UUID_P(1);
139#ifdef NOT_USED
140 Oid subtype = PG_GETARG_OID(3);
141#endif
142 bool *recheck = (bool *) PG_GETARG_POINTER(4);
143 uuidKEY *kkk = (uuidKEY *) DatumGetPointer(entry->key);
145
146 /* All cases served by this function are exact */
147 *recheck = false;
148
149 key.lower = (GBT_NUMKEY *) &kkk->lower;
150 key.upper = (GBT_NUMKEY *) &kkk->upper;
151
152 PG_RETURN_BOOL(gbt_num_consistent(&key, query, &strategy,
153 GIST_LEAF(entry), &tinfo,
154 fcinfo->flinfo));
155}
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:81
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_UINT16(n)
Definition fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
#define GIST_LEAF(entry)
Definition gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
unsigned int Oid
uint16 StrategyNumber
Definition stratnum.h:22
#define PG_GETARG_UUID_P(X)
Definition uuid.h:40

References DatumGetPointer(), fb(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_GETARG_UUID_P, PG_RETURN_BOOL, and tinfo.

◆ gbt_uuid_fetch()

Datum gbt_uuid_fetch ( PG_FUNCTION_ARGS  )

Definition at line 126 of file btree_uuid.c.

127{
128 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
129
131}
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 199 of file btree_uuid.c.

200{
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
215
216 PG_RETURN_POINTER(result);
217}
#define penalty_num(result, olower, oupper, nlower, nupper)
static double uuid_2_double(const pg_uuid_t *u)
Definition btree_uuid.c:171

References DatumGetPointer(), fb(), penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and uuid_2_double().

◆ gbt_uuid_picksplit()

Datum gbt_uuid_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 220 of file btree_uuid.c.

221{
224 &tinfo, fcinfo->flinfo));
225}
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 228 of file btree_uuid.c.

229{
232 bool *result = (bool *) PG_GETARG_POINTER(2);
233
234 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
235 PG_RETURN_POINTER(result);
236}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_uuid_sortsupport()

Datum gbt_uuid_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 249 of file btree_uuid.c.

250{
252
254 ssup->ssup_extra = NULL;
255
257}
static int gbt_uuid_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition btree_uuid.c:239
#define PG_RETURN_VOID()
Definition fmgr.h:350
struct SortSupportData * SortSupport
Definition sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)

References SortSupportData::comparator, fb(), 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 239 of file btree_uuid.c.

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

References DatumGetPointer(), fb(), uuid_internal_cmp(), x, and y.

Referenced by gbt_uuid_sortsupport().

◆ gbt_uuid_union()

Datum gbt_uuid_union ( PG_FUNCTION_ARGS  )

Definition at line 158 of file btree_uuid.c.

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

References fb(), 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 50 of file btree_uuid.c.

51{
52 return uuid_internal_cmp((const pg_uuid_t *) a, (const pg_uuid_t *) b) == 0;
53}
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 44 of file btree_uuid.c.

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

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 38 of file btree_uuid.c.

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

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 68 of file btree_uuid.c.

69{
70 uuidKEY *ia = (uuidKEY *) (((const Nsrt *) a)->t);
71 uuidKEY *ib = (uuidKEY *) (((const Nsrt *) b)->t);
72 int res;
73
74 res = uuid_internal_cmp(&ia->lower, &ib->lower);
75 if (res == 0)
76 res = uuid_internal_cmp(&ia->upper, &ib->upper);
77 return res;
78}

References a, b, fb(), and uuid_internal_cmp().

◆ gbt_uuidle()

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

Definition at line 56 of file btree_uuid.c.

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

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 62 of file btree_uuid.c.

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

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 171 of file btree_uuid.c.

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] = pg_bswap64(uu[0]);
186 uu[1] = pg_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}
uint64_t uint64
Definition c.h:547
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, fb(), 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 32 of file btree_uuid.c.

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

References fb(), 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,
}
@ gbt_t_uuid
Definition btree_gist.h:37
static bool gbt_uuidle(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_uuid.c:56
static bool gbt_uuideq(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_uuid.c:50
static bool gbt_uuidgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_uuid.c:38
static bool gbt_uuidge(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_uuid.c:44
static bool gbt_uuidlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_uuid.c:62
static int gbt_uuidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition btree_uuid.c:68

Definition at line 81 of file btree_uuid.c.

82{
85 32, /* sizeof(gbtreekey32) */
92 NULL
93};

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