PostgreSQL Source Code  git master
btree_inet.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "catalog/pg_type.h"
#include "utils/builtins.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

typedef struct inetkey inetKEY

Function Documentation

◆ gbt_inet_compress()

Datum gbt_inet_compress ( PG_FUNCTION_ARGS  )

Definition at line 93 of file btree_inet.c.

94 {
95  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
96  GISTENTRY *retval;
97 
98  if (entry->leafkey)
99  {
100  inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
101  bool failure = false;
102 
103  retval = palloc(sizeof(GISTENTRY));
104  r->lower = convert_network_to_scalar(entry->key, INETOID, &failure);
105  Assert(!failure);
106  r->upper = r->lower;
107  gistentryinit(*retval, PointerGetDatum(r),
108  entry->rel, entry->page,
109  entry->offset, false);
110  }
111  else
112  retval = entry;
113 
114  PG_RETURN_POINTER(retval);
115 }
#define Assert(condition)
Definition: c.h:812
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:244
void * palloc(Size size)
Definition: mcxt.c:1317
double convert_network_to_scalar(Datum value, Oid typid, bool *failure)
Definition: network.c:1496
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
OffsetNumber offset
Definition: gist.h:163
Datum key
Definition: gist.h:160
Page page
Definition: gist.h:162
Relation rel
Definition: gist.h:161
bool leafkey
Definition: gist.h:164
double lower
Definition: btree_inet.c:13
double upper
Definition: btree_inet.c:14

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.

◆ gbt_inet_consistent()

Datum gbt_inet_consistent ( PG_FUNCTION_ARGS  )

Definition at line 119 of file btree_inet.c.

120 {
121  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
122  Datum dquery = PG_GETARG_DATUM(1);
124 
125  /* Oid subtype = PG_GETARG_OID(3); */
126  bool *recheck = (bool *) PG_GETARG_POINTER(4);
127  inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
129  double query;
130  bool failure = false;
131 
132  query = convert_network_to_scalar(dquery, INETOID, &failure);
133  Assert(!failure);
134 
135  /* All cases served by this function are inexact */
136  *recheck = true;
137 
138  key.lower = (GBT_NUMKEY *) &kkk->lower;
139  key.upper = (GBT_NUMKEY *) &kkk->upper;
140 
142  &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
143 }
static const gbtree_ninfo tinfo
Definition: btree_inet.c:72
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_DATUM(n)
Definition: fmgr.h:268
#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:170
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
uint16 StrategyNumber
Definition: stratnum.h:22

References Assert, convert_network_to_scalar(), DatumGetPointer(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, sort-test::key, inetkey::lower, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, tinfo, and inetkey::upper.

◆ gbt_inet_penalty()

Datum gbt_inet_penalty ( PG_FUNCTION_ARGS  )

Definition at line 158 of file btree_inet.c.

159 {
160  inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
161  inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
162  float *result = (float *) PG_GETARG_POINTER(2);
163 
164  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
165 
166  PG_RETURN_POINTER(result);
167 }
#define penalty_num(result, olower, oupper, nlower, nupper)

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

◆ gbt_inet_picksplit()

Datum gbt_inet_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 170 of file btree_inet.c.

171 {
174  &tinfo, fcinfo->flinfo));
175 }
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_inet_same()

Datum gbt_inet_same ( PG_FUNCTION_ARGS  )

Definition at line 178 of file btree_inet.c.

179 {
180  inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0);
181  inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1);
182  bool *result = (bool *) PG_GETARG_POINTER(2);
183 
184  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
185  PG_RETURN_POINTER(result);
186 }
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_inet_union()

Datum gbt_inet_union ( PG_FUNCTION_ARGS  )

Definition at line 147 of file btree_inet.c.

148 {
150  void *out = palloc(sizeof(inetKEY));
151 
152  *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
153  PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
154 }
struct inetkey inetKEY
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_ineteq()

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

Definition at line 39 of file btree_inet.c.

40 {
41  return (*((const double *) a) == *((const double *) b));
42 }
int b
Definition: isn.c:69
int a
Definition: isn.c:68

References a, and b.

◆ gbt_inetge()

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

Definition at line 34 of file btree_inet.c.

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

References a, and b.

◆ gbt_inetgt()

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

Definition at line 29 of file btree_inet.c.

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

References a, and b.

◆ gbt_inetkey_cmp()

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

Definition at line 55 of file btree_inet.c.

56 {
57  inetKEY *ia = (inetKEY *) (((const Nsrt *) a)->t);
58  inetKEY *ib = (inetKEY *) (((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, inetkey::lower, and inetkey::upper.

◆ gbt_inetle()

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

Definition at line 44 of file btree_inet.c.

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

References a, and b.

◆ gbt_inetlt()

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

Definition at line 49 of file btree_inet.c.

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

References a, and b.

◆ 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_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_penalty  )

◆ PG_FUNCTION_INFO_V1() [4/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_same  )

◆ PG_FUNCTION_INFO_V1() [6/6]

PG_FUNCTION_INFO_V1 ( gbt_inet_union  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(double),
16,
NULL
}
@ gbt_t_inet
Definition: btree_gist.h:36
static bool gbt_inetge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:34
static int gbt_inetkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:55
static bool gbt_inetgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:29
static bool gbt_inetle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:44
static bool gbt_inetlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:49
static bool gbt_ineteq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_inet.c:39

Definition at line 72 of file btree_inet.c.

Referenced by gbt_inet_consistent(), gbt_inet_picksplit(), gbt_inet_same(), and gbt_inet_union().