PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_inet.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/builtins.h"
#include "utils/inet.h"
#include "catalog/pg_type.h"
Include dependency graph for btree_inet.c:

Go to the source code of this file.

Data Structures

struct  inetkey
 

Typedefs

typedef struct inetkey inetKEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_inet_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_inet_union)
 
 PG_FUNCTION_INFO_V1 (gbt_inet_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_inet_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_inet_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_inet_same)
 
static bool gbt_inetgt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_inetge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_ineteq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_inetle (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_inetlt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_inetkey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
Datum gbt_inet_compress (PG_FUNCTION_ARGS)
 
Datum gbt_inet_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_inet_union (PG_FUNCTION_ARGS)
 
Datum gbt_inet_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_inet_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_inet_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Typedef Documentation

Function Documentation

Datum gbt_inet_compress ( PG_FUNCTION_ARGS  )

Definition at line 94 of file btree_inet.c.

References convert_network_to_scalar(), FALSE, gistentryinit, INETOID, GISTENTRY::key, GISTENTRY::leafkey, inetkey::lower, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, GISTENTRY::rel, and inetkey::upper.

95 {
96  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
97  GISTENTRY *retval;
98 
99  if (entry->leafkey)
100  {
101  inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
102 
103  retval = palloc(sizeof(GISTENTRY));
105  r->upper = r->lower;
106  gistentryinit(*retval, PointerGetDatum(r),
107  entry->rel, entry->page,
108  entry->offset, FALSE);
109  }
110  else
111  retval = entry;
112 
113  PG_RETURN_POINTER(retval);
114 }
Relation rel
Definition: gist.h:124
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PointerGetDatum(X)
Definition: postgres.h:562
#define INETOID
Definition: pg_type.h:448
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Page page
Definition: gist.h:125
#define FALSE
Definition: c.h:219
double convert_network_to_scalar(Datum value, Oid typid)
Definition: network.c:907
Datum key
Definition: gist.h:123
bool leafkey
Definition: gist.h:127
double upper
Definition: btree_inet.c:15
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
double lower
Definition: btree_inet.c:14
void * palloc(Size size)
Definition: mcxt.c:848
OffsetNumber offset
Definition: gist.h:126
Datum gbt_inet_consistent ( PG_FUNCTION_ARGS  )

Definition at line 118 of file btree_inet.c.

References convert_network_to_scalar(), DatumGetPointer, gbt_num_consistent(), GIST_LEAF, INETOID, GISTENTRY::key, inetkey::lower, GBT_NUMKEY_R::lower, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, inetkey::upper, and GBT_NUMKEY_R::upper.

119 {
120  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
123 
124  /* Oid subtype = PG_GETARG_OID(3); */
125  bool *recheck = (bool *) PG_GETARG_POINTER(4);
126  inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
127  GBT_NUMKEY_R key;
128 
129  /* All cases served by this function are inexact */
130  *recheck = true;
131 
132  key.lower = (GBT_NUMKEY *) &kkk->lower;
133  key.upper = (GBT_NUMKEY *) &kkk->upper;
134 
135  PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query,
136  &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
137 }
#define GIST_LEAF(entry)
Definition: gist.h:133
const GBT_NUMKEY * lower
#define INETOID
Definition: pg_type.h:448
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
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)
double convert_network_to_scalar(Datum value, Oid typid)
Definition: network.c:907
Datum key
Definition: gist.h:123
char GBT_NUMKEY
double upper
Definition: btree_inet.c:15
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static const gbtree_ninfo tinfo
Definition: btree_inet.c:73
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
double lower
Definition: btree_inet.c:14
Datum gbt_inet_penalty ( PG_FUNCTION_ARGS  )

Definition at line 152 of file btree_inet.c.

References DatumGetPointer, inetkey::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and inetkey::upper.

153 {
154  inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
155  inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
156  float *result = (float *) PG_GETARG_POINTER(2);
157 
158  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
159 
160  PG_RETURN_POINTER(result);
161 
162 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define penalty_num(result, olower, oupper, nlower, nupper)
double upper
Definition: btree_inet.c:15
#define DatumGetPointer(X)
Definition: postgres.h:555
double lower
Definition: btree_inet.c:14
Datum gbt_inet_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 165 of file btree_inet.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

166 {
170  &tinfo, fcinfo->flinfo
171  ));
172 }
#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_inet.c:73
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum gbt_inet_same ( PG_FUNCTION_ARGS  )

Definition at line 175 of file btree_inet.c.

References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

176 {
177  inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0);
178  inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1);
179  bool *result = (bool *) PG_GETARG_POINTER(2);
180 
181  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
182  PG_RETURN_POINTER(result);
183 }
#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)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_inet.c:73
Datum gbt_inet_union ( PG_FUNCTION_ARGS  )

Definition at line 141 of file btree_inet.c.

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

142 {
144  void *out = palloc(sizeof(inetKEY));
145 
146  *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
147  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
148 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
struct inetkey inetKEY
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_inet.c:73
void * palloc(Size size)
Definition: mcxt.c:848
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static bool gbt_ineteq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 40 of file btree_inet.c.

41 {
42  return (*((const double *) a) == *((const double *) b));
43 }
static bool gbt_inetge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 35 of file btree_inet.c.

36 {
37  return (*((const double *) a) >= *((const double *) b));
38 }
static bool gbt_inetgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 30 of file btree_inet.c.

31 {
32  return (*((const double *) a) > *((const double *) b));
33 }
static int gbt_inetkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 56 of file btree_inet.c.

References inetkey::lower, and inetkey::upper.

57 {
58  inetKEY *ia = (inetKEY *) (((const Nsrt *) a)->t);
59  inetKEY *ib = (inetKEY *) (((const Nsrt *) b)->t);
60 
61  if (ia->lower == ib->lower)
62  {
63  if (ia->upper == ib->upper)
64  return 0;
65 
66  return (ia->upper > ib->upper) ? 1 : -1;
67  }
68 
69  return (ia->lower > ib->lower) ? 1 : -1;
70 }
double upper
Definition: btree_inet.c:15
double lower
Definition: btree_inet.c:14
static bool gbt_inetle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 45 of file btree_inet.c.

46 {
47  return (*((const double *) a) <= *((const double *) b));
48 }
static bool gbt_inetlt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 50 of file btree_inet.c.

51 {
52  return (*((const double *) a) < *((const double *) b));
53 }
PG_FUNCTION_INFO_V1 ( gbt_inet_compress  )
PG_FUNCTION_INFO_V1 ( gbt_inet_union  )
PG_FUNCTION_INFO_V1 ( gbt_inet_picksplit  )
PG_FUNCTION_INFO_V1 ( gbt_inet_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_inet_penalty  )
PG_FUNCTION_INFO_V1 ( gbt_inet_same  )

Variable Documentation

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(double),
16,
NULL
}
static bool gbt_inetle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:45
static bool gbt_inetgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:30
static int gbt_inetkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:56
static bool gbt_ineteq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:40
static bool gbt_inetge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:35
static bool gbt_inetlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:50

Definition at line 73 of file btree_inet.c.