2 * contrib/btree_gist/btree_enum.c
6 #include "btree_gist.h"
7 #include "btree_utils_num.h"
9 #include "utils/fmgrprotos.h"
11 /* enums are really Oids, so we just use the same structure */
22 PG_FUNCTION_INFO_V1(gbt_enum_compress
);
23 PG_FUNCTION_INFO_V1(gbt_enum_fetch
);
24 PG_FUNCTION_INFO_V1(gbt_enum_union
);
25 PG_FUNCTION_INFO_V1(gbt_enum_picksplit
);
26 PG_FUNCTION_INFO_V1(gbt_enum_consistent
);
27 PG_FUNCTION_INFO_V1(gbt_enum_penalty
);
28 PG_FUNCTION_INFO_V1(gbt_enum_same
);
32 gbt_enumgt(const void *a
, const void *b
, FmgrInfo
*flinfo
)
34 return DatumGetBool(CallerFInfoFunctionCall2(enum_gt
, flinfo
, InvalidOid
,
35 ObjectIdGetDatum(*((const Oid
*) a
)),
36 ObjectIdGetDatum(*((const Oid
*) b
))));
39 gbt_enumge(const void *a
, const void *b
, FmgrInfo
*flinfo
)
41 return DatumGetBool(CallerFInfoFunctionCall2(enum_ge
, flinfo
, InvalidOid
,
42 ObjectIdGetDatum(*((const Oid
*) a
)),
43 ObjectIdGetDatum(*((const Oid
*) b
))));
46 gbt_enumeq(const void *a
, const void *b
, FmgrInfo
*flinfo
)
48 return (*((const Oid
*) a
) == *((const Oid
*) b
));
51 gbt_enumle(const void *a
, const void *b
, FmgrInfo
*flinfo
)
53 return DatumGetBool(CallerFInfoFunctionCall2(enum_le
, flinfo
, InvalidOid
,
54 ObjectIdGetDatum(*((const Oid
*) a
)),
55 ObjectIdGetDatum(*((const Oid
*) b
))));
58 gbt_enumlt(const void *a
, const void *b
, FmgrInfo
*flinfo
)
60 return DatumGetBool(CallerFInfoFunctionCall2(enum_lt
, flinfo
, InvalidOid
,
61 ObjectIdGetDatum(*((const Oid
*) a
)),
62 ObjectIdGetDatum(*((const Oid
*) b
))));
66 gbt_enumkey_cmp(const void *a
, const void *b
, FmgrInfo
*flinfo
)
68 oidKEY
*ia
= (oidKEY
*) (((const Nsrt
*) a
)->t
);
69 oidKEY
*ib
= (oidKEY
*) (((const Nsrt
*) b
)->t
);
71 if (ia
->lower
== ib
->lower
)
73 if (ia
->upper
== ib
->upper
)
76 return DatumGetInt32(CallerFInfoFunctionCall2(enum_cmp
, flinfo
, InvalidOid
,
77 ObjectIdGetDatum(ia
->upper
),
78 ObjectIdGetDatum(ib
->upper
)));
81 return DatumGetInt32(CallerFInfoFunctionCall2(enum_cmp
, flinfo
, InvalidOid
,
82 ObjectIdGetDatum(ia
->lower
),
83 ObjectIdGetDatum(ib
->lower
)));
86 static const gbtree_ninfo tinfo
=
90 8, /* sizeof(gbtreekey8) */
97 NULL
/* no KNN support at least for now */
101 /**************************************************
103 **************************************************/
107 gbt_enum_compress(PG_FUNCTION_ARGS
)
109 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
111 PG_RETURN_POINTER(gbt_num_compress(entry
, &tinfo
));
115 gbt_enum_fetch(PG_FUNCTION_ARGS
)
117 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
119 PG_RETURN_POINTER(gbt_num_fetch(entry
, &tinfo
));
123 gbt_enum_consistent(PG_FUNCTION_ARGS
)
125 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
126 Oid query
= PG_GETARG_OID(1);
127 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
129 /* Oid subtype = PG_GETARG_OID(3); */
130 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
131 oidKEY
*kkk
= (oidKEY
*) DatumGetPointer(entry
->key
);
134 /* All cases served by this function are exact */
137 key
.lower
= (GBT_NUMKEY
*) &kkk
->lower
;
138 key
.upper
= (GBT_NUMKEY
*) &kkk
->upper
;
140 PG_RETURN_BOOL(gbt_num_consistent(&key
, &query
, &strategy
,
141 GIST_LEAF(entry
), &tinfo
,
146 gbt_enum_union(PG_FUNCTION_ARGS
)
148 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
149 void *out
= palloc(sizeof(oidKEY
));
151 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY
);
152 PG_RETURN_POINTER(gbt_num_union(out
, entryvec
, &tinfo
, fcinfo
->flinfo
));
157 gbt_enum_penalty(PG_FUNCTION_ARGS
)
159 oidKEY
*origentry
= (oidKEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(0))->key
);
160 oidKEY
*newentry
= (oidKEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(1))->key
);
161 float *result
= (float *) PG_GETARG_POINTER(2);
163 penalty_num(result
, origentry
->lower
, origentry
->upper
, newentry
->lower
, newentry
->upper
);
165 PG_RETURN_POINTER(result
);
169 gbt_enum_picksplit(PG_FUNCTION_ARGS
)
171 PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector
*) PG_GETARG_POINTER(0),
172 (GIST_SPLITVEC
*) PG_GETARG_POINTER(1),
173 &tinfo
, fcinfo
->flinfo
));
177 gbt_enum_same(PG_FUNCTION_ARGS
)
179 oidKEY
*b1
= (oidKEY
*) PG_GETARG_POINTER(0);
180 oidKEY
*b2
= (oidKEY
*) PG_GETARG_POINTER(1);
181 bool *result
= (bool *) PG_GETARG_POINTER(2);
183 *result
= gbt_num_same((void *) b1
, (void *) b2
, &tinfo
, fcinfo
->flinfo
);
184 PG_RETURN_POINTER(result
);