4 #include "btree_gist.h"
5 #include "btree_utils_var.h"
6 #include "utils/builtins.h"
12 PG_FUNCTION_INFO_V1(gbt_bytea_compress
);
13 PG_FUNCTION_INFO_V1(gbt_bytea_union
);
14 PG_FUNCTION_INFO_V1(gbt_bytea_picksplit
);
15 PG_FUNCTION_INFO_V1(gbt_bytea_consistent
);
16 PG_FUNCTION_INFO_V1(gbt_bytea_penalty
);
17 PG_FUNCTION_INFO_V1(gbt_bytea_same
);
19 Datum
gbt_bytea_compress(PG_FUNCTION_ARGS
);
20 Datum
gbt_bytea_union(PG_FUNCTION_ARGS
);
21 Datum
gbt_bytea_picksplit(PG_FUNCTION_ARGS
);
22 Datum
gbt_bytea_consistent(PG_FUNCTION_ARGS
);
23 Datum
gbt_bytea_penalty(PG_FUNCTION_ARGS
);
24 Datum
gbt_bytea_same(PG_FUNCTION_ARGS
);
27 /* define for comparison */
30 gbt_byteagt(const void *a
, const void *b
)
32 return (DatumGetBool(DirectFunctionCall2(byteagt
, PointerGetDatum(a
), PointerGetDatum(b
))));
36 gbt_byteage(const void *a
, const void *b
)
38 return (DatumGetBool(DirectFunctionCall2(byteage
, PointerGetDatum(a
), PointerGetDatum(b
))));
42 gbt_byteaeq(const void *a
, const void *b
)
44 return (DatumGetBool(DirectFunctionCall2(byteaeq
, PointerGetDatum(a
), PointerGetDatum(b
))));
48 gbt_byteale(const void *a
, const void *b
)
50 return (DatumGetBool(DirectFunctionCall2(byteale
, PointerGetDatum(a
), PointerGetDatum(b
))));
54 gbt_bytealt(const void *a
, const void *b
)
56 return (DatumGetBool(DirectFunctionCall2(bytealt
, PointerGetDatum(a
), PointerGetDatum(b
))));
61 gbt_byteacmp(const bytea
*a
, const bytea
*b
)
64 (DatumGetInt32(DirectFunctionCall2(byteacmp
, PointerGetDatum(a
), PointerGetDatum(b
))));
68 static const gbtree_vinfo tinfo
=
83 /**************************************************
85 **************************************************/
89 gbt_bytea_compress(PG_FUNCTION_ARGS
)
91 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
93 PG_RETURN_POINTER(gbt_var_compress(entry
, &tinfo
));
99 gbt_bytea_consistent(PG_FUNCTION_ARGS
)
101 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
102 void *query
= (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
103 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
104 /* Oid subtype = PG_GETARG_OID(3); */
105 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
107 GBT_VARKEY
*key
= (GBT_VARKEY
*) DatumGetPointer(entry
->key
);
108 GBT_VARKEY_R r
= gbt_var_key_readable(key
);
110 /* All cases served by this function are exact */
113 retval
= gbt_var_consistent(&r
, query
, &strategy
, GIST_LEAF(entry
), &tinfo
);
114 PG_RETURN_BOOL(retval
);
120 gbt_bytea_union(PG_FUNCTION_ARGS
)
122 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
123 int32
*size
= (int *) PG_GETARG_POINTER(1);
125 PG_RETURN_POINTER(gbt_var_union(entryvec
, size
, &tinfo
));
130 gbt_bytea_picksplit(PG_FUNCTION_ARGS
)
132 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
133 GIST_SPLITVEC
*v
= (GIST_SPLITVEC
*) PG_GETARG_POINTER(1);
135 gbt_var_picksplit(entryvec
, v
, &tinfo
);
136 PG_RETURN_POINTER(v
);
140 gbt_bytea_same(PG_FUNCTION_ARGS
)
142 Datum d1
= PG_GETARG_DATUM(0);
143 Datum d2
= PG_GETARG_DATUM(1);
144 bool *result
= (bool *) PG_GETARG_POINTER(2);
146 PG_RETURN_POINTER(gbt_var_same(result
, d1
, d2
, &tinfo
));
151 gbt_bytea_penalty(PG_FUNCTION_ARGS
)
153 GISTENTRY
*o
= (GISTENTRY
*) PG_GETARG_POINTER(0);
154 GISTENTRY
*n
= (GISTENTRY
*) PG_GETARG_POINTER(1);
155 float *result
= (float *) PG_GETARG_POINTER(2);
157 PG_RETURN_POINTER(gbt_var_penalty(result
, o
, n
, &tinfo
));