Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

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 "utils/rel.h"
9#include "utils/sortsupport.h"
10
11typedef struct boolkey
12{
13 bool lower;
14 bool upper;
16
17/* GiST support functions */
26
27static bool
28gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
29{
30 return (*((const bool *) a) > *((const bool *) b));
31}
32static bool
33gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
34{
35 return (*((const bool *) a) >= *((const bool *) b));
36}
37static bool
38gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
39{
40 return (*((const bool *) a) == *((const bool *) b));
41}
42static bool
43gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
44{
45 return (*((const bool *) a) <= *((const bool *) b));
46}
47static bool
48gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
49{
50 return (*((const bool *) a) < *((const bool *) b));
51}
52
53static int
54gbt_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
71static const gbtree_ninfo tinfo =
72{
74 sizeof(bool),
75 2, /* sizeof(gbtreekey2) */
82};
83
84
85/**************************************************
86 * GiST support functions
87 **************************************************/
88
91{
93
95}
96
99{
100 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
101
103}
104
105Datum
107{
108 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
109 bool query = PG_GETARG_INT16(1);
111
112 /* Oid subtype = PG_GETARG_OID(3); */
113 bool *recheck = (bool *) PG_GETARG_POINTER(4);
114 boolKEY *kkk = (boolKEY *) DatumGetPointer(entry->key);
116
117 /* All cases served by this function are exact */
118 *recheck = false;
119
120 key.lower = (GBT_NUMKEY *) &kkk->lower;
121 key.upper = (GBT_NUMKEY *) &kkk->upper;
122
123 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
124 GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
125}
126
127Datum
129{
131 void *out = palloc(sizeof(boolKEY));
132
133 *(int *) PG_GETARG_POINTER(1) = sizeof(boolKEY);
134 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
135}
136
137Datum
139{
140 boolKEY *origentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
142 float *result = (float *) PG_GETARG_POINTER(2);
143
144 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
145
146 PG_RETURN_POINTER(result);
147}
148
149Datum
151{
154 &tinfo, fcinfo->flinfo));
155}
156
157Datum
159{
160 boolKEY *b1 = (boolKEY *) PG_GETARG_POINTER(0);
161 boolKEY *b2 = (boolKEY *) PG_GETARG_POINTER(1);
162 bool *result = (bool *) PG_GETARG_POINTER(2);
163
164 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
165 PG_RETURN_POINTER(result);
166}
167
168static int
170{
171 boolKEY *arg1 = (boolKEY *) DatumGetPointer(x);
172 boolKEY *arg2 = (boolKEY *) DatumGetPointer(y);
173
174 /* for leaf items we expect lower == upper, so only compare lower */
175 return (int32) arg1->lower - (int32) arg2->lower;
176}
177
178Datum
180{
182
184 ssup->ssup_extra = NULL;
185
187}
Datum gbt_bool_compress(PG_FUNCTION_ARGS)
Definition: btree_bool.c:90
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:138
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:106
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:150
static int gbt_bool_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_bool.c:169
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
Datum gbt_bool_sortsupport(PG_FUNCTION_ARGS)
Definition: btree_bool.c:179
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:98
Datum gbt_bool_union(PG_FUNCTION_ARGS)
Definition: btree_bool.c:128
Datum gbt_bool_same(PG_FUNCTION_ARGS)
Definition: btree_bool.c:158
@ gbt_t_bool
Definition: btree_gist.h:35
GISTENTRY * gbt_num_compress(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_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define penalty_num(result, olower, oupper, nlower, nupper)
char GBT_NUMKEY
int32_t int32
Definition: c.h:535
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#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:171
int y
Definition: isn.c:76
int b
Definition: isn.c:74
int x
Definition: isn.c:75
int a
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1365
uint64_t Datum
Definition: postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
Datum key
Definition: gist.h:161
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87
bool lower
Definition: btree_bool.c:13
bool upper
Definition: btree_bool.c:14