PostgreSQL Source Code git master
btree_oid.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/sortsupport.h"
Include dependency graph for btree_oid.c:

Go to the source code of this file.

Data Structures

struct  oidKEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_oid_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_union)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_same)
 
 PG_FUNCTION_INFO_V1 (gbt_oid_sortsupport)
 
static bool gbt_oidgt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_oidge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_oideq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_oidle (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_oidlt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_oidkey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_oid_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (oid_dist)
 
Datum oid_dist (PG_FUNCTION_ARGS)
 
Datum gbt_oid_compress (PG_FUNCTION_ARGS)
 
Datum gbt_oid_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_oid_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_oid_distance (PG_FUNCTION_ARGS)
 
Datum gbt_oid_union (PG_FUNCTION_ARGS)
 
Datum gbt_oid_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_oid_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_oid_same (PG_FUNCTION_ARGS)
 
static int gbt_oid_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_oid_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

◆ gbt_oid_compress()

Datum gbt_oid_compress ( PG_FUNCTION_ARGS  )

Definition at line 120 of file btree_oid.c.

121{
122 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
123
125}
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361

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

◆ gbt_oid_consistent()

Datum gbt_oid_consistent ( PG_FUNCTION_ARGS  )

Definition at line 136 of file btree_oid.c.

137{
138 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139 Oid query = PG_GETARG_OID(1);
141
142 /* Oid subtype = PG_GETARG_OID(3); */
143 bool *recheck = (bool *) PG_GETARG_POINTER(4);
144 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
146
147 /* All cases served by this function are exact */
148 *recheck = false;
149
150 key.lower = (GBT_NUMKEY *) &kkk->lower;
151 key.upper = (GBT_NUMKEY *) &kkk->upper;
152
153 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
154 GIST_LEAF(entry), &tinfo, 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
#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:359
#define GIST_LEAF(entry)
Definition: gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
unsigned int Oid
Definition: postgres_ext.h:30
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:161
Oid upper
Definition: btree_enum.c:18
Oid lower
Definition: btree_enum.c:17

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

◆ gbt_oid_dist()

static float8 gbt_oid_dist ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 72 of file btree_oid.c.

73{
74 Oid aa = *(const Oid *) a;
75 Oid bb = *(const Oid *) b;
76
77 if (aa < bb)
78 return (float8) (bb - aa);
79 else
80 return (float8) (aa - bb);
81}
double float8
Definition: c.h:601
int b
Definition: isn.c:74
int a
Definition: isn.c:73

References a, and b.

◆ gbt_oid_distance()

Datum gbt_oid_distance ( PG_FUNCTION_ARGS  )

Definition at line 158 of file btree_oid.c.

159{
160 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
161 Oid query = PG_GETARG_OID(1);
162
163 /* Oid subtype = PG_GETARG_OID(3); */
164 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
166
167 key.lower = (GBT_NUMKEY *) &kkk->lower;
168 key.upper = (GBT_NUMKEY *) &kkk->upper;
169
171 &tinfo, fcinfo->flinfo));
172}
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367

References DatumGetPointer(), gbt_num_distance(), GIST_LEAF, GISTENTRY::key, sort-test::key, oidKEY::lower, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_FLOAT8, tinfo, and oidKEY::upper.

◆ gbt_oid_fetch()

Datum gbt_oid_fetch ( PG_FUNCTION_ARGS  )

Definition at line 128 of file btree_oid.c.

129{
130 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
131
133}
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

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

◆ gbt_oid_penalty()

Datum gbt_oid_penalty ( PG_FUNCTION_ARGS  )

Definition at line 185 of file btree_oid.c.

186{
187 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
188 oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
189 float *result = (float *) PG_GETARG_POINTER(2);
190
191 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
192
193 PG_RETURN_POINTER(result);
194}
#define penalty_num(result, olower, oupper, nlower, nupper)

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

◆ gbt_oid_picksplit()

Datum gbt_oid_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 197 of file btree_oid.c.

198{
201 &tinfo, fcinfo->flinfo));
202}
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_oid_same()

Datum gbt_oid_same ( PG_FUNCTION_ARGS  )

Definition at line 205 of file btree_oid.c.

206{
207 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
208 oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
209 bool *result = (bool *) PG_GETARG_POINTER(2);
210
211 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
212 PG_RETURN_POINTER(result);
213}
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_oid_sortsupport()

Datum gbt_oid_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 231 of file btree_oid.c.

232{
234
236 ssup->ssup_extra = NULL;
237
239}
static int gbt_oid_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_oid.c:216
#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_oid_ssup_cmp(), PG_GETARG_POINTER, PG_RETURN_VOID, and SortSupportData::ssup_extra.

◆ gbt_oid_ssup_cmp()

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

Definition at line 216 of file btree_oid.c.

217{
218 oidKEY *arg1 = (oidKEY *) DatumGetPointer(x);
219 oidKEY *arg2 = (oidKEY *) DatumGetPointer(y);
220
221 /* for leaf items we expect lower == upper, so only compare lower */
222 if (arg1->lower > arg2->lower)
223 return 1;
224 else if (arg1->lower < arg2->lower)
225 return -1;
226 else
227 return 0;
228}
int y
Definition: isn.c:76
int x
Definition: isn.c:75

References DatumGetPointer(), oidKEY::lower, x, and y.

Referenced by gbt_oid_sortsupport().

◆ gbt_oid_union()

Datum gbt_oid_union ( PG_FUNCTION_ARGS  )

Definition at line 175 of file btree_oid.c.

176{
178 void *out = palloc(sizeof(oidKEY));
179
180 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
181 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
182}
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * palloc(Size size)
Definition: mcxt.c:1939

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

◆ gbt_oideq()

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

Definition at line 39 of file btree_oid.c.

40{
41 return (*((const Oid *) a) == *((const Oid *) b));
42}

References a, and b.

◆ gbt_oidge()

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

Definition at line 34 of file btree_oid.c.

35{
36 return (*((const Oid *) a) >= *((const Oid *) b));
37}

References a, and b.

◆ gbt_oidgt()

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

Definition at line 29 of file btree_oid.c.

30{
31 return (*((const Oid *) a) > *((const Oid *) b));
32}

References a, and b.

◆ gbt_oidkey_cmp()

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

Definition at line 55 of file btree_oid.c.

56{
57 oidKEY *ia = (oidKEY *) (((const Nsrt *) a)->t);
58 oidKEY *ib = (oidKEY *) (((const Nsrt *) b)->t);
59
60 if (ia->lower == ib->lower)
61 {
62 if (ia->upper == ib->upper)
63 return 0;
64
65 return (ia->upper > ib->upper) ? 1 : -1;
66 }
67
68 return (ia->lower > ib->lower) ? 1 : -1;
69}

References a, b, oidKEY::lower, and oidKEY::upper.

◆ gbt_oidle()

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

Definition at line 44 of file btree_oid.c.

45{
46 return (*((const Oid *) a) <= *((const Oid *) b));
47}

References a, and b.

◆ gbt_oidlt()

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

Definition at line 49 of file btree_oid.c.

50{
51 return (*((const Oid *) a) < *((const Oid *) b));
52}

References a, and b.

◆ oid_dist()

Datum oid_dist ( PG_FUNCTION_ARGS  )

Definition at line 101 of file btree_oid.c.

102{
103 Oid a = PG_GETARG_OID(0);
104 Oid b = PG_GETARG_OID(1);
105 Oid res;
106
107 if (a < b)
108 res = b - a;
109 else
110 res = a - b;
111 PG_RETURN_OID(res);
112}
#define PG_RETURN_OID(x)
Definition: fmgr.h:360

References a, b, PG_GETARG_OID, and PG_RETURN_OID.

◆ PG_FUNCTION_INFO_V1() [1/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_compress  )

◆ PG_FUNCTION_INFO_V1() [2/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_distance  )

◆ PG_FUNCTION_INFO_V1() [4/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_fetch  )

◆ PG_FUNCTION_INFO_V1() [5/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_penalty  )

◆ PG_FUNCTION_INFO_V1() [6/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_picksplit  )

◆ PG_FUNCTION_INFO_V1() [7/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_same  )

◆ PG_FUNCTION_INFO_V1() [8/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [9/10]

PG_FUNCTION_INFO_V1 ( gbt_oid_union  )

◆ PG_FUNCTION_INFO_V1() [10/10]

PG_FUNCTION_INFO_V1 ( oid_dist  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(Oid),
8,
}
@ gbt_t_oid
Definition: btree_gist.h:25
static bool gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:49
static bool gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:44
static bool gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:39
static bool gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:34
static int gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:55
static bool gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:29
static float8 gbt_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:72

Definition at line 84 of file btree_oid.c.

Referenced by gbt_oid_compress(), gbt_oid_consistent(), gbt_oid_distance(), gbt_oid_fetch(), gbt_oid_picksplit(), gbt_oid_same(), and gbt_oid_union().