PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_oid.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.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)
 
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)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

Datum gbt_oid_compress ( PG_FUNCTION_ARGS  )

Definition at line 121 of file btree_oid.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

122 {
123  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
124 
126 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
Datum gbt_oid_consistent ( PG_FUNCTION_ARGS  )

Definition at line 137 of file btree_oid.c.

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

138 {
139  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
140  Oid query = PG_GETARG_OID(1);
142 
143  /* Oid subtype = PG_GETARG_OID(3); */
144  bool *recheck = (bool *) PG_GETARG_POINTER(4);
145  oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
146  GBT_NUMKEY_R key;
147 
148  /* All cases served by this function are exact */
149  *recheck = false;
150 
151  key.lower = (GBT_NUMKEY *) &kkk->lower;
152  key.upper = (GBT_NUMKEY *) &kkk->upper;
153 
155  gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
156  );
157 }
#define GIST_LEAF(entry)
Definition: gist.h:133
Oid lower
Definition: btree_enum.c:15
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
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)
unsigned int Oid
Definition: postgres_ext.h:31
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#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
Oid upper
Definition: btree_enum.c:16
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 }
unsigned int Oid
Definition: postgres_ext.h:31
double float8
Definition: c.h:381
Datum gbt_oid_distance ( PG_FUNCTION_ARGS  )

Definition at line 161 of file btree_oid.c.

References DatumGetPointer, gbt_num_distance(), GIST_LEAF, GISTENTRY::key, oidKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_FLOAT8, oidKEY::upper, and GBT_NUMKEY_R::upper.

162 {
163  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
164  Oid query = PG_GETARG_OID(1);
165 
166  /* Oid subtype = PG_GETARG_OID(3); */
167  oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
168  GBT_NUMKEY_R key;
169 
170  key.lower = (GBT_NUMKEY *) &kkk->lower;
171  key.upper = (GBT_NUMKEY *) &kkk->upper;
172 
174  gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
175  );
176 }
#define GIST_LEAF(entry)
Definition: gist.h:133
Oid lower
Definition: btree_enum.c:15
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
const GBT_NUMKEY * lower
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:326
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
unsigned int Oid
Definition: postgres_ext.h:31
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define DatumGetPointer(X)
Definition: postgres.h:555
Oid upper
Definition: btree_enum.c:16
Datum gbt_oid_fetch ( PG_FUNCTION_ARGS  )

Definition at line 129 of file btree_oid.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

130 {
131  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
132 
134 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum gbt_oid_penalty ( PG_FUNCTION_ARGS  )

Definition at line 191 of file btree_oid.c.

References DatumGetPointer, oidKEY::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, result, and oidKEY::upper.

192 {
193  oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
194  oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
195  float *result = (float *) PG_GETARG_POINTER(2);
196 
197  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
198 
199  PG_RETURN_POINTER(result);
200 }
Oid lower
Definition: btree_enum.c:15
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define penalty_num(result, olower, oupper, nlower, nupper)
#define DatumGetPointer(X)
Definition: postgres.h:555
Oid upper
Definition: btree_enum.c:16
Datum gbt_oid_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 203 of file btree_oid.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

204 {
208  &tinfo, fcinfo->flinfo
209  ));
210 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum gbt_oid_same ( PG_FUNCTION_ARGS  )

Definition at line 213 of file btree_oid.c.

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

214 {
215  oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
216  oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
217  bool *result = (bool *) PG_GETARG_POINTER(2);
218 
219  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
220  PG_RETURN_POINTER(result);
221 }
#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)
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum gbt_oid_union ( PG_FUNCTION_ARGS  )

Definition at line 180 of file btree_oid.c.

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

181 {
183  void *out = palloc(sizeof(oidKEY));
184 
185  *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
186  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
187 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
static const gbtree_ninfo tinfo
Definition: btree_oid.c:84
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
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_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 }
unsigned int Oid
Definition: postgres_ext.h:31
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 }
unsigned int Oid
Definition: postgres_ext.h:31
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 }
unsigned int Oid
Definition: postgres_ext.h:31
static int gbt_oidkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 55 of file btree_oid.c.

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

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 }
Oid lower
Definition: btree_enum.c:15
Oid upper
Definition: btree_enum.c:16
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 }
unsigned int Oid
Definition: postgres_ext.h:31
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 }
unsigned int Oid
Definition: postgres_ext.h:31
Datum oid_dist ( PG_FUNCTION_ARGS  )

Definition at line 101 of file btree_oid.c.

References PG_GETARG_OID, and PG_RETURN_OID.

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 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
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 ( oid_dist  )

Variable Documentation

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(Oid),
8,
}
static bool gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:34
static bool gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:49
unsigned int Oid
Definition: postgres_ext.h:31
static bool gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:44
static float8 gbt_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:72
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 bool gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_oid.c:39

Definition at line 84 of file btree_oid.c.