Only skip pages marked as clean in the visibility map, if the last 32
[PostgreSQL.git] / contrib / btree_gist / btree_oid.c
blob7132a11a2b65d97917ea73c945ca293c9446a665
1 /*
2 * $PostgreSQL:$
3 */
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct
9 Oid lower;
10 Oid upper;
11 } oidKEY;
14 ** OID ops
16 PG_FUNCTION_INFO_V1(gbt_oid_compress);
17 PG_FUNCTION_INFO_V1(gbt_oid_union);
18 PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
19 PG_FUNCTION_INFO_V1(gbt_oid_consistent);
20 PG_FUNCTION_INFO_V1(gbt_oid_penalty);
21 PG_FUNCTION_INFO_V1(gbt_oid_same);
23 Datum gbt_oid_compress(PG_FUNCTION_ARGS);
24 Datum gbt_oid_union(PG_FUNCTION_ARGS);
25 Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
26 Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
27 Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
28 Datum gbt_oid_same(PG_FUNCTION_ARGS);
31 static bool
32 gbt_oidgt(const void *a, const void *b)
34 return (*((Oid *) a) > *((Oid *) b));
36 static bool
37 gbt_oidge(const void *a, const void *b)
39 return (*((Oid *) a) >= *((Oid *) b));
41 static bool
42 gbt_oideq(const void *a, const void *b)
44 return (*((Oid *) a) == *((Oid *) b));
46 static bool
47 gbt_oidle(const void *a, const void *b)
49 return (*((Oid *) a) <= *((Oid *) b));
51 static bool
52 gbt_oidlt(const void *a, const void *b)
54 return (*((Oid *) a) < *((Oid *) b));
57 static int
58 gbt_oidkey_cmp(const void *a, const void *b)
61 if (*(Oid *) &(((Nsrt *) a)->t[0]) > *(Oid *) &(((Nsrt *) b)->t[0]))
62 return 1;
63 else if (*(Oid *) &(((Nsrt *) a)->t[0]) < *(Oid *) &(((Nsrt *) b)->t[0]))
64 return -1;
65 return 0;
70 static const gbtree_ninfo tinfo =
72 gbt_t_oid,
73 sizeof(Oid),
74 gbt_oidgt,
75 gbt_oidge,
76 gbt_oideq,
77 gbt_oidle,
78 gbt_oidlt,
79 gbt_oidkey_cmp
83 /**************************************************
84 * Oid ops
85 **************************************************/
88 Datum
89 gbt_oid_compress(PG_FUNCTION_ARGS)
91 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
92 GISTENTRY *retval = NULL;
94 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
98 Datum
99 gbt_oid_consistent(PG_FUNCTION_ARGS)
101 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
102 Oid query = PG_GETARG_OID(1);
103 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
104 /* Oid subtype = PG_GETARG_OID(3); */
105 bool *recheck = (bool *) PG_GETARG_POINTER(4);
106 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
107 GBT_NUMKEY_R key;
109 /* All cases served by this function are exact */
110 *recheck = false;
112 key.lower = (GBT_NUMKEY *) & kkk->lower;
113 key.upper = (GBT_NUMKEY *) & kkk->upper;
115 PG_RETURN_BOOL(
116 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
121 Datum
122 gbt_oid_union(PG_FUNCTION_ARGS)
124 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
125 void *out = palloc(sizeof(oidKEY));
127 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
128 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
132 Datum
133 gbt_oid_penalty(PG_FUNCTION_ARGS)
135 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
136 oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
137 float *result = (float *) PG_GETARG_POINTER(2);
139 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
141 PG_RETURN_POINTER(result);
144 Datum
145 gbt_oid_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_oid_same(PG_FUNCTION_ARGS)
157 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
158 oidKEY *b2 = (oidKEY *) 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);