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/sortsupport.h"
9
10typedef struct boolkey
11{
12 bool lower;
13 bool upper;
15
16/* GiST support functions */
25
26static bool
27gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
28{
29 return (*((const bool *) a) > *((const bool *) b));
30}
31static bool
32gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
33{
34 return (*((const bool *) a) >= *((const bool *) b));
35}
36static bool
37gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
38{
39 return (*((const bool *) a) == *((const bool *) b));
40}
41static bool
42gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
43{
44 return (*((const bool *) a) <= *((const bool *) b));
45}
46static bool
47gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
48{
49 return (*((const bool *) a) < *((const bool *) b));
50}
51
52static int
53gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
54{
55 boolKEY *ia = (boolKEY *) (((const Nsrt *) a)->t);
56 boolKEY *ib = (boolKEY *) (((const Nsrt *) b)->t);
57
58 if (ia->lower == ib->lower)
59 {
60 if (ia->upper == ib->upper)
61 return 0;
62
63 return (ia->upper > ib->upper) ? 1 : -1;
64 }
65
66 return (ia->lower > ib->lower) ? 1 : -1;
67}
68
69
70static const gbtree_ninfo tinfo =
71{
73 sizeof(bool),
74 2, /* sizeof(gbtreekey2) */
81};
82
83
84/**************************************************
85 * GiST support functions
86 **************************************************/
87
90{
92
94}
95
98{
100
102}
103
104Datum
106{
107 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
108 bool query = PG_GETARG_INT16(1);
110
111 /* Oid subtype = PG_GETARG_OID(3); */
112 bool *recheck = (bool *) PG_GETARG_POINTER(4);
113 boolKEY *kkk = (boolKEY *) DatumGetPointer(entry->key);
115
116 /* All cases served by this function are exact */
117 *recheck = false;
118
119 key.lower = (GBT_NUMKEY *) &kkk->lower;
120 key.upper = (GBT_NUMKEY *) &kkk->upper;
121
122 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
123 GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
124}
125
126Datum
128{
130 void *out = palloc(sizeof(boolKEY));
131
132 *(int *) PG_GETARG_POINTER(1) = sizeof(boolKEY);
133 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
134}
135
136Datum
138{
139 boolKEY *origentry = (boolKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
141 float *result = (float *) PG_GETARG_POINTER(2);
142
143 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
144
145 PG_RETURN_POINTER(result);
146}
147
148Datum
150{
153 &tinfo, fcinfo->flinfo));
154}
155
156Datum
158{
159 boolKEY *b1 = (boolKEY *) PG_GETARG_POINTER(0);
160 boolKEY *b2 = (boolKEY *) PG_GETARG_POINTER(1);
161 bool *result = (bool *) PG_GETARG_POINTER(2);
162
163 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
164 PG_RETURN_POINTER(result);
165}
166
167static int
169{
170 boolKEY *arg1 = (boolKEY *) DatumGetPointer(x);
171 boolKEY *arg2 = (boolKEY *) DatumGetPointer(y);
172
173 /* for leaf items we expect lower == upper, so only compare lower */
174 return (int32) arg1->lower - (int32) arg2->lower;
175}
176
177Datum
179{
181
183 ssup->ssup_extra = NULL;
184
186}
Datum gbt_bool_compress(PG_FUNCTION_ARGS)
Definition: btree_bool.c:89
static bool gbt_boolgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:27
Datum gbt_bool_penalty(PG_FUNCTION_ARGS)
Definition: btree_bool.c:137
static bool gbt_boollt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:47
Datum gbt_bool_consistent(PG_FUNCTION_ARGS)
Definition: btree_bool.c:105
static bool gbt_boolge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:32
static int gbt_boolkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:53
struct boolkey boolKEY
Datum gbt_bool_picksplit(PG_FUNCTION_ARGS)
Definition: btree_bool.c:149
static int gbt_bool_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_bool.c:168
static const gbtree_ninfo tinfo
Definition: btree_bool.c:70
PG_FUNCTION_INFO_V1(gbt_bool_compress)
static bool gbt_boolle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:42
Datum gbt_bool_sortsupport(PG_FUNCTION_ARGS)
Definition: btree_bool.c:178
static bool gbt_booleq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_bool.c:37
Datum gbt_bool_fetch(PG_FUNCTION_ARGS)
Definition: btree_bool.c:97
Datum gbt_bool_union(PG_FUNCTION_ARGS)
Definition: btree_bool.c:127
Datum gbt_bool_same(PG_FUNCTION_ARGS)
Definition: btree_bool.c:157
@ 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:498
#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:1945
uintptr_t Datum
Definition: postgres.h:69
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
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:12
bool upper
Definition: btree_bool.c:13