1
#include "btree_gist.h"
2
#include "btree_utils_num.h"
4
typedef struct int32key
13
PG_FUNCTION_INFO_V1(gbt_int4_compress);
14
PG_FUNCTION_INFO_V1(gbt_int4_union);
15
PG_FUNCTION_INFO_V1(gbt_int4_picksplit);
16
PG_FUNCTION_INFO_V1(gbt_int4_consistent);
17
PG_FUNCTION_INFO_V1(gbt_int4_penalty);
18
PG_FUNCTION_INFO_V1(gbt_int4_same);
20
Datum gbt_int4_compress(PG_FUNCTION_ARGS);
21
Datum gbt_int4_union(PG_FUNCTION_ARGS);
22
Datum gbt_int4_picksplit(PG_FUNCTION_ARGS);
23
Datum gbt_int4_consistent(PG_FUNCTION_ARGS);
24
Datum gbt_int4_penalty(PG_FUNCTION_ARGS);
25
Datum gbt_int4_same(PG_FUNCTION_ARGS);
29
gbt_int4gt(const void *a, const void *b)
31
return (*((int32 *) a) > *((int32 *) b));
34
gbt_int4ge(const void *a, const void *b)
36
return (*((int32 *) a) >= *((int32 *) b));
39
gbt_int4eq(const void *a, const void *b)
41
return (*((int32 *) a) == *((int32 *) b));
44
gbt_int4le(const void *a, const void *b)
46
return (*((int32 *) a) <= *((int32 *) b));
49
gbt_int4lt(const void *a, const void *b)
51
return (*((int32 *) a) < *((int32 *) b));
55
gbt_int4key_cmp(const void *a, const void *b)
58
if (*(int32 *) &(((Nsrt *) a)->t[0]) > *(int32 *) &(((Nsrt *) b)->t[0]))
60
else if (*(int32 *) &(((Nsrt *) a)->t[0]) < *(int32 *) &(((Nsrt *) b)->t[0]))
67
static const gbtree_ninfo tinfo =
80
/**************************************************
82
**************************************************/
86
gbt_int4_compress(PG_FUNCTION_ARGS)
88
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
89
GISTENTRY *retval = NULL;
91
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
96
gbt_int4_consistent(PG_FUNCTION_ARGS)
99
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
100
int32 query = PG_GETARG_INT32(1);
101
int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key);
103
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
105
key.lower = (GBT_NUMKEY *) & kkk->lower;
106
key.upper = (GBT_NUMKEY *) & kkk->upper;
109
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
115
gbt_int4_union(PG_FUNCTION_ARGS)
117
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
118
void *out = palloc(sizeof(int32KEY));
120
*(int *) PG_GETARG_POINTER(1) = sizeof(int32KEY);
121
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
126
gbt_int4_penalty(PG_FUNCTION_ARGS)
128
int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
129
int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
130
float *result = (float *) PG_GETARG_POINTER(2);
135
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
140
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
141
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
144
PG_RETURN_POINTER(result);
148
gbt_int4_picksplit(PG_FUNCTION_ARGS)
150
PG_RETURN_POINTER(gbt_num_picksplit(
151
(GistEntryVector *) PG_GETARG_POINTER(0),
152
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
158
gbt_int4_same(PG_FUNCTION_ARGS)
160
int32KEY *b1 = (int32KEY *) PG_GETARG_POINTER(0);
161
int32KEY *b2 = (int32KEY *) 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);