PostgreSQL Source Code  git master
btree_bool.c
Go to the documentation of this file.
1 /*
2  * contrib/btree_gist/btree_bool.c
3  */
4 #include "postgres.h"
5 
6 #include "btree_gist.h"
7 #include "btree_utils_num.h"
8 #include "common/int.h"
9 
10 typedef struct boolkey
11 {
12  bool lower;
13  bool upper;
15 
16 /*
17 ** bool ops
18 */
26 
27 static bool
28 gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
29 {
30  return (*((const bool *) a) > *((const bool *) b));
31 }
32 static bool
33 gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
34 {
35  return (*((const bool *) a) >= *((const bool *) b));
36 }
37 static bool
38 gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
39 {
40  return (*((const bool *) a) == *((const bool *) b));
41 }
42 static bool
43 gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
44 {
45  return (*((const bool *) a) <= *((const bool *) b));
46 }
47 static bool
48 gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
49 {
50  return (*((const bool *) a) < *((const bool *) b));
51 }
52 
53 static int
54 gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
55 {
56  boolKEY *ia = (boolKEY *) (((const Nsrt *) a)->t);
57  boolKEY *ib = (boolKEY *) (((const Nsrt *) b)->t);
58 
59  if (ia->lower == ib->lower)
60  {
61  if (ia->upper == ib->upper)
62  return 0;
63 
64  return (ia->upper > ib->upper) ? 1 : -1;
65  }
66 
67  return (ia->lower > ib->lower) ? 1 : -1;
68 }
69 
70 
71 static const gbtree_ninfo tinfo =
72 {
73  gbt_t_bool,
74  sizeof(bool),
75  2, /* sizeof(gbtreekey2) */
76  gbt_boolgt,
77  gbt_boolge,
78  gbt_booleq,
79  gbt_boolle,
80  gbt_boollt,
82 };
83 
84 
85 /**************************************************
86  * bool ops
87  **************************************************/
88 
89 
90 Datum
92 {
93  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
94 
96 }
97 
98 Datum
100 {
101  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
102 
104 }
105 
106 Datum
108 {
109  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
110  bool query = PG_GETARG_INT16(1);
112 
113  /* Oid subtype = PG_GETARG_OID(3); */
114  bool *recheck = (bool *) PG_GETARG_POINTER(4);
115  boolKEY *kkk = (boolKEY *) DatumGetPointer(entry->key);
117 
118  /* All cases served by this function are exact */
119  *recheck = false;
120 
121  key.lower = (GBT_NUMKEY *) &kkk->lower;
122  key.upper = (GBT_NUMKEY *) &kkk->upper;
123 
124  PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
125  GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
126 }
127 
128 
129 Datum
131 {
133  void *out = palloc(sizeof(boolKEY));
134 
135  *(int *) PG_GETARG_POINTER(1) = sizeof(boolKEY);
136  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
137 }
138 
139 
140 Datum
142 {
143  boolKEY *origentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
144  boolKEY *newentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
145  float *result = (float *) PG_GETARG_POINTER(2);
146 
147  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
148 
149  PG_RETURN_POINTER(result);
150 }
151 
152 Datum
154 {
157  &tinfo, fcinfo->flinfo));
158 }
159 
160 Datum
162 {
163  boolKEY *b1 = (boolKEY *) PG_GETARG_POINTER(0);
164  boolKEY *b2 = (boolKEY *) PG_GETARG_POINTER(1);
165  bool *result = (bool *) PG_GETARG_POINTER(2);
166 
167  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
168  PG_RETURN_POINTER(result);
169 }
Datum gbt_bool_compress(PG_FUNCTION_ARGS)
Definition: btree_bool.c:91
static bool gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:28
Datum gbt_bool_penalty(PG_FUNCTION_ARGS)
Definition: btree_bool.c:141
static bool gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:48
Datum gbt_bool_consistent(PG_FUNCTION_ARGS)
Definition: btree_bool.c:107
static bool gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:33
static int gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:54
struct boolkey boolKEY
Datum gbt_bool_picksplit(PG_FUNCTION_ARGS)
Definition: btree_bool.c:153
static const gbtree_ninfo tinfo
Definition: btree_bool.c:71
PG_FUNCTION_INFO_V1(gbt_bool_compress)
static bool gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:43
static bool gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:38
Datum gbt_bool_fetch(PG_FUNCTION_ARGS)
Definition: btree_bool.c:99
Datum gbt_bool_union(PG_FUNCTION_ARGS)
Definition: btree_bool.c:130
Datum gbt_bool_same(PG_FUNCTION_ARGS)
Definition: btree_bool.c:161
@ gbt_t_bool
Definition: btree_gist.h:35
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define penalty_num(result, olower, oupper, nlower, nupper)
char GBT_NUMKEY
unsigned char bool
Definition: c.h:443
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271
#define GIST_LEAF(entry)
Definition: gist.h:170
int b
Definition: isn.c:70
int a
Definition: isn.c:69
void * palloc(Size size)
Definition: mcxt.c:1304
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:160
bool lower
Definition: btree_bool.c:12
bool upper
Definition: btree_bool.c:13