Only skip pages marked as clean in the visibility map, if the last 32
[PostgreSQL.git] / contrib / btree_gist / btree_int2.c
blob5a6fcaf5f95955708432fe510a3d0f27aaa631d2
1 /*
2 * $PostgreSQL:$
3 */
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct int16key
9 int16 lower;
10 int16 upper;
11 } int16KEY;
14 ** int16 ops
16 PG_FUNCTION_INFO_V1(gbt_int2_compress);
17 PG_FUNCTION_INFO_V1(gbt_int2_union);
18 PG_FUNCTION_INFO_V1(gbt_int2_picksplit);
19 PG_FUNCTION_INFO_V1(gbt_int2_consistent);
20 PG_FUNCTION_INFO_V1(gbt_int2_penalty);
21 PG_FUNCTION_INFO_V1(gbt_int2_same);
23 Datum gbt_int2_compress(PG_FUNCTION_ARGS);
24 Datum gbt_int2_union(PG_FUNCTION_ARGS);
25 Datum gbt_int2_picksplit(PG_FUNCTION_ARGS);
26 Datum gbt_int2_consistent(PG_FUNCTION_ARGS);
27 Datum gbt_int2_penalty(PG_FUNCTION_ARGS);
28 Datum gbt_int2_same(PG_FUNCTION_ARGS);
30 static bool
31 gbt_int2gt(const void *a, const void *b)
33 return (*((int16 *) a) > *((int16 *) b));
35 static bool
36 gbt_int2ge(const void *a, const void *b)
38 return (*((int16 *) a) >= *((int16 *) b));
40 static bool
41 gbt_int2eq(const void *a, const void *b)
43 return (*((int16 *) a) == *((int16 *) b));
45 static bool
46 gbt_int2le(const void *a, const void *b)
48 return (*((int16 *) a) <= *((int16 *) b));
50 static bool
51 gbt_int2lt(const void *a, const void *b)
53 return (*((int16 *) a) < *((int16 *) b));
56 static int
57 gbt_int2key_cmp(const void *a, const void *b)
60 if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
61 return 1;
62 else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
63 return -1;
64 return 0;
69 static const gbtree_ninfo tinfo =
71 gbt_t_int2,
72 sizeof(int16),
73 gbt_int2gt,
74 gbt_int2ge,
75 gbt_int2eq,
76 gbt_int2le,
77 gbt_int2lt,
78 gbt_int2key_cmp
86 /**************************************************
87 * int16 ops
88 **************************************************/
91 Datum
92 gbt_int2_compress(PG_FUNCTION_ARGS)
94 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
95 GISTENTRY *retval = NULL;
97 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
101 Datum
102 gbt_int2_consistent(PG_FUNCTION_ARGS)
104 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
105 int16 query = PG_GETARG_INT16(1);
106 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
107 /* Oid subtype = PG_GETARG_OID(3); */
108 bool *recheck = (bool *) PG_GETARG_POINTER(4);
109 int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key);
110 GBT_NUMKEY_R key;
112 /* All cases served by this function are exact */
113 *recheck = false;
115 key.lower = (GBT_NUMKEY *) & kkk->lower;
116 key.upper = (GBT_NUMKEY *) & kkk->upper;
118 PG_RETURN_BOOL(
119 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
124 Datum
125 gbt_int2_union(PG_FUNCTION_ARGS)
127 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
128 void *out = palloc(sizeof(int16KEY));
130 *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
131 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
135 Datum
136 gbt_int2_penalty(PG_FUNCTION_ARGS)
138 int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
139 int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
140 float *result = (float *) PG_GETARG_POINTER(2);
142 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
144 PG_RETURN_POINTER(result);
147 Datum
148 gbt_int2_picksplit(PG_FUNCTION_ARGS)
150 PG_RETURN_POINTER(gbt_num_picksplit(
151 (GistEntryVector *) PG_GETARG_POINTER(0),
152 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
153 &tinfo
157 Datum
158 gbt_int2_same(PG_FUNCTION_ARGS)
160 int16KEY *b1 = (int16KEY *) PG_GETARG_POINTER(0);
161 int16KEY *b2 = (int16KEY *) PG_GETARG_POINTER(1);
162 bool *result = (bool *) PG_GETARG_POINTER(2);
164 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
165 PG_RETURN_POINTER(result);