1
#include "btree_gist.h"
2
#include "btree_utils_num.h"
4
typedef struct int64key
13
PG_FUNCTION_INFO_V1(gbt_int8_compress);
14
PG_FUNCTION_INFO_V1(gbt_int8_union);
15
PG_FUNCTION_INFO_V1(gbt_int8_picksplit);
16
PG_FUNCTION_INFO_V1(gbt_int8_consistent);
17
PG_FUNCTION_INFO_V1(gbt_int8_penalty);
18
PG_FUNCTION_INFO_V1(gbt_int8_same);
20
Datum gbt_int8_compress(PG_FUNCTION_ARGS);
21
Datum gbt_int8_union(PG_FUNCTION_ARGS);
22
Datum gbt_int8_picksplit(PG_FUNCTION_ARGS);
23
Datum gbt_int8_consistent(PG_FUNCTION_ARGS);
24
Datum gbt_int8_penalty(PG_FUNCTION_ARGS);
25
Datum gbt_int8_same(PG_FUNCTION_ARGS);
29
gbt_int8gt(const void *a, const void *b)
31
return (*((int64 *) a) > *((int64 *) b));
34
gbt_int8ge(const void *a, const void *b)
36
return (*((int64 *) a) >= *((int64 *) b));
39
gbt_int8eq(const void *a, const void *b)
41
return (*((int64 *) a) == *((int64 *) b));
44
gbt_int8le(const void *a, const void *b)
46
return (*((int64 *) a) <= *((int64 *) b));
49
gbt_int8lt(const void *a, const void *b)
51
return (*((int64 *) a) < *((int64 *) b));
55
gbt_int8key_cmp(const void *a, const void *b)
58
if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
60
else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
67
static const gbtree_ninfo tinfo =
80
/**************************************************
82
**************************************************/
86
gbt_int8_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_int8_consistent(PG_FUNCTION_ARGS)
98
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
99
int64 query = PG_GETARG_INT64(1);
100
int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
102
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
104
key.lower = (GBT_NUMKEY *) & kkk->lower;
105
key.upper = (GBT_NUMKEY *) & kkk->upper;
108
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
114
gbt_int8_union(PG_FUNCTION_ARGS)
116
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
117
void *out = palloc(sizeof(int64KEY));
119
*(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
120
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
125
gbt_int8_penalty(PG_FUNCTION_ARGS)
127
int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
128
int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
129
float *result = (float *) PG_GETARG_POINTER(2);
134
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
139
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
140
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
143
PG_RETURN_POINTER(result);
148
gbt_int8_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_int8_same(PG_FUNCTION_ARGS)
160
int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0);
161
int64KEY *b2 = (int64KEY *) 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);