Only skip pages marked as clean in the visibility map, if the last 32
[PostgreSQL.git] / contrib / btree_gist / btree_float4.c
blobf58c9b6c2ea64da8eaf0aaef9b1cf4e68755cf6c
1 /*
2 * $PostgreSQL:$
3 */
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct float4key
9 float4 lower;
10 float4 upper;
11 } float4KEY;
14 ** float4 ops
16 PG_FUNCTION_INFO_V1(gbt_float4_compress);
17 PG_FUNCTION_INFO_V1(gbt_float4_union);
18 PG_FUNCTION_INFO_V1(gbt_float4_picksplit);
19 PG_FUNCTION_INFO_V1(gbt_float4_consistent);
20 PG_FUNCTION_INFO_V1(gbt_float4_penalty);
21 PG_FUNCTION_INFO_V1(gbt_float4_same);
23 Datum gbt_float4_compress(PG_FUNCTION_ARGS);
24 Datum gbt_float4_union(PG_FUNCTION_ARGS);
25 Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
26 Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
27 Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
28 Datum gbt_float4_same(PG_FUNCTION_ARGS);
30 static bool
31 gbt_float4gt(const void *a, const void *b)
33 return (*((float4 *) a) > *((float4 *) b));
35 static bool
36 gbt_float4ge(const void *a, const void *b)
38 return (*((float4 *) a) >= *((float4 *) b));
40 static bool
41 gbt_float4eq(const void *a, const void *b)
43 return (*((float4 *) a) == *((float4 *) b));
45 static bool
46 gbt_float4le(const void *a, const void *b)
48 return (*((float4 *) a) <= *((float4 *) b));
50 static bool
51 gbt_float4lt(const void *a, const void *b)
53 return (*((float4 *) a) < *((float4 *) b));
56 static int
57 gbt_float4key_cmp(const void *a, const void *b)
60 if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
61 return 1;
62 else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
63 return -1;
64 return 0;
69 static const gbtree_ninfo tinfo =
71 gbt_t_float4,
72 sizeof(float4),
73 gbt_float4gt,
74 gbt_float4ge,
75 gbt_float4eq,
76 gbt_float4le,
77 gbt_float4lt,
78 gbt_float4key_cmp
82 /**************************************************
83 * float4 ops
84 **************************************************/
87 Datum
88 gbt_float4_compress(PG_FUNCTION_ARGS)
90 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
91 GISTENTRY *retval = NULL;
93 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
97 Datum
98 gbt_float4_consistent(PG_FUNCTION_ARGS)
100 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
101 float4 query = PG_GETARG_FLOAT4(1);
102 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
103 /* Oid subtype = PG_GETARG_OID(3); */
104 bool *recheck = (bool *) PG_GETARG_POINTER(4);
105 float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
106 GBT_NUMKEY_R key;
108 /* All cases served by this function are exact */
109 *recheck = false;
111 key.lower = (GBT_NUMKEY *) & kkk->lower;
112 key.upper = (GBT_NUMKEY *) & kkk->upper;
114 PG_RETURN_BOOL(
115 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
120 Datum
121 gbt_float4_union(PG_FUNCTION_ARGS)
123 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
124 void *out = palloc(sizeof(float4KEY));
126 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
127 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
131 Datum
132 gbt_float4_penalty(PG_FUNCTION_ARGS)
134 float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
135 float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
136 float *result = (float *) PG_GETARG_POINTER(2);
138 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
140 PG_RETURN_POINTER(result);
144 Datum
145 gbt_float4_picksplit(PG_FUNCTION_ARGS)
147 PG_RETURN_POINTER(gbt_num_picksplit(
148 (GistEntryVector *) PG_GETARG_POINTER(0),
149 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
150 &tinfo
154 Datum
155 gbt_float4_same(PG_FUNCTION_ARGS)
157 float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
158 float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
159 bool *result = (bool *) PG_GETARG_POINTER(2);
161 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
162 PG_RETURN_POINTER(result);