PostgreSQL Source Code  git master
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

◆ inetKEY

Function Documentation

◆ gbt_inet_compress()

Datum gbt_inet_compress ( PG_FUNCTION_ARGS  )

Definition at line 94 of file btree_inet.c.

References Assert, convert_network_to_scalar(), gistentryinit, 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  bool failure = false;
103 
104  retval = palloc(sizeof(GISTENTRY));
105  r->lower = convert_network_to_scalar(entry->key, INETOID, &failure);
106  Assert(!failure);
107  r->upper = r->lower;
108  gistentryinit(*retval, PointerGetDatum(r),
109  entry->rel, entry->page,
110  entry->offset, false);
111  }
112  else
113  retval = entry;
114 
115  PG_RETURN_POINTER(retval);
116 }
Relation rel
Definition: gist.h:124
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
#define PointerGetDatum(X)
Definition: postgres.h:541
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
Page page
Definition: gist.h:125
double convert_network_to_scalar(Datum value, Oid typid, bool *failure)
Definition: network.c:910
Datum key
Definition: gist.h:123
bool leafkey
Definition: gist.h:127
double upper
Definition: btree_inet.c:15
#define Assert(condition)
Definition: c.h:699
#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:924
OffsetNumber offset
Definition: gist.h:126

◆ gbt_inet_consistent()

Datum gbt_inet_consistent ( PG_FUNCTION_ARGS  )

Definition at line 120 of file btree_inet.c.

References Assert, convert_network_to_scalar(), DatumGetPointer, gbt_num_consistent(), GIST_LEAF, 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.

121 {
122  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
123  Datum dquery = PG_GETARG_DATUM(1);
125 
126  /* Oid subtype = PG_GETARG_OID(3); */
127  bool *recheck = (bool *) PG_GETARG_POINTER(4);
128  inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
129  GBT_NUMKEY_R key;
130  double query;
131  bool failure = false;
132 
133  query = convert_network_to_scalar(dquery, INETOID, &failure);
134  Assert(!failure);
135 
136  /* All cases served by this function are inexact */
137  *recheck = true;
138 
139  key.lower = (GBT_NUMKEY *) &kkk->lower;
140  key.upper = (GBT_NUMKEY *) &kkk->upper;
141 
142  PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query,
143  &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
144 }
#define GIST_LEAF(entry)
Definition: gist.h:133
const GBT_NUMKEY * lower
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:238
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
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, bool *failure)
Definition: network.c:910
Datum key
Definition: gist.h:123
char GBT_NUMKEY
double upper
Definition: btree_inet.c:15
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
uintptr_t Datum
Definition: postgres.h:367
static const gbtree_ninfo tinfo
Definition: btree_inet.c:73
#define Assert(condition)
Definition: c.h:699
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:242
#define DatumGetPointer(X)
Definition: postgres.h:534
double lower
Definition: btree_inet.c:14

◆ gbt_inet_penalty()

Datum gbt_inet_penalty ( PG_FUNCTION_ARGS  )

Definition at line 159 of file btree_inet.c.

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

160 {
161  inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
162  inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
163  float *result = (float *) PG_GETARG_POINTER(2);
164 
165  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
166 
167  PG_RETURN_POINTER(result);
168 
169 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
#define penalty_num(result, olower, oupper, nlower, nupper)
double upper
Definition: btree_inet.c:15
#define DatumGetPointer(X)
Definition: postgres.h:534
double lower
Definition: btree_inet.c:14

◆ gbt_inet_picksplit()

Datum gbt_inet_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 172 of file btree_inet.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

173 {
177  &tinfo, fcinfo->flinfo
178  ));
179 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
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)

◆ gbt_inet_same()

Datum gbt_inet_same ( PG_FUNCTION_ARGS  )

Definition at line 182 of file btree_inet.c.

References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

183 {
184  inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0);
185  inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1);
186  bool *result = (bool *) PG_GETARG_POINTER(2);
187 
188  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
189  PG_RETURN_POINTER(result);
190 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
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:246
static const gbtree_ninfo tinfo
Definition: btree_inet.c:73

◆ gbt_inet_union()

Datum gbt_inet_union ( PG_FUNCTION_ARGS  )

Definition at line 148 of file btree_inet.c.

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

149 {
151  void *out = palloc(sizeof(inetKEY));
152 
153  *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
154  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
155 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:326
struct inetkey inetKEY
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
static const gbtree_ninfo tinfo
Definition: btree_inet.c:73
void * palloc(Size size)
Definition: mcxt.c:924
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

◆ gbt_ineteq()

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 }

◆ gbt_inetge()

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 }

◆ gbt_inetgt()

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 }

◆ gbt_inetkey_cmp()

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

◆ gbt_inetle()

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 }

◆ gbt_inetlt()

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() [1/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_compress  )

◆ PG_FUNCTION_INFO_V1() [2/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_union  )

◆ PG_FUNCTION_INFO_V1() [3/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_picksplit  )

◆ PG_FUNCTION_INFO_V1() [4/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_consistent  )

◆ PG_FUNCTION_INFO_V1() [5/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_penalty  )

◆ PG_FUNCTION_INFO_V1() [6/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_same  )

Variable Documentation

◆ tinfo

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.